fix object auth without app_auth

This commit is contained in:
Matthew K. Fu JuYuan committed 2012-10-16 14:23:44 +08:00
1 parent d027cf8e6a
commit 6dfe10040b
6 files changed
+29 -14

No files matched your search

+3 -3
View File
@@ -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
+1 -1
View File
@@ -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
+7 -6
View File
@@ -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