diff --git a/app/controllers/accounts/invitations_controller.rb b/app/controllers/accounts/invitations_controller.rb index 1ef2c49ac..d6978bbb2 100644 --- a/app/controllers/accounts/invitations_controller.rb +++ b/app/controllers/accounts/invitations_controller.rb @@ -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 diff --git a/app/controllers/accounts/memberships_controller.rb b/app/controllers/accounts/memberships_controller.rb index 3d9fe28eb..b73ccb833 100644 --- a/app/controllers/accounts/memberships_controller.rb +++ b/app/controllers/accounts/memberships_controller.rb @@ -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"}