From 6dfe10040b9249293715ea83c35cd1fe2186559e Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 16 Oct 2012 14:23:44 +0800 Subject: [PATCH] fix object auth without app_auth --- .../object_auths_new_interface_controller.rb | 2 ++ app/models/app_manager.rb | 6 +++--- app/models/module_app.rb | 2 +- app/models/object_auth.rb | 13 +++++++------ lib/orbit_core_lib.rb | 2 +- lib/tasks/nccu.rake | 18 +++++++++++++++--- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb index 69e94429..fae94666 100644 --- a/app/controllers/admin/object_auths_new_interface_controller.rb +++ b/app/controllers/admin/object_auths_new_interface_controller.rb @@ -37,10 +37,12 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController users_to_remove = oa.auth_users - user_sat users_to_new.each do |new_user| + oa.privilege_users << new_user oa.add_user_to_privilege_list(new_user) end users_to_remove.each do |remove_user| + oa.privilege_users.delete_if{|user| user == remove_user} oa.remove_user_from_privilege_list(remove_user) end oa diff --git a/app/models/app_manager.rb b/app/models/app_manager.rb index 0d81a0ec..d2fdc24d 100644 --- a/app/models/app_manager.rb +++ b/app/models/app_manager.rb @@ -2,11 +2,11 @@ class AppManager include Mongoid::Document include Mongoid::Timestamps - belongs_to :user + belongs_to :user,index: true - belongs_to :managing_app, :polymorphic => true #,:class_name => 'ModuleApp',:inverse_of => :managers,:foreign_key => "user_id" + belongs_to :managing_app, :polymorphic => true,index: 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 9708316f..ef249a0b 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -54,7 +54,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? && !self.managing_users.include?(user) - submanager = self.sub_managers.create(:user => user,:rule_creator => assigner) + submanager = self.sub_managers.create(:user_id => user.id,:rule_creator_id => assigner.id) end submanager end diff --git a/app/models/object_auth.rb b/app/models/object_auth.rb index 960509f0..6c7405ca 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -2,7 +2,7 @@ class ObjectAuth < PrototypeAuth include OrbitCoreLib::ObjectTokenUnility validates_uniqueness_of :title ,:scope => [:obj_authable_type,:obj_authable_id] #{ |c| } belongs_to :obj_authable, polymorphic: true - after_save :check_user_has_app_auth + after_save :check_user_has_can_access_app # > - Something.find_with_auth(query) # > - or Something.find(query).auth def siblings @@ -14,15 +14,16 @@ class ObjectAuth < PrototypeAuth class_obj.find self.obj_authable_id end - def check_user_has_app_auth - sub_managing_users = auth_obj.app_auth.sub_managing_users rescue [] - app_auth = auth_obj.app_auth + def check_user_has_can_access_app + sub_managing_users = auth_obj.module_app.sub_managing_users rescue [] + module_app = auth_obj.module_app self.auth_users.each do |auth_user| if !sub_managing_users.include? auth_user && !auth_user.admin? - app_auth.assign_sub_manager(auth_user,User.current) - app_auth.save! + module_app.assign_sub_manager(auth_user,User.current) + module_app.save end end + end end \ No newline at end of file diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index cf72012b..eac9c40b 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -92,7 +92,7 @@ module OrbitCoreLib authed_users(title).include?(User.current) end - def app_auth + def module_app ModuleApp.first(conditions: {:title => self.class::APP_NAME} ) end diff --git a/lib/tasks/nccu.rake b/lib/tasks/nccu.rake index 8cae04e2..5dfaad00 100644 --- a/lib/tasks/nccu.rake +++ b/lib/tasks/nccu.rake @@ -78,10 +78,22 @@ namespace :nccu do end + task :add_nccu_account_1016 => :environment do + a = ["waynedd@nccu.edu.tw","sfchang@nccu.edu.tw","kyokolin@nccu.edu.tw","sfaylin@nccu.edu.tw","jinyulin@nccu.edu.tw"] + users_ary = User.any_in(email: a) + NewsBulletinCategory.all.each do |cate| + oa = ObjectAuth.first({conditions:{title: "submit",obj_authable_type: "NewsBulletinCategory",obj_authable_id: cate.id}}) + oa.privilege_users = oa.privilege_users + users_ary + oa.save + end + users_ary = User.any_in(email: a) + key = 'Announcement' + bc = BulletinCategory.first({conditions:{key: key}}) + oa = ObjectAuth.first({conditions:{title: "submit",obj_authable_type: "BulletinCategory",obj_authable_id: bc.id}}) + oa.privilege_users = oa.privilege_users + users_ary + oa.save - - - + end end \ No newline at end of file