From d9d7099da639d89de15f6792939f4e01c14bf292 Mon Sep 17 00:00:00 2001 From: chris2tof Date: Sat, 12 Nov 2011 17:54:45 +0800 Subject: [PATCH] Fix bug: users can now be saved --- app/helpers/panel/user_helper.rb | 12 ++++++++++++ app/models/user/attribute_model.rb | 2 +- app/models/user/user_attribute.rb | 2 +- app/views/panel/users/_show_user_attribute.html.erb | 4 ++-- app/views/panel/users/_user_attribute.html.erb | 12 ++++++------ app/views/panel/users/show.html.erb | 8 ++------ lib/central_server_exchange_app.rb | 4 ++-- 7 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 app/helpers/panel/user_helper.rb diff --git a/app/helpers/panel/user_helper.rb b/app/helpers/panel/user_helper.rb new file mode 100644 index 00000000..a0fd1366 --- /dev/null +++ b/app/helpers/panel/user_helper.rb @@ -0,0 +1,12 @@ +module Panel::UserHelper + + def show_user_attribute(object, key, locale = '') + attribute = object.attribute_values.detect {|av| av.key.to_s.eql?(key.to_s) || av[locale.to_s].eql?(locale.to_s) } + if locale.to_s.blank? + attribute['key'] + else + attribute[locale.to_s] + end + end + +end diff --git a/app/models/user/attribute_model.rb b/app/models/user/attribute_model.rb index 5cc11aa2..0bd5b3ca 100644 --- a/app/models/user/attribute_model.rb +++ b/app/models/user/attribute_model.rb @@ -11,7 +11,7 @@ class AttributeModel field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - embedded_in :user_attribute_model, :inverse_of => :attribute_models + embedded_in :user_attribute_model validates_uniqueness_of :key # Destroy the i18n_variable diff --git a/app/models/user/user_attribute.rb b/app/models/user/user_attribute.rb index 002ec4be..ddf04cc1 100644 --- a/app/models/user/user_attribute.rb +++ b/app/models/user/user_attribute.rb @@ -7,7 +7,7 @@ class UserAttribute has_many :attribute_values # Update or create the attribute_value records - def attributes=(*args) + def attribute_values=(*args) args[0].each do |value| if value[:id].blank? attribute_values.build(value) diff --git a/app/views/panel/users/_show_user_attribute.html.erb b/app/views/panel/users/_show_user_attribute.html.erb index 261fab9a..2531f29a 100644 --- a/app/views/panel/users/_show_user_attribute.html.erb +++ b/app/views/panel/users/_show_user_attribute.html.erb @@ -6,9 +6,9 @@ <%= attr.i18n_variable[I18n.locale] %> <% if attr["locale"] && attr["markup"] == 'text_field' %> - <%= show_user_attribute["#{attr.key}_#{I18n.locale}"] rescue nil %> + <%= show_user_attribute(object, attr.key, I18n.locale) %> <% else %> - <%= show_user_attribute["#{attr.key}"] rescue nil %> + <%= show_user_attribute(object, attr.key) %> <% end %> diff --git a/app/views/panel/users/_user_attribute.html.erb b/app/views/panel/users/_user_attribute.html.erb index 7eeb9b15..f9e4fd76 100644 --- a/app/views/panel/users/_user_attribute.html.erb +++ b/app/views/panel/users/_user_attribute.html.erb @@ -14,23 +14,23 @@ <% ua.get_enabled_attribute_models.each do |attr| %> <% value = user_attribute.attribute_values.detect{|v| v.key == attr.key } %> - <%= hidden_field_tag "user[user_#{type}s][][attributes][][id]", value.id rescue nil %> - <%= hidden_field_tag "user[user_#{type}s][][attributes][][key]", attr.key %> + <%= hidden_field_tag "user[user_#{type}s][][attribute_values][][id]", value.id rescue nil %> + <%= hidden_field_tag "user[user_#{type}s][][attribute_values][][key]", attr.key %> <%= attr.i18n_variable[I18n.locale] %> <% if attr["locale"] && attr["markup"] == 'text_field' %> - <%= hidden_field_tag "user[user_#{type}s][][attributes][][non_locale]", nil %> + <%= hidden_field_tag "user[user_#{type}s][][attribute_values][][non_locale]", nil %> <% @site_valid_locales.each do |locale| %> - <%= text_field_tag "user[user_#{type}s][][attributes][][#{locale}]", (value[locale] rescue nil) %> + <%= text_field_tag "user[user_#{type}s][][attribute_values][][#{locale}]", (value[locale] rescue nil) %> <% end -%> <% else %> > <% if attr["markup"] == "text_field" %> - <%= text_field_tag "user[user_#{type}s][][attributes][][non_locale]", (value['non_locale'] rescue nil) %> + <%= text_field_tag "user[user_#{type}s][][attribute_values][][non_locale]", (value['non_locale'] rescue nil) %> <% elsif attr["markup"] == "select" %> - <%= select_tag "user[user_#{type}s][][attributes][][non_locale]", options_for_select(attr["options"], value['non_locale']) %> + <%= select_tag "user[user_#{type}s][][attribute_values][][non_locale]", options_for_select(attr["options"], value['non_locale']) %> <% end -%> <% end -%> diff --git a/app/views/panel/users/show.html.erb b/app/views/panel/users/show.html.erb index ec6d40a3..3a82861d 100644 --- a/app/views/panel/users/show.html.erb +++ b/app/views/panel/users/show.html.erb @@ -14,9 +14,7 @@
<%= t('panel.infos') %> <% @user_info_models.each do |am| %> - <%= render :partial => 'show_user_attribute', - :object => @user.get_info_from_model_key(am.key), - :locals => {:am => am} %> + <%= render :partial => 'show_user_attribute', :locals => {:am => am, :object => @user.get_info_from_model_key(am.key)} %> <% end -%>
<% end %> @@ -25,9 +23,7 @@
<%= t('panel.roles') %> <% @user.get_active_role_models.each do |am| %> - <%= render :partial => 'show_user_attribute', - :object => @user.get_role_from_model_key(am.key), - :locals => {:am => am} %> + <%= render :partial => 'show_user_attribute', :locals => {:am => am, :object => @user.get_role_from_model_key(am.key)} %> <% end -%>
<% end %> diff --git a/lib/central_server_exchange_app.rb b/lib/central_server_exchange_app.rb index 5a650c1c..6cb84b4d 100644 --- a/lib/central_server_exchange_app.rb +++ b/lib/central_server_exchange_app.rb @@ -31,8 +31,8 @@ class CentralServerExchangeApp < Sinatra::Base post '/purchase/design' do begin private_key = OpenSSL::PKey::RSA.new(@site.private_key) - design = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase'])) - design.save + p_design = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase'])) + p_design.save body 'true' rescue body 'false'