Skip to content

Commit

Permalink
handle invite not found
Browse files Browse the repository at this point in the history
  • Loading branch information
nid90 committed Jan 6, 2025
1 parent b95a1d5 commit 38edfc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/controllers/accounts/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ def create
end

def destroy
@invite = Accounts::Organization.find_by!(slug: params[:organization_id])
.pending_invites.find(params[:id])
@invite.destroy
redirect_to accounts_organization_teams_path(current_organization),
notice: "Invitation to #{@invite.email} has been cancelled"
@invite = current_organization.pending_invites.find_by(id: params[:id])

if @invite&.destroy
redirect_to accounts_organization_teams_path(current_organization),
notice: "Invitation to #{@invite.email} has been cancelled"
else
redirect_to accounts_organization_teams_path(current_organization),
flash: {error: "Could not cancel the invitation."}
end
end

protected
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/accounts/memberships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ class Accounts::MembershipsController < SignedInApplicationController
def destroy
@membership = current_organization.memberships.find_by(id: params[:id])

if @membership.blank?
redirect_to teams_accounts_organization_path(current_organization),
flash: {error: "Could not find the member to remove."}
return
end

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"}
Expand Down

0 comments on commit 38edfc5

Please sign in to comment.