orbit-basic/app/controllers/admin/app_auths_controller.rb

73 lines
2.2 KiB
Ruby
Raw Normal View History

2011-12-20 08:47:17 +00:00
class Admin::AppAuthsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
# before_filter :is_admin? ,:only => :index
2011-12-20 08:47:17 +00:00
def index
2012-01-12 06:13:41 +00:00
# @roles = Role.all.entries
# apps = Purchase.where(:type =>"App")
# @app_auth_data = apps.entries.map do |app|
# app_c = eval(app.app_controller)
# obj = app_c.new
# obj_auth = obj.send "auth"
# [:app_obj => app,:auth_field => obj_auth]
# end
if current_user.admin?
@module_apps = ModuleApp.all
else
@module_apps = current_user.managing_apps.collect{|t| t.managing_app}
end
2011-12-20 08:47:17 +00:00
end
def create
app_auth = AppAuth.find_or_create_by(module_app_id: params[:module_app_id])
params[:new].each do |item|
field = item[0]
field_value = item[1]
if field_value!=''
case field
when 'role'
app_auth.send("add_#{field}",(Role.find field_value)) rescue nil
when 'sub_role'
app_auth.send("add_#{field}",(SubRole.find field_value)) rescue nil
when 'privilege_user'
app_auth.add_user_to_privilege_list (User.find field_value) rescue nil
when 'blocked_user'
app_auth.add_user_to_black_list (User.find field_value) rescue nil
end
end
end
app = ModuleApp.find params[:module_app_id] rescue nil
redirect_to edit_admin_module_app_path(app)
end
def remove
app_auth = AppAuth.find( params[:id] )
type = params[:type]
field_value = params[:target_id]
if field_value!=''
case type
when 'role'
app_auth.remove_role(Role.find field_value) rescue nil
when 'sub_role'
app_auth.remove_sub_role(SubRole.find field_value) rescue nil
when 'privilege_user'
app_auth.remove_user_from_privilege_list (User.find field_value) rescue nil
when 'blocked_user'
app_auth.remove_user_from_black_list (User.find field_value) rescue nil
end
end
app = ModuleApp.find params[:module_app_id] rescue nil
redirect_to edit_admin_module_app_path(app)
end
2012-01-13 10:20:04 +00:00
def edit
@module_app = ModuleApp.find(params[:id])
end
2012-02-13 09:33:48 +00:00
def show
@module_app = ModuleApp.find(params[:id])
end
2012-01-13 10:20:04 +00:00
2011-12-20 08:47:17 +00:00
end