diff --git a/app/controllers/admin/authorizations_controller.rb b/app/controllers/admin/authorizations_controller.rb index e293a25c2..07b0de7f8 100644 --- a/app/controllers/admin/authorizations_controller.rb +++ b/app/controllers/admin/authorizations_controller.rb @@ -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? diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f93dea0bd..6bc21b1bf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/helpers/orbit_backend_helper.rb b/app/helpers/orbit_backend_helper.rb index 33fa94447..f99245bd4 100644 --- a/app/helpers/orbit_backend_helper.rb +++ b/app/helpers/orbit_backend_helper.rb @@ -12,13 +12,13 @@ module OrbitBackendHelper def show_form_status_field(object) #by_object = (!object.is_expired? and object.is_pending?) - by_user = ((object.category.authed_users("fact_check_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?) + by_user = ((object.category.authed_users("approval_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?) by_user end def show_approval_link(object) by_object = (!object.is_expired? and object.is_pending?) - by_user = ((object.category.authed_users("fact_check_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?) + by_user = ((object.category.authed_users("approval_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?) by_object and by_user end @@ -279,6 +279,10 @@ module OrbitBackendHelper if show_approval_link(object) content_tag :li, link_to(t(quick[:translation] || :approval_), eval("#{quick[:link]}('#{object.id}')"), class: "preview_trigger #{quick[:class]}") end + when 'authorization' + if authorization + content_tag :li, link_to(t(quick[:translation] || :authorization_), eval("#{quick[:link]}"), class: "preview_trigger #{quick[:class]}") + end when 'edit' if authorization || approvable content_tag :li, link_to(t(quick[:translation] || :edit), eval("#{quick[:link]}('#{object.id}')"), class: quick[:class]) diff --git a/app/views/admin/authorizations/index.html.erb b/app/views/admin/authorizations/index.html.erb index 24f4a80a2..93d1d951c 100644 --- a/app/views/admin/authorizations/index.html.erb +++ b/app/views/admin/authorizations/index.html.erb @@ -5,7 +5,7 @@
@@ -14,12 +14,14 @@