Change authorization to accept other than category

This commit is contained in:
chris committed 2013-07-25 17:36:55 +08:00
1 parent 0c208d0020
commit da1d70efcb
7 files changed
+60 -52

No files matched your search

@@ -5,26 +5,25 @@ class Admin::AuthorizationsController < OrbitBackendController
def index
@module_apps ||= ModuleApp.where(is_authorizable: true).order_by([:title, :asc])
if @module_apps && @module_apps.include?(@module_app)
case @type
when 'category'
type = 'submit'
when 'approval'
type = 'fact_check'
else
@users = @module_app.managing_users
end
if type
if @module_app.has_category
@categories = @module_app.categories
unless @categories.blank?
@category ||= @categories.first
@users = @category.get_object_auth_by_title("#{type}_#{@module_app.key}").auth_users
if @type
case @type
when 'category', 'approval'
if @module_app.has_category
@objects = @module_app.categories
else
@error = t(:no_category)
end
else
@error = t(:no_category)
@objects = @klass.all
end
unless @objects.blank?
@object ||= @objects.first
@users = @object.get_object_auth_by_title("#{@type}_#{@module_app.key}").auth_users
else
@error = t(:no_data)
end
else
@users = @module_app.managing_users
end
elsif @module_apps
@module_app = @module_apps.first
@@ -36,21 +35,15 @@ class Admin::AuthorizationsController < OrbitBackendController
def add(users)
unless users.blank?
case @type
when 'category'
type = 'submit'
when 'approval'
type = 'fact_check'
else
add_managers(users) unless users.blank?
end
if type
if @category
object_auth = @category.get_object_auth_by_title("#{type}_#{@module_app.key}")
if @type
if @object
object_auth = @object.get_object_auth_by_title("#{@type}_#{@module_app.key}")
add_users_to_object_auth(object_auth, users)
else
@error = t(:no_category)
@error = t(:no_data)
end
else
add_managers(users) unless users.blank?
end
end
@users = users
@@ -74,9 +67,8 @@ class Admin::AuthorizationsController < OrbitBackendController
def modal_select
existing_users = User.find(params[:ids]) rescue []
roles = Role.all
case @type
when 'category', 'approval'
@category_id = @category.id if @category
if @type
@object_id = @object.id if @object
@sorted_users = roles.inject({}) do |users, role|
users[role] = role.users.where(admin: false).not_guest_user - existing_users - @module_app.managing_users
users
@@ -92,18 +84,16 @@ class Admin::AuthorizationsController < OrbitBackendController
def remove_users
@users = User.find(params[:ids]) rescue []
unless @users.blank?
case @type
when 'category'
type = 'submit'
when 'approval'
type = 'fact_check'
if @type
if @object
object_auth = @object.get_object_auth_by_title("#{@type}_#{@module_app.key}")
remove_users_form_object_auth(object_auth, @users)
else
@error = t(:no_data)
end
else
remove_managers(@users)
end
if type
object_auth = @category.get_object_auth_by_title("#{type}_#{@module_app.key}")
remove_users_form_object_auth(object_auth, @users)
end
end
render 'admin/authorizations/remove_users'
end
@@ -144,8 +134,11 @@ class Admin::AuthorizationsController < OrbitBackendController
def setup_vars
@module_app = ModuleApp.first(conditions: {:key => params[:module]} ) if params[:module]
@category = Category.find(params[:id]) rescue nil
@type = params[:type]
@type = params[:type].underscore if params[:type]
if @type
@klass = @type.classify.constantize
@object = @klass.find(params[:id]) rescue nil
end
end
def user_is_manager?
+1 -1
View File
@@ -410,7 +410,7 @@ class ApplicationController < ActionController::Base
if check_permission(:manager)
object.create_user_id != current_user.id
else
!object.category.authed_users('fact_check').include?(current_user) rescue false
!object.category.authed_users("approval_#{@module_app.key}").include?(current_user) rescue false
end
else
false