thecore 1.4.8 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/user.rb +28 -5
- data/lib/thecore/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89226b95672590a7bb4e37006bf9d309df3b977a
|
4
|
+
data.tar.gz: a3a6192e70e327554a52a8a2dbb7331cffdb8aaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e8999c7b950a0b90355af8a2a9a58ff65670344bce215e2144a2b3f715a5fc521cfcffb540ea54b305a218902bf792aa285042720d10d5b67d2dfde4c9add8e
|
7
|
+
data.tar.gz: 125065f52f176d66b700320bbdf06963239cfe6c8338b57a095cbcbf56c11351797ee74283f1d9f4949b7740227ee442033e4614d13fa4c79f1239ed26499fd9
|
data/app/models/user.rb
CHANGED
@@ -23,6 +23,8 @@ class User < ApplicationRecord
|
|
23
23
|
validates :password, presence: true, on: :create
|
24
24
|
validates :password_confirmation, presence: true, on: :create
|
25
25
|
|
26
|
+
validates :roles, presence: true, on: :create
|
27
|
+
|
26
28
|
def self.paged(page_number)
|
27
29
|
order(admin: :desc, username: :asc).page page_number
|
28
30
|
end
|
@@ -54,7 +56,7 @@ class User < ApplicationRecord
|
|
54
56
|
username
|
55
57
|
end
|
56
58
|
|
57
|
-
#serialize :roles, Array
|
59
|
+
# serialize :roles, Array if Settings.single_role_per_user == "f"
|
58
60
|
def roles_enum
|
59
61
|
# Do not EDIT below this line
|
60
62
|
ROLES.each_with_index.map {|a,i| [I18n.t("roles.#{a.to_sym}"), (i+1).to_s]}
|
@@ -64,8 +66,20 @@ class User < ApplicationRecord
|
|
64
66
|
# if user.has_role? :admin
|
65
67
|
|
66
68
|
# for roles array stored in db... take each value, see if it matches the second column in the roles_enum array, if so, retu the 1st col of the enum as a uprcase,space_to_underscore,symbol .
|
67
|
-
|
68
|
-
|
69
|
+
begin
|
70
|
+
# roles array (enum)
|
71
|
+
chosen_roles = self.roles.map { |r| r.blank? ? nil : ROLES[r.to_i - 1] }
|
72
|
+
chosen_roles.compact.include? role
|
73
|
+
rescue
|
74
|
+
# single role
|
75
|
+
# ROLES[self.roles.to_i - 1] == role
|
76
|
+
Rails.logger.debug "ROLES: #{self.roles.to_s}"
|
77
|
+
self.roles.to_s == role.to_s
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def roles
|
82
|
+
ROLES[super.to_i - 1]
|
69
83
|
end
|
70
84
|
|
71
85
|
RailsAdmin.config do |config|
|
@@ -96,10 +110,18 @@ class User < ApplicationRecord
|
|
96
110
|
field :roles, :enum do
|
97
111
|
visible !ROLES.blank?
|
98
112
|
pretty_value do # used in list view columns and show views, defaults to formatted_value for non-association fields
|
99
|
-
|
113
|
+
begin
|
114
|
+
value.map { |v| bindings[:object].roles_enum.rassoc(v)[0] rescue nil }.compact.join ", "
|
115
|
+
rescue
|
116
|
+
I18n.t "roles.#{ROLES[value.to_i - 1]}"
|
117
|
+
end
|
100
118
|
end
|
101
119
|
export_value do
|
102
|
-
|
120
|
+
begin
|
121
|
+
value.map { |v| bindings[:object].roles_enum.rassoc(v)[0] rescue nil }.compact.join ", " # used in exports, where no html/data is allowed
|
122
|
+
rescue
|
123
|
+
I18n.t "roles.#{ROLES[value.to_i - 1]}"
|
124
|
+
end
|
103
125
|
end
|
104
126
|
queryable false
|
105
127
|
end
|
@@ -112,6 +134,7 @@ class User < ApplicationRecord
|
|
112
134
|
visible false
|
113
135
|
end
|
114
136
|
exclude_fields :lock_version
|
137
|
+
field :authentication_token
|
115
138
|
# include UserRailsAdminListConcern
|
116
139
|
end
|
117
140
|
show do
|
data/lib/thecore/version.rb
CHANGED