Skip to content

Commit

Permalink
Merge pull request #1847 from datadryad/default-dashboard
Browse files Browse the repository at this point in the history
Default to admin dashboard for admins
  • Loading branch information
alinvetian authored Sep 20, 2024
2 parents c1afae6 + be3a0fc commit 47aa2eb
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 103 deletions.
5 changes: 2 additions & 3 deletions app/controllers/stash_datacite/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def review
@resource.save!
@resource.reload
if @resource.identifier.payment_type.blank? || @resource.identifier.payment_type == 'unknown'
session[:origin] = 'resource'
session[:redirect_resource_id] = @resource.id
@target_page = stash_url_helpers.review_resource_path(@resource.id)
@aff_tenant = StashEngine::Tenant.find_by_ror_id(@resource.identifier&.submitter_affiliation&.ror_id).partner_list.first
end
end
Expand Down Expand Up @@ -73,7 +72,7 @@ def submission
session[:returnURL] = nil
redirect_to(return_url, notice: "Submitted updates for #{@resource.identifier}, title: #{@resource.title}", allow_other_host: true)
else
redirect_to(stash_url_helpers.dashboard_path(doi: @resource.identifier.identifier), notice: resource_submitted_message(@resource))
redirect_to(stash_url_helpers.choose_dashboard_path(doi: @resource.identifier.identifier), notice: resource_submitted_message(@resource))
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/stash_engine/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def set_return_to_path_from_referrer

def user_not_authorized
flash[:alert] = 'You are not authorized to view this information.'
redirect_back(fallback_location: '/stash/dashboard')
redirect_back(fallback_location: choose_dashboard_path)
end

def display_authorization_failure
Rails.logger.warn("Resource #{resource ? resource.id : 'nil'}: user ID is #{resource.user_id || 'nil'} but " \
"current user is #{current_user.id || 'nil'}")
flash[:alert] = 'You do not have permission to modify this dataset.'
redirect_back(fallback_location: '/stash/dashboard')
redirect_back(fallback_location: choose_dashboard_path)
end

def redirect_url_for(original_url, host, port)
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/stash_engine/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class DashboardController < ApplicationController

MAX_VALIDATION_TRIES = 5

def choose
return redirect_to admin_dashboard_path if current_user.min_admin?

redirect_to dashboard_path
end

def show
@doi = CGI.escape(params[:doi] || '')
end
Expand Down
17 changes: 8 additions & 9 deletions app/controllers/stash_engine/metadata_entry_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def edit_by_doi

