4
4
#
5
5
# Table name: users
6
6
#
7
- # id :integer not null, primary key
8
- # authentication_token :string
9
- # confirmation_sent_at :datetime
10
- # confirmation_token :string
11
- # confirmed_at :datetime
12
- # current_sign_in_at :datetime
13
- # current_sign_in_ip :string
14
- # email :string not null
15
- # encrypted_password :string not null
16
- # failed_attempts :integer default(0)
17
- # image_content_type :string
18
- # image_file_name :string
19
- # image_file_size :bigint
20
- # image_updated_at :datetime
21
- # invitation_token :string
22
- # last_seen_at :datetime
23
- # last_sign_in_at :datetime
24
- # last_sign_in_ip :string
25
- # locked_at :datetime
26
- # preferences :text
27
- # rails_tz :string(255)
28
- # remember_created_at :datetime
29
- # reset_password_sent_at :datetime
30
- # reset_password_token :string
31
- # roles_mask :integer
32
- # sign_in_count :integer default(0)
33
- # tzinfo_tz :string(255)
34
- # unconfirmed_email :string
35
- # unlock_token :string
36
- # user_name :string not null
37
- # created_at :datetime
38
- # updated_at :datetime
7
+ # id :integer not null, primary key
8
+ # authentication_token :string
9
+ # confirmation_sent_at :datetime
10
+ # confirmation_token :string
11
+ # confirmed_at :datetime
12
+ # contactable(Is the user contactable - consent status re: email communications ) :enum default("unknown"), not null
13
+ # current_sign_in_at :datetime
14
+ # current_sign_in_ip :string
15
+ # email :string not null
16
+ # encrypted_password :string not null
17
+ # failed_attempts :integer default(0)
18
+ # image_content_type :string
19
+ # image_file_name :string
20
+ # image_file_size :bigint
21
+ # image_updated_at :datetime
22
+ # invitation_token :string
23
+ # last_seen_at :datetime
24
+ # last_sign_in_at :datetime
25
+ # last_sign_in_ip :string
26
+ # locked_at :datetime
27
+ # preferences :text
28
+ # rails_tz :string(255)
29
+ # remember_created_at :datetime
30
+ # reset_password_sent_at :datetime
31
+ # reset_password_token :string
32
+ # roles_mask :integer
33
+ # sign_in_count :integer default(0)
34
+ # tzinfo_tz :string(255)
35
+ # unconfirmed_email :string
36
+ # unlock_token :string
37
+ # user_name :string not null
38
+ # created_at :datetime
39
+ # updated_at :datetime
39
40
#
40
41
# Indexes
41
42
#
@@ -61,6 +62,25 @@ class User < ApplicationRecord
61
62
:recoverable , :rememberable , :trackable , :validatable ,
62
63
:confirmable , :lockable , :timeoutable
63
64
65
+ # Defines a reusable mapping (CONSENT_ENUM) of consent constants
66
+ CONSENT_UNASKED = 'unasked'
67
+ CONSENT_CONSENTED = 'consented'
68
+ CONSENT_UNCONSENTED = 'unconsented'
69
+
70
+ CONSENT_ENUM = {
71
+ CONSENT_UNASKED => CONSENT_UNASKED ,
72
+ CONSENT_CONSENTED => CONSENT_CONSENTED ,
73
+ CONSENT_UNCONSENTED => CONSENT_UNCONSENTED
74
+ } . freeze
75
+
76
+ # enum :consent, {
77
+ # CONSENT_UNASKED => CONSENT_UNASKED,
78
+ # CONSENT_CONSENTED => CONSENT_CONSENTED,
79
+ # CONSENT_UNCONSENTED => CONSENT_UNCONSENTED
80
+ # }, prefix: :consent
81
+
82
+ enum :contactable , CONSENT_ENUM , prefix : :contactable , validate : true
83
+
64
84
# http://www.phase2technology.com/blog/authentication-permissions-and-roles-in-rails-with-devise-cancan-and-role-model/
65
85
include RoleModel
66
86
@@ -210,8 +230,8 @@ def login
210
230
def excluded_login
211
231
reserved_user_names = [ 'admin' , 'harvester' , 'analysis_runner' , 'root' , 'superuser' , 'administrator' , 'admins' ,
212
232
'administrators' ]
213
- errors . add ( :login , 'is reserved' ) if reserved_user_names . include? ( login . downcase )
214
- errors . add ( :user_name , 'is reserved' ) if reserved_user_names . include? ( user_name . downcase )
233
+ errors . add ( :login , 'is reserved' ) if reserved_user_names . include? ( login & .downcase )
234
+ errors . add ( :user_name , 'is reserved' ) if reserved_user_names . include? ( user_name & .downcase )
215
235
end
216
236
217
237
# format, uniqueness, and presence are validated by devise
@@ -345,10 +365,11 @@ def admin?
345
365
end
346
366
347
367
# Define filter api settings
368
+ # @return [Hash] filter settings
348
369
def self . filter_settings
349
370
{
350
- valid_fields : [ :id , :user_name , :roles_mask , :last_seen_at , :created_at , :updated_at ] ,
351
- render_fields : [ :id , :user_name , :roles_mask ] ,
371
+ valid_fields : [ :id , :user_name , :roles_mask , :last_seen_at , :created_at , :updated_at , :contactable ] ,
372
+ render_fields : [ :id , :user_name , :roles_mask , :contactable ] ,
352
373
text_fields : [ :user_name ] ,
353
374
custom_fields : lambda { |item , user |
354
375
# 'item' is the user being processed, 'user' is the currently logged in user
0 commit comments