Give Admins Ability to Delete Invitations (#10959)
* WIP: Gives Admins the ability to delete invitations from /admin/invitations * Refactors #destroy to properly delete invites, redirect, & display messages * Adds additional flash message and makes existing messages more explicit * Adds spec to test the deletion of invitations in admin/invitations
This commit is contained in:
parent
d2db2f683d
commit
a6aabb2149
4 changed files with 30 additions and 1 deletions
|
|
@ -19,6 +19,17 @@ module Admin
|
|||
saw_onboarding: false,
|
||||
editor_version: :v2,
|
||||
registered: false)
|
||||
flash[:success] = "The invite has been sent to the user's email."
|
||||
redirect_to admin_invitations_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@invitation = User.where(registered: false).find(params[:id])
|
||||
if @invitation.destroy
|
||||
flash[:success] = "The invitation has been deleted."
|
||||
else
|
||||
flash[:danger] = @invitation.errors_as_sentence
|
||||
end
|
||||
redirect_to admin_invitations_path
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@
|
|||
<td><%= user.id %></td>
|
||||
<td><%= user.name %></td>
|
||||
<td><%= user.email %></td>
|
||||
<h5>
|
||||
<td><%= link_to "Delete", url_for(action: :destroy, id: user.id), method: :delete, data: { confirm: "Are you sure you want to delete this pending invite?" }, class: "btn btn-danger" %></td>
|
||||
</h5>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ Rails.application.routes.draw do
|
|||
resources :comments, only: [:index]
|
||||
resources :events, only: %i[index create update]
|
||||
resources :feedback_messages, only: %i[index show]
|
||||
resources :invitations, only: %i[index new create]
|
||||
resources :invitations, only: %i[index new create destroy]
|
||||
resources :pages, only: %i[index new create edit update destroy]
|
||||
resources :mods, only: %i[index update]
|
||||
resources :moderator_actions, only: %i[index]
|
||||
|
|
|
|||
|
|
@ -30,4 +30,19 @@ RSpec.describe "/admin/invitations", type: :request do
|
|||
expect(User.last.registered).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /admin/invitations" do
|
||||
let!(:invitation) { create(:user, registered: false) }
|
||||
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
it "deletes the invitation" do
|
||||
expect do
|
||||
delete "/admin/invitations/#{invitation.id}"
|
||||
end.to change { User.all.count }.by(-1)
|
||||
expect(response.body).to redirect_to "/admin/invitations"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue