Manger and SubManager

This commit is contained in:
Matthew Fu 2012-01-13 18:20:04 +08:00
parent c0efb5d1bc
commit 42c89220e3
8 changed files with 158 additions and 1 deletions

View File

@ -15,4 +15,10 @@ class Admin::AppAuthsController < ApplicationController
@module_apps = ModuleApp.all @module_apps = ModuleApp.all
end end
def edit
@module_app = ModuleApp.find(params[:id])
end
end end

View File

@ -18,6 +18,7 @@ class Admin::ModuleAppsController < ApplicationController
end end
def update def update
@module_app = ModuleApp.find(params[:id]) @module_app = ModuleApp.find(params[:id])
unless params['module_app']['enable_frontend'].nil? unless params['module_app']['enable_frontend'].nil?
@ -30,4 +31,56 @@ class Admin::ModuleAppsController < ApplicationController
format.js { render 'admin/attributes/toggle_enable' } format.js { render 'admin/attributes/toggle_enable' }
end end
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 end

View File

@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
def front_end_available(module_app_title='') def front_end_available(module_app_title='')
app_controller = ModuleApp.first(conditions: {:title => module_app_title} ) app_controller = ModuleApp.first(conditions: {:title => module_app_title} )
unless app_controller.enable_frontend? unless app_controller.enable_frontend?
render :nothing render :nothing => true
end end
end end

12
app/models/app_manager.rb Normal file
View File

@ -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

View File

@ -14,8 +14,45 @@ class ModuleApp
field :app_pages ,type: Array field :app_pages ,type: Array
field :widgets ,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 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
end end

View File

@ -14,6 +14,9 @@ class User
has_many :app_auths,as: :privilege_apps,:inverse_of => :privilege_lists has_many :app_auths,as: :privilege_apps,:inverse_of => :privilege_lists
has_many :blocked_apps, :inverse_of => :blocked_users, :class_name => "AppAuth" has_many :blocked_apps, :inverse_of => :blocked_users, :class_name => "AppAuth"
has_many :privilege_apps, :inverse_of => :privilege_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 belongs_to :role
has_and_belongs_to_many :sub_roles has_and_belongs_to_many :sub_roles
accepts_nested_attributes_for :attribute_values, :allow_destroy => true accepts_nested_attributes_for :attribute_values, :allow_destroy => true

View File

@ -0,0 +1,41 @@
<% content_for :secondary do %>
<% end %>
<!-- Remove if CSS done-->
<br />
<br />
<br />
<!-- Remove if CSS done-->
<div id="manager_management">
<h1><%= @module_app.title %></h1>
<dl id="manager">
<dt>Manager</ht>
<% @module_app.managers.each do |manager| %>
<dd><%= manager.user.name %> -AuthBy:<%= manager.rule_creator.name %> <%= link_to '[X]',remove_manager_admin_module_app_path(@module_app,manager),:method => :delete unless manager.user == current_user%> </dd>
<% end %>
<dd>Add:
<%= form_tag(assign_manager_admin_module_app_path) do %>
<%= text_field_tag 'manager_id' %>
<%= submit_tag 'Add Manager' %>
<% end %>
</dd>
</dl>
<dl id="sub_manager">
<dt>Sub Manager</ht>
<% @module_app.sub_managers.each do |manager| %>
<dd><%= manager.user.name %> -AuthBy:<%= manager.rule_creator.name %> <%= link_to '[X]',remove_sub_manager_admin_module_app_path(@module_app,manager),:method => :delete unless manager.user == current_user%> </dd>
<% end %>
<dd>Add:
<%= form_tag(assign_sub_manager_admin_module_app_path) do %>
<%= text_field_tag 'sub_manager_id' %>
<%= submit_tag 'Add Sub Manager' %>
<% end %>
</dd>
</dl>
</div>

View File

@ -40,6 +40,11 @@ PrototypeR4::Application.routes.draw do
end end
resources :module_apps do resources :module_apps do
member do member do
match 'assign_manager' ,:action=> 'assign_manager',:via => "post",:as =>:assign_manager
match 'assign_sub_manager' ,:action=> 'assign_sub_manager',:via => "post",:as =>:assign_sub_manager
match 'remove_manager/:app_manager_id' ,:action=> 'remove_manager',:via => "delete",:as =>:remove_manager
match 'remove_sub_manager/:app_sub_manager_id' ,:action=> 'remove_sub_manager',:via => "delete",:as =>:remove_sub_manager
get 'reload_frontend_pages' get 'reload_frontend_pages'
end end
end end