Orbit/app/models/object_auth.rb

33 lines
1.0 KiB
Ruby
Raw Permalink Normal View History

class ObjectAuth < PrototypeAuth
2012-12-03 10:52:36 +00:00
include OrbitCoreLib::ObjectTokenUtility
validates_uniqueness_of :title ,:scope => [:obj_authable_type,:obj_authable_id] #{ |c| }
belongs_to :obj_authable, polymorphic: true
2012-10-16 06:23:44 +00:00
after_save :check_user_has_can_access_app
# > - Something.find_with_auth(query)
# > - or Something.find(query).auth
2012-10-04 10:20:21 +00:00
def siblings
ObjectAuth.where({obj_authable_type: obj_authable_type,title: title})
end
def auth_obj
class_obj = eval(self.obj_authable_type)
class_obj.find self.obj_authable_id
end
2012-10-16 06:23:44 +00:00
def check_user_has_can_access_app
if auth_obj.is_a?(PageContext)
module_app = ModuleApp.where(key: 'page_content').first
else
module_app = auth_obj.module_app
end
sub_managing_users = module_app.sub_managing_users rescue []
self.auth_users.each do |auth_user|
if !sub_managing_users.include? auth_user && !auth_user.admin?
2012-10-16 06:23:44 +00:00
module_app.assign_sub_manager(auth_user,User.current)
module_app.save
end
end
2012-10-16 06:23:44 +00:00
end
end