if ownership_transfer_needed?
if current_user
ca = CurationActivity.create(status: @resource.current_curation_status || 'in_progress',
user_id: 0,
resource_id: @resource.id,
note: "Transferring ownership to #{current_user.name} (#{current_user.id}) using an edit code")
ca = CurationActivity.create(
status: @resource.current_curation_status || 'in_progress', user_id: 0, resource_id: @resource.id,
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
Expand All @@ -74,12 +74,11 @@ def edit_by_doi
redirect_to stash_url_helpers.choose_sso_path and return
end
end

if @resource&.current_resource_state&.resource_state == 'in_progress'
redirect_to(stash_url_helpers.metadata_entry_pages_find_or_create_path(resource_id: resource.id))
else
new_version
redirect_to(stash_url_helpers.metadata_entry_pages_find_or_create_path(resource_id: resource.id)) and return
end

new_version
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

Expand Down Expand Up @@ -167,7 +166,7 @@ def require_can_duplicate
redirect_to(stash_url_helpers.metadata_entry_pages_find_or_create_path(resource_id: @identifier.in_progress_resource.id))
false
elsif @identifier.processing? || @identifier.error?
redirect_to stash_url_helpers.dashboard_path,
redirect_to stash_url_helpers.choose_dashboard_path,
alert: 'You may not create a new version of the dataset until processing completes or any errors are resolved'
false
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/stash_engine/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def destroy
session[:returnURL] = nil
redirect_to(return_url, allow_other_host: true, notice: notice)
elsif current_user
redirect_to return_to_path_or(dashboard_path), notice: notice
redirect_to return_to_path_or(choose_dashboard_path), notice: notice
else
redirect_to root_path, notice: notice
end
Expand Down Expand Up @@ -238,7 +238,7 @@ def resource_params
end

def require_in_progress
redirect_to dashboard_path, alert: 'You may only edit the current version of the dataset' unless resource.current_state == 'in_progress'
redirect_to choose_dashboard_path, alert: 'You may only edit the current version of the dataset' unless resource.current_state == 'in_progress'
false
end

Expand Down
24 changes: 9 additions & 15 deletions app/controllers/stash_engine/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_login
existing.update(first_name: params[:first_name], last_name: params[:last_name], email: params[:email],
tenant_id: params[:tenant_id])
session[:user_id] = existing.id
redirect_to stash_url_helpers.dashboard_path, status: :found
redirect_to stash_url_helpers.choose_dashboard_path, status: :found
end

def choose_sso
Expand All @@ -117,6 +117,7 @@ def no_partner

# send the user to the tenant's SSO url
def sso
session[:target_page] = params[:target_page] if params[:target_page]
if StashEngine::Tenant.exists?(params[:tenant_id])
tenant = StashEngine::Tenant.find(params[:tenant_id])
case tenant&.authentication&.strategy
Expand Down Expand Up @@ -157,9 +158,7 @@ def orcid_preprocessor
@auth_hash = request.env['omniauth.auth']
@params = request.env['omniauth.params']
if @params['origin'] == 'feedback'
session[:origin] = @params['origin']
session[:contact_method] = @params['m']
session[:link_location] = @params['l']
session[:target_page] = stash_url_helpers.feedback_path(m: @params['m'], l: @params['l'])
elsif @params['origin'] == 'metadata'
metadata_callback
elsif @params['invitation'] && @params['identifier_id']
Expand All @@ -179,7 +178,7 @@ def login_from_orcid
user = @users.first
session[:user_id] = user.id
# tenant = Tenant.find(user.tenant_id) # this was used to redirect to correct tenant, now not needed
redirect_to stash_url_helpers.dashboard_path
redirect_to stash_url_helpers.choose_dashboard_path
end

# get orcid emails as returned by API
Expand Down Expand Up @@ -288,17 +287,12 @@ def validate_ip(tenant:)
end

def do_redirect
case session[:origin]
when 'feedback'
redirect_to stash_url_helpers.feedback_path(m: session[:contact_method], l: session[:link_location])
session[:origin] = session[:contact_method] = session[:link_location] = nil
when 'account'
redirect_to stash_url_helpers.my_account_path
when 'resource'
redirect_to stash_url_helpers.review_resource_path(session[:redirect_resource_id])
else
redirect_to stash_url_helpers.dashboard_path
target_page = session[:target_page]
if target_page.present?
session[:target_page] = nil
redirect_to target_page and return
end
redirect_to stash_url_helpers.choose_dashboard_path
end

def set_default_tenant
Expand Down
15 changes: 7 additions & 8 deletions app/controllers/stash_engine/shared_security_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ def require_login
# to the login page. Now that they are logged in, we will redirect to the target_page,
# but first clear it from the session so we don't continually redirect to it.
session[:target_page] = nil
redirect_to target_page
redirect_to target_page and return
end
return
end

return if valid_edit_code?

flash[:alert] = 'You must be logged in.'
session[:target_page] = request.fullpath
flash[:alert] = 'You must log in and select an institution (or none).'
redirect_to stash_url_helpers.choose_login_path
end

Expand All @@ -47,21 +46,21 @@ def require_not_obsolete
return if @resource&.current_resource_state&.resource_state == 'in_progress'

flash[:alert] = 'You may not edit a submitted version of your dataset by using the back button. Please open your dataset from the editing link'
redirect_to stash_url_helpers.dashboard_path
redirect_to stash_url_helpers.choose_dashboard_path
end

def require_superuser
return if current_user && current_user.superuser?

flash[:alert] = 'You must be a superuser to view this information.'
redirect_to stash_url_helpers.dashboard_path
redirect_to stash_url_helpers.choose_dashboard_path
end

def require_curator
return if current_user && current_user.min_curator?

flash[:alert] = 'You must be a curator to view this information.'
redirect_to stash_url_helpers.dashboard_path
redirect_to stash_url_helpers.choose_dashboard_path
end

def ajax_require_curator
Expand All @@ -72,7 +71,7 @@ def require_min_app_admin
return if current_user && current_user.min_app_admin?

flash[:alert] = 'You must be a curator to view this information.'
redirect_to stash_url_helpers.dashboard_path
redirect_to stash_url_helpers.choose_dashboard_path
end

def ajax_require_min_app_admin
Expand All @@ -83,7 +82,7 @@ def require_admin
return if current_user && current_user.min_admin?

flash[:alert] = 'You must be an administrator to view this information.'
redirect_to stash_url_helpers.dashboard_path
redirect_to stash_url_helpers.choose_dashboard_path
end

# this requires a method called resource in the controller that returns the current resource (usually @resource)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stash_engine/user_account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class UserAccountController < ApplicationController
before_action :require_user_login

def index
session[:origin] = 'account'
@target_page = stash_url_helpers.my_account_path
end

def edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
method: :post, :html => { onsubmit: "document.body.classList.add('prevent-clicks')" }) do -%>
<button class="o-button__submit">Forcibly edit dataset</button>
<%= hidden_field_tag :resource_id, res&.id, id: "resource_id_#{res&.id}" %>
<%= hidden_field_tag :return_url, '/stash/dashboard' %>
<% end %>
<p>Forcibly editing a dataset will assign it to you, and begin an editing session.
Please only do this if you know the author is unable/unwilling to submit it.</p>
Expand Down
1 change: 1 addition & 0 deletions app/views/stash_engine/shared/_change_tenant.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<div class="t-login__choose">
<div class="c-institution__container" style="width: 100%">
<%= form_with(url: sso_path, method: :post, html: {style: 'justify-content: space-between;'}) do %>
<% if @target_page %><input type="hidden" name="target_page" value="<%= @target_page %>"><% end %>
<%= react_component('components/TenantForm', {tenants: tenant_select}) %>
<span style="flex-grow: 1"></span>
<button class="o-button__plain-text7" id="keep_tenant" aria-expanded="true" aria-controls="edit_tenant-form"><i class="fas fa-times" aria-hidden="true"></i> Cancel</button>
Expand Down
1 change: 0 additions & 1 deletion app/views/stash_engine/user_admin/_user_datasets.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<% if policy(p.resource).curator_edit? %>
<%= form_with(url: stash_url_helpers.metadata_entry_pages_new_version_path, method: :post) do %>
<%= hidden_field_tag :resource_id, p.resource.id, id: "resource_id_#{p.resource.id}" %>
<%= hidden_field_tag :return_url, '/stash/dashboard' %>
<button class="c-admin-edit-icon js-trap-curator-url" title="Edit dataset" aria-label="Edit dataset"><i class="fa fa-pencil" aria-hidden="true"></i></button>
<% end %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
to: 'generic_files#check_frictionless',
as: 'generic_file_check_frictionless'

get 'choose_dashboard', to: 'dashboard#choose', as: 'choose_dashboard'
get 'dashboard', to: 'dashboard#show', as: 'dashboard'
get 'dashboard/user_datasets', to: 'dashboard#user_datasets'
get 'ajax_wait', to: 'dashboard#ajax_wait', as: 'ajax_wait'
Expand Down
Loading

0 comments on commit 47aa2eb

Please sign in to comment.