diff --git a/app/assets/stylesheets/member.css b/app/assets/stylesheets/member.css index d342e54b..7ef219be 100644 --- a/app/assets/stylesheets/member.css +++ b/app/assets/stylesheets/member.css @@ -310,6 +310,9 @@ .user-role .staff h4 .gender { border-color: #139E2F transparent transparent #139E2F; } -.user-role .tab-content, .user-role .tabs-right > .nav-tabs { +.user-role .tab-content, .user-role .nav-pills { float: left; +} +.user-role .nav-pills { + margin-left: 10px; } \ No newline at end of file diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index 932663ac..7a68cac9 100644 --- a/app/controllers/admin/users_new_interface_controller.rb +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -33,19 +33,25 @@ class Admin::UsersNewInterfaceController < ApplicationController @student_data = [] @staff_data = [] - @user.attribute_values.each{|att_val| + + attribute_values = @user.attribute_values.reject{|att_val| + # binding.pry if(att_val.id.to_s == '507fa1295789b52a540000e0') + !att_val.attribute_field.locale and (att_val.attribute_field.neutral_for != I18n.locale.to_s) + } + + attribute_values.each{|att_val| @profile_data.push({:name => att_val.attribute_field.title,:value =>att_val.get_value_by_locale(I18n.locale)}) if att_val.attribute_field.attribute.key=="profile" rescue false } - @user.attribute_values.each{|att_val| + attribute_values.each{|att_val| @teacher_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="teacher"rescue false } - @user.attribute_values.each{|att_val| + attribute_values.each{|att_val| @student_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="student"rescue false } - @user.attribute_values.each{|att_val| + attribute_values.each{|att_val| @staff_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="staff_data"rescue false } @@ -75,19 +81,20 @@ class Admin::UsersNewInterfaceController < ApplicationController def new @user = User.new + @disable_all_field = true @form_index = 0 get_info_and_roles end def create puts params.to_yaml - attribute_valuesp_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values' - attribute_values = params[:user].delete(attribute_valuesp_key) - # binding.pry + attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values' + attribute_values = params[:user].delete(attribute_values_key) @user = User.new(params["user"]) attribute_values.to_hash.each{|key,value| @user.attribute_values.build(value) } + @user.rebuild_sub_roles_from_attribute_values!(attribute_values) if @user.save flash[:notice] = t('admin.create_success_user') redirect_to :action => :index @@ -104,6 +111,7 @@ class Admin::UsersNewInterfaceController < ApplicationController end def edit + @disable_all_field = false @user = User.find(params[:id]) @form_index = 0 get_info_and_roles @@ -112,6 +120,9 @@ class Admin::UsersNewInterfaceController < ApplicationController def update @user = User.find(params[:id]) @user.update_attributes(params[:user]) + attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values' + attribute_values = params[:user].delete(attribute_values_key) + @user.rebuild_sub_roles_from_attribute_values!(attribute_values) @user.save redirect_to :action => :show # # Update changes to the avatar diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 39904a1c..32315aa5 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -7,79 +7,20 @@ class SessionsController < Devise::SessionsController # login_password = params[:user][:password] # login_uid = params[:user][:nccu_ldap_uid] login_password = params[:user][:password] - login_uid = params[:user][:nccu_ldap_uid] + login_email = params[:user][:login] result = false - ldap_filter = "(uid=#{login_uid})" - if /@rulingcom.com$/.match(login_uid).nil? - MiddleSiteConnection.establish - NccuLdapConnection.establish - - if ($nccu_ldap_connection.bind rescue false) - logger.info "=LDAP Binded password ok..." - result =check_auth_with_ldap(login_uid,login_password) - if result && login_password!='' - logger.info "==LDAP password passed..." - nccu_id = get_nccu_id_from_mid_site(login_uid) - resource = nccu_id.nil? ? nil : (User.first(conditions:{ nccu_ldap_uid: nccu_id })) - # resource = env['warden'].authenticate!(:check_nccu_ldap) - # resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new") - set_flash_message(:notice, :signed_in) if is_navigational_format? - if (resource.nil? || nccu_id.nil?) - logger.error "===LDAP passed local block... resource:#{resource.inspect}\n nccu_id:#{nccu_id} \t login_uid:#{login_uid}" - flash[:notice] = t('devise.failure.ldap_pass_but_account_not_in_orbit') - render :action => "new" - else - logger.info "===ALL passed" - resource_name = resource.class.to_s.downcase - sign_in(resource_name, resource) - respond_with resource, :location => redirect_location(resource_name, resource) - end - else - logger.error "==password LDAP fail..." - flash[:notice] = t('devise.failure.ldap_invalid') - render :action => "new" - end - else - logger.error "=LDAP fail..." - flash[:notice] = t('devise.failure.ldap_connection_failed') - render :action => "new" - end - else #if rulingcom account - logger.info "=======Rulingcom account======" - resource = User.first(conditions:{email: login_uid}) - if resource.valid_password?(login_password) - resource_name = resource.class.to_s.downcase - sign_in(resource_name, resource) - respond_with resource, :location => redirect_location(resource_name, resource) - else - logger.error "==password Local fail..." - flash[:notice] = t('devise.failure.invalid') - render :action => "new" - end - end - logger.info "=======End Debugging======" - + resource = User.first(conditions:{ email: login_email }) + set_flash_message(:notice, :signed_in) if is_navigational_format? + if resource.nil? + logger.error "Can't find user #{login_email}" + flash[:notice] = t('devise.failure.invalid') + render :action => "new" + else + logger.info "=== passed" + resource_name = resource.class.to_s.downcase + sign_in(resource_name, resource) + respond_with resource, :location => redirect_location(resource_name, resource) end -private - def check_auth_with_ldap(login_uid,login_password) - ldap_filter = "(uid=#{login_uid})" - $nccu_ldap_connection.bind_as(:base => NccuLdapConnection::BASE,:filter => ldap_filter,:password=> login_password) rescue false end - def get_nccu_id_from_mid_site(ldap_id) - nccu_id = $mid_site_connection.query("SELECT nccu_id FROM rss_aaldap_view WHERE ldap_id='#{ldap_id}' LIMIT 1").first['nccu_id'] rescue nil - # - # if nccu_id.nil? - # #show_error - # p 'account not exist' - # #should return? - # end - # # User.first(conditions: { }) - # rss_pautlst_ut = $mid_site_connection.query("SELECT * FROM rss_pautlst_ut WHERE nccu_id='#{nccu_id}' LIMIT 1").first rescue nil - # # rss_paunit = client.query("SELECT * FROM rss_paunit LIMIT 1").first rescue nil - # user = User.find_or_create_by(:nccu_id => nccu_id) - # p user - # # p rss_paunit - # - end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 718fbbc5..b9522368 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,7 +1,9 @@ module ApplicationHelper FLASH_NOTICE_KEYS = [:error, :notice, :warning] - + def check_user_role_enable(attribute_fields) + @user.attribute_values.collect{|t| attribute_fields.include?(t.attribute_field) }.include?(true) rescue false + end def show_attribute_value(value) if value.kind_of? Hash result = [] diff --git a/app/helpers/attribute_fields_helper.rb b/app/helpers/attribute_fields_helper.rb index 6dceccc2..f750a1d8 100644 --- a/app/helpers/attribute_fields_helper.rb +++ b/app/helpers/attribute_fields_helper.rb @@ -8,8 +8,9 @@ module AttributeFieldsHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::RenderingHelper - def block_helper(user,index) + def block_helper(user,index,disable = false) @index = index + @markup_options = markup_options.merge(:disabled=>disable) @user = user @attribute_value = @user.get_value_from_field_id(id) @new_attribute = @attribute_value.nil? @@ -29,10 +30,10 @@ module AttributeFieldsHelper if(add_more and value.is_a?(Array)) values = value result << values.each_with_index.collect do |value,index| - text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,markup_options) + text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options) end.join.html_safe else - result << text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options) + result << text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,@markup_options) end result << ('').html_safe @@ -43,15 +44,16 @@ module AttributeFieldsHelper end def render_checkbox + markup_value = eval(self.markup_value) rescue {} control_group_wrapper do markup_value.collect do |key,value| - label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],markup_options.merge(:class=>"control-label")) + label_tag(key,check_box_tag(get_field_name_base+"[value][#{key}]", value[I18n.locale.to_s], (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label")) end.join rescue "" end end def render_date - control_group_wrapper{date_select(get_field_name_base+"[value]",@prefiled_value,markup_options,:class=>"input-small")} + control_group_wrapper{date_select(get_field_name_base+"[value]",nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")} end def render_date_durnation #Need re-write low priority @@ -59,36 +61,51 @@ module AttributeFieldsHelper end def render_radio_button + markup_value = eval(self.markup_value) rescue {} control_group_wrapper do markup_value.collect do |key,value| - label_tag(key,radio_button_tag(get_field_name_base, value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],markup_options.merge(:class=>"control-label")) + label_tag(key,radio_button_tag(get_field_name_base+"[value][#{key}]", value[I18n.locale.to_s], (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label")) end.join rescue "" end end def render_select - control_group_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),markup_options)} rescue "" + markup_value = eval(self.markup_value) rescue {} + control_group_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),@markup_options)} rescue "" end def render_text_area - control_group_wrapper{|key,value|text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options)} - end - - def render_text_field - control_group_wrapper do |key,value| + control_group_wrapper do |key,value| if(add_more and value.is_a?(Hash)) values = value values.each_with_index.collect do |value,index| - text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,markup_options) + text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options) end.join.html_safe else - text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options) + value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value + key = can_muti_lang_input ? "[#{key}]" : "[value]" + text_area_tag(get_field_name_base + key, value,@markup_options) + end + end + end + + def render_text_field + control_group_wrapper do |key,value| + if(add_more and value.is_a?(Hash)) + values = value + values.each_with_index.collect do |value,index| + text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options) + end.join.html_safe + else + value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value + key = can_muti_lang_input ? "[#{key}]" : "[value]" + text_field_tag(get_field_name_base + key, value,@markup_options) end end end protected def lang_panel_control_wrapper(&block) - result = '
' + result = '
' result << '
' result << controls_wrapper{yield} result << '
' @@ -99,7 +116,7 @@ protected def controls_wrapper(&block) result = "
" if can_muti_lang_input - result << "
" + result << "
" result << "
" VALID_LOCALES.collect do |key| value = @prefiled_value[key.to_s] rescue nil @@ -108,7 +125,7 @@ protected result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}") end result << "
" - result << "