forked from rubyforgood/homeward-tails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The goal of this ticket was to add the ability for staff to deactivate ‘fosterer’ accounts just like how ‘staff’ accounts can already be deactivated. A migration was generated to add ‘deactivated_at’ to the ‘adopter_foster_account’ table. Since this functionality was going to be repeated in multiple places I decided to refactor. I pulled out the ’staff/staff/_deactivate_toggle.html.erb’ partial and put it in ‘app/views/partials’ so it was more accessible. I then refactored this to be more generic so multiple roles could use it. Related files were added/edited to make this work. For example, ‘update.turbo_stream.erb’ was added to the ‘staff/fosterers’ directory, and the one within ‘staff/staff’ was edited to fit the refactor. I’m not sure if there is potential to refactor these turbo files to keep the code even more DRY. Also, ‘deactivate’, ‘activate’, ‘update_activation’, and ‘set_fosterer’ were all added to the ‘fosterers_controller.rb’ to facilitate the new behavior. ‘set_fosterer’ involved authentication with ‘Action Policy’. Shoutout to @jmilljr24 for hardcore carrying me on the back half of this PR with all things related to the policies and routes. I’ve yet to add tests for this, but the behavior is functioning. Extra tidbit: Added a new gem to the gem file called "binding_of_caller" that enables the REPL and local/instance variable inspection when an error blows up the website.
- Loading branch information
1 parent
4762c1a
commit 5bebaa6
Showing
15 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/controllers/organizations/staff/fosterers_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
class Organizations::Staff::FosterersController < Organizations::BaseController | ||
layout "dashboard" | ||
before_action :set_fosterer, only: %i[update_activation] | ||
|
||
def index | ||
authorize! AdopterFosterAccount, context: {organization: Current.organization} | ||
|
||
@fosterer_accounts = authorized_scope(AdopterFosterAccount.fosterers) | ||
end | ||
|
||
def deactivate | ||
@fosterer_account.deactivate | ||
respond_to do |format| | ||
format.html { redirect_to staff_fosterers_index_path, notice: "Fosterer account deactivated." } | ||
format.turbo_stream { render "organizations/staff/fosterers/update" } | ||
end | ||
end | ||
|
||
def activate | ||
@fosterer_account.activate | ||
respond_to do |format| | ||
format.html { redirect_to staff_fosterers_index_path, notice: "Fosterer account activated." } | ||
format.turbo_stream { render "organizations/staff/fosterers/update" } | ||
end | ||
end | ||
|
||
def update_activation | ||
if @fosterer_account.deactivated_at | ||
activate | ||
else | ||
deactivate | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_fosterer | ||
@fosterer_account = AdopterFosterAccount.find(params[:fosterer_id]) | ||
|
||
authorize! @fosterer_account | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
manage_tasks | ||
view_organization_dashboard | ||
manage_faqs | ||
manage_adopter_foster_accounts | ||
] | ||
).freeze | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
app/views/organizations/staff/fosterers/update.turbo_stream.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= turbo_stream.replace_all ".deactivate_toggle_#{@fosterer_account.id}", partial: "partials/deactivate_toggle", | ||
locals: {account: @fosterer_account, role: "fosterer"} %> |
10 changes: 0 additions & 10 deletions
10
app/views/organizations/staff/staff/_deactivate_toggle.html.erb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<%= turbo_stream.replace_all ".staff_deactivate_toggle_#{@staff_account.id}", partial: "deactivate_toggle", | ||
locals: {staff: @staff_account} %> | ||
<%= turbo_stream.replace_all ".staff_deactivate_toggle_#{@staff_account.id}", partial: "partials/deactivate_toggle", | ||
locals: {account: @staff_account, role: "staff"} %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class=<%= "deactivate_toggle_#{account.id}" %>> | ||
<%= form_with model: account, url: send("staff_#{role}_update_activation_path", account), method: "post" do |form| %> | ||
<div class='form-group d-flex justify-content-center'> | ||
<div class="form-check form-switch"> | ||
<%= form.check_box :deactivated?, { class: "form-check-input", | ||
role: "switch", id: "flexSwitchCheckChecked", onchange: "this.form.requestSubmit()" }, true, false %> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20240531155857_add_deactivated_at_to_adopter_foster_accounts.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddDeactivatedAtToAdopterFosterAccounts < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :adopter_foster_accounts, :deactivated_at, :datetime | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.