diff --git a/app/controllers/stash_api/datasets_controller.rb b/app/controllers/stash_api/datasets_controller.rb index 116eb44ca8..a764e24369 100644 --- a/app/controllers/stash_api/datasets_controller.rb +++ b/app/controllers/stash_api/datasets_controller.rb @@ -579,7 +579,7 @@ def check_may_set_payment_id def duplicate_resource nr = @resource.amoeba_dup nr.curation_activities&.update_all(user_id: @user.id) - nr.current_editor_id = @resource.user_id + nr.current_editor_id = @user.id nr.save! @resource = nr end diff --git a/app/controllers/stash_datacite/resources_controller/dataset_presenter.rb b/app/controllers/stash_datacite/resources_controller/dataset_presenter.rb index 15970cca84..64285bcfb6 100644 --- a/app/controllers/stash_datacite/resources_controller/dataset_presenter.rb +++ b/app/controllers/stash_datacite/resources_controller/dataset_presenter.rb @@ -54,12 +54,12 @@ def publication_date def edited_by_name u = resource.editor - u = resource.user if u.nil? + u = resource.submitter if u.nil? "#{u.first_name} #{u.last_name}" end def edited_by_name_w_role - return edited_by_name if resource.current_editor_id.nil? || resource.user_id == resource.current_editor_id + return edited_by_name if resource.current_editor_id.nil? || resource.users.pluck(&:id).include?(resource.current_editor_id) "#{edited_by_name} (admin)" end diff --git a/app/controllers/stash_engine/admin_dashboard_controller.rb b/app/controllers/stash_engine/admin_dashboard_controller.rb index cb70165554..51337ec682 100644 --- a/app/controllers/stash_engine/admin_dashboard_controller.rb +++ b/app/controllers/stash_engine/admin_dashboard_controller.rb @@ -15,7 +15,7 @@ def index; end def results @datasets = StashEngine::Resource.latest_per_dataset.select( :id, :title, :total_file_size, :user_id, :tenant_id, :identifier_id, :last_curation_activity_id, :publication_date, - :current_editor_id, :current_resource_state_id + :user_id, :current_resource_state_id ).distinct add_fields @@ -117,7 +117,7 @@ def setup_paging # rubocop:disable Style/MultilineIfModifier def setup_limits session[:admin_search_role] = params[:user_role] if params[:user_role].present? - @user_role = current_user.roles.find_by(id: session[:admin_search_role]) || current_user.roles.first + @user_role = current_user.roles.admin_roles.find_by(id: session[:admin_search_role]) || current_user.roles.admin_roles.first @role_object = @user_role.role_object @tenant_limit = @role_object.is_a?(StashEngine::Tenant) ? policy_scope(StashEngine::Tenant) : StashEngine::Tenant.enabled if @role_object.is_a?(StashEngine::JournalOrganization) @@ -187,12 +187,8 @@ def view_field end def curator_field - @datasets = @datasets.joins("left outer join ( - select stash_engine_users.* from stash_engine_users - inner join stash_engine_roles on stash_engine_users.id = stash_engine_roles.user_id - and role in ('curator', 'superuser') - ) curator on curator.id = stash_engine_resources.current_editor_id") - .select("CONCAT_WS(' ', curator.first_name, curator.last_name) as curator_name") + @datasets = @datasets.left_outer_joins(:curator) + .select("CONCAT_WS(' ', stash_engine_users.first_name, stash_engine_users.last_name) as curator_name") end def author_field @@ -229,7 +225,7 @@ def add_filters :affiliation, :value ).present? @datasets = @datasets.where( - 'curator.id': Integer(@filters[:curator], exception: false) ? @filters[:curator] : nil + 'stash_engine_users.id': Integer(@filters[:curator], exception: false) ? @filters[:curator] : nil ) if @filters[:curator].present? && current_user.min_app_admin? unless @search_string.blank? search_string = %r{^10.[\S]+/[\S]+$}.match(@search_string) ? "\"#{@search_string}\"" : @search_string @@ -332,7 +328,7 @@ def add_subqueries @datasets = @datasets.preload(:authors) if @fields.include?('authors') @datasets = @datasets.preload(:tenant).preload(authors: :affiliations) if @fields.include?('affiliations') @datasets = @datasets.preload(tenant: :ror_orgs).preload(authors: { affiliations: :ror_org }) if @fields.include?('countries') - @datasets = @datasets.preload(:user) if @fields.include?('submitter') + @datasets = @datasets.preload(:roles) if @fields.include?('submitter') @datasets = @datasets.preload(identifier: :counter_stat) if @fields.include?('metrics') if @fields.include?('journal') || @fields.include?('sponsor') || @fields.include?('identifiers') @datasets = @datasets.preload(:resource_publication) @@ -357,7 +353,7 @@ def curation_activity_change decipher_curation_activity @note = params.dig(:curation_activity, :note) - @resource.current_editor_id = current_user.id + @resource.user_id = current_user.id @resource.publication_date = @pub_date @resource.hold_for_peer_review = true if @status == 'peer_review' @resource.peer_review_end_date = (Time.now.utc + 6.months) if @status == 'peer_review' @@ -418,11 +414,11 @@ def state_error def current_editor_change editor_id = params.dig(:current_editor, :id) if editor_id&.to_i == 0 - @resource.update(current_editor_id: nil) + @resource.update(user_id: nil) @status = 'submitted' if @resource.current_curation_status == 'curation' @curator_name = '' else - @resource.update(current_editor_id: editor_id) + @resource.update(user_id: editor_id) @curator_name = StashEngine::User.find(editor_id)&.name end @note = "Changing current editor to #{@curator_name.presence || 'unassigned'}. " + params.dig(:curation_activity, :note) diff --git a/app/controllers/stash_engine/admin_datasets_controller/stats.rb b/app/controllers/stash_engine/admin_datasets_controller/stats.rb index eb67fe82e1..ed02ccafb1 100644 --- a/app/controllers/stash_engine/admin_datasets_controller/stats.rb +++ b/app/controllers/stash_engine/admin_datasets_controller/stats.rb @@ -60,7 +60,7 @@ def datasets_with_resource_state_count(state:) def datasets_with_curation_status_count(status:, only_unclaimed: false) query = "#{STATUS_QUERY_BASE} WHERE ser.updated_at < '#{@untouched_since}' AND ser.created_at > '#{@since}' AND seca.status = '#{status}'" - query += ' AND (ser.current_editor_id is NULL or ser.current_editor_id = ser.user_id)' if only_unclaimed + query += ' AND (ser.user_id is NULL)' if only_unclaimed ApplicationRecord.connection.execute(query)&.first&.first end diff --git a/app/controllers/stash_engine/application_controller.rb b/app/controllers/stash_engine/application_controller.rb index 90a5198d7c..1a3fdc5535 100644 --- a/app/controllers/stash_engine/application_controller.rb +++ b/app/controllers/stash_engine/application_controller.rb @@ -33,7 +33,7 @@ def user_not_authorized end def display_authorization_failure - Rails.logger.warn("Resource #{resource ? resource.id : 'nil'}: user ID is #{resource.user_id || 'nil'} but " \ + Rails.logger.warn("Resource #{resource ? resource.id : 'nil'}: user IDs are #{resource.users&.map(&:id)&.join(', ')} but " \ "current user is #{current_user.id || 'nil'}") flash[:alert] = 'You do not have permission to modify this dataset.' redirect_back(fallback_location: choose_dashboard_path) diff --git a/app/controllers/stash_engine/dashboard_controller.rb b/app/controllers/stash_engine/dashboard_controller.rb index 35b26ab82e..b408615cae 100644 --- a/app/controllers/stash_engine/dashboard_controller.rb +++ b/app/controllers/stash_engine/dashboard_controller.rb @@ -29,8 +29,18 @@ def user_datasets @page_size = params[:page_size] || '10' respond_to do |format| format.js do - @datasets = policy_scope(Identifier, policy_scope_class: IdentifierPolicy::DashboardScope).page(@page).per(@page_size) - @datasets = @datasets.preload(latest_resource: %i[last_curation_activity stash_version current_resource_state]) + @datasets = current_user.resources.latest_per_dataset.distinct + .joins(:last_curation_activity) + .select("stash_engine_resources.*, + CASE + WHEN status in ('in_progress', 'action_required') THEN 0 + WHEN status='peer_review' THEN 1 + WHEN status in ('submitted', 'curation', 'processing') THEN 2 + WHEN status='withdrawn' THEN 4 + ELSE 3 + END as sort_order") + .order('sort_order asc, stash_engine_resources.updated_at desc').page(@page).per(@page_size) + @datasets = @datasets.preload(%i[last_curation_activity stash_version current_resource_state]) end end end diff --git a/app/controllers/stash_engine/metadata_entry_pages_controller.rb b/app/controllers/stash_engine/metadata_entry_pages_controller.rb index 9c7ed78094..6b4a9c3904 100644 --- a/app/controllers/stash_engine/metadata_entry_pages_controller.rb +++ b/app/controllers/stash_engine/metadata_entry_pages_controller.rb @@ -51,9 +51,9 @@ def edit_by_doi note: "Transferring ownership to #{current_user.name} (#{current_user.id}) using an edit code" ) @resource.curation_activities << ca - @resource.user_id = current_user.id - @resource.current_editor_id = current_user.id - @resource.save + @resource.submitter = current_user.id + @resource.update(current_editor_id: current_user.id) + @resource.reload else # The user will need to login (possibly creating an # account), and then they will be redirected back to this @@ -68,7 +68,7 @@ def edit_by_doi # that they have access to edit this dataset. But if they were not logged in, # log them in as the dataset owner, and ensure the tenant_id is set correctly. unless current_user - session[:user_id] = resource.user_id + session[:user_id] = resource.submitter.id if current_user.tenant_id.blank? session[:target_page] = stash_url_helpers.metadata_entry_pages_find_or_create_path(resource_id: resource.id) redirect_to stash_url_helpers.choose_sso_path and return @@ -136,7 +136,7 @@ def accept_agreement private def ownership_transfer_needed? - valid_edit_code? && (resource.user_id == 0) + (valid_edit_code? && resource.submitter.id == 0) || resource.submitter.blank? end def resource_exist diff --git a/app/controllers/stash_engine/pages_controller.rb b/app/controllers/stash_engine/pages_controller.rb index b7011585ab..dd62b35719 100644 --- a/app/controllers/stash_engine/pages_controller.rb +++ b/app/controllers/stash_engine/pages_controller.rb @@ -25,37 +25,5 @@ def sitemap def app_404 render status: :not_found end - - private - - # TODO: need to change query so it's not tenant-specific - def find_identifiers(my_tenant) - join_conditions = <<-SQL - INNER JOIN stash_engine_resources - ON stash_engine_identifiers.id = stash_engine_resources.identifier_id - INNER JOIN stash_engine_users - ON stash_engine_resources.user_id = stash_engine_users.id - SQL - - Identifier.select(:id, :identifier, :identifier_type, :updated_at).distinct - .joins(join_conditions) - .where('stash_engine_users.tenant_id = ?', my_tenant.id) - end - - def gen_xml_from_identifiers(ar_identifiers) - builder = Nokogiri::XML::Builder.new do |xml| - xml.urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do - ar_identifiers.each { |iden| add_url(xml, iden) } - end - end - builder.to_xml - end - - def add_url(xml, identifier) - xml.url do - xml.loc "https://#{Rails.application.default_url_options[:host]}#{APP_CONFIG.stash_mount}/dataset/#{identifier}" - xml.lastmod identifier.updated_at.strftime('%Y-%m-%d') - end - end end end diff --git a/app/controllers/stash_engine/resources_controller.rb b/app/controllers/stash_engine/resources_controller.rb index dc82e85609..61bc9d00ac 100644 --- a/app/controllers/stash_engine/resources_controller.rb +++ b/app/controllers/stash_engine/resources_controller.rb @@ -53,12 +53,15 @@ def edit; end # POST /resources # POST /resources.json def create - resource = authorize Resource.new(user_id: current_user.id, current_editor_id: current_user.id, tenant_id: current_user.tenant_id) + resource = authorize Resource.new(current_editor_id: current_user.id, tenant_id: current_user.tenant_id) my_id = Stash::Doi::DataciteGen.mint_id(resource: resource) id_type, id_text = my_id.split(':', 2) db_id_obj = Identifier.create(identifier: id_text, identifier_type: id_type.upcase, import_info: 'manuscript') resource.identifier_id = db_id_obj.id resource.save + resource.creator = current_user.id + resource.submitter = current_user.id + resource.reload resource.fill_blank_author! import_manuscript_using_params(resource) if params['journalID'] session[:resource_type] = current_user.min_app_admin? && params.key?(:collection) ? 'collection' : 'dataset' @@ -115,7 +118,7 @@ def destroy # Review responds as a get request to review the resource before saving def review - resource.update(tenant_id: resource.user.tenant_id) unless resource.tenant_id == resource.user.tenant_id + resource.update(tenant_id: resource.submitter.tenant_id) unless resource.tenant_id == resource.submitter.tenant_id end # Submission of the resource to the repository diff --git a/app/controllers/stash_engine/shared_security_controller.rb b/app/controllers/stash_engine/shared_security_controller.rb index 81dde39249..ce81a14339 100644 --- a/app/controllers/stash_engine/shared_security_controller.rb +++ b/app/controllers/stash_engine/shared_security_controller.rb @@ -115,7 +115,7 @@ def ajax_require_modifiable # these owner/admin need to be in controller since they address the current_user from session, not easily available from model def owner?(resource:) - current_user.present? && resource&.user_id == current_user.id + current_user.present? && resource&.users&.include?(current_user) end def admin?(resource:) diff --git a/app/controllers/stash_engine/user_admin_controller.rb b/app/controllers/stash_engine/user_admin_controller.rb index 099ded8e02..2e97a6b509 100644 --- a/app/controllers/stash_engine/user_admin_controller.rb +++ b/app/controllers/stash_engine/user_admin_controller.rb @@ -6,7 +6,7 @@ class UserAdminController < ApplicationController before_action :require_user_login before_action :load, only: %i[popup edit set_role user_profile] before_action :setup_roles, only: %i[set_role user_profile] - before_action :setup_paging, only: :index + before_action :setup_paging, only: %i[index user_profile] def index setup_facets @@ -98,12 +98,13 @@ def set_role # profile for a user showing stats and datasets def user_profile @user = User.find(params[:id]) - @progress_count = Resource.in_progress.where(user_id: @user.id).count + @progress_count = @user.resources.in_progress.distinct.count # some of these columns are calculated values for display that aren't stored (publication date) - @resources = Resource.where(user_id: @user.id).latest_per_dataset - @presenters = @resources.map { |res| StashDatacite::ResourcesController::DatasetPresenter.new(res) } - setup_ds_status_facets - sort_and_paginate_datasets + @resources = @user.resources.latest_per_dataset.distinct.joins(:last_curation_activity) + .select('stash_engine_resources.*, stash_engine_curation_activities.status') + ord = helpers.sortable_table_order(whitelist: %w[title status publication_date total_file_size updated_at current_editor_id]) + add_profile_filters + @resources = @resources.order(ord).page(@page).per(@page_size) end private @@ -123,7 +124,7 @@ def load end def setup_roles - @system_role = @user.roles.where(role_object_type: nil)&.first + @system_role = @user.roles.system_roles&.first @tenant_role = @user.roles.tenant_roles&.first @journal_role = @user.roles.journal_roles&.first @publisher_role = @user.roles.journal_org_roles&.first @@ -147,17 +148,6 @@ def check_tenant_role setup_roles end - def setup_ds_status_facets - @status_facets = @presenters.map(&:embargo_status).uniq.sort - return unless params[:status] - - @presenters.keep_if { |i| i.embargo_status == params[:status] } - end - - def sort_and_paginate_datasets - @page_presenters = Kaminari.paginate_array(@presenters).page(@page).per(@page_size) - end - def setup_facets @tenant_facets = StashEngine::Tenant.enabled.sort_by(&:short_name) end @@ -175,6 +165,13 @@ def add_filters @users = @users.where(tenant_id: params[:tenant_id]) if params[:tenant_id].present? end + def add_profile_filters + @status_facets = @resources.map(&:status).uniq.sort + return unless profile_params[:status] + + @resources = @resources.where('stash_engine_curation_activities.status': profile_params[:status]) + end + def edit_params params.permit(:id, :field, :email, :tenant_id) end @@ -182,5 +179,9 @@ def edit_params def role_params params.permit(:role, :tenant_role, :publisher, :publisher_role, :funder, :funder_role, :journal_role, journal: %i[value label]) end + + def profile_params + params.permit(:status) + end end end diff --git a/app/helpers/stash_engine/admin_dashboard_helper.rb b/app/helpers/stash_engine/admin_dashboard_helper.rb index d11fd63927..09b2926890 100644 --- a/app/helpers/stash_engine/admin_dashboard_helper.rb +++ b/app/helpers/stash_engine/admin_dashboard_helper.rb @@ -60,7 +60,9 @@ def csv_report_row(dataset) end].flatten.concat(affs).uniq.reject(&:blank?).first(6).join('; ') end if @fields.include?('submitter') - row << "#{dataset.user.first_name} #{dataset.user.last_name}#{dataset.user.orcid ? " ORCID: #{dataset.user.orcid}" : ''}" + row << "#{dataset.submitter&.first_name} #{dataset.submitter&.last_name}#{ + dataset.submitter.orcid.present? ? " ORCID: #{dataset.submitter.orcid}" : '' + }" end row << StashEngine::CurationActivity.readable_status(dataset.last_curation_activity.status) if @fields.include?('status') row << filesize(dataset.total_file_size) if @fields.include?('size') diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 5b890763cd..d00d266555 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -18,7 +18,7 @@ def user_name(user) def assign_variables(resource) @resource = resource - @user = resource.owner_author || resource.user + @user = resource.owner_author || resource.submitter @user_name = user_name(@user) @helpdesk_email = APP_CONFIG['helpdesk_email'] || 'help@datadryad.org' @bcc_emails = APP_CONFIG['submission_bc_emails'] || [@helpdesk_email] diff --git a/app/mailers/stash_engine/resource_mailer.rb b/app/mailers/stash_engine/resource_mailer.rb index fbd8f320b0..34fe6002a7 100644 --- a/app/mailers/stash_engine/resource_mailer.rb +++ b/app/mailers/stash_engine/resource_mailer.rb @@ -90,7 +90,7 @@ def user_name(user) def assign_variables(resource) @resource = resource - @user = resource.owner_author || resource.user + @user = resource.owner_author || resource.submitter @user_name = user_name(@user) @helpdesk_email = APP_CONFIG['helpdesk_email'] || 'help@datadryad.org' @bcc_emails = APP_CONFIG['submission_bc_emails'] || [@helpdesk_email] diff --git a/app/models/stash_api/dataset_parser.rb b/app/models/stash_api/dataset_parser.rb index 0e3deb6d48..a4cabaa948 100644 --- a/app/models/stash_api/dataset_parser.rb +++ b/app/models/stash_api/dataset_parser.rb @@ -34,10 +34,9 @@ def parse resource_id: @resource.id, note: user_note ) - + @resource.submitter = owning_user_id @resource.update( title: remove_html(@hash['title']), - user_id: owning_user_id, current_editor_id: owning_user_id, skip_datacite_update: @hash['skipDataciteUpdate'] || false, skip_emails: @hash['skipEmails'] || false, @@ -62,7 +61,7 @@ def save_identifier end def send_submit_invitation_email(metadata) - return if @hash['triggerSubmitInvitation'] != true || @resource.user.email.blank? + return if @hash['triggerSubmitInvitation'] != true || @resource.submitter.email.blank? StashApi::ApiMailer.send_submit_request(@resource, metadata).deliver_now end @@ -70,7 +69,7 @@ def send_submit_invitation_email(metadata) def resource_uniq? return true if @id - query = StashEngine::Resource.joins(:user).where( + query = StashEngine::Resource.joins(:users).where( stash_engine_resources: { title: @hash[:title] }, stash_engine_users: { orcid: @user.orcid } ) @@ -172,17 +171,17 @@ def clear_previous_metadata def create_dataset(doi_string: nil) # Resource needs to be created early, since minting an ID is based on the resource's tenant, add identifier afterward - # The user_id is initially set to the user that made the API call, though ownership may be changed + # The submitter is initially set to the user that made the API call, though may be changed # to a different user in the `parse` method based on metadata sent in the API call. - @resource = StashEngine::Resource.create( - user_id: @user.id, current_editor_id: @user.id, title: '', tenant_id: @user.tenant_id - ) - + @resource = StashEngine::Resource.new(current_editor_id: @user.id, tenant_id: @user.tenant_id) my_id = doi_string || Stash::Doi::DataciteGen.mint_id(resource: @resource) id_type, id_text = my_id.split(':', 2) - ident = StashEngine::Identifier.create(identifier: id_text, identifier_type: id_type.upcase) - - ident.resources << @resource # add resource to identifier + db_id_obj = StashEngine::Identifier.create(identifier: id_text, identifier_type: id_type.upcase) + @resource.identifier_id = db_id_obj.id + @resource.save + @resource.creator = @user.id + @resource.submitter = @user.id + @resource.reload add_default_values # for license, publisher, resource type end diff --git a/app/models/stash_api/version/metadata.rb b/app/models/stash_api/version/metadata.rb index 69ed6bd8ce..f36d82da5f 100644 --- a/app/models/stash_api/version/metadata.rb +++ b/app/models/stash_api/version/metadata.rb @@ -40,7 +40,7 @@ def value loosenValidation: @resource.loosen_validation || nil } vals[:changedFields] = changed_fields if @item_view - vals[:userId] = @resource.user_id if @post + vals[:userId] = @resource&.submitter&.id if @post vals end # rubocop:enable Metrics/AbcSize diff --git a/app/models/stash_datacite/resource/completions.rb b/app/models/stash_datacite/resource/completions.rb index 02b63e13d0..bb8235f8b6 100644 --- a/app/models/stash_datacite/resource/completions.rb +++ b/app/models/stash_datacite/resource/completions.rb @@ -17,7 +17,7 @@ def initialize(resource) def duplicate_submission return unless @resource.title && @resource.title.split.size > 3 - other_submissions = StashEngine::Resource.where(user_id: @resource.user_id) + other_submissions = @resource.submitter.resources found_dup = nil other_submissions.each do |sub| next if sub.identifier_id == @resource.identifier_id diff --git a/app/models/stash_datacite/resource/metadata_entry.rb b/app/models/stash_datacite/resource/metadata_entry.rb index f139977aa4..5e7aa23ac8 100644 --- a/app/models/stash_datacite/resource/metadata_entry.rb +++ b/app/models/stash_datacite/resource/metadata_entry.rb @@ -133,7 +133,7 @@ def create_publisher def ensure_author_orcid return if @resource.owner_author # the owner is already represented by an author with their orcid - user = @resource.user + user = @resource.submitter this_author = @resource.authors.where(author_first_name: user.first_name, author_last_name: user.last_name).first diff --git a/app/models/stash_engine/author.rb b/app/models/stash_engine/author.rb index 045ba5875d..47e8885ebe 100644 --- a/app/models/stash_engine/author.rb +++ b/app/models/stash_engine/author.rb @@ -81,7 +81,7 @@ def author_html_email_string # user can set their own ORCiD def init_user_orcid return unless author_orcid - return unless (user = resource&.user) + return unless (user = resource&.submitter) return if user&.orcid user.orcid = author_orcid diff --git a/app/models/stash_engine/identifier.rb b/app/models/stash_engine/identifier.rb index 8d9dfc34a0..bf55934a18 100644 --- a/app/models/stash_engine/identifier.rb +++ b/app/models/stash_engine/identifier.rb @@ -160,7 +160,7 @@ def latest_viewable_resource(user: nil) return latest_resource_with_public_metadata if user.nil? lr = latest_resource - return lr if lr&.admin_for_this_item?(user: user) + return lr if lr&.permission_to_edit?(user: user) latest_resource_with_public_metadata end @@ -173,7 +173,7 @@ def latest_downloadable_resource(user: nil) return latest_resource_with_public_download if user.nil? lr = resources.submitted_only.by_version_desc.first - return lr if lr&.admin_for_this_item?(user: user) + return lr if lr&.permission_to_edit?(user: user) latest_resource_with_public_download end diff --git a/app/models/stash_engine/proxy_user.rb b/app/models/stash_engine/proxy_user.rb index 128fd86e7b..8d6da453e3 100644 --- a/app/models/stash_engine/proxy_user.rb +++ b/app/models/stash_engine/proxy_user.rb @@ -29,8 +29,8 @@ module StashEngine # Roleless user for API proxy class ProxyUser < ApplicationRecord self.table_name = 'stash_engine_users' - has_many :resources, foreign_key: :user_id has_many :roles, -> { where.not(role_object_type: nil) }, foreign_key: :user_id + has_many :resources, through: :roles, source: :role_object, source_type: 'StashEngine::Resource' has_many :journals, through: :roles, source: :role_object, source_type: 'StashEngine::Journal' has_many :journal_organizations, through: :roles, source: :role_object, source_type: 'StashEngine::JournalOrganization' has_many :funders, through: :roles, source: :role_object, source_type: 'StashEngine::Funder' @@ -111,32 +111,6 @@ def tenant Tenant.find(tenant_id) end - # gets the latest completed resources by user, a lot of SQL since this becomes complicated - def latest_completed_resource_per_identifier - # Joining on version is messy, so we just assume the latest version in a - # group is the one with the highest resource_id. - # - # Note that resources with null identifiers (resources not yet assigned - # a DOI) are assumed to be different from one another. This is a little - # hacky, but should be OK since most of the time this will be a transient - # state immediately after submission. However, if we reach an error state - # before a DOI is reserved, we could end up with multiple instances of the - # "same" resource appearing in the table. - query = <<-SQL - id IN - (SELECT MAX(resources.id) AS resources_id - FROM stash_engine_resources resources - JOIN stash_engine_resource_states AS states - ON resources.current_resource_state_id = states.id - WHERE resources.user_id = ? - AND states.resource_state IN ('submitted', 'processing', 'error') - GROUP BY resources.identifier_id, - IF(resources.identifier_id IS NULL, resources.id, 0)) - SQL - - Resource.where(query, id) - end - end end diff --git a/app/models/stash_engine/resource.rb b/app/models/stash_engine/resource.rb index 2293e19c5a..acce8c04e4 100644 --- a/app/models/stash_engine/resource.rb +++ b/app/models/stash_engine/resource.rb @@ -59,10 +59,12 @@ class Resource < ApplicationRecord # rubocop:disable Metrics/ClassLength has_many :software_files, class_name: 'StashEngine::SoftwareFile', dependent: :destroy has_many :supp_files, class_name: 'StashEngine::SuppFile', dependent: :destroy has_many :edit_histories, class_name: 'StashEngine::EditHistory' + has_many :roles, class_name: 'StashEngine::Role', as: :role_object, dependent: :destroy + has_many :users, through: :roles, class_name: 'StashEngine::User' has_one :stash_version, class_name: 'StashEngine::Version', dependent: :destroy belongs_to :identifier, class_name: 'StashEngine::Identifier', foreign_key: 'identifier_id' - belongs_to :user, class_name: 'StashEngine::User' belongs_to :tenant, class_name: 'StashEngine::Tenant', optional: true + has_one :curator, class_name: 'StashEngine::User', primary_key: 'user_id', foreign_key: 'id' has_one :current_resource_state, class_name: 'StashEngine::ResourceState', primary_key: 'current_resource_state_id', @@ -147,7 +149,7 @@ def download_token # see https://github.com/amoeba-rb/amoeba/issues/76 %i[contributors datacite_dates descriptions geolocations temporal_coverages publication_years publisher related_identifiers resource_type rights sizes - subjects resource_publication].each do |assoc| + subjects resource_publication roles].each do |assoc| include_association assoc end end @@ -251,7 +253,7 @@ def ensure_state_and_version str = 'stash_engine_curation_activities.status IN (?)' arr = [my_states] if user_id - str += ' OR stash_engine_resources.user_id = ?' + str += ' OR stash_engine_roles.user_id = ?' arr.push(user_id) end if tenant_id @@ -266,7 +268,8 @@ def ensure_state_and_version str += " OR (dcs_contributors.contributor_type = 'funder' AND dcs_contributors.name_identifier_id IN (?))" arr.push(funder_ids) end - joins(:last_curation_activity).left_outer_joins(:resource_publication).joins(JOIN_FOR_CONTRIBUTORS).distinct.where(str, *arr) + joins(:last_curation_activity).left_outer_joins(:resource_publication).left_outer_joins(:roles) + .joins(JOIN_FOR_CONTRIBUTORS).distinct.where(str, *arr) end # limits to the latest resource for each dataset if added to resources @@ -479,7 +482,7 @@ def current_state=(value) end def init_state - self.current_resource_state_id = ResourceState.create(resource_id: id, resource_state: 'in_progress', user_id: user_id).id + self.current_resource_state_id = ResourceState.create(resource_id: id, resource_state: 'in_progress', user_id: current_editor_id).id end private :init_state @@ -621,6 +624,22 @@ def previous_resource_published? # ----------------------------------------------------------- # Permissions + def creator + roles.find_by(role: 'creator')&.user + end + + def submitter + roles.find_by(role: 'submitter')&.user + end + + def creator=(user_id) + roles.find_or_create_by(role: 'creator').update(user_id: user_id) + end + + def submitter=(user_id) + roles.find_or_create_by(role: 'submitter').update(user_id: user_id) + end + # can edit means they are not locked out because edits in progress and have permission def can_edit?(user:) # only curators and above (not limited curators) have permission to edit @@ -649,21 +668,24 @@ def funders_match?(user:) def permission_to_edit?(user:) return false unless user - # curator, dataset owner or admin for the same tenant + # collaborators + return true if users.include?(user) + + # curator or admin for the memebr institution admin_for_this_item?(user: user) end # Checks if someone may download files for this resource # 1. Repo's status, resource_state = 'submitted', meaning they are available to download from the repo # 2. Curation state of files_public? means anyone may download - # 3. if not public then users with admin privileges over the item can still download + # 3. if not public then users with edit/admin privileges over the item can still download # Note: the special download links mean anyone with that link may download and this doesn't apply def may_download?(ui_user: nil) # doing this to avoid collision with the association called user return false unless current_resource_state&.resource_state == 'submitted' # is available in the repo return true if files_published? # published and this one available for download return false if ui_user.blank? # the rest of the cases require users - admin_for_this_item?(user: ui_user) + permission_to_edit?(user: ui_user) end # see if the user may view based on curation status & roles and etc. I don't see this as being particularly complex for Rubocop @@ -671,7 +693,7 @@ def may_view?(ui_user: nil) return true if metadata_published? # anyone can view return false if ui_user.blank? # otherwise unknown person can't view and this prevents later nil checks - admin_for_this_item?(user: ui_user) + permission_to_edit?(user: ui_user) end # ------------------------------------------------------------ @@ -694,13 +716,13 @@ def self.submitted_dataset_count # may not be able to match one up def owner_author - return nil unless user&.orcid.present? # apparently there are cases where user doesn't have an orcid + return nil unless submitter&.orcid.present? # apparently there are cases where user doesn't have an orcid - authors.where(author_orcid: user.orcid).first + authors.where(author_orcid: submitter.orcid).first end def fill_blank_author! - return if authors.count > 0 || user.blank? # already has some authors filled in or no user to know about + return if authors.count > 0 || submitter.blank? # already has some authors filled in or no user to know about fill_author_from_user! end @@ -708,21 +730,21 @@ def fill_blank_author! # TODO: Move this to the Author model as `Author.from_user` perhaps so that we do not need to comingle # StashDatacite objects directly here. def fill_author_from_user! - f_name = user.first_name - l_name = user.last_name - orcid = (user.orcid.blank? ? nil : user.orcid) - email = user.email + f_name = submitter.first_name + l_name = submitter.last_name + orcid = (submitter.orcid.blank? ? nil : submitter.orcid) + email = submitter.email # TODO: This probably belongs somewhere else, but without it here, the affiliation sometimes doesn't exist StashDatacite::AuthorPatch.patch! unless StashEngine::Author.method_defined?(:affiliation) - affiliation = user.affiliation - affiliation = StashDatacite::Affiliation.from_long_name(long_name: user.tenant.long_name) if affiliation.blank? && - user.tenant.present? && !%w[dryad localhost].include?(user.tenant.id) + affiliation = submitter.affiliation + affiliation = StashDatacite::Affiliation.from_long_name(long_name: submitter.tenant.long_name) if affiliation.blank? && + submitter.tenant.present? && !%w[dryad localhost].include?(submitter.tenant.id) StashEngine::Author.create(resource_id: id, author_orcid: orcid, affiliation: affiliation, author_first_name: f_name, author_last_name: l_name, author_email: email) # disabling because we no longer wnat this with UC Press - # author.affiliation_by_name(user.tenant.short_name) if user.try(:tenant) + # author.affiliation_by_name(submitter.tenant.short_name) if submitter.try(:tenant) end # ----------------------------------------------------------- @@ -766,7 +788,7 @@ def dataset_in_progress_editor_id # calculated current editor name, ignores nil current editor as current logged in user def dataset_in_progress_editor - return user if dataset_in_progress_editor_id.nil? + return submitter if dataset_in_progress_editor_id.nil? User.where(id: dataset_in_progress_editor_id).first end @@ -1091,8 +1113,8 @@ def prepare_for_curation # so assign it to the previous curator, with a fallback process auto_assign_curator(target_status: target_status) - # If the last user to edit it was the current_editor return it to curation status - return unless last_curation_activity.user_id == current_editor_id + # If the last user to edit it was the curator return it to curation status + return unless last_curation_activity.user_id == user_id curation_activities << StashEngine::CurationActivity.create(user_id: 0, status: 'curation', note: 'System set back to curation') @@ -1142,17 +1164,17 @@ def create_post_submission_status(prior_cur_act) # rubocop:enable Metrics/AbcSize def auto_assign_curator(target_status:) - target_curator = identifier.most_recent_curator + target_curator = curator&.min_curator? ? curator : identifier.most_recent_curator if target_curator.nil? || !target_curator.min_curator? # if the previous curator does not exist, or is no longer a curator, # set it to a random current curator , but not a superuser cur_list = StashEngine::User.curators.to_a target_curator = cur_list[rand(cur_list.length)] end - return unless target_curator - update(current_editor_id: target_curator.id) + update(user_id: target_curator.id) unless curator == target_curator + curation_activities << StashEngine::CurationActivity.create( user_id: 0, status: target_status, note: "System auto-assigned curator #{target_curator&.name}" diff --git a/app/models/stash_engine/role.rb b/app/models/stash_engine/role.rb index 0e184e29cb..ef93794e0f 100644 --- a/app/models/stash_engine/role.rb +++ b/app/models/stash_engine/role.rb @@ -22,7 +22,7 @@ module StashEngine class Role < ApplicationRecord self.table_name = 'stash_engine_roles' - belongs_to :user, class_name: 'User' + belongs_to :user, class_name: 'StashEngine::User' belongs_to :role_object, polymorphic: true, optional: true # only join after relevant scopes for query efficiency @@ -31,6 +31,9 @@ class Role < ApplicationRecord belongs_to :journal_organization, class_name: 'StashEngine::JournalOrganization', foreign_key: 'role_object_id', optional: true belongs_to :funder, class_name: 'StashEngine::Funder', foreign_key: 'role_object_id', optional: true + scope :submission_roles, -> { where(role_object_type: 'StashEngine::Resource') } + scope :admin_roles, -> { where("role_object_type is null or role_object_type != 'StashEngine::Resource'") } + scope :system_roles, -> { where(role_object_type: nil) } scope :tenant_roles, -> { where(role_object_type: 'StashEngine::Tenant') } scope :funder_roles, -> { where(role_object_type: 'StashEngine::Funder') } diff --git a/app/models/stash_engine/user.rb b/app/models/stash_engine/user.rb index 9d6b442296..bb36c690a8 100644 --- a/app/models/stash_engine/user.rb +++ b/app/models/stash_engine/user.rb @@ -27,8 +27,8 @@ module StashEngine class User < ApplicationRecord self.table_name = 'stash_engine_users' - has_many :resources - has_many :roles, -> { order(role_object_type: :asc) }, dependent: :destroy + has_many :roles, dependent: :destroy + has_many :resources, through: :roles, source: :role_object, source_type: 'StashEngine::Resource' has_many :journals, through: :roles, source: :role_object, source_type: 'StashEngine::Journal' has_many :journal_organizations, through: :roles, source: :role_object, source_type: 'StashEngine::JournalOrganization' has_many :funders, through: :roles, source: :role_object, source_type: 'StashEngine::Funder' @@ -177,32 +177,6 @@ def tenant Tenant.find(tenant_id) end - # gets the latest completed resources by user, a lot of SQL since this becomes complicated - def latest_completed_resource_per_identifier - # Joining on version is messy, so we just assume the latest version in a - # group is the one with the highest resource_id. - # - # Note that resources with null identifiers (resources not yet assigned - # a DOI) are assumed to be different from one another. This is a little - # hacky, but should be OK since most of the time this will be a transient - # state immediately after submission. However, if we reach an error state - # before a DOI is reserved, we could end up with multiple instances of the - # "same" resource appearing in the table. - query = <<-SQL - id IN - (SELECT MAX(resources.id) AS resources_id - FROM stash_engine_resources resources - JOIN stash_engine_resource_states AS states - ON resources.current_resource_state_id = states.id - WHERE resources.user_id = ? - AND states.resource_state IN ('submitted', 'processing', 'error') - GROUP BY resources.identifier_id, - IF(resources.identifier_id IS NULL, resources.id, 0)) - SQL - - Resource.where(query, id) - end - def self.init_user_from_auth(user, auth) user.email = auth.info.email.split(';').first # because ucla has two values separated by ; # name is kludgy and many places do not provide them broken out diff --git a/app/policies/stash_engine/curation_activity_policy.rb b/app/policies/stash_engine/curation_activity_policy.rb index 55b8f45790..2acef4fa55 100644 --- a/app/policies/stash_engine/curation_activity_policy.rb +++ b/app/policies/stash_engine/curation_activity_policy.rb @@ -11,7 +11,7 @@ def curation_note? def file_note? @user.min_app_admin? || - @user.id == @resource.user_id + @resource.users.include?(@user) end end diff --git a/app/policies/stash_engine/identifier_policy.rb b/app/policies/stash_engine/identifier_policy.rb index f87f04bedf..c5575d781d 100644 --- a/app/policies/stash_engine/identifier_policy.rb +++ b/app/policies/stash_engine/identifier_policy.rb @@ -27,31 +27,5 @@ def resolve attr_reader :user, :scope end - class DashboardScope - def initialize(user, scope) - @user = user - @scope = scope - end - - def resolve - @scope - .joins(latest_resource: :last_curation_activity) - .where(latest_resource: { user_id: @user&.id }) - .select("stash_engine_identifiers.id, identifier, identifier_type, pub_state, latest_resource_id, - CASE - WHEN status in ('in_progress', 'action_required') THEN 0 - WHEN status='peer_review' THEN 1 - WHEN status in ('submitted', 'curation', 'processing') THEN 2 - WHEN status='withdrawn' THEN 4 - ELSE 3 - END as sort_order") - .order('sort_order asc, latest_resource.updated_at desc') - end - - private - - attr_reader :user, :scope - end - end end diff --git a/app/policies/stash_engine/resource_policy.rb b/app/policies/stash_engine/resource_policy.rb index 630d359b6b..0d3e1c0e81 100644 --- a/app/policies/stash_engine/resource_policy.rb +++ b/app/policies/stash_engine/resource_policy.rb @@ -20,22 +20,7 @@ def curate? def curator_edit? (curate? && (@resource.current_resource_state&.resource_state == 'submitted')) || - (@resource.current_resource_state&.resource_state == 'in_progress' && @resource&.current_editor_id == @user.id) - end - - class Scope - def initialize(user, scope) - @user = user - @scope = scope - end - - def resolve - @scope.where(user_id: @user.id) - end - - private - - attr_reader :user, :scope + (@resource.current_resource_state&.resource_state == 'in_progress' && @resource&.user_id == @user.id) end class VersionScope diff --git a/app/views/stash_datacite/resources/_review.html.erb b/app/views/stash_datacite/resources/_review.html.erb index 2a622499d2..122ca6b354 100644 --- a/app/views/stash_datacite/resources/_review.html.erb +++ b/app/views/stash_datacite/resources/_review.html.erb @@ -154,7 +154,7 @@ <%= hidden_field_tag :software_license, @resource&.identifier&.software_license&.identifier || 'MIT' %> <%= check_box_tag 'all_filled', 1, true, :style => "display: none;", class: 'all_filled js-agrees' %>
- <% if current_user&.id != @resource.user_id # only show to admins %> + <% if current_user.min_app_admin? # only show to admins %>

