diff --git a/app/assets/javascripts/hyrax/permissions/control.es6 b/app/assets/javascripts/hyrax/permissions/control.es6 index 48d1b8abbf..9e0b4487ea 100644 --- a/app/assets/javascripts/hyrax/permissions/control.es6 +++ b/app/assets/javascripts/hyrax/permissions/control.es6 @@ -2,6 +2,7 @@ import { Registry } from './registry' import { UserControls } from './user_controls' import { GroupControls } from './group_controls' import VisibilityComponent from '../save_work/visibility_component' +import AdminSetWidget from 'hyrax/editor/admin_set_widget' export default class PermissionsControl { /** @@ -14,13 +15,14 @@ export default class PermissionsControl { if (element.length === 0) { return } + this.adminSetWidget = new AdminSetWidget(element.find('select[id="admin_set_id"]')) this.element = element this.registry = new Registry(this.element, this.object_name(), template_id) this.user_controls = new UserControls(this.element, this.registry) this.group_controls = new GroupControls(this.element, this.registry) if (with_visibility_component) { - this.visibility_component = new VisibilityComponent(this.element) + this.visibility_component = new VisibilityComponent(this.element, this.adminSetWidget) } else { this.visibility_component = null } diff --git a/app/controllers/hyrax/file_sets_controller.rb b/app/controllers/hyrax/file_sets_controller.rb index 4fb3a9ded8..d0806a1442 100644 --- a/app/controllers/hyrax/file_sets_controller.rb +++ b/app/controllers/hyrax/file_sets_controller.rb @@ -43,6 +43,7 @@ class FileSetsController < ApplicationController # GET /concern/file_sets/:id def edit + @file_set_admin_set_option = file_set_admin_set_option initialize_edit_form end @@ -255,6 +256,19 @@ def add_breadcrumb_for_action end end + # Retrieves the admin set the file_set belongs to + def file_set_admin_set_option + return @admin_set_option if @admin_set_option + parent_work = parent(file_set: presenter) + admin_set_tesim = parent_work.solr_document[:admin_set_tesim].first + + service = Hyrax::AdminSetService.new(self) + admin_set_option = Hyrax::AdminSetOptionsPresenter.new(service).select_options.reject do |option| + option[0] != admin_set_tesim + end + admin_set_option + end + def initialize_edit_form guard_for_workflow_restriction_on!(parent: parent) @@ -267,6 +281,7 @@ def initialize_edit_form end @version_list = Hyrax::VersionListPresenter.for(file_set: file_set) @groups = current_user.groups + @is_admin = current_ability.admin? end include WorkflowsHelper # Provides #workflow_restriction?, and yes I mean include not helper; helper exposes the module methods diff --git a/app/helpers/hyrax/hyrax_helper_behavior.rb b/app/helpers/hyrax/hyrax_helper_behavior.rb index bd1d6030df..1af81dae80 100644 --- a/app/helpers/hyrax/hyrax_helper_behavior.rb +++ b/app/helpers/hyrax/hyrax_helper_behavior.rb @@ -24,8 +24,11 @@ module HyraxHelperBehavior # @return [Array] the list of all user groups def available_user_groups(ability:) return ::User.group_service.role_names if ability.admin? - - ability.user_groups + # Excluding "public" and "registered" groups if non-admin user + user_groups = ability.user_groups.dup + user_groups.delete("public") + user_groups.delete("registered") + user_groups end # Which translations are available for the user to select diff --git a/app/views/hyrax/file_sets/_admin_set_options.html.erb b/app/views/hyrax/file_sets/_admin_set_options.html.erb new file mode 100644 index 0000000000..31e7866ce7 --- /dev/null +++ b/app/views/hyrax/file_sets/_admin_set_options.html.erb @@ -0,0 +1,9 @@ + +<% if Flipflop.assign_admin_set? %> + <% if @file_set_admin_set_option.present? %> + <%= select_tag :admin_set_id, + options_for_select(@file_set_admin_set_option.map { |option| [option[0], option[1], option[2]] }), + include_blank: false, + class: 'form-control d-none' %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/hyrax/file_sets/_permission.html.erb b/app/views/hyrax/file_sets/_permission.html.erb index d0f3dcb0d3..3675300be1 100644 --- a/app/views/hyrax/file_sets/_permission.html.erb +++ b/app/views/hyrax/file_sets/_permission.html.erb @@ -5,6 +5,14 @@ data: { param_key: file_set.model_name.param_key }, class: 'nav-safety' } do |f| %> + + <% if !@is_admin %> +
+
+ <%= render 'admin_set_options' %> +
+
+ <% end %> <%= hidden_field_tag('redirect_tab', 'permissions') %> <%= render "permission_form", f: f %>
diff --git a/app/views/hyrax/file_sets/_permission_form.html.erb b/app/views/hyrax/file_sets/_permission_form.html.erb index 93da4743a3..ac2d1b2340 100644 --- a/app/views/hyrax/file_sets/_permission_form.html.erb +++ b/app/views/hyrax/file_sets/_permission_form.html.erb @@ -49,7 +49,7 @@
- <%= select_tag 'new_group_name_skel', options_for_select([t('.select_group')] + current_user.groups), class: 'form-control' %> + <%= select_tag 'new_group_name_skel', options_for_select([t('.select_group')] + available_user_groups(ability: current_ability)), class: 'form-control' %>
diff --git a/spec/controllers/hyrax/file_sets_controller_spec.rb b/spec/controllers/hyrax/file_sets_controller_spec.rb index 94c9ff8fc7..e1ef12396d 100644 --- a/spec/controllers/hyrax/file_sets_controller_spec.rb +++ b/spec/controllers/hyrax/file_sets_controller_spec.rb @@ -3,6 +3,7 @@ RSpec.describe Hyrax::FileSetsController do routes { Rails.application.routes } let(:user) { FactoryBot.create(:user) } + let(:admin_set) { FactoryBot.valkyrie_create(:hyrax_admin_set, user: user, with_permission_template: true) } let(:work_user) { user } before do allow(Hyrax.config.characterization_service).to receive(:run).and_return(true) @@ -545,7 +546,9 @@ let(:user) { FactoryBot.create(:user) } before { sign_in user } let(:file) { fixture_file_upload('/world.png', 'image/png') } - let(:work) { FactoryBot.valkyrie_create(:hyrax_work, title: "test title", uploaded_files: [FactoryBot.create(:uploaded_file, user: work_user)], edit_users: [work_user]) } + let(:work) do + FactoryBot.valkyrie_create(:hyrax_work, title: "test title", admin_set_id: admin_set.id, uploaded_files: [FactoryBot.create(:uploaded_file, user: work_user)], edit_users: [work_user]) + end let(:file_set) { query_service.find_members(resource: work).first } let(:file_metadata) { query_service.custom_queries.find_files(file_set: file_set).first } let(:uploaded) { storage_adapter.find_by(id: file_metadata.file_identifier) } diff --git a/spec/features/edit_file_spec.rb b/spec/features/edit_file_spec.rb index 870c2c836b..4f4c762c1c 100644 --- a/spec/features/edit_file_spec.rb +++ b/spec/features/edit_file_spec.rb @@ -3,6 +3,7 @@ let(:user) { create(:user) } let(:permission_template) { create(:permission_template, source_id: admin_set.id) } let!(:workflow) { create(:workflow, allows_access_grant: true, active: true, permission_template_id: permission_template.id) } + let(:options_presenter) { double(select_options: []) } let(:admin_set) do if Hyrax.config.disable_wings @@ -32,6 +33,8 @@ before do sign_in user + # mock the admin set options presenter to avoid hitting Solr + allow(Hyrax::AdminSetOptionsPresenter).to receive(:new).and_return(options_presenter) unless Hyrax.config.disable_wings Hydra::Works::AddFileToFileSet.call(file_set, file, :original_file)