-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove staff account relation with organization * Copy deactivated_at logic from StaffAccount to User * Create UserPolicy in lieu of StaffAccountPolicy * Refactor verify_active_staff to remove staff_account logic * Create UserPolicy test * Refactor the staff index route action logic * Remove unused routes deactivation routes * Change http request type from post to put for accuracy * Remove useless staff_account conditional * Refactor deactivation logic * Refactor staff_account conditionals * Refactor organization_staff class method for role logic * Remove staff_account logic from service * Add organization to role assignment in service * Remove more staff_account references * Drop staff_accounts * Refactor the conditionals on the adoptable pets page * Fix localization ref * Remove optional Person from User * Fail loudly on activation changes * Fix this test implementation to actually test OrganizationPolicy * Fix incorrect usage of tenancy in test * Remove unused instance variables * Remove unnecessary organization method as AdopterApp has org association * Define organization for verify_active_staff check * Move staff? check to user model * Move role method to authorizable concern * Add flash message for updating activation * Remove old references to staff_account * Loudly fail activation updates * Replace staff_account activation logic
- Loading branch information
Showing
53 changed files
with
235 additions
and
397 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
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,43 +1,35 @@ | ||
class Organizations::Staff::StaffController < Organizations::BaseController | ||
before_action :set_staff_account, only: [:deactivate, :activate, :update_activation] | ||
before_action :set_staff, only: [:update_activation] | ||
|
||
layout "dashboard" | ||
|
||
def index | ||
authorize! StaffAccount, context: {organization: Current.organization} | ||
authorize! User, context: {organization: Current.organization} | ||
|
||
@staff_accounts = authorized_scope(StaffAccount.all) | ||
@staff = authorized_scope(User.staff) | ||
end | ||
|
||
def deactivate | ||
@staff_account.deactivate | ||
respond_to do |format| | ||
format.html { redirect_to staff_staff_index_path, notice: t(".success") } | ||
format.turbo_stream { render "organizations/staff/staff/update" } | ||
def update_activation | ||
if @staff.deactivated_at | ||
@staff.activate | ||
else | ||
@staff.deactivate | ||
end | ||
end | ||
|
||
def activate | ||
@staff_account.activate | ||
respond_to do |format| | ||
format.html { redirect_to staff_staff_index_path, notice: t(".success") } | ||
format.turbo_stream { render "organizations/staff/staff/update" } | ||
end | ||
end | ||
|
||
def update_activation | ||
if @staff_account.deactivated_at | ||
activate | ||
else | ||
deactivate | ||
success = @staff.deactivated_at.nil? ? | ||
t(".activated", staff: @staff.full_name) : | ||
t(".deactivated", staff: @staff.full_name) | ||
format.html { redirect_to staff_staff_index_path, notice: success } | ||
format.turbo_stream { flash.now[:notice] = success } | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_staff_account | ||
@staff_account = StaffAccount.find(params[:staff_id]) | ||
def set_staff | ||
@staff = User.find(params[:staff_id]) | ||
|
||
authorize! @staff_account | ||
authorize! @staff | ||
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
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 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Organizations::UserPolicy < ApplicationPolicy | ||
pre_check :verify_organization! | ||
pre_check :verify_active_staff! | ||
|
||
def index? | ||
permission?(:manage_staff) | ||
end | ||
|
||
def update_activation? | ||
permission?(:activate_staff) && record.id != user.id | ||
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
Oops, something went wrong.