From 42c89220e3b73d43efcfbe5466aa826e25caa1b0 Mon Sep 17 00:00:00 2001 From: Matthew Fu Date: Fri, 13 Jan 2012 18:20:04 +0800 Subject: [PATCH 1/6] Manger and SubManager --- app/controllers/admin/app_auths_controller.rb | 6 +++ .../admin/module_apps_controller.rb | 53 +++++++++++++++++++ app/controllers/application_controller.rb | 2 +- app/models/app_manager.rb | 12 +++++ app/models/module_app.rb | 37 +++++++++++++ app/models/user/user.rb | 3 ++ app/views/admin/module_apps/edit.html.erb | 41 ++++++++++++++ config/routes.rb | 5 ++ 8 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 app/models/app_manager.rb create mode 100644 app/views/admin/module_apps/edit.html.erb diff --git a/app/controllers/admin/app_auths_controller.rb b/app/controllers/admin/app_auths_controller.rb index e925b857..6cbbf62e 100644 --- a/app/controllers/admin/app_auths_controller.rb +++ b/app/controllers/admin/app_auths_controller.rb @@ -15,4 +15,10 @@ class Admin::AppAuthsController < ApplicationController @module_apps = ModuleApp.all end + def edit + @module_app = ModuleApp.find(params[:id]) + end + + + end \ No newline at end of file diff --git a/app/controllers/admin/module_apps_controller.rb b/app/controllers/admin/module_apps_controller.rb index 142830f1..34fcf1fd 100644 --- a/app/controllers/admin/module_apps_controller.rb +++ b/app/controllers/admin/module_apps_controller.rb @@ -18,6 +18,7 @@ class Admin::ModuleAppsController < ApplicationController end + def update @module_app = ModuleApp.find(params[:id]) unless params['module_app']['enable_frontend'].nil? @@ -30,4 +31,56 @@ class Admin::ModuleAppsController < ApplicationController format.js { render 'admin/attributes/toggle_enable' } end end + + def assign_sub_manager + @module_app = ModuleApp.find(params[:id]) + @assign_to_user = User.find params[:sub_manager_id] rescue nil + unless @assign_to_user.nil? + if @module_app.assign_sub_manager(@assign_to_user,current_user) + flash[:notice] = t('admin.app_auth.assign_success_sub_manager') + else + flash[:notice] = t('admin.app_auth.assign_fail_sub_manager') + end + else + flash[:notice] = t('admin.app_auth.assign_fail_sub_manager_no_user') + end + redirect_to :action => "edit" + end + + def assign_manager + @module_app = ModuleApp.find(params[:id]) + @assign_to_user = User.find params[:manager_id] rescue nil + unless @assign_to_user.nil? + if @module_app.assign_manager(@assign_to_user,current_user) + flash[:notice] = t('admin.app_auth.assign_success_manager') + else + flash[:notice] = t('admin.app_auth.assign_fail_manager') + end + else + flash[:notice] = t('admin.app_auth.assign_fail_manager_no_user') + end + redirect_to :action => "edit" + end + + def remove_manager + @module_app = ModuleApp.find(params[:id]) + @app_manager = AppManager.find(params[:app_manager_id]) rescue nil + if @module_app.remove_manager(@app_manager.user) + flash[:notice] = t('admin.app_auth.delete_success_manager') + else + flash[:notice] = t('admin.app_auth.delete_fail_manager') + end + redirect_to :action => "edit" + end + + def remove_sub_manager + @module_app = ModuleApp.find(params[:id]) + @app_sub_manager = AppManager.find(params[:app_sub_manager_id]) rescue nil + if @module_app.remove_sub_manager(@app_sub_manager.user) + flash[:notice] = t('admin.app_auth.delete_success_sub_manager') + else + flash[:notice] = t('admin.app_auth.delete_fail_sub_manager') + end + redirect_to :action => "edit" + end end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0227c252..4bd847c7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base def front_end_available(module_app_title='') app_controller = ModuleApp.first(conditions: {:title => module_app_title} ) unless app_controller.enable_frontend? - render :nothing + render :nothing => true end end diff --git a/app/models/app_manager.rb b/app/models/app_manager.rb new file mode 100644 index 00000000..46cbbb91 --- /dev/null +++ b/app/models/app_manager.rb @@ -0,0 +1,12 @@ +class AppManager + include Mongoid::Document + include Mongoid::Timestamps + + belongs_to :user + + belongs_to :managing_app, :polymorphic => true #,:class_name => 'ModuleApp',:inverse_of => :managers,:foreign_key => "user_id" + belongs_to :sub_managing_app, :polymorphic => true #,:class_name => 'ModuleApp',:inverse_of => :sub_manager,:foreign_key => "sub_user_id" + + belongs_to :rule_creator,:class_name => 'User' + +end \ No newline at end of file diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 18e8a6d7..d02a1cd4 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -14,8 +14,45 @@ class ModuleApp field :app_pages ,type: Array field :widgets ,type: Array + has_many :managers,as: :managing_app ,:class_name => "AppManager" #,:dependent => :destroy,:foreign_key => "managing_app_id",:inverse_of => :managing_app + has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager"#, :dependent => :destroy,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app + has_one :app_auth,dependent: :delete + + def assign_manager(user,assigner) + manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil + if manager.nil? + manager = self.managers.create(:user => user,:rule_creator => assigner) + end + manager + end + + def assign_sub_manager(user,assigner) + submanager = AppManager.first(conditions: {sub_managing_app_id: self.id,user_id: user.id}) rescue nil + if submanager.nil? + submanager = self.sub_managers.create(:user => user,:rule_creator => assigner) + end + submanager + end + + def remove_manager(user) + manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil + if manager + manager.destroy + else + false + end + end + + def remove_sub_manager(user) + submanager = AppManager.first(conditions: {sub_managing_app_id: self.id,user_id: user.id}) rescue nil + if submanager + submanager.destroy + else + false + end + end end diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 60199ce7..13d282bb 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -14,6 +14,9 @@ class User has_many :app_auths,as: :privilege_apps,:inverse_of => :privilege_lists has_many :blocked_apps, :inverse_of => :blocked_users, :class_name => "AppAuth" has_many :privilege_apps, :inverse_of => :privilege_users, :class_name => "AppAuth" + + has_many :managing_apps,:class_name => "AppManager" + belongs_to :role has_and_belongs_to_many :sub_roles accepts_nested_attributes_for :attribute_values, :allow_destroy => true diff --git a/app/views/admin/module_apps/edit.html.erb b/app/views/admin/module_apps/edit.html.erb new file mode 100644 index 00000000..ff967273 --- /dev/null +++ b/app/views/admin/module_apps/edit.html.erb @@ -0,0 +1,41 @@ +<% content_for :secondary do %> +<% end %> + + +
+
+
+ + +
+

<%= @module_app.title %>

+
+
Manager + <% @module_app.managers.each do |manager| %> +
<%= manager.user.name %> -AuthBy:<%= manager.rule_creator.name %> <%= link_to '[X]',remove_manager_admin_module_app_path(@module_app,manager),:method => :delete unless manager.user == current_user%>
+ <% end %> +
Add: + <%= form_tag(assign_manager_admin_module_app_path) do %> + <%= text_field_tag 'manager_id' %> + <%= submit_tag 'Add Manager' %> + <% end %> +
+
+ + +
+
Sub Manager + <% @module_app.sub_managers.each do |manager| %> +
<%= manager.user.name %> -AuthBy:<%= manager.rule_creator.name %> <%= link_to '[X]',remove_sub_manager_admin_module_app_path(@module_app,manager),:method => :delete unless manager.user == current_user%>
+ <% end %> +
Add: + <%= form_tag(assign_sub_manager_admin_module_app_path) do %> + <%= text_field_tag 'sub_manager_id' %> + <%= submit_tag 'Add Sub Manager' %> + <% end %> +
+
+ + +
+ diff --git a/config/routes.rb b/config/routes.rb index f2b4cc17..e0e9eec2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,6 +40,11 @@ PrototypeR4::Application.routes.draw do end resources :module_apps do member do + match 'assign_manager' ,:action=> 'assign_manager',:via => "post",:as =>:assign_manager + match 'assign_sub_manager' ,:action=> 'assign_sub_manager',:via => "post",:as =>:assign_sub_manager + + match 'remove_manager/:app_manager_id' ,:action=> 'remove_manager',:via => "delete",:as =>:remove_manager + match 'remove_sub_manager/:app_sub_manager_id' ,:action=> 'remove_sub_manager',:via => "delete",:as =>:remove_sub_manager get 'reload_frontend_pages' end end From 1dea9ba156f7da4d5190b173b2e192ccda914148 Mon Sep 17 00:00:00 2001 From: Matthew Fu Date: Mon, 16 Jan 2012 18:52:08 +0800 Subject: [PATCH 2/6] Add methods to work with manager role,add task to build user test data --- .../admin/module_apps_controller.rb | 73 +++++++++++++------ lib/tasks/user.rake | 29 ++++++++ 2 files changed, 78 insertions(+), 24 deletions(-) create mode 100644 lib/tasks/user.rake diff --git a/app/controllers/admin/module_apps_controller.rb b/app/controllers/admin/module_apps_controller.rb index 34fcf1fd..129453b1 100644 --- a/app/controllers/admin/module_apps_controller.rb +++ b/app/controllers/admin/module_apps_controller.rb @@ -1,4 +1,7 @@ class Admin::ModuleAppsController < ApplicationController + before_filter :user_has_manager_privilege?, :only => [ :assign_manager, :remove_manager ] + before_filter :user_has_sub_manager_privilege?, :only => [ :assign_sub_manager, :remove_sub_manager ] + layout "admin" def index @@ -32,55 +35,77 @@ class Admin::ModuleAppsController < ApplicationController end end + def assign_sub_manager - @module_app = ModuleApp.find(params[:id]) - @assign_to_user = User.find params[:sub_manager_id] rescue nil - unless @assign_to_user.nil? - if @module_app.assign_sub_manager(@assign_to_user,current_user) - flash[:notice] = t('admin.app_auth.assign_success_sub_manager') + unless @assign_to_user.nil? + if @module_app.assign_sub_manager(@assign_to_user,current_user) + flash[:notice] = t('admin.app_auth.assigning_manager.add_sub_manager_ok') + else + flash[:notice] = t('admin.app_auth.assigning_manager.add_sub_manager_fail') + end else - flash[:notice] = t('admin.app_auth.assign_fail_sub_manager') - end - else - flash[:notice] = t('admin.app_auth.assign_fail_sub_manager_no_user') - end - redirect_to :action => "edit" + flash[:notice] = t('admin.app_auth.assigning_manager.failed_no_user') + end + redirect_to :action => "edit" end + def assign_manager - @module_app = ModuleApp.find(params[:id]) - @assign_to_user = User.find params[:manager_id] rescue nil unless @assign_to_user.nil? if @module_app.assign_manager(@assign_to_user,current_user) - flash[:notice] = t('admin.app_auth.assign_success_manager') + flash[:notice] = t('admin.app_auth.assigning_sub_manager.add_manager_ok') else - flash[:notice] = t('admin.app_auth.assign_fail_manager') + flash[:notice] = t('admin.app_auth.assigning_sub_manager.add_manager_fail') end else - flash[:notice] = t('admin.app_auth.assign_fail_manager_no_user') + flash[:notice] = t('admin.app_auth.assigning_sub_manager.failed_no_user') end redirect_to :action => "edit" end + def remove_manager - @module_app = ModuleApp.find(params[:id]) - @app_manager = AppManager.find(params[:app_manager_id]) rescue nil if @module_app.remove_manager(@app_manager.user) - flash[:notice] = t('admin.app_auth.delete_success_manager') + flash[:notice] = t('admin.app_auth.delete_manager.success') else - flash[:notice] = t('admin.app_auth.delete_fail_manager') + flash[:notice] = t('admin.app_auth.delete_manager.fail') end redirect_to :action => "edit" end + def remove_sub_manager - @module_app = ModuleApp.find(params[:id]) - @app_sub_manager = AppManager.find(params[:app_sub_manager_id]) rescue nil if @module_app.remove_sub_manager(@app_sub_manager.user) - flash[:notice] = t('admin.app_auth.delete_success_sub_manager') + flash[:notice] = t('admin.app_auth.delete_sub_manager.success') else - flash[:notice] = t('admin.app_auth.delete_fail_sub_manager') + flash[:notice] = t('admin.app_auth.delete_sub_manager.fail') end redirect_to :action => "edit" end + + + private + def user_has_manager_privilege? + @module_app = ModuleApp.find(params[:id]) + @assign_to_user = User.find params[:manager_id] rescue nil + if current_user.admin? #only admin can assign app's manager + return + end + #user is not permited to do that + flash[:notice] = t('admin.app_auth.operation_not_permitted') + redirect_to :action => "edit" # [TODO] maybe need to redirect to some other page + end + + + def user_has_sub_manager_privilege? + @module_app = ModuleApp.find(params[:id]) + @assign_to_user = User.find params[:sub_manager_id] rescue nil + if current_user.admin? || @module_app.managers.include?(current_user) #admin or app's manager can assign app's subanager + return + end + #user is not permited to do that + flash[:notice] = t('admin.app_auth.operation_not_permitted') + redirect_to :action => "edit" # [TODO] maybe need to redirect to some other page + end + end \ No newline at end of file diff --git a/lib/tasks/user.rake b/lib/tasks/user.rake new file mode 100644 index 00000000..31ed7c24 --- /dev/null +++ b/lib/tasks/user.rake @@ -0,0 +1,29 @@ +# encoding: utf-8 +namespace :user do + + task :build => :environment do + User.all(conditions: {email: /nor/}).destroy_all + + username_list = %w{nor1 nor2 nor3 nor4 nor5 nor6 nor7} + userfirstname_list_en = %w{ One Two Thre For Fiv Six Sen } + userlastname_list_en = %w{ Aa Bb Cc Dd Ee Ff Gg } + + userfirstname_list_ct = %w{ 一一 二二 三三 四四 五五 六六 七七 } + userlastname_list_ct = %w{ 陳 林 吳 李 鄭 方 王 } + + first_name_field = AttributeField.first(conditions: {key: "first_name"}) + last_name_field = AttributeField.first(conditions: {key: "last_name"}) + major_field = AttributeField.first(conditions: {key: "major"}) + department_field = AttributeField.first(conditions: {key: "department"}) + + stud_role = Role.first(conditions: {key: 'student'}) + + username_list.each_with_index do |username,index| + user = User.create( :email => "#{username}@rulingcom.com", :password => 'password', :password_confirmation => 'password', :admin => false ,:role_id => stud_role.id,:sub_role_ids => [stud_role.sub_roles[Random.rand(stud_role.sub_roles.count-1)].id]) + AttributeValue.create( :user_id => user.id, :attribute_field_id => first_name_field.id, :key => 'first_name', :en => userfirstname_list_en[index], :zh_tw => userfirstname_list_ct[index] ) + AttributeValue.create( :user_id => user.id, :attribute_field_id => last_name_field.id, :key => 'last_name', :en => userlastname_list_en[index], :zh_tw => userlastname_list_ct[index] ) + AttributeValue.create( :user_id => user.id, :attribute_field_id => major_field.id, :key => 'major', :en => 'Information management', :zh_tw => '信息化管理' ) + AttributeValue.create( :user_id => user.id, :attribute_field_id => department_field.id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' ) + end + end +end From 9fa6131ad301d586065094d422982b6266f9d24d Mon Sep 17 00:00:00 2001 From: Matthew Fu Date: Tue, 17 Jan 2012 16:20:03 +0800 Subject: [PATCH 3/6] First complete with manager and submanager --- app/controllers/admin/app_auths_controller.rb | 10 +++++++--- .../admin/module_apps_controller.rb | 14 +++++++++----- app/helpers/admin/module_app_helper.rb | 19 +++++++++++++++++++ app/models/module_app.rb | 12 +++++++++--- app/views/admin/module_apps/edit.html.erb | 8 ++++---- config/locales/en.yml | 2 ++ config/locales/zh_tw.yml | 2 ++ 7 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 app/helpers/admin/module_app_helper.rb diff --git a/app/controllers/admin/app_auths_controller.rb b/app/controllers/admin/app_auths_controller.rb index 6cbbf62e..1bbb5a2e 100644 --- a/app/controllers/admin/app_auths_controller.rb +++ b/app/controllers/admin/app_auths_controller.rb @@ -1,7 +1,7 @@ class Admin::AppAuthsController < ApplicationController layout "admin" before_filter :authenticate_user! - before_filter :is_admin? +# before_filter :is_admin? ,:only => :index def index # @roles = Role.all.entries @@ -12,13 +12,17 @@ class Admin::AppAuthsController < ApplicationController # obj_auth = obj.send "auth" # [:app_obj => app,:auth_field => obj_auth] # end - @module_apps = ModuleApp.all + if current_user.admin? + @module_apps = ModuleApp.all + else + @module_apps = current_user.managing_apps.collect{|t| t.managing_app} + end end def edit @module_app = ModuleApp.find(params[:id]) end - + end \ No newline at end of file diff --git a/app/controllers/admin/module_apps_controller.rb b/app/controllers/admin/module_apps_controller.rb index 129453b1..914c5138 100644 --- a/app/controllers/admin/module_apps_controller.rb +++ b/app/controllers/admin/module_apps_controller.rb @@ -37,7 +37,7 @@ class Admin::ModuleAppsController < ApplicationController def assign_sub_manager - unless @assign_to_user.nil? + unless @assign_to_user.nil? || @assign_to_user.admin? if @module_app.assign_sub_manager(@assign_to_user,current_user) flash[:notice] = t('admin.app_auth.assigning_manager.add_sub_manager_ok') else @@ -46,12 +46,13 @@ class Admin::ModuleAppsController < ApplicationController else flash[:notice] = t('admin.app_auth.assigning_manager.failed_no_user') end - redirect_to :action => "edit" + flash[:notice] = t('admin.app_auth.can_not_add_this_user') + redirect_to :action => "edit" end def assign_manager - unless @assign_to_user.nil? + unless @assign_to_user.nil? || @assign_to_user.admin? if @module_app.assign_manager(@assign_to_user,current_user) flash[:notice] = t('admin.app_auth.assigning_sub_manager.add_manager_ok') else @@ -60,11 +61,13 @@ class Admin::ModuleAppsController < ApplicationController else flash[:notice] = t('admin.app_auth.assigning_sub_manager.failed_no_user') end - redirect_to :action => "edit" + flash[:notice] = t('admin.app_auth.can_not_add_this_user') + redirect_to :action => "edit" end def remove_manager + @app_manager = AppManager.find(params[:app_manager_id]) if @module_app.remove_manager(@app_manager.user) flash[:notice] = t('admin.app_auth.delete_manager.success') else @@ -75,6 +78,7 @@ class Admin::ModuleAppsController < ApplicationController def remove_sub_manager + @app_sub_manager = AppManager.find(params[:app_sub_manager_id]) if @module_app.remove_sub_manager(@app_sub_manager.user) flash[:notice] = t('admin.app_auth.delete_sub_manager.success') else @@ -100,7 +104,7 @@ class Admin::ModuleAppsController < ApplicationController def user_has_sub_manager_privilege? @module_app = ModuleApp.find(params[:id]) @assign_to_user = User.find params[:sub_manager_id] rescue nil - if current_user.admin? || @module_app.managers.include?(current_user) #admin or app's manager can assign app's subanager + if current_user.admin? || @module_app.managing_users.include?(current_user) #admin or app's manager can assign app's subanager return end #user is not permited to do that diff --git a/app/helpers/admin/module_app_helper.rb b/app/helpers/admin/module_app_helper.rb new file mode 100644 index 00000000..0a636e9c --- /dev/null +++ b/app/helpers/admin/module_app_helper.rb @@ -0,0 +1,19 @@ +module Admin::ModuleAppHelper + + def if_permit_to_delete(item) + case item.downcase + when :manager + current_user.admin? + when :sub_manager + @module_app.managing_users.include?(current_user) || current_user.admin? + end + end + + def if_permit_to_assign(item) + if_permit_to_delete(item) + end + + def get_auth_by(manager_obj) + "-AuthBy: " +( manager_obj.rule_creator==current_user ? t('me') : manager_obj.rule_creator.name) + end +end diff --git a/app/models/module_app.rb b/app/models/module_app.rb index d02a1cd4..70d0d7da 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -19,11 +19,17 @@ class ModuleApp has_one :app_auth,dependent: :delete - + def managing_users + self.managers.collect{ |t| t.user } + end + + def sub_managing_users + self.sub_managers.collect{ |t| t.user } + end def assign_manager(user,assigner) manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil - if manager.nil? + if manager.nil? manager = self.managers.create(:user => user,:rule_creator => assigner) end manager @@ -31,7 +37,7 @@ class ModuleApp def assign_sub_manager(user,assigner) submanager = AppManager.first(conditions: {sub_managing_app_id: self.id,user_id: user.id}) rescue nil - if submanager.nil? + if submanager.nil? && !self.managing_users.include?(user) submanager = self.sub_managers.create(:user => user,:rule_creator => assigner) end submanager diff --git a/app/views/admin/module_apps/edit.html.erb b/app/views/admin/module_apps/edit.html.erb index ff967273..96859a21 100644 --- a/app/views/admin/module_apps/edit.html.erb +++ b/app/views/admin/module_apps/edit.html.erb @@ -12,11 +12,11 @@
Manager <% @module_app.managers.each do |manager| %> -
<%= manager.user.name %> -AuthBy:<%= manager.rule_creator.name %> <%= link_to '[X]',remove_manager_admin_module_app_path(@module_app,manager),:method => :delete unless manager.user == current_user%>
+
<%= manager.user.name %> <%= get_auth_by(manager) %> <%= link_to '[X]',remove_manager_admin_module_app_path(@module_app,manager),:method => :delete if if_permit_to_delete(:manager) && manager.user != current_user %>
<% end %>
Add: <%= form_tag(assign_manager_admin_module_app_path) do %> - <%= text_field_tag 'manager_id' %> + <%= text_field_tag 'manager_id','Enter User ID here',:disabled => !if_permit_to_assign(:manager)%> <%= submit_tag 'Add Manager' %> <% end %>
@@ -26,11 +26,11 @@
Sub Manager <% @module_app.sub_managers.each do |manager| %> -
<%= manager.user.name %> -AuthBy:<%= manager.rule_creator.name %> <%= link_to '[X]',remove_sub_manager_admin_module_app_path(@module_app,manager),:method => :delete unless manager.user == current_user%>
+
<%= manager.user.name %> -AuthBy:<%= manager.rule_creator.name %> <%= link_to '[X]',remove_sub_manager_admin_module_app_path(@module_app,manager),:method => :delete if if_permit_to_delete(:sub_manager) && manager.user != current_user %>
<% end %>
Add: <%= form_tag(assign_sub_manager_admin_module_app_path) do %> - <%= text_field_tag 'sub_manager_id' %> + <%= text_field_tag 'sub_manager_id','Enter User ID here',:disabled => !if_permit_to_assign(:sub_manager)%> <%= submit_tag 'Add Sub Manager' %> <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index f9d77062..c44d2359 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,6 +5,8 @@ en: _locale: English + me: Me + add: Add back: Back create: Create diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 5034ce8a..c1d0552c 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,8 @@ zh_tw: _locale: 中文 + me: 我 + add: 新增 back: 回去 create: 創造 From 37b8b8555421cf8a9cca7026718a472e762af899 Mon Sep 17 00:00:00 2001 From: Matthew Fu Date: Wed, 18 Jan 2012 11:51:38 +0800 Subject: [PATCH 4/6] put setup APP var setup into Orbit class --- app/controllers/obit_frontend_component_controller.rb | 6 ++++++ .../panel/new_blog/front_end/posts_controller.rb | 8 -------- .../controllers/panel/new_blog/widget/posts_controller.rb | 8 -------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/app/controllers/obit_frontend_component_controller.rb b/app/controllers/obit_frontend_component_controller.rb index d5bfaac6..06bb06a5 100644 --- a/app/controllers/obit_frontend_component_controller.rb +++ b/app/controllers/obit_frontend_component_controller.rb @@ -1,4 +1,10 @@ class ObitFrontendComponentController< ApplicationController + before_filter :setup_vars before_filter {|c| c.front_end_available(@app_title)} layout 'production' + + def setup_vars + @app_title = request.fullpath.split('/')[2] + end + end \ No newline at end of file diff --git a/vendor/built_in_modules/new_blog/app/controllers/panel/new_blog/front_end/posts_controller.rb b/vendor/built_in_modules/new_blog/app/controllers/panel/new_blog/front_end/posts_controller.rb index 2471e5fd..1aeb34b2 100644 --- a/vendor/built_in_modules/new_blog/app/controllers/panel/new_blog/front_end/posts_controller.rb +++ b/vendor/built_in_modules/new_blog/app/controllers/panel/new_blog/front_end/posts_controller.rb @@ -1,14 +1,6 @@ class Panel::NewBlog::FrontEnd::PostsController < ObitFrontendController - - - def initialize - super - @app_title = NewBlog::MOUDLEAPP_TITLE - end - # GET /posts # GET /posts.xml - def index @posts = Post.all end diff --git a/vendor/built_in_modules/new_blog/app/controllers/panel/new_blog/widget/posts_controller.rb b/vendor/built_in_modules/new_blog/app/controllers/panel/new_blog/widget/posts_controller.rb index 796155bc..dab532ee 100644 --- a/vendor/built_in_modules/new_blog/app/controllers/panel/new_blog/widget/posts_controller.rb +++ b/vendor/built_in_modules/new_blog/app/controllers/panel/new_blog/widget/posts_controller.rb @@ -1,12 +1,4 @@ class Panel::NewBlog::Widget::PostsController < ObitWidgetController - - layout 'production' - - def initialize - super - @app_title = NewBlog::MOUDLEAPP_TITLE - end - # GET /posts # GET /posts.xml def index From f1a3008e2b125b41756c680ea7f32d4e431d4f71 Mon Sep 17 00:00:00 2001 From: Matthew Fu Date: Wed, 18 Jan 2012 12:04:01 +0800 Subject: [PATCH 5/6] update app package for previous commit --- lib/NewBlog.zip | Bin 53327 -> 53345 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/NewBlog.zip b/lib/NewBlog.zip index 3513cabf8668eed283bebaac3103fd657c43901e..71f0e09101e32b59c1c13c6bc32357663d03d909 100644 GIT binary patch delta 7922 zcmai13tWup_n&#D%XFJbYO0xrj^ExDA-swjm=b|9*U`_c`Z0=Q-y*=X}q3+KU*EiWqu< z(-~^oG~(Z`1y0#|=3EUQPQW`)PCy^skVY^KX-xco-vTE|wvSCT(~A?Jhkpp}i`URxCRnTx6qhDm(|JhL=OuI19g16}LF=jBaOi2c3$3k#BoHHr}eoy`m~8 zUH=$u_2W&hRz7X&X+6$fhO50fC3Bnixi->Qdo9ks%9YM{Y@xZ*Ms@@p_6jicoA1!+ zn^m=5j~5Y|crSkXT0d~>t9wtLaEe_kS^E!8-=xp9lqe&{`lm*#AN|NyuAJ4GnbvLPHSx~txf8#z8w-W zDzsAIu9KFQy2qS5eec zO@8qD$cR_6A73skkjB08TYRT>Nksc!TaLY#70i3hJ{`ZfHTTKc?lfo`m%M!Pm%5RO z>yQ7(z1V7MNZtADxcX=RO&S+hm+*V)&G~2Ee3kLtwS7MyvU&7&!41c~%`wisZh@S} z%G{TzGVK0H?Fk8uYp&H9&3e6=SD?2tgIge780OkE`WtCx-QjgN48F3Grab6RE5Bb- zeYe3g;=A%~OQOElt+Y0~wTAQCoYC!e_cpU*n@W#~w@s~WIe5Q>eX4E3i;z9uRv)e$ zOfzo{EtBOqf51j+ z`R0d)q<2x>9gp~3jQ763Z+sQn{Z^XBpBeo2WL3=Fh=txY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^A6wTEZC)J;8V#WKM>aZ=qVV}+iWX^+Q!5*7+JL1;!OGT2X!*Bb z(avMUd_`XCaDS0ub=)}4k{sZ*u@ukp5FQU+3 zQ@gz~eogIcN(d%d1G?r;2?z1DC1~LmoU~jx+)jgvEe!0M5XEg%km|Q-!IbMl%8!t6 zJskCHCmAoUGnG179c<*bgQTbLU=fWKM^Xn;I#?(w9g~e=pyRXl)`pjymGkDI{GFuO l Date: Thu, 19 Jan 2012 17:47:52 +0800 Subject: [PATCH 6/6] User role and sub_role simple interface complete --- app/controllers/admin/app_auths_controller.rb | 43 ++++++++++++++++++ .../admin/module_apps_controller.rb | 5 +-- app/views/admin/module_apps/edit.html.erb | 44 +++++++++++++++---- config/routes.rb | 8 +++- 4 files changed, 88 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/app_auths_controller.rb b/app/controllers/admin/app_auths_controller.rb index 1bbb5a2e..cb3340fd 100644 --- a/app/controllers/admin/app_auths_controller.rb +++ b/app/controllers/admin/app_auths_controller.rb @@ -19,6 +19,49 @@ class Admin::AppAuthsController < ApplicationController end end + def create + app_auth = AppAuth.find_or_create_by(module_app_id: params[:module_app_id]) + params[:new].each do |item| + field = item[0] + field_value = item[1] + if field_value!='' + case field + when 'role' + app_auth.send("add_#{field}",(Role.find field_value)) rescue nil + when 'sub_role' + app_auth.send("add_#{field}",(SubRole.find field_value)) rescue nil + when 'privilege_user' + app_auth.add_user_to_privilege_list (User.find field_value) rescue nil + when 'blocked_user' + app_auth.add_user_to_black_list (User.find field_value) rescue nil + end + end + end + app = ModuleApp.find params[:module_app_id] rescue nil + redirect_to edit_admin_module_app_path(app) + end + + def remove + app_auth = AppAuth.find( params[:id] ) + type = params[:type] + field_value = params[:target_id] + if field_value!='' + case type + when 'role' + app_auth.remove_role(Role.find field_value) rescue nil + when 'sub_role' + app_auth.remove_sub_role(SubRole.find field_value) rescue nil + when 'privilege_user' + app_auth.remove_user_from_privilege_list (User.find field_value) rescue nil + when 'blocked_user' + app_auth.remove_user_from_black_list (User.find field_value) rescue nil + end + end + + app = ModuleApp.find params[:module_app_id] rescue nil + redirect_to edit_admin_module_app_path(app) + end + def edit @module_app = ModuleApp.find(params[:id]) end diff --git a/app/controllers/admin/module_apps_controller.rb b/app/controllers/admin/module_apps_controller.rb index 914c5138..56c2523f 100644 --- a/app/controllers/admin/module_apps_controller.rb +++ b/app/controllers/admin/module_apps_controller.rb @@ -18,7 +18,6 @@ class Admin::ModuleAppsController < ApplicationController def edit @module_app = ModuleApp.find(params[:id]) - end @@ -91,7 +90,7 @@ class Admin::ModuleAppsController < ApplicationController private def user_has_manager_privilege? @module_app = ModuleApp.find(params[:id]) - @assign_to_user = User.find params[:manager_id] rescue nil + @assign_to_user = User.find params[:manager][:id] rescue nil if current_user.admin? #only admin can assign app's manager return end @@ -103,7 +102,7 @@ class Admin::ModuleAppsController < ApplicationController def user_has_sub_manager_privilege? @module_app = ModuleApp.find(params[:id]) - @assign_to_user = User.find params[:sub_manager_id] rescue nil + @assign_to_user = User.find params[:sub_manager][:id] rescue nil if current_user.admin? || @module_app.managing_users.include?(current_user) #admin or app's manager can assign app's subanager return end diff --git a/app/views/admin/module_apps/edit.html.erb b/app/views/admin/module_apps/edit.html.erb index 96859a21..9429e963 100644 --- a/app/views/admin/module_apps/edit.html.erb +++ b/app/views/admin/module_apps/edit.html.erb @@ -6,9 +6,11 @@

+

<%= @module_app.title %>

-

<%= @module_app.title %>

+

Manager

+
Manager <% @module_app.managers.each do |manager| %> @@ -16,13 +18,11 @@ <% end %>
Add: <%= form_tag(assign_manager_admin_module_app_path) do %> - <%= text_field_tag 'manager_id','Enter User ID here',:disabled => !if_permit_to_assign(:manager)%> + <%= collection_select(:manager,:id, User.all, :id, :name, :prompt => true,:disabled => !if_permit_to_assign(:manager))%> <%= submit_tag 'Add Manager' %> <% end %>
- -
Sub Manager <% @module_app.sub_managers.each do |manager| %> @@ -30,12 +30,40 @@ <% end %>
Add: <%= form_tag(assign_sub_manager_admin_module_app_path) do %> - <%= text_field_tag 'sub_manager_id','Enter User ID here',:disabled => !if_permit_to_assign(:sub_manager)%> + <%= collection_select(:sub_manager,:id, User.all, :id, :name, :prompt => true,:disabled => !if_permit_to_assign(:sub_manager))%> <%= submit_tag 'Add Sub Manager' %> <% end %>
- -
- +
+

User Role

+ <%= form_tag(admin_module_app_app_auths_path(@module_app),:method => :post) do %> + <%= collection_select(:new,:role, Role.all, :id, :key, :prompt => true) %> + <%= submit_tag 'Add Role' %>
+ <%= collection_select(:new,:sub_role, SubRole.all, :id, :key, :prompt => true) %> + <%= submit_tag 'Add SubRole' %>
+ <%= collection_select(:new,:privilege_user, User.all, :id, :name, :prompt => true) %> + <%= submit_tag 'Add PrivilegeList' %>
+ <%= collection_select(:new,:blocked_user, User.all, :id, :name, :prompt => true) %> + <%= submit_tag 'Add BlockedList' %>
+ <% end %> +
    Roles
