2012-05-16 04:10:16 +00:00
|
|
|
class Admin::ModuleAppsNewInterfaceController < OrbitBackendController
|
2013-03-07 08:51:47 +00:00
|
|
|
before_filter :check_auth
|
|
|
|
# before_filter :authenticate_user!
|
|
|
|
# before_filter :is_admin?
|
2012-05-11 08:44:40 +00:00
|
|
|
include AdminHelper
|
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
def index
|
|
|
|
@module_app = ModuleApp.find params[:module_app_id]
|
|
|
|
@managers = @module_app.managing_users
|
|
|
|
end
|
2012-05-11 08:44:40 +00:00
|
|
|
|
2013-03-07 08:51:47 +00:00
|
|
|
def check_auth
|
|
|
|
|
|
|
|
unless is_admin? and is_manager?
|
|
|
|
flash[:error] = "unauthorized access"
|
|
|
|
if request.env["HTTP_REFERER"]
|
|
|
|
redirect_to :back
|
|
|
|
else
|
|
|
|
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
|
|
|
|
end
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-11 08:44:40 +00:00
|
|
|
def setting
|
2012-12-19 10:51:17 +00:00
|
|
|
@sys_users = User.all(conditions: {admin: false}).includes(:avatar).not_guest_user
|
2012-05-11 08:44:40 +00:00
|
|
|
@module_app = ModuleApp.find(params[:module_app_id])
|
|
|
|
@options_from_collection_for_select_bulletin_categorys = [@module_app].collect{|ma| [ma.title,ma.id] }
|
|
|
|
# if params.has_key? :category
|
|
|
|
# @bulletin_category = BulletinCategory.find params[:category][:id]
|
|
|
|
# else
|
|
|
|
# @bulletin_category = @bulletin_categorys.first
|
|
|
|
# end
|
|
|
|
@users_array = @module_app.managing_users rescue []
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_setting
|
|
|
|
module_app = update_setting_by_params
|
|
|
|
if module_app.save!
|
2012-09-12 11:12:50 +00:00
|
|
|
flash[:notice] = t('update.success_')
|
2012-05-11 08:44:40 +00:00
|
|
|
else
|
2012-09-12 11:12:50 +00:00
|
|
|
flash[:notice] = t('update.fail')
|
2012-05-11 08:44:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_list
|
|
|
|
@module_app = ModuleApp.find params[:module_app][:id]
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
def update_setting_by_params
|
2012-05-15 08:39:23 +00:00
|
|
|
user_sat = []
|
2012-05-11 08:44:40 +00:00
|
|
|
ma = ModuleApp.find params[:module_app][:id]
|
2012-05-18 07:20:45 +00:00
|
|
|
user_sat += User.find params[:users].keys if params.has_key?('users')
|
2012-05-11 08:44:40 +00:00
|
|
|
users_to_new = user_sat - ma.managing_users
|
|
|
|
users_to_remove = ma.managing_users - user_sat
|
|
|
|
|
|
|
|
users_to_new.each do |new_user|
|
|
|
|
ma.assign_manager(new_user,current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
users_to_remove.each do |remove_user|
|
|
|
|
ma.remove_manager(remove_user)
|
|
|
|
end
|
|
|
|
ma
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_categorys(id = nil)
|
|
|
|
@bulletin_categorys = []
|
|
|
|
if(is_manager? || is_admin?)
|
2012-07-09 04:05:21 +00:00
|
|
|
@bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.all)
|
2012-05-11 08:44:40 +00:00
|
|
|
elsif is_sub_manager?
|
|
|
|
@bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-19 10:51:17 +00:00
|
|
|
end
|