Merge pull request #115 from snap-cloud/admin-delete-users

Admin delete users
This commit is contained in:
Michael Ball 2021-03-08 21:25:09 -08:00 committed by GitHub
commit 7e2e785386
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 3 deletions

View file

@ -66,6 +66,16 @@ module Admin
def edit; end
def destroy
if @user.destroy
redirect_to admin_users_path,
notice: "User #{@user.id} (#{@user.email}) deleted."
else
redirect_to admin_users_path,
error: "User #{@user.id} (#{@user.emai}) could not be deleted. #{@user.full_messages.join(',')}"
end
end
private
def user_params

View file

@ -35,7 +35,8 @@ class UserDatatable < AjaxDatatablesRails::Base
roles: record.roles.any? ? show_roles(record.get_roles) : 'None',
view_url: admin_user_path(record),
edit_url: edit_admin_user_path(record),
DT_RowId: record.id
DT_RowId: record.id,
confirmed: record.confirmed_at.present?
}
end
end

View file

@ -20,6 +20,7 @@
%th{ width: '0' } Conferences Attended
%th{ width: '50%' } Roles
%th{ width: '0' } Actions
%th{ style: 'display: none' } Confirmed?
%tbody
:javascript
@ -37,6 +38,7 @@
{
"data": "confirmed_at",
"render": function (data, type, row, meta) {
console.log(meta)
return '<input type="checkbox" class="switch-checkbox" '+
'id="user_'+row.id+'_confirmed" '+
'name="user_'+row.id+'_confirmed" '+
@ -73,6 +75,11 @@
'<a class="btn-primary" href="'+data.edit_url+'">Edit</a>'+
'</div>';
}
},
{
"data": "confirmed",
"className": 'hidden',
"render": false
}
]
});

View file

@ -12,8 +12,10 @@
.tab-content
#user-info-content.tab-pane{class: "#{'active' unless params[:tab] == 'submissions-content'}"}
- if can? :edit, @user
.pull-right
.pull-right.btn-group
= link_to 'Edit', edit_admin_user_path(@user), class: 'btn btn-primary'
= link_to 'Delete', admin_user_path(@user),method: :delete, class: 'btn btn-danger',
data: {confirm: "Are you sure?"}
%table.table
- @show_attributes.each do |attr|
%tr

View file

@ -103,4 +103,21 @@ describe Admin::UsersController do
end
end
end
describe 'DELETE #destroy' do
before do
delete :destroy, params: { id: user.id }
end
it 'redirects to admin users index path' do
expect(response).to redirect_to admin_users_path
end
it 'shows success message in flash notice' do
expect(flash[:notice]).to match("User #{user.id} (#{user.email}) deleted.")
end
it 'deletes the user' do
expect { user.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end

View file

@ -8,7 +8,7 @@ describe UserDatatable do
end
let(:data_cols) do
[:id, :confirmed_at, :email, :name, :username, :attended, :roles, :view_url, :edit_url, :DT_RowId]
[:id, :confirmed_at, :email, :name, :username, :attended, :roles, :view_url, :edit_url, :DT_RowId, :confirmed]
end
let(:view) do
view = double(