Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
tofarr committed May 24, 2024
2 parents 6056696 + fdb0720 commit 457c20d
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/_index-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ index-table is for displaying tabular information in the hub views.
It expects to be the primary content of the given page (full width).
*/

.assigned-clients-page-body, .clients-page-body {
.assigned-clients-index-page-body, .clients-index-page-body {
main, .flash-alerts .grid {
width: fit-content;
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/_take-action-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}

.assigned-clients-page-body, .clients-page-body {
.assigned-clients-index-page-body, .clients-index-page-body {
.take-action-box .take-action-box-inner {
display: flex;
align-items: center;
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/role_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def role_type_from_role_name(role_name)
end

def user_group(user)
return if user.role.nil?

if user.role_type == OrganizationLeadRole::TYPE
user.role.organization.name
elsif user.role_type == CoalitionLeadRole::TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

<p class="text--help text--bold spacing-below-25"><%= t(".by_clicking_submit") %></p>

<button type="submit" class="button button--cta">
<%= f.button :submit, class: "button button--cta", data: {disable_with: t("general.submit") } do %>
<%= t("general.submit") %>
</button><%= link_to t("general.cancel"), :back, class: "button" %>
<% end %><%= link_to t("general.cancel"), :back, class: "button" %>
<% end %>
</div>
Expand Down
5 changes: 3 additions & 2 deletions app/views/hub/bulk_actions/change_organization/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

<p class="text--help text--bold spacing-below-25"><%= t(".by_clicking_submit") %></p>

<button type="submit" class="button button--cta">

<%= f.button :submit, class: "button button--cta", data: {disable_with: t("general.submit") } do %>
<%= t("general.submit") %>
</button><%= link_to t("general.cancel"), :back, class: "button" %>
<% end %><%= link_to t("general.cancel"), :back, class: "button" %>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hub/bulk_actions/send_a_message/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

<p class="text--help text--bold spacing-below-25"><%= t(".by_clicking_submit") %></p>

<button type="submit" class="button button--cta">
<%= f.button :submit, class: "button button--cta", data: {disable_with: t("general.submit") } do %>
<%= t("general.submit") %>
</button><%= link_to t("general.cancel"), :back, class: "button" %>
<% end %><%= link_to t("general.cancel"), :back, class: "button" %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/hub.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

</head>

<body class="admin honeycrisp-compact hub <%= controller_name.gsub("_", "-") %>-page-body">
<body class="admin honeycrisp-compact hub <%= controller_name.gsub("_", "-") %>-<%= action_name.gsub("_", "-") %>-page-body">
<a href="#maincontent" id="skip-content-link" class="skip-link button--green"><%= t('views.layouts.application.skip_content') %></a>

<div class="columns">
Expand Down
69 changes: 69 additions & 0 deletions lib/tasks/cleanup_orphaned_users.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace :cleanup_orphaned_users do
desc 'Remove users that do not have a role'
task find_orphaned_users: [:environment] do
admin_orphaned_users = User.joins("LEFT JOIN admin_roles ON users.role_id = admin_roles.id AND users.role_type = 'AdminRole'")
.where(admin_roles: { id: nil }, role_type: 'AdminRole')

greeter_orphaned_users = User.joins("LEFT JOIN greeter_roles ON users.role_id = greeter_roles.id AND users.role_type = 'GreeterRole'")
.where(greeter_roles: { id: nil }, role_type: 'GreeterRole')

site_coordinator_orphaned_users = User.joins("LEFT JOIN site_coordinator_roles ON users.role_id = site_coordinator_roles.id AND users.role_type = 'SiteCoordinatorRole'")
.where(site_coordinator_roles: { id: nil }, role_type: 'SiteCoordinatorRole')

client_success_orphaned_users = User.joins("LEFT JOIN client_success_roles ON users.role_id = client_success_roles.id AND users.role_type = 'ClientSuccessRole'")
.where(client_success_roles: { id: nil }, role_type: 'ClientSuccessRole')

coalition_lead_orphaned_users = User.joins("LEFT JOIN coalition_lead_roles ON users.role_id = coalition_lead_roles.id AND users.role_type = 'CoalitionLeadRole'")
.where(coalition_lead_roles: { id: nil }, role_type: 'CoalitionLeadRole')

organization_lead_orphaned_users = User.joins("LEFT JOIN organization_lead_roles ON users.role_id = organization_lead_roles.id AND users.role_type = 'OrganizationLeadRole'")
.where(organization_lead_roles: { id: nil }, role_type: 'OrganizationLeadRole')

team_member_orphaned_users = User.joins("LEFT JOIN team_member_roles ON users.role_id = team_member_roles.id AND users.role_type = 'TeamMemberRole'")
.where(team_member_roles: { id: nil }, role_type: 'TeamMemberRole')

orphaned_users = admin_orphaned_users + greeter_orphaned_users + site_coordinator_orphaned_users + client_success_orphaned_users + coalition_lead_orphaned_users + organization_lead_orphaned_users + team_member_orphaned_users

puts "These users have no roles: #{orphaned_users.pluck(:id)}"
end

desc "Replace user_id calls in other models and delete old user"
task :replace_user_associations_and_delete_old_user, [:old_user_id, :new_user_id] => :environment do |t, args|
old_user_id = args[:old_user_id]
new_user_id = args[:new_user_id]
if old_user_id.nil? || new_user_id.nil?
puts "Please provide a user ID."
next
end

old_user = User.find_by(id: old_user_id)
new_user = User.find_by(id: new_user_id)

if old_user.nil? || new_user.nil?
puts "Please provide users that exist"
else
if old_user.role.present?
puts "Role for old user ##{old_user_id} is present, are you sure you want to delete?"
next
end

logs = AccessLog.where(user: old_user)
logs.update(user: new_user)

notes = Note.where(user_id: old_user)
notes.update(user: new_user)

notifications = UserNotification.where(user_id: old_user)
notifications.update(user: new_user)

system_notes = SystemNote.where(user_id: old_user)
system_notes.update(user: new_user)

puts "User with ID #{old_user_id} and associated records have been replaced with ID #{new_user_id}."

old_user.destroy!

puts "User with ID #{old_user_id} has been deleted"
end
end
end
58 changes: 58 additions & 0 deletions spec/tasks/cleanup_orphaned_users_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'rails_helper'

describe "cleanup_orphaned_users:find_orphaned_users" do
include_context "rake"

around { |example| capture_output { example.run } }

before(:all) do
Rails.application.load_tasks
end

let!(:team_member_user) { create :team_member_user }
let!(:admin_user) { create :admin_user }

context "when there are users without roles" do

before do
team_member_user.role.destroy
admin_user.role.destroy
end

it "it finds users without roles" do
expect {
task.invoke
}.to output(/These users have no roles: \[#{admin_user.id}, #{team_member_user.id}]/).to_stdout
end
end
end

describe "cleanup_orphaned_users:replace_user_associations_and_delete_old_user" do
include_context "rake"

around { |example| capture_output { example.run } }

before(:all) do
Rails.application.load_tasks
end

let!(:team_member_user) { create :team_member_user }
let!(:admin_user) { create :admin_user }

context "when old and new user exists" do
let!(:new_user){ create :team_member_user}
let!(:old_user){ create :team_member_user}
let!(:access_log) { create :access_log, user: old_user }
let!(:note) { create :note, user: old_user }

before do
old_user.role.destroy
end

it "it finds users without roles" do
task.invoke(old_user.id, new_user.id)
expect(access_log.reload.user).to eq new_user
expect(note.reload.user).to eq new_user
end
end
end

0 comments on commit 457c20d

Please sign in to comment.