From 20a1a6e30f87f08f7453c7faddd8550efd361f18 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 11 May 2012 16:44:40 +0800 Subject: [PATCH] New Interface for App Auth and Object Auth --- .../module_apps_new_interface_controller.rb | 66 +++++++++++++++++ .../object_auths_new_interface_controller.rb | 71 +++++++++++++++++++ app/helpers/application_helper.rb | 20 +++++- .../_modal_list.html.erb | 42 +++++++++++ .../_privilege_user.html.erb | 25 +++++++ .../setting.html.erb | 56 +++++++++++++++ .../module_apps_new_interface/setting.js.erb | 2 + .../update_setting.js.erb | 1 + .../user_list.js.erb | 2 + .../_modal_list.html.erb | 42 +++++++++++ .../_privilege_user.html.erb | 25 +++++++ .../setting.html.erb | 57 +++++++++++++++ .../object_auths_new_interface/setting.js.erb | 2 + .../update_setting.js.erb | 1 + .../user_list.js.erb | 2 + app/views/layouts/_side_bar.html.erb | 16 ++--- config/locales/en.yml | 4 ++ config/locales/zh_tw.yml | 6 +- lib/orbit_core_lib.rb | 4 ++ .../back_end/bulletin_categorys_helper.rb | 2 +- .../app/models/bulletin_category.rb | 4 ++ .../news_bulletin_categorys_helper.rb | 2 +- .../news/app/models/news_bulletin_category.rb | 4 ++ 23 files changed, 442 insertions(+), 14 deletions(-) create mode 100644 app/controllers/admin/module_apps_new_interface_controller.rb create mode 100644 app/controllers/admin/object_auths_new_interface_controller.rb create mode 100644 app/views/admin/module_apps_new_interface/_modal_list.html.erb create mode 100644 app/views/admin/module_apps_new_interface/_privilege_user.html.erb create mode 100644 app/views/admin/module_apps_new_interface/setting.html.erb create mode 100644 app/views/admin/module_apps_new_interface/setting.js.erb create mode 100644 app/views/admin/module_apps_new_interface/update_setting.js.erb create mode 100644 app/views/admin/module_apps_new_interface/user_list.js.erb create mode 100644 app/views/admin/object_auths_new_interface/_modal_list.html.erb create mode 100644 app/views/admin/object_auths_new_interface/_privilege_user.html.erb create mode 100644 app/views/admin/object_auths_new_interface/setting.html.erb create mode 100644 app/views/admin/object_auths_new_interface/setting.js.erb create mode 100644 app/views/admin/object_auths_new_interface/update_setting.js.erb create mode 100644 app/views/admin/object_auths_new_interface/user_list.js.erb diff --git a/app/controllers/admin/module_apps_new_interface_controller.rb b/app/controllers/admin/module_apps_new_interface_controller.rb new file mode 100644 index 00000000..52292588 --- /dev/null +++ b/app/controllers/admin/module_apps_new_interface_controller.rb @@ -0,0 +1,66 @@ +class Admin::ModuleAppsNewInterfaceController < ApplicationController + before_filter :authenticate_user! + before_filter :is_admin? + include AdminHelper + + layout "new_admin" + + def setting + @sys_users = User.all(conditions: {admin: false}) + @module_app = ModuleApp.find(params[:module_app_id]) + @options_from_collection_for_select_bulletin_categorys = [@module_app].collect{|ma| [ma.title,ma.id] } + # if params.has_key? :category + # @bulletin_category = BulletinCategory.find params[:category][:id] + # else + # @bulletin_category = @bulletin_categorys.first + # end + @users_array = @module_app.managing_users rescue [] + + respond_to do |format| + format.html + format.js + end + end + + def update_setting + module_app = update_setting_by_params + if module_app.save! + flash[:notice] = "Update Done" + else + flash[:notice] = "Update Failed" + end + end + + def user_list + @module_app = ModuleApp.find params[:module_app][:id] + end + + protected + def update_setting_by_params + ma = ModuleApp.find params[:module_app][:id] + user_sat = User.find params[:users].keys + users_to_new = user_sat - ma.managing_users + users_to_remove = ma.managing_users - user_sat + + users_to_new.each do |new_user| + ma.assign_manager(new_user,current_user) + end + + users_to_remove.each do |remove_user| + ma.remove_manager(remove_user) + end + ma + end + + def get_categorys(id = nil) + @bulletin_categorys = [] + if(is_manager? || is_admin?) + @bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true)) + elsif is_sub_manager? + @bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new') + end + end + + + +end \ No newline at end of file diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb new file mode 100644 index 00000000..427ec722 --- /dev/null +++ b/app/controllers/admin/object_auths_new_interface_controller.rb @@ -0,0 +1,71 @@ +class Admin::ObjectAuthsNewInterfaceController < ApplicationController + include OrbitCoreLib::PermissionUnility + layout "new_admin" + before_filter :force_order + + layout "new_admin" + + + def setting + @sys_users = User.all(conditions: {admin: false}) + @ob_auth = ObjectAuth.find params[:object_auth_id] + @options_from_collection_for_select_ob_auth = [@ob_auth].collect{|oa| [oa.auth_obj.pp_object,oa.id] } + @users_array = @ob_auth.privilege_users rescue [] + + respond_to do |format| + format.html + format.js + end + end + + def update_setting + ob_auth = update_setting_by_params + if ob_auth.save! + flash[:notice] = t("admin.object_auth.update_done") + else + flash[:notice] = t("admin.object_auth.update_failed") + end + end + + def user_list + @ob_auth = ObjectAuth.find params[:ob_auth][:id] + end + + protected + def update_setting_by_params + oa = ObjectAuth.find params[:ob_auth][:id] + user_sat = User.find params[:users].keys + users_to_new = user_sat - oa.auth_users + users_to_remove = oa.auth_users - user_sat + + users_to_new.each do |new_user| + oa.add_user_to_privilege_list(new_user) + end + + users_to_remove.each do |remove_user| + oa.remove_user_from_privilege_list(remove_user) + end + oa + end + + # def get_categorys(id = nil) + # @bulletin_categorys = [] + # if(is_manager? || is_admin?) + # @bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true)) + # elsif is_sub_manager? + # @bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new') + # end + # end + + def force_order + authenticate_user! + check_if_user_can_do_object_auth + end + + def check_if_user_can_do_object_auth + unless check_permission(:manager) + render :nothing => true, :status => 403 + end + end + +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 844fbe14..cd7a15dd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -68,9 +68,23 @@ module ApplicationHelper end end - def active_sys_call_for_app(controller_name,action_name,app_title,field = :id) - unless active_for_action(controller_name,action_name).nil? - app = ModuleApp.find params[field] + def active_for_ob_auths_object(object_class,field = :object_auth_id) + unless active_for_action("object_auths_new_interface","setting").nil? + ob_auth = ObjectAuth.find params[field] + ob_auth.obj_authable_type == object_class.to_s ? 'active' : nil + end + end + + def active_for_ob_auth(ob_auth_title,field = :object_auth_id) + unless active_for_action("module_apps_new_interface","setting").nil? + oa_auth = ObjectAuth.find params[field] + oa_auth.title == ob_auth_title ? 'active' : nil + end + end + + def active_for_app_auth(app_title ='', opt={:controller_name => 'module_apps_new_interface',:action_name=>'setting',:field => :module_app_id}) + unless active_for_action(opt[:controller_name],opt[:action_name]).nil? + app = ModuleApp.find params[opt[:field]] app.title == app_title ? 'active' : nil else nil diff --git a/app/views/admin/module_apps_new_interface/_modal_list.html.erb b/app/views/admin/module_apps_new_interface/_modal_list.html.erb new file mode 100644 index 00000000..b5b0ebcd --- /dev/null +++ b/app/views/admin/module_apps_new_interface/_modal_list.html.erb @@ -0,0 +1,42 @@ +<% if module_app -%> + +