2011-12-20 08:47:17 +00:00
|
|
|
class Admin::ModuleAppsController < ApplicationController
|
2012-01-16 10:52:08 +00:00
|
|
|
before_filter :user_has_manager_privilege?, :only => [ :assign_manager, :remove_manager ]
|
|
|
|
before_filter :user_has_sub_manager_privilege?, :only => [ :assign_sub_manager, :remove_sub_manager ]
|
|
|
|
|
2012-04-27 10:38:21 +00:00
|
|
|
layout "new_admin"
|
2011-12-20 08:47:17 +00:00
|
|
|
|
2012-01-05 08:21:33 +00:00
|
|
|
def index
|
|
|
|
@module_apps = ModuleApp.all.entries
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def reload_frontend_pages
|
|
|
|
@module_app = ModuleApp.find(params[:id])
|
2012-08-09 07:25:30 +00:00
|
|
|
|
|
|
|
@frontend_path = @module_app.widgets.keys[0] if ( !@module_app.widgets.blank? && @module_app.widgets[0].blank? )
|
|
|
|
|
|
|
|
@frontend_style = @module_app.widgets[@frontend_path] if ( !@frontend_path.blank? )
|
|
|
|
|
2012-05-13 16:33:52 +00:00
|
|
|
case @module_app.key
|
|
|
|
when 'announcement'
|
|
|
|
@categories = BulletinCategory.all
|
|
|
|
@tags = AnnouncementTag.all
|
|
|
|
when 'news'
|
|
|
|
@categories = NewsBulletinCategory.all
|
|
|
|
@tags = NewsTag.all
|
|
|
|
when 'web_resource'
|
|
|
|
@categories = WebLinkCategory.all
|
|
|
|
@tags = WebResourceTag.all
|
2012-08-21 09:37:25 +00:00
|
|
|
when 'archive'
|
|
|
|
@categories = ArchiveFileCategory.all
|
|
|
|
@tags = ArchiveTag.all
|
2012-05-13 16:33:52 +00:00
|
|
|
end
|
2012-01-05 08:21:33 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.js {}
|
|
|
|
end
|
2011-12-20 08:47:17 +00:00
|
|
|
end
|
2012-01-12 06:13:41 +00:00
|
|
|
|
2012-05-10 03:51:44 +00:00
|
|
|
def module_auth_proc
|
|
|
|
@module_app = ModuleApp.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2012-01-12 06:13:41 +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
|
|
|
|
2012-01-12 06:13:41 +00:00
|
|
|
def update
|
|
|
|
@module_app = ModuleApp.find(params[:id])
|
|
|
|
unless params['module_app']['enable_frontend'].nil?
|
|
|
|
@module_app.update_attribute('enable_frontend',params['module_app']['enable_frontend'])
|
|
|
|
@module_app.save!
|
|
|
|
end
|
|
|
|
@attribute = @module_app
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :action => :index }
|
|
|
|
format.js { render 'admin/attributes/toggle_enable' }
|
|
|
|
end
|
|
|
|
end
|
2012-01-13 10:20:04 +00:00
|
|
|
|
2012-01-16 10:52:08 +00:00
|
|
|
|
2012-01-13 10:20:04 +00:00
|
|
|
def assign_sub_manager
|
2012-01-17 08:20:03 +00:00
|
|
|
unless @assign_to_user.nil? || @assign_to_user.admin?
|
2012-01-16 10:52:08 +00:00
|
|
|
if @module_app.assign_sub_manager(@assign_to_user,current_user)
|
|
|
|
flash[:notice] = t('admin.app_auth.assigning_manager.add_sub_manager_ok')
|
|
|
|
else
|
|
|
|
flash[:notice] = t('admin.app_auth.assigning_manager.add_sub_manager_fail')
|
|
|
|
end
|
2012-01-13 10:20:04 +00:00
|
|
|
else
|
2012-01-16 10:52:08 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.assigning_manager.failed_no_user')
|
|
|
|
end
|
2012-01-17 08:20:03 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.can_not_add_this_user')
|
|
|
|
redirect_to :action => "edit"
|
2012-01-13 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
2012-01-16 10:52:08 +00:00
|
|
|
|
2012-01-13 10:20:04 +00:00
|
|
|
def assign_manager
|
2012-01-17 08:20:03 +00:00
|
|
|
unless @assign_to_user.nil? || @assign_to_user.admin?
|
2012-01-13 10:20:04 +00:00
|
|
|
if @module_app.assign_manager(@assign_to_user,current_user)
|
2012-01-16 10:52:08 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.assigning_sub_manager.add_manager_ok')
|
2012-01-13 10:20:04 +00:00
|
|
|
else
|
2012-01-16 10:52:08 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.assigning_sub_manager.add_manager_fail')
|
2012-01-13 10:20:04 +00:00
|
|
|
end
|
|
|
|
else
|
2012-01-16 10:52:08 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.assigning_sub_manager.failed_no_user')
|
2012-01-13 10:20:04 +00:00
|
|
|
end
|
2012-01-17 08:20:03 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.can_not_add_this_user')
|
|
|
|
redirect_to :action => "edit"
|
2012-01-13 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
2012-01-16 10:52:08 +00:00
|
|
|
|
2012-01-13 10:20:04 +00:00
|
|
|
def remove_manager
|
2012-01-17 08:20:03 +00:00
|
|
|
@app_manager = AppManager.find(params[:app_manager_id])
|
2012-01-13 10:20:04 +00:00
|
|
|
if @module_app.remove_manager(@app_manager.user)
|
2012-01-16 10:52:08 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.delete_manager.success')
|
2012-01-13 10:20:04 +00:00
|
|
|
else
|
2012-01-16 10:52:08 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.delete_manager.fail')
|
2012-01-13 10:20:04 +00:00
|
|
|
end
|
|
|
|
redirect_to :action => "edit"
|
|
|
|
end
|
|
|
|
|
2012-01-16 10:52:08 +00:00
|
|
|
|
2012-01-13 10:20:04 +00:00
|
|
|
def remove_sub_manager
|
2012-01-17 08:20:03 +00:00
|
|
|
@app_sub_manager = AppManager.find(params[:app_sub_manager_id])
|
2012-01-13 10:20:04 +00:00
|
|
|
if @module_app.remove_sub_manager(@app_sub_manager.user)
|
2012-01-16 10:52:08 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.delete_sub_manager.success')
|
2012-01-13 10:20:04 +00:00
|
|
|
else
|
2012-01-16 10:52:08 +00:00
|
|
|
flash[:notice] = t('admin.app_auth.delete_sub_manager.fail')
|
2012-01-13 10:20:04 +00:00
|
|
|
end
|
|
|
|
redirect_to :action => "edit"
|
|
|
|
end
|
2012-01-16 10:52:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
def user_has_manager_privilege?
|
|
|
|
@module_app = ModuleApp.find(params[:id])
|
2012-01-19 09:47:52 +00:00
|
|
|
@assign_to_user = User.find params[:manager][:id] rescue nil
|
2012-01-16 10:52:08 +00:00
|
|
|
if current_user.admin? #only admin can assign app's manager
|
|
|
|
return
|
|
|
|
end
|
|
|
|
#user is not permited to do that
|
|
|
|
flash[:notice] = t('admin.app_auth.operation_not_permitted')
|
2012-02-17 09:50:23 +00:00
|
|
|
render :nothing => true, :status => 403
|
2012-01-16 10:52:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def user_has_sub_manager_privilege?
|
|
|
|
@module_app = ModuleApp.find(params[:id])
|
2012-01-19 09:47:52 +00:00
|
|
|
@assign_to_user = User.find params[:sub_manager][:id] rescue nil
|
2012-01-17 08:20:03 +00:00
|
|
|
if current_user.admin? || @module_app.managing_users.include?(current_user) #admin or app's manager can assign app's subanager
|
2012-01-16 10:52:08 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
#user is not permited to do that
|
|
|
|
flash[:notice] = t('admin.app_auth.operation_not_permitted')
|
2012-02-17 09:50:23 +00:00
|
|
|
render :nothing => true, :status => 403
|
2012-01-16 10:52:08 +00:00
|
|
|
end
|
|
|
|
|
2011-12-20 08:47:17 +00:00
|
|
|
end
|