63 lines
1.7 KiB
Ruby
63 lines
1.7 KiB
Ruby
class ModuleApp
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
field :title
|
|
field :version
|
|
field :organization
|
|
field :author
|
|
field :intro
|
|
field :update_info
|
|
field :create_date
|
|
field :enable_frontend,type: Boolean
|
|
|
|
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
|
|
|
|
has_one :app_auth,dependent: :delete
|
|
|
|
end
|