Merge pull request #115 from snap-cloud/admin-delete-users
Admin delete users
This commit is contained in:
commit
7e2e785386
6 changed files with 40 additions and 3 deletions
|
|
@ -66,6 +66,16 @@ module Admin
|
||||||
|
|
||||||
def edit; end
|
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
|
private
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ class UserDatatable < AjaxDatatablesRails::Base
|
||||||
roles: record.roles.any? ? show_roles(record.get_roles) : 'None',
|
roles: record.roles.any? ? show_roles(record.get_roles) : 'None',
|
||||||
view_url: admin_user_path(record),
|
view_url: admin_user_path(record),
|
||||||
edit_url: edit_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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
%th{ width: '0' } Conferences Attended
|
%th{ width: '0' } Conferences Attended
|
||||||
%th{ width: '50%' } Roles
|
%th{ width: '50%' } Roles
|
||||||
%th{ width: '0' } Actions
|
%th{ width: '0' } Actions
|
||||||
|
%th{ style: 'display: none' } Confirmed?
|
||||||
%tbody
|
%tbody
|
||||||
|
|
||||||
:javascript
|
:javascript
|
||||||
|
|
@ -37,6 +38,7 @@
|
||||||
{
|
{
|
||||||
"data": "confirmed_at",
|
"data": "confirmed_at",
|
||||||
"render": function (data, type, row, meta) {
|
"render": function (data, type, row, meta) {
|
||||||
|
console.log(meta)
|
||||||
return '<input type="checkbox" class="switch-checkbox" '+
|
return '<input type="checkbox" class="switch-checkbox" '+
|
||||||
'id="user_'+row.id+'_confirmed" '+
|
'id="user_'+row.id+'_confirmed" '+
|
||||||
'name="user_'+row.id+'_confirmed" '+
|
'name="user_'+row.id+'_confirmed" '+
|
||||||
|
|
@ -73,6 +75,11 @@
|
||||||
'<a class="btn-primary" href="'+data.edit_url+'">Edit</a>'+
|
'<a class="btn-primary" href="'+data.edit_url+'">Edit</a>'+
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": "confirmed",
|
||||||
|
"className": 'hidden',
|
||||||
|
"render": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,10 @@
|
||||||
.tab-content
|
.tab-content
|
||||||
#user-info-content.tab-pane{class: "#{'active' unless params[:tab] == 'submissions-content'}"}
|
#user-info-content.tab-pane{class: "#{'active' unless params[:tab] == 'submissions-content'}"}
|
||||||
- if can? :edit, @user
|
- if can? :edit, @user
|
||||||
.pull-right
|
.pull-right.btn-group
|
||||||
= link_to 'Edit', edit_admin_user_path(@user), class: 'btn btn-primary'
|
= 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
|
%table.table
|
||||||
- @show_attributes.each do |attr|
|
- @show_attributes.each do |attr|
|
||||||
%tr
|
%tr
|
||||||
|
|
|
||||||
|
|
@ -103,4 +103,21 @@ describe Admin::UsersController do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ describe UserDatatable do
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:data_cols) do
|
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
|
end
|
||||||
let(:view) do
|
let(:view) do
|
||||||
view = double(
|
view = double(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue