From 676d10ce36a77be8f56969dd0d403ea8679db17e Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 8 Mar 2021 19:24:34 -0800 Subject: [PATCH 1/4] HACK! Show confirmed status in the all users export --- app/controllers/admin/users_controller.rb | 6 ++++++ app/datatables/user_datatable.rb | 3 ++- app/views/admin/users/index.html.haml | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index e49c02f5..0cfdfd82 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -66,6 +66,12 @@ module Admin def edit; end + def delete + @user.destroy! + flash[:notice] = "User #{@user.id} (#{@user.emai}) successfully deleted." + redirect_to admin_users_path + end + private def user_params diff --git a/app/datatables/user_datatable.rb b/app/datatables/user_datatable.rb index 45200ebb..cc29e995 100644 --- a/app/datatables/user_datatable.rb +++ b/app/datatables/user_datatable.rb @@ -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 diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml index 6e2c13df..5e3d8894 100644 --- a/app/views/admin/users/index.html.haml +++ b/app/views/admin/users/index.html.haml @@ -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 'Edit'+ ''; } + }, + { + "data": "confirmed", + "className": 'sr-only', + "render": false } ] }); From 331e0a16104934e4ced3653293c02b3f1fa5011c Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 8 Mar 2021 19:28:12 -0800 Subject: [PATCH 2/4] better hidden class for admin datatable --- app/views/admin/users/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml index 5e3d8894..3d52ce6c 100644 --- a/app/views/admin/users/index.html.haml +++ b/app/views/admin/users/index.html.haml @@ -78,7 +78,7 @@ }, { "data": "confirmed", - "className": 'sr-only', + "className": 'hidden', "render": false } ] From 332bf8f1dfd37f3bfb44103908da2775a6693da0 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 8 Mar 2021 20:19:57 -0800 Subject: [PATCH 3/4] Support the ability for admins to delete users --- app/controllers/admin/users_controller.rb | 12 ++++++++---- app/views/admin/users/show.html.haml | 4 +++- spec/controllers/admin/users_controller_spec.rb | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 0cfdfd82..2eb2032a 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -66,10 +66,14 @@ module Admin def edit; end - def delete - @user.destroy! - flash[:notice] = "User #{@user.id} (#{@user.emai}) successfully deleted." - redirect_to admin_users_path + 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 diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index b90e72d9..c0a8f1fb 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -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 diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 51dfb04c..c3d29b81 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -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 From d93390faa62ebf302511bc7f39b122f8c7a240d0 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 8 Mar 2021 21:00:06 -0800 Subject: [PATCH 4/4] Fix datatables spec --- spec/datatables/user_datatable_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/datatables/user_datatable_spec.rb b/spec/datatables/user_datatable_spec.rb index 44c57d7b..6c0de8d8 100644 --- a/spec/datatables/user_datatable_spec.rb +++ b/spec/datatables/user_datatable_spec.rb @@ -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(