Merge pull request #1097 from shlok007/manual_confirmation
Ability to confirm users by admin
This commit is contained in:
commit
9c5fd18c3e
7 changed files with 90 additions and 16 deletions
|
|
@ -10,6 +10,17 @@ module Admin
|
||||||
@users = User.all
|
@users = User.all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This action allow admins to manually toggle confirmation state of another user
|
||||||
|
def toggle_confirmation
|
||||||
|
if user_params[:to_confirm] == 'true'
|
||||||
|
@user.confirm
|
||||||
|
elsif user_params[:to_confirm] == 'false'
|
||||||
|
@user.confirmed_at = nil
|
||||||
|
@user.save
|
||||||
|
end
|
||||||
|
head :ok
|
||||||
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
# Variable @show_attributes holds the attributes that are visible for the 'show' action
|
# Variable @show_attributes holds the attributes that are visible for the 'show' action
|
||||||
# If you want to change the attributes that are shown in the 'show' action of users
|
# If you want to change the attributes that are shown in the 'show' action of users
|
||||||
|
|
@ -40,7 +51,7 @@ module Admin
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:email, :name, :email_public, :biography, :nickname, :affiliation, :is_admin, :username, :login, :is_disabled,
|
params.require(:user).permit(:email, :name, :email_public, :biography, :nickname, :affiliation, :is_admin, :username, :login, :is_disabled,
|
||||||
:tshirt, :mobile, :volunteer_experience, :languages, role_ids: [])
|
:tshirt, :mobile, :volunteer_experience, :languages, :to_confirm, role_ids: [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
%th #
|
%th #
|
||||||
%th E-Mail
|
%th E-Mail
|
||||||
%th Date registered
|
%th Date registered
|
||||||
%th Status
|
%th Confirmed?
|
||||||
- recent_users.each_with_index do |user, index|
|
- recent_users.each_with_index do |user, index|
|
||||||
%tbody
|
%tbody
|
||||||
%tr
|
%tr
|
||||||
|
|
@ -14,10 +14,12 @@
|
||||||
%td= link_to user.email, admin_user_path(user.id)
|
%td= link_to user.email, admin_user_path(user.id)
|
||||||
%td= user.created_at.strftime('%m/%d/%Y')
|
%td= user.created_at.strftime('%m/%d/%Y')
|
||||||
%td
|
%td
|
||||||
- if user.confirmed?
|
= check_box_tag user.id, user.id, user.confirmed?,
|
||||||
%span.label.label-success Confirmed
|
method: :patch,
|
||||||
-else
|
url: "/admin/users/#{user.id}/toggle_confirmation?user[to_confirm]=",
|
||||||
%span.label.label-danger Unconfirmed
|
class: 'switch-checkbox',
|
||||||
|
readonly: true,
|
||||||
|
data: { size: 'small', on_color: 'success', off_color: 'warning', on_text: 'Yes', off_text: 'No' }
|
||||||
- else
|
- else
|
||||||
%h5.text-warning.text-center
|
%h5.text-warning.text-center
|
||||||
No sign ups!
|
No sign ups!
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,22 @@
|
||||||
= semantic_form_for [:admin, @user] do |f|
|
= semantic_form_for [:admin, @user] do |f|
|
||||||
= f.inputs 'Basic Information' do
|
= f.inputs 'Basic Information' do
|
||||||
|
.pull-right
|
||||||
|
%b
|
||||||
|
Confirmed?
|
||||||
|
- if can? :toggle_confirmation, @user
|
||||||
|
= check_box_tag @user.id, @user.id, @user.confirmed?,
|
||||||
|
method: :patch,
|
||||||
|
url: "/admin/users/#{@user.id}/toggle_confirmation?user[to_confirm]=",
|
||||||
|
class: 'switch-checkbox',
|
||||||
|
readonly: false,
|
||||||
|
data: { size: 'small', on_color: 'success', off_color: 'warning', on_text: 'Yes', off_text: 'No' }
|
||||||
|
- else
|
||||||
|
= check_box_tag @user.id, @user.id, @user.confirmed?,
|
||||||
|
method: :patch,
|
||||||
|
url: "/admin/users/#{@user.id}/toggle_confirmation?user[to_confirm]=",
|
||||||
|
class: 'switch-checkbox',
|
||||||
|
readonly: true,
|
||||||
|
data: { size: 'small', on_color: 'success', off_color: 'warning', on_text: 'Yes', off_text: 'No' }
|
||||||
= f.input :is_admin, hint: 'An admin can create a new conference, manage users and make other users admins.'
|
= f.input :is_admin, hint: 'An admin can create a new conference, manage users and make other users admins.'
|
||||||
= f.input :name, :as => :string
|
= f.input :name, :as => :string
|
||||||
= f.input :email
|
= f.input :email
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
%table.table.table-striped.table-bordered.table-hover.datatable
|
%table.table.table-striped.table-bordered.table-hover.datatable
|
||||||
%thead
|
%thead
|
||||||
%th ID
|
%th ID
|
||||||
%th State
|
%th Confirmed?
|
||||||
%th Email
|
%th Email
|
||||||
%th Name
|
%th Name
|
||||||
%th Attended Conferences
|
%th Attended Conferences
|
||||||
|
|
@ -23,10 +23,20 @@
|
||||||
%td
|
%td
|
||||||
= user.id
|
= user.id
|
||||||
%td
|
%td
|
||||||
- if user.confirmed?
|
- if can? :toggle_confirmation, user
|
||||||
confirmed
|
= check_box_tag user.id, user.id, user.confirmed?,
|
||||||
|
method: :patch,
|
||||||
|
url: "/admin/users/#{user.id}/toggle_confirmation?user[to_confirm]=",
|
||||||
|
class: 'switch-checkbox',
|
||||||
|
readonly: false,
|
||||||
|
data: { size: 'small', on_color: 'success', off_color: 'warning', on_text: 'Yes', off_text: 'No' }
|
||||||
- else
|
- else
|
||||||
unconfirmed
|
= check_box_tag user.id, user.id, user.confirmed?,
|
||||||
|
method: :patch,
|
||||||
|
url: "/admin/users/#{user.id}/toggle_confirmation?user[to_confirm]=",
|
||||||
|
class: 'switch-checkbox',
|
||||||
|
readonly: true,
|
||||||
|
data: { size: 'small', on_color: 'success', off_color: 'warning', on_text: 'Yes', off_text: 'No' }
|
||||||
%td
|
%td
|
||||||
= user.email
|
= user.email
|
||||||
%td
|
%td
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,6 @@
|
||||||
- if can? :edit, @user
|
- if can? :edit, @user
|
||||||
.pull-right
|
.pull-right
|
||||||
= link_to 'Edit', edit_admin_user_path(@user), class: 'btn btn-primary'
|
= link_to 'Edit', edit_admin_user_path(@user), class: 'btn btn-primary'
|
||||||
- if @user.confirmed?
|
|
||||||
%span.label.label-success
|
|
||||||
confirmed
|
|
||||||
- else
|
|
||||||
%span.label.label-warning
|
|
||||||
unconfirmed
|
|
||||||
%table.table
|
%table.table
|
||||||
- @show_attributes.each do |attr|
|
- @show_attributes.each do |attr|
|
||||||
%tr
|
%tr
|
||||||
|
|
@ -32,6 +26,28 @@
|
||||||
- elsif attr == 'biography'
|
- elsif attr == 'biography'
|
||||||
%td
|
%td
|
||||||
= markdown(@user.biography)
|
= markdown(@user.biography)
|
||||||
|
- elsif attr == 'email'
|
||||||
|
%td
|
||||||
|
= @user.send(attr)
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
%b
|
||||||
|
Confirmed?
|
||||||
|
%td
|
||||||
|
- if can? :toggle_confirmation, @user
|
||||||
|
= check_box_tag @user.id, @user.id, @user.confirmed?,
|
||||||
|
method: :patch,
|
||||||
|
url: "/admin/users/#{@user.id}/toggle_confirmation?user[to_confirm]=",
|
||||||
|
class: 'switch-checkbox',
|
||||||
|
readonly: false,
|
||||||
|
data: { size: 'small', on_color: 'success', off_color: 'warning', on_text: 'Yes', off_text: 'No' }
|
||||||
|
- else
|
||||||
|
= check_box_tag @user.id, @user.id, @user.confirmed?,
|
||||||
|
method: :patch,
|
||||||
|
url: "/admin/users/#{@user.id}/toggle_confirmation?user[to_confirm]=",
|
||||||
|
class: 'switch-checkbox',
|
||||||
|
readonly: true,
|
||||||
|
data: { size: 'small', on_color: 'success', off_color: 'warning', on_text: 'Yes', off_text: 'No' }
|
||||||
- else
|
- else
|
||||||
%td= @user.send(attr)
|
%td= @user.send(attr)
|
||||||
#submissions-content.tab-pane{class: "#{'active' if params[:tab] == 'submissions-content'}"}
|
#submissions-content.tab-pane{class: "#{'active' if params[:tab] == 'submissions-content'}"}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@ Osem::Application.routes.draw do
|
||||||
|
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
resources :users
|
resources :users
|
||||||
|
resources :users do
|
||||||
|
member do
|
||||||
|
patch :toggle_confirmation
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :comments, only: [:index]
|
resources :comments, only: [:index]
|
||||||
resources :conference do
|
resources :conference do
|
||||||
resource :contact, except: [:index, :new, :create, :show, :destroy]
|
resource :contact, except: [:index, :new, :create, :show, :destroy]
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,19 @@ describe Admin::UsersController do
|
||||||
expect(response).to render_template :index
|
expect(response).to render_template :index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
describe 'PATCH #toggle_confirmation' do
|
||||||
|
it 'confirms user' do
|
||||||
|
user_to_confirm = create(:user, email: 'unconfirmed_user@osem.io', confirmed_at: nil)
|
||||||
|
patch :toggle_confirmation, id: user_to_confirm.id, user: { to_confirm: 'true' }
|
||||||
|
user_to_confirm.reload
|
||||||
|
expect(user_to_confirm.confirmed?).to eq true
|
||||||
|
end
|
||||||
|
it 'undo confirmation of user' do
|
||||||
|
patch :toggle_confirmation, id: user.id, user: { to_confirm: 'false' }
|
||||||
|
user.reload
|
||||||
|
expect(user.confirmed?).to eq false
|
||||||
|
end
|
||||||
|
end
|
||||||
describe 'PATCH #update' do
|
describe 'PATCH #update' do
|
||||||
context 'valid attributes' do
|
context 'valid attributes' do
|
||||||
before :each do
|
before :each do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue