Manger and SubManager
This commit is contained in:
1 parent
5ae8e84b93
commit
18a82d7f47
7 files changed
+157
No files matched your search
@@ -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
|
||||
@@ -14,9 +14,46 @@ 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
|
||||
|
||||
field :app_pages ,type: Array
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user