Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin tenant removal fixes #1857

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/stash_engine/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SessionsController < ApplicationController

# this is the place omniauth calls back for shibboleth logins
def callback
current_user.roles.tenant_roles.delete_all
current_user.update(tenant_id: params[:tenant_id])
do_redirect
end
Expand Down Expand Up @@ -111,6 +112,7 @@ def choose_sso

# no partner, so set as generic dryad tenant without membership benefits
def no_partner
session[:target_page] = params[:target_page] if params[:target_page]
set_default_tenant
do_redirect
end
Expand All @@ -122,6 +124,7 @@ def sso
tenant = StashEngine::Tenant.find(params[:tenant_id])
case tenant&.authentication&.strategy
when 'author_match'
current_user.roles.tenant_roles.delete_all
current_user.update(tenant_id: tenant.id)
do_redirect
when 'ip_address'
Expand Down Expand Up @@ -274,6 +277,7 @@ def validate_ip(tenant:)
net = IPAddr.new(range)
next unless net.include?(IPAddr.new(request.remote_ip))

current_user.roles.tenant_roles.delete_all
current_user.update(tenant_id: tenant.id)
do_redirect
return nil # adding nil here to jump out of loop and return early since rubocop sucks & requires a return value
Expand All @@ -298,6 +302,7 @@ def do_redirect
def set_default_tenant
return unless current_user.present?

current_user.roles.tenant_roles.delete_all
current_user.update(tenant_id: APP_CONFIG.default_tenant)
end
end
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 @@ -26,6 +26,7 @@
<br/><br/>
<p>Is your institution not a member of Dryad?</p>
<%= form_with(url: no_partner_path, method: :post) do |f| %>
<% if @target_page %><input type="hidden" name="target_page" value="<%= @target_page %>"><% end %>
<%= f.button type: 'submit', class: 'o-button__plain-text7' do %>
<i class="fa fa-minus-circle" aria-hidden="true"></i> Remove member affiliation (<%= current_tenant.short_name %>)
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/stash_engine/user_admin/edit.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ when 'tenant_id'
end %>";
<% if @field == 'tenant_id' %>
$('#edit_roles_form').html("<%= escape_javascript(render partial: 'admin_role_form', locals: { user: @user }) %>");
document.getElementById('user_role_<%= @user.id %>').innerHTML = "<%= @user.roles.present? ? @user.roles.map{|r| "#{r.role_object_type&.delete_prefix("StashEngine::")&.sub('JournalOrganization', 'Publisher')} #{r.role}".strip.capitalize }.join(", ") : "User" %>";
<% end %>

document.getElementById('genericModalDialog').close();