<%= check_box_tag :hide_readme, true, !@resource.display_readme %> <%= label_tag :hide_readme, "Hide the README on the landing page"%> @@ -194,7 +194,7 @@ $('#software_license').val($("#zenodo_license option:selected").val()); }); - <% if current_user && (current_user.id != @resource.user_id) %> + <% if current_user && (current_user != @resource.submitter) %> $('#agree_to_license, #agree_to_tos, #agree_to_dda').prop('disabled', true); <% end %> diff --git a/app/views/stash_engine/admin_dashboard/_curation_form.html.erb b/app/views/stash_engine/admin_dashboard/_curation_form.html.erb index 68ceeba4be..19a8ce444d 100644 --- a/app/views/stash_engine/admin_dashboard/_curation_form.html.erb +++ b/app/views/stash_engine/admin_dashboard/_curation_form.html.erb @@ -29,7 +29,7 @@ <%= form.fields_for :current_editor, @resource do |r| %>

<%= r.label :id, 'Curator', class: 'c-input__label' %> - <%= r.select :id, options_for_select([['(unassign)', '0']] + editor_select, @resource.current_editor_id), {include_blank: true}, {class: 'c-input__select', id: 'current_editor'} %> + <%= r.select :id, options_for_select([['(unassign)', '0']] + editor_select, @resource.user_id), {include_blank: true}, {class: 'c-input__select', id: 'current_editor'} %>
<% end %> <% end %> diff --git a/app/views/stash_engine/admin_dashboard/_role_select.html.erb b/app/views/stash_engine/admin_dashboard/_role_select.html.erb index 89198a5398..19bd5304b0 100644 --- a/app/views/stash_engine/admin_dashboard/_role_select.html.erb +++ b/app/views/stash_engine/admin_dashboard/_role_select.html.erb @@ -1,4 +1,4 @@ -<% roles = current_user.roles.map { |r| +<% roles = current_user.roles.admin_roles.map { |r| obj = r.role_object label = nil label = obj.title if defined?(obj.title) diff --git a/app/views/stash_engine/admin_dashboard/_table_row.html.erb b/app/views/stash_engine/admin_dashboard/_table_row.html.erb index b27d01eb43..322bc15a9b 100644 --- a/app/views/stash_engine/admin_dashboard/_table_row.html.erb +++ b/app/views/stash_engine/admin_dashboard/_table_row.html.erb @@ -26,9 +26,9 @@ <% end %> <% if @fields.include?('submitter') %> - <% if dataset.user.orcid %><% end %> - <%= "#{dataset.user.first_name} #{dataset.user.last_name}" %> - <% if dataset.user.orcid %><% end %> + <% if dataset.submitter&.orcid %><% end %> + <%= "#{dataset.submitter&.first_name} #{dataset.submitter&.last_name}" %> + <% if dataset.submitter&.orcid %><% end %> <% end %> <% if @fields.include?('status') %> diff --git a/app/views/stash_engine/dashboard/_user_datasets.html.erb b/app/views/stash_engine/dashboard/_user_datasets.html.erb index 8067675a71..fcffac43ad 100644 --- a/app/views/stash_engine/dashboard/_user_datasets.html.erb +++ b/app/views/stash_engine/dashboard/_user_datasets.html.erb @@ -1,10 +1,9 @@ <% @datasets.each_with_index do |dataset, i| %> - <% resource = dataset&.latest_resource %> - <% title = resource.title.blank? ? '[No title supplied]' : resource.title %> + <% title = dataset.title.blank? ? '[No title supplied]' : dataset.title %> <% delete_confirm = 'Are you sure you want to remove this dataset' - if resource&.stash_version.version > 1 + if dataset&.stash_version.version > 1 delete_confirm << ' version?' - if dataset.pub_state == 'published' + if dataset.identifier.pub_state == 'published' delete_confirm << ' The published version will still be available.' end else @@ -34,13 +33,13 @@
  • - <% if resource.submitted? # merritt state %> - <%= link_to title, stash_url_helpers.show_path(dataset.identifier_str) %> + <% if dataset.submitted? # merritt state %> + <%= link_to title, stash_url_helpers.show_path(dataset.identifier.identifier_str) %> <% else %> <%= title %> <% end %>

    -

    DOI: <%= dataset.identifier %>Version <%= resource&.stash_version.version%><%= time_ago_in_words(resource.updated_at, include_seconds: true) %> since last update<% if dataset.pub_state == 'published' %>Published: <%= formatted_date(dataset.date_last_published) %><% if dataset.sort_order != 3 %> Previous version published<% end %><% end %>

    +

    DOI: <%= dataset.identifier.identifier %>Version <%= dataset&.stash_version.version%><%= time_ago_in_words(dataset.updated_at, include_seconds: true) %> since last update<% if dataset.identifier.pub_state == 'published' %>Published: <%= formatted_date(dataset.identifier.date_last_published) %><% if dataset.sort_order != 3 %> Previous version published<% end %><% end %>

    @@ -55,27 +54,27 @@ <%when 3%> success-status <%end%> - "><%= resource&.last_curation_activity&.readable_status %> + "><%= dataset&.last_curation_activity&.readable_status %>
    - <% if resource&.last_curation_activity.status == 'in_progress' %> - <% if resource.current_editor_id == current_user&.id %> - <%= button_to stash_url_helpers.metadata_entry_pages_find_or_create_path(resource_id: resource.id), name: 'resume', form_class: 'o-button__inline-form', class: 'o-button__plain-text7', method: :post do %> + <% if dataset&.last_curation_activity.status == 'in_progress' %> + <% if dataset.current_editor_id == current_user&.id %> + <%= button_to stash_url_helpers.metadata_entry_pages_find_or_create_path(resource_id: dataset.id), name: 'resume', form_class: 'o-button__inline-form', class: 'o-button__plain-text7', method: :post do %> Resume <% end %> - <%= button_to stash_url_helpers.resource_path(resource), method: :delete, data: { confirm: delete_confirm }, name: 'delete', form_class: 'o-button__inline-form', class: 'o-button__plain-text7', title: resource&.stash_version.version > 1 ? 'Revert to previous version' : 'Delete dataset' do %> - <%= resource&.stash_version.version > 1 ? 'Revert' : 'Delete' %> + <%= button_to stash_url_helpers.resource_path(dataset), method: :delete, data: { confirm: delete_confirm }, name: 'delete', form_class: 'o-button__inline-form', class: 'o-button__plain-text7', title: dataset&.stash_version.version > 1 ? 'Revert to previous version' : 'Delete dataset' do %> + <%= dataset&.stash_version.version > 1 ? 'Revert' : 'Delete' %> <% end %> - <% elsif resource.current_editor_id.present? %> - Dataset being edited by <%= resource.editor.name %> + <% elsif dataset.current_editor_id.present? %> + Dataset being edited by <%= dataset.editor.name %> <% end %> <% end %> <% if dataset.sort_order == 1 %> - <%= button_to stash_url_helpers.peer_review_release_path, method: :patch, params: {stash_engine_resource: { id: resource.id }}, name: 'release', data: { confirm: 'Is this dataset ready for curation and publication?' }, form_class: 'o-button__inline-form', class: 'o-button__plain-text7' do %> + <%= button_to stash_url_helpers.peer_review_release_path, method: :patch, params: {stash_engine_resource: { id: daatset.id }}, name: 'release', data: { confirm: 'Is this dataset ready for curation and publication?' }, form_class: 'o-button__inline-form', class: 'o-button__plain-text7' do %> Release for curation <% end %> <% end %> - <% if ['submitted', 'action_required'].include?(resource&.last_curation_activity.status) || dataset.sort_order == 1 || dataset.sort_order >= 3 %> - <%= form_with(url: stash_url_helpers.metadata_entry_pages_new_version_path(resource_id: resource.id), method: :post, class: 'o-button__inline-form') do %> + <% if ['submitted', 'action_required'].include?(dataset&.last_curation_activity.status) || dataset.sort_order == 1 || dataset.sort_order >= 3 %> + <%= form_with(url: stash_url_helpers.metadata_entry_pages_new_version_path(resource_id: dataset.id), method: :post, class: 'o-button__inline-form') do %> <% end %> <% end %> diff --git a/app/views/stash_engine/landing/_privileged_banner.html.erb b/app/views/stash_engine/landing/_privileged_banner.html.erb index 07279a5567..e2cebd08c5 100644 --- a/app/views/stash_engine/landing/_privileged_banner.html.erb +++ b/app/views/stash_engine/landing/_privileged_banner.html.erb @@ -1,5 +1,6 @@
    -

    This is the <%= resource&.user_id == current_user&.id ? 'owner' : 'administrator' %> view of this <%= resource&.resource_type&.resource_type %>, including any unpublished changes. + <% role = @resource&.roles&.find {|ro| ro.user_id == current_user.id} %> +

    This is the <%= role ? role.role : 'administrator' %> view of this <%= resource&.resource_type&.resource_type %>, including any unpublished changes. <% if @resource&.identifier&.pub_state == 'published' %> Public view diff --git a/app/views/stash_engine/shared/_dataset_non_user_editor.html.erb b/app/views/stash_engine/shared/_dataset_non_user_editor.html.erb index 0cd02afbe9..6f0e9c2cec 100644 --- a/app/views/stash_engine/shared/_dataset_non_user_editor.html.erb +++ b/app/views/stash_engine/shared/_dataset_non_user_editor.html.erb @@ -1,10 +1,10 @@ <% # takes resource as local %> -<% unless current_user&.id == resource.user_id %> +<% unless resource&.users&.include?(current_user) %> <% revertible = resource.identifier.resources.count > 1 %>

    - You are editing <%= resource.user.name %>'s dataset. + You are editing <%= resource.submitter.name %>'s dataset. <% unless revertible %>

    This dataset has never been submitted, so no checkpoints have been created. Any changes you make are permanent.

    <% end %> diff --git a/app/views/stash_engine/user_admin/_admin_user_table.html.erb b/app/views/stash_engine/user_admin/_admin_user_table.html.erb index 2d80436fac..108fd0409c 100644 --- a/app/views/stash_engine/user_admin/_admin_user_table.html.erb +++ b/app/views/stash_engine/user_admin/_admin_user_table.html.erb @@ -67,7 +67,7 @@
    - <%= u.roles.present? ? u.roles.map{|r| "#{r.role_object_type&.delete_prefix("StashEngine::")&.sub('JournalOrganization', 'Publisher')} #{r.role}".strip.capitalize }.join(", ") : "User" %> + <%= u.roles.present? ? u.roles.admin_roles.map{|r| "#{r.role_object_type&.delete_prefix("StashEngine::")&.sub('JournalOrganization', 'Publisher')} #{r.role}".strip.capitalize }.join(", ") : "User" %>
    <% if policy([:stash_engine, :user]).set_role? %>
    diff --git a/app/views/stash_engine/user_admin/_facet_status.html.erb b/app/views/stash_engine/user_admin/_facet_status.html.erb index 74372cf633..5cd8eb824d 100644 --- a/app/views/stash_engine/user_admin/_facet_status.html.erb +++ b/app/views/stash_engine/user_admin/_facet_status.html.erb @@ -1,8 +1,8 @@ <%# takes tenants as local: facets %> <%= "No filters available" unless facets.present? %> <% if facets.present? %> - -