-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle deleting a member from an org
- Loading branch information
Shivam Singhal
committed
Nov 5, 2024
1 parent
140b174
commit 2c97b5f
Showing
2 changed files
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Accounts::MembershipsController < SignedInApplicationController | ||
before_action :require_write_access!, only: %i[destroy] | ||
|
||
def destroy | ||
@membership = current_organization.memberships.find_by(id: params[:id]) | ||
|
||
unless helpers.can_current_user_remove_member?(@membership.user) | ||
redirect_to teams_accounts_organization_path(current_organization), | ||
flash: { error: "You don't have permission to remove this member" } | ||
return | ||
end | ||
|
||
if @membership.discarded? | ||
redirect_to teams_accounts_organization_path(current_organization), | ||
flash: { error: "Member was already removed" } | ||
elsif @membership.discard | ||
puts "MembershipsController inside foo destroy" | ||
redirect_to teams_accounts_organization_path(current_organization), | ||
notice: "Member #{@membership.user.email} has been removed" | ||
else | ||
redirect_to teams_accounts_organization_path(current_organization), | ||
flash: {error: "#{@membership.errors.full_messages.to_sentence}"} | ||
end | ||
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