+ <% unless @module_app.app_auth.nil? %> + <% @module_app.app_auth.roles.each do |role| %> +
  • <%= role.key %> Build in:<%= role.built_in ? 'Yes' : 'No' %> <%= link_to '[X]',remove_admin_module_app_app_auth_path(@module_app,@module_app.app_auth,'role',role),:method => :delete %>
  • + <% end %> +
      Sub Roles
    + <% @module_app.app_auth.sub_roles.each do |role| %> +
  • <%= role.key %> Build in:<%= role.built_in ? 'Yes' : 'No' %>
  • <%= link_to '[X]',remove_admin_module_app_app_auth_path(@module_app,@module_app.app_auth,'sub_role',role),:method => :delete %> + <% end %> +
      PrivilegeList
    + <% @module_app.app_auth.privilege_users.each do |user| %> +
  • <%= user.name %> <%= link_to '[X]',remove_admin_module_app_app_auth_path(@module_app,@module_app.app_auth,'privilege_user',user),:method => :delete %>
  • + <% end %> +
      BlockedList
    + <% @module_app.app_auth.blocked_users.each do |user| %> +
  • <%= user.name %><%= link_to '[X]',remove_admin_module_app_app_auth_path(@module_app,@module_app.app_auth,'blocked_user',user),:method => :delete %>
  • + <% end %> +<% end %> +
    diff --git a/config/routes.rb b/config/routes.rb index e0e9eec2..efa64576 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ PrototypeR4::Application.routes.draw do # routes for admin namespace :admin do resources :assets - resources :app_auths + resources :app_auths resources :designs do collection do @@ -39,6 +39,12 @@ PrototypeR4::Application.routes.draw do end end resources :module_apps do + resources :app_auths do + member do + match 'remove/:type/:target_id' ,:action=> 'remove',:via => "delete",:as =>:remove + end + end + member do match 'assign_manager' ,:action=> 'assign_manager',:via => "post",:as =>:assign_manager match 'assign_sub_manager' ,:action=> 'assign_sub_manager',:via => "post",:as =>:assign_sub_manager