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 @@
<%= link_to t(:module_authorization), admin_authorizations_path(@module_app.key) %> - <%= link_to t(:category_auth), admin_authorizations_path(@module_app.key, type: 'category') %> - <%= link_to t(:approval_), admin_authorizations_path(@module_app.key, type: 'approval') %> + <% @module_app.authorizable_models.each do |authorizable_model| %> + <%= link_to (authorizable_model.eql?('Category') ? t(:category_auth) : "#{authorizable_model.underscore.humanize} #{t(:authorization_)}"), admin_authorizations_path(@module_app.key, type: authorizable_model) %> + <% end %> + <%= link_to t(:approval_), admin_authorizations_path(@module_app.key, type: 'approval') if @module_app.is_approvable %> <% if @error %> <%= @error %> <% else %> - <%= select_tag :category, options_from_collection_for_select(@categories, "id", "title", @category.id), :onchange => "window.location.href = '/admin/authorizations/'+'#{@module_app.key}/#{@type}/'+$(this).val();" if @categories %> + <%= select_tag @type.underscore.humanize, options_from_collection_for_select(@objects, "id", "title", @object.id), :onchange => "window.location.href = '/admin/authorizations/'+'#{@module_app.key}/#{@type}/'+$(this).val();" if @objects %> @@ -30,7 +32,7 @@
- <%= link_to content_tag(:i, nil, class: "icons-plus") + ' ' + t(:add), '#', class: 'btn btn-primary select_user_modal', rel: admin_modal_select_authorizations_path(@module_app.key, @type, @category) %> - <%= link_to content_tag(:i, nil, class: "icon-trash") + ' ' + t(:delete), '#', id: 'remove_users', class: 'btn btn-danger', rel: admin_remove_users_authorizations_path(@module_app.key, @type, @category) %> + <%= link_to content_tag(:i, nil, class: "icons-plus") + ' ' + t(:add), '#', class: 'btn btn-primary select_user_modal', rel: admin_modal_select_authorizations_path(@module_app.key, @type, @object) %> + <%= link_to content_tag(:i, nil, class: "icon-trash") + ' ' + t(:delete), '#', id: 'remove_users', class: 'btn btn-danger', rel: admin_remove_users_authorizations_path(@module_app.key, @type, @object) %>
diff --git a/app/views/admin/authorizations/modal_select.js.erb b/app/views/admin/authorizations/modal_select.js.erb index 41e31a170..900185629 100644 --- a/app/views/admin/authorizations/modal_select.js.erb +++ b/app/views/admin/authorizations/modal_select.js.erb @@ -1,2 +1,2 @@ -$("#select_user").html("<%= j render partial: 'admin/member_selects/modal_select', locals: {role_form_url: admin_add_roles_authorizations_path(@module_app.key, @type, @category_id), user_form_url: admin_add_users_authorizations_path(@module_app.key, @type, @category_id)} %>"); +$("#select_user").html("<%= j render partial: 'admin/member_selects/modal_select', locals: {role_form_url: admin_add_roles_authorizations_path(@module_app.key, @type, @object_id), user_form_url: admin_add_users_authorizations_path(@module_app.key, @type, @cobject_id)} %>"); $("#member-filter").modal(); \ No newline at end of file diff --git a/config/locales/new_ui.en.yml b/config/locales/new_ui.en.yml index 21bdbfda2..1aca842a6 100644 --- a/config/locales/new_ui.en.yml +++ b/config/locales/new_ui.en.yml @@ -5,6 +5,7 @@ en: add_to_default: Add to default alternative: Alternative approval_setting: Approval Setting + authorization_: Authorization change: Change change_file: Change file create: @@ -31,8 +32,10 @@ en: next: Next no_app: No module no_category: No Available Category + no_data: No data no_date: No date no_file: No file + path: Path previous: Previous remove: Remove remove_default: Remove default diff --git a/lib/tasks/new_ui.rake b/lib/tasks/new_ui.rake index a90fc80b1..70584a8db 100644 --- a/lib/tasks/new_ui.rake +++ b/lib/tasks/new_ui.rake @@ -53,7 +53,7 @@ namespace :new_ui do when 'fact_check' new_object_auth = new_category.get_object_auth_by_title("approval_#{module_app.key}") else - new_object_auth = new_category.get_object_auth_by_title("submit_#{module_app.key}") + new_object_auth = new_category.get_object_auth_by_title("category_#{module_app.key}") end object_auth.auth_users.each do |user| new_object_auth.add_user_to_privilege_list(user) @@ -85,4 +85,10 @@ namespace :new_ui do end end + task :change_auth_naming => :environment do + ObjectAuth.where(title: /submit_/).each do |auth| + auth.update_attribute(:title, auth.title.gsub('submit_', 'category_')) + end + end + end