Skip to content

Commit bd934a5

Browse files
committed
[feature] Add ability to deactivate accounts
Fixes #129
1 parent cb0aa16 commit bd934a5

File tree

11 files changed

+34
-11
lines changed

11 files changed

+34
-11
lines changed

app/assets/javascripts/manage/lib/setupDataTables.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var setupDataTables = function() {
3838
{ orderable: true, data: "id", visible: false },
3939
{ orderable: true, data: "email" },
4040
{ orderable: true, data: "role" },
41+
{ orderable: true, data: "active" },
4142
{ orderable: true, data: "created_at" }
4243
]
4344
});

app/controllers/manage/admins_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def destroy
4646

4747
def user_params
4848
params.require(:user).permit(
49-
:email, :password, :password_confirmation, :remember_me, :role
49+
:email, :password, :password_confirmation, :remember_me, :role, :is_active
5050
)
5151
end
5252

app/datatables/admin_datatable.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ class AdminDatatable < AjaxDatatablesRails::Base
33

44
def view_columns
55
@view_columns ||= {
6-
id: { source: 'User.id' },
7-
email: { source: 'User.email' },
8-
role: { source: 'User.role', searchable: false },
9-
created_at: { source: 'User.created_at', searchable: false }
6+
id: { source: "User.id" },
7+
email: { source: "User.email" },
8+
role: { source: "User.role", searchable: false },
9+
active: { source: "User.is_active", searchable: false },
10+
created_at: { source: "User.created_at", searchable: false },
1011
}
1112
end
1213

@@ -18,7 +19,8 @@ def data
1819
id: record.id,
1920
email: link_to(bold(record.email), manage_admin_path(record)),
2021
role: record.role.titleize,
21-
created_at: display_datetime(record.created_at)
22+
active: record.is_active ? '<span class="badge badge-secondary">Active</span>'.html_safe : '<span class="badge badge-danger">Inactive<span>'.html_safe,
23+
created_at: display_datetime(record.created_at),
2224
}
2325
end
2426
end
@@ -27,5 +29,6 @@ def data
2729
def get_raw_records
2830
User.where(role: [:admin, :admin_limited_access, :event_tracking])
2931
end
32+
3033
# rubocop:enable Naming/AccessorMethodName
3134
end

app/models/user.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def set_default_role
2323
end
2424

2525
def active_for_authentication?
26-
true
26+
super && is_active
2727
end
2828

2929
def send_devise_notification(notification, *args)
@@ -59,9 +59,9 @@ def self.from_omniauth(auth)
5959
matching_provider = where(provider: auth.provider, uid: auth.uid)
6060
matching_email = where(email: auth.info.email)
6161
matching_provider.or(matching_email).first_or_create do |user|
62-
user.uid = auth.uid
63-
user.email = auth.info.email
64-
user.password = Devise.friendly_token[0, 20]
62+
user.uid = auth.uid
63+
user.email = auth.info.email
64+
user.password = Devise.friendly_token[0, 20]
6565
end
6666
end
6767

app/views/manage/admins/_form.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
.form-inputs
1313
= f.input :email, input_html: { "data-validate" => "presence" }, required: true
1414
= f.input :role, collection: User.roles.to_a.collect{|c| [c[0].titleize, c[0]]}, include_blank: false
15+
= f.input :is_active, collection: [['Active', true], ['Inactive', false]], as: :radio_buttons
1516

1617
.center
1718
= f.button :submit, value: ( @user.new_record? ? 'Create' : 'Save' ), class: 'btn-primary'

app/views/manage/admins/index.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
%th ID
99
%th Email
1010
%th Role
11+
%th Login access
1112
%th Registered on
1213
%tbody

app/views/manage/admins/show.html.haml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
%b Role:
1313
= @user.role.titleize
1414

15+
%p
16+
%b Login access:
17+
- if @user.is_active
18+
%span.badge.badge-success Active
19+
- else
20+
%span.badge.badge-danger Inactive
21+
1522
%p
1623
%b Registered:
1724
= display_datetime(@user.created_at)

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ en:
4444
notes: Notes are shared with applicants. Supports Markdown and HTML.
4545
user:
4646
role: Limited access prevents the admin from adding, modifying, or deleting any records; modifications through the check-in process are allowed. Event tracking limits to only event tracking.
47+
is_active: Deactivating a user will prevent them from logging in. Their access will be immediately revoked from the admin and application pages.
4748
message:
4849
type: Bulk emails are sent once, manually. Automated emails are sent upon a desired trigger/event.
4950
name: A friendly name to recognize this email. Applicants won't see this.
@@ -100,6 +101,8 @@ en:
100101
user:
101102
102103
labels:
104+
user:
105+
is_active: Login access
103106
hackathon_config:
104107
name: Hackathon Name
105108
email_from: From Email
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddIsActiveToUsers < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :users, :is_active, :boolean, default: true
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2019_05_21_171801) do
13+
ActiveRecord::Schema.define(version: 2019_05_21_213729) do
1414

1515
create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
1616
t.string "name", null: false
@@ -268,6 +268,7 @@
268268
t.string "uid"
269269
t.datetime "reminder_sent_at"
270270
t.integer "role", default: 0
271+
t.boolean "is_active", default: true
271272
t.index ["email"], name: "index_users_on_email", unique: true
272273
t.index ["provider"], name: "index_users_on_provider"
273274
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

0 commit comments

Comments
 (0)