From 282d9ddacb567b5ca80372a22d9bce99fead6cec Mon Sep 17 00:00:00 2001
From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com>
Date: Wed, 21 Aug 2024 22:39:39 -0700
Subject: [PATCH 1/6] Adds in action for reset_password_partner_user
This commit adds in a new action to the partner_users_controller to reset
the corresponding user's password.
It also adds in a new route for the action
-reset_password_partner_user
-/partners/:partner_id/users/:id/reset_password(.:format)
-partner_users#reset_password
[Ticket: 4596]
---
app/controllers/partner_users_controller.rb | 11 +++++++++++
config/routes.rb | 1 +
2 files changed, 12 insertions(+)
diff --git a/app/controllers/partner_users_controller.rb b/app/controllers/partner_users_controller.rb
index bb20c2f5f5..9b89665100 100644
--- a/app/controllers/partner_users_controller.rb
+++ b/app/controllers/partner_users_controller.rb
@@ -51,6 +51,17 @@ def resend_invitation
end
end
+ def reset_password
+ user = User.find(params[:id])
+
+ user.send_reset_password_instructions
+ if user.errors.none?
+ redirect_back(fallback_location: root_path, notice: "Password e-mail sent!")
+ else
+ redirect_back(fallback_location: "/", alert: user.errors.full_messages.to_sentence)
+ end end
+
+
private
def set_partner
diff --git a/config/routes.rb b/config/routes.rb
index d9595315dd..a97548c5cd 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -206,6 +206,7 @@ def set_up_flipper
resources :users, only: [:index, :create, :destroy], controller: 'partner_users' do
member do
post :resend_invitation
+ post :reset_password
end
end
From 50650bc1dcdb4d74c47531b35fbf427076ac13c6 Mon Sep 17 00:00:00 2001
From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com>
Date: Thu, 22 Aug 2024 10:14:13 -0700
Subject: [PATCH 2/6] Adds in and stylizes the reset password button on 'Manage
Users' page
---
app/views/partner_users/_users.html.erb | 3 +++
1 file changed, 3 insertions(+)
diff --git a/app/views/partner_users/_users.html.erb b/app/views/partner_users/_users.html.erb
index 74d7f6fb9d..f4fc9965c6 100644
--- a/app/views/partner_users/_users.html.erb
+++ b/app/views/partner_users/_users.html.erb
@@ -53,6 +53,9 @@
Resend Invitation
<% end %>
<% end %>
+ <%= button_to reset_password_partner_user_path(partner, user), method: :post, data: { confirm: "Are you sure?" }, class: "btn btn-info btn-xs mb-2" do %>
+ Reset Password
+ <% end %>
<%= button_to partner_user_path(partner, user), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger btn-xs" do %>
Remove Access
<% end %>
From 1a1fca8211a6e765ff98c563a0f909bc19e268ef Mon Sep 17 00:00:00 2001
From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com>
Date: Thu, 22 Aug 2024 10:28:18 -0700
Subject: [PATCH 3/6] Adds in rspec for new controller action
---
app/controllers/partner_users_controller.rb | 5 +++--
spec/requests/partner_users_requests_spec.rb | 19 +++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/app/controllers/partner_users_controller.rb b/app/controllers/partner_users_controller.rb
index 9b89665100..ed79519484 100644
--- a/app/controllers/partner_users_controller.rb
+++ b/app/controllers/partner_users_controller.rb
@@ -53,13 +53,14 @@ def resend_invitation
def reset_password
user = User.find(params[:id])
-
+
user.send_reset_password_instructions
if user.errors.none?
redirect_back(fallback_location: root_path, notice: "Password e-mail sent!")
else
redirect_back(fallback_location: "/", alert: user.errors.full_messages.to_sentence)
- end end
+ end
+ end
private
diff --git a/spec/requests/partner_users_requests_spec.rb b/spec/requests/partner_users_requests_spec.rb
index 3fd3a5d71f..841d039429 100644
--- a/spec/requests/partner_users_requests_spec.rb
+++ b/spec/requests/partner_users_requests_spec.rb
@@ -111,4 +111,23 @@
end
end
end
+
+ describe "POST #reset_password" do
+ let!(:partner_user) do
+ UserInviteService.invite(
+ email: "meow@example.com",
+ name: "Meow Mix",
+ roles: [Role::PARTNER],
+ resource: partner
+ )
+ end
+
+ context "when the partner needs to reset a user's password" do
+ it "resends the reset password email and redirects back to root_path" do
+ post reset_password_partner_user_path(default_params.merge(partner_id: partner, id: partner_user))
+
+ expect(response).to redirect_to(root_path)
+ end
+ end
+ end
end
From f3a9dc45f1ca3e1c19e80445094fe432974149e5 Mon Sep 17 00:00:00 2001
From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com>
Date: Thu, 22 Aug 2024 10:58:46 -0700
Subject: [PATCH 4/6] Updates rspec for reset password
Adds in check for ActionMailer count increases by 1
Adds in check for the expected notice message
[Ticket: 4596]
---
app/controllers/partner_users_controller.rb | 7 +------
spec/requests/partner_users_requests_spec.rb | 4 ++--
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/app/controllers/partner_users_controller.rb b/app/controllers/partner_users_controller.rb
index ed79519484..102da47f34 100644
--- a/app/controllers/partner_users_controller.rb
+++ b/app/controllers/partner_users_controller.rb
@@ -55,14 +55,9 @@ def reset_password
user = User.find(params[:id])
user.send_reset_password_instructions
- if user.errors.none?
- redirect_back(fallback_location: root_path, notice: "Password e-mail sent!")
- else
- redirect_back(fallback_location: "/", alert: user.errors.full_messages.to_sentence)
- end
+ redirect_back(fallback_location: root_path, notice: "Password e-mail sent!")
end
-
private
def set_partner
diff --git a/spec/requests/partner_users_requests_spec.rb b/spec/requests/partner_users_requests_spec.rb
index 841d039429..87cc19ad02 100644
--- a/spec/requests/partner_users_requests_spec.rb
+++ b/spec/requests/partner_users_requests_spec.rb
@@ -124,9 +124,9 @@
context "when the partner needs to reset a user's password" do
it "resends the reset password email and redirects back to root_path" do
- post reset_password_partner_user_path(default_params.merge(partner_id: partner, id: partner_user))
-
+ expect { post reset_password_partner_user_path(default_params.merge(partner_id: partner, id: partner_user)) }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(response).to redirect_to(root_path)
+ expect(flash[:notice]).to eq("Password e-mail sent!")
end
end
end
From b91207d258ef0cfecd66aa5c3ee3c831dd757ce6 Mon Sep 17 00:00:00 2001
From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com>
Date: Thu, 22 Aug 2024 11:08:03 -0700
Subject: [PATCH 5/6] Changes icon on reset-password to a key
---
app/views/partner_users/_users.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/views/partner_users/_users.html.erb b/app/views/partner_users/_users.html.erb
index f4fc9965c6..7018148cdf 100644
--- a/app/views/partner_users/_users.html.erb
+++ b/app/views/partner_users/_users.html.erb
@@ -54,7 +54,7 @@
<% end %>
<% end %>
<%= button_to reset_password_partner_user_path(partner, user), method: :post, data: { confirm: "Are you sure?" }, class: "btn btn-info btn-xs mb-2" do %>
- Reset Password
+ Reset Password
<% end %>
<%= button_to partner_user_path(partner, user), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger btn-xs" do %>
Remove Access
From 44a816b044908fd289f58724ed7b0184be3a154d Mon Sep 17 00:00:00 2001
From: Enoch Hsu <1529929+ewoknock@users.noreply.github.com>
Date: Fri, 23 Aug 2024 13:01:45 -0700
Subject: [PATCH 6/6] Updating rspec test description to be more accurate
---
spec/requests/partner_users_requests_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/spec/requests/partner_users_requests_spec.rb b/spec/requests/partner_users_requests_spec.rb
index 87cc19ad02..c15a59828b 100644
--- a/spec/requests/partner_users_requests_spec.rb
+++ b/spec/requests/partner_users_requests_spec.rb
@@ -122,7 +122,7 @@
)
end
- context "when the partner needs to reset a user's password" do
+ context "when a bank needs to reset a partner user's password" do
it "resends the reset password email and redirects back to root_path" do
expect { post reset_password_partner_user_path(default_params.merge(partner_id: partner, id: partner_user)) }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(response).to redirect_to(root_path)