Skip to content

Commit

Permalink
Handle deleting a member from an org
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivam Singhal committed Nov 5, 2024
1 parent 140b174 commit 2c97b5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/controllers/accounts/memberships_controller.rb
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
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

resources :teams, only: %i[create update destroy]
resources :invitations, only: [:create]
resources :memberships, only: [:destroy]
end

resource :user, only: [:edit, :update] do
Expand Down

0 comments on commit 2c97b5f

Please sign in to comment.