diff --git a/app/controllers/admin/app_auths_controller.rb b/app/controllers/admin/app_auths_controller.rb
index e925b857..6cbbf62e 100644
--- a/app/controllers/admin/app_auths_controller.rb
+++ b/app/controllers/admin/app_auths_controller.rb
@@ -15,4 +15,10 @@ class Admin::AppAuthsController < ApplicationController
@module_apps = ModuleApp.all
end
+ def edit
+ @module_app = ModuleApp.find(params[:id])
+ end
+
+
+
end
\ No newline at end of file
diff --git a/app/controllers/admin/module_apps_controller.rb b/app/controllers/admin/module_apps_controller.rb
index 142830f1..34fcf1fd 100644
--- a/app/controllers/admin/module_apps_controller.rb
+++ b/app/controllers/admin/module_apps_controller.rb
@@ -18,6 +18,7 @@ class Admin::ModuleAppsController < ApplicationController
end
+
def update
@module_app = ModuleApp.find(params[:id])
unless params['module_app']['enable_frontend'].nil?
@@ -30,4 +31,56 @@ class Admin::ModuleAppsController < ApplicationController
format.js { render 'admin/attributes/toggle_enable' }
end
end
+
+ def assign_sub_manager
+ @module_app = ModuleApp.find(params[:id])
+ @assign_to_user = User.find params[:sub_manager_id] rescue nil
+ unless @assign_to_user.nil?
+ if @module_app.assign_sub_manager(@assign_to_user,current_user)
+ flash[:notice] = t('admin.app_auth.assign_success_sub_manager')
+ else
+ flash[:notice] = t('admin.app_auth.assign_fail_sub_manager')
+ end
+ else
+ flash[:notice] = t('admin.app_auth.assign_fail_sub_manager_no_user')
+ end
+ redirect_to :action => "edit"
+ end
+
+ def assign_manager
+ @module_app = ModuleApp.find(params[:id])
+ @assign_to_user = User.find params[:manager_id] rescue nil
+ unless @assign_to_user.nil?
+ if @module_app.assign_manager(@assign_to_user,current_user)
+ flash[:notice] = t('admin.app_auth.assign_success_manager')
+ else
+ flash[:notice] = t('admin.app_auth.assign_fail_manager')
+ end
+ else
+ flash[:notice] = t('admin.app_auth.assign_fail_manager_no_user')
+ end
+ redirect_to :action => "edit"
+ end
+
+ def remove_manager
+ @module_app = ModuleApp.find(params[:id])
+ @app_manager = AppManager.find(params[:app_manager_id]) rescue nil
+ if @module_app.remove_manager(@app_manager.user)
+ flash[:notice] = t('admin.app_auth.delete_success_manager')
+ else
+ flash[:notice] = t('admin.app_auth.delete_fail_manager')
+ end
+ redirect_to :action => "edit"
+ end
+
+ def remove_sub_manager
+ @module_app = ModuleApp.find(params[:id])
+ @app_sub_manager = AppManager.find(params[:app_sub_manager_id]) rescue nil
+ if @module_app.remove_sub_manager(@app_sub_manager.user)
+ flash[:notice] = t('admin.app_auth.delete_success_sub_manager')
+ else
+ flash[:notice] = t('admin.app_auth.delete_fail_sub_manager')
+ end
+ redirect_to :action => "edit"
+ end
end
\ No newline at end of file
diff --git a/app/models/app_manager.rb b/app/models/app_manager.rb
new file mode 100644
index 00000000..46cbbb91
--- /dev/null
+++ b/app/models/app_manager.rb
@@ -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
\ No newline at end of file
diff --git a/app/models/module_app.rb b/app/models/module_app.rb
index d398f7ef..029d55fa 100644
--- a/app/models/module_app.rb
+++ b/app/models/module_app.rb
@@ -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
diff --git a/app/models/user/user.rb b/app/models/user/user.rb
index 60199ce7..13d282bb 100644
--- a/app/models/user/user.rb
+++ b/app/models/user/user.rb
@@ -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
diff --git a/app/views/admin/module_apps/edit.html.erb b/app/views/admin/module_apps/edit.html.erb
new file mode 100644
index 00000000..ff967273
--- /dev/null
+++ b/app/views/admin/module_apps/edit.html.erb
@@ -0,0 +1,41 @@
+<% content_for :secondary do %>
+<% end %>
+
+
+
+
+
+
+
+