thecore 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20160331101902_add_admin_user.rb +1 -147
- data/lib/thecore/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec9c9509efb10e679d7135e82f8bc300d8ec5441
|
4
|
+
data.tar.gz: f626477ca7cfdc95e37855db65cf16fbc35a29a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e84eb7350a2c566f78091adc08ae801bb598bae2a05d9f6f078fd8e71772d213a71fa5cf8fc27ff725515b7395dd6e8f36af8ab476591e549c8c603f56648fc8
|
7
|
+
data.tar.gz: 25e4425d68e9e87ad6ea9cc2a02a7416eab57d4b019ca868664a9fa7275dc58d311dfdbbb7e952d5322ab29f1fb76fd113e8ffa5ff76800fe4d04c88fab42991
|
@@ -1,150 +1,4 @@
|
|
1
1
|
class AddAdminUser < ActiveRecord::Migration[4.2]
|
2
|
-
# Model actual as of today
|
3
|
-
class User < ActiveRecord::Base
|
4
|
-
# Include default devise modules. Others available are:
|
5
|
-
# :confirmable, :lockable, :timeoutable and :omniauthable
|
6
|
-
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable #, :confirmable
|
7
|
-
|
8
|
-
before_create :generate_authentication_token
|
9
|
-
|
10
|
-
paginates_per 50
|
11
|
-
|
12
|
-
# Validations
|
13
|
-
# :username
|
14
|
-
validates :username, uniqueness: { case_sensitive: false }
|
15
|
-
validates_format_of :username, with: /\A[a-zA-Z0-9]*\z/, on: :create, message: "can only contain letters and digits"
|
16
|
-
validates :username, length: { in: 4..15 }
|
17
|
-
# :email
|
18
|
-
validates :email, uniqueness: { case_sensitive: false }
|
19
|
-
validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
20
|
-
|
21
|
-
validates :username, presence: true
|
22
|
-
validates :email, presence: true
|
23
|
-
|
24
|
-
validates :password, presence: true, on: :create
|
25
|
-
validates :password_confirmation, presence: true, on: :create
|
26
|
-
|
27
|
-
def self.paged(page_number)
|
28
|
-
order(admin: :desc, username: :asc).page page_number
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.search_and_order(search, page_number)
|
32
|
-
if search
|
33
|
-
where("username LIKE ?", "%#{search.downcase}%").order(
|
34
|
-
admin: :desc, username: :asc
|
35
|
-
).page page_number
|
36
|
-
else
|
37
|
-
order(admin: :desc, username: :asc).page page_number
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.last_signups(count)
|
42
|
-
order(created_at: :desc).limit(count).select("id","username","slug","created_at")
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.last_signins(count)
|
46
|
-
order(last_sign_in_at:
|
47
|
-
:desc).limit(count).select("id","username","slug","last_sign_in_at")
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.users_count
|
51
|
-
where("admin = ? AND locked = ?",false,false).count
|
52
|
-
end
|
53
|
-
|
54
|
-
serialize :roles, Array
|
55
|
-
def roles_enum
|
56
|
-
# Do not EDIT below this line
|
57
|
-
ROLES.each_with_index.map {|a,i| [I18n.t("roles.#{a.to_sym}"), (i+1).to_s]}
|
58
|
-
end
|
59
|
-
def has_role? role
|
60
|
-
# example called from cancan's app/models/ability.rb
|
61
|
-
# if user.has_role? :admin
|
62
|
-
|
63
|
-
# 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 .
|
64
|
-
chosen_roles = self.roles.map { |r| r.blank? ? nil : ROLES[r.to_i - 1] }
|
65
|
-
chosen_roles.compact.include? role
|
66
|
-
end
|
67
|
-
|
68
|
-
def title
|
69
|
-
username
|
70
|
-
end
|
71
|
-
|
72
|
-
rails_admin do
|
73
|
-
navigation_label I18n.t("admin.settings.label")
|
74
|
-
weight 10
|
75
|
-
# Field present Everywhere
|
76
|
-
field :email do
|
77
|
-
required true
|
78
|
-
end
|
79
|
-
field :username do
|
80
|
-
required true
|
81
|
-
end
|
82
|
-
field :code
|
83
|
-
field :roles, :enum do
|
84
|
-
pretty_value do # used in list view columns and show views, defaults to formatted_value for non-association fields
|
85
|
-
value.map { |v| bindings[:object].roles_enum.rassoc(v)[0] rescue nil }.compact.join ", "
|
86
|
-
end
|
87
|
-
export_value do
|
88
|
-
value.map { |v| bindings[:object].roles_enum.rassoc(v)[0] rescue nil }.compact.join ", " # used in exports, where no html/data is allowed
|
89
|
-
end
|
90
|
-
queryable false
|
91
|
-
end
|
92
|
-
field :admin do
|
93
|
-
visible do
|
94
|
-
bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
|
95
|
-
end
|
96
|
-
end
|
97
|
-
field :locked do
|
98
|
-
visible do
|
99
|
-
bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
|
100
|
-
end
|
101
|
-
end
|
102
|
-
field :third_party do
|
103
|
-
visible do
|
104
|
-
bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Fields only in lists and forms
|
109
|
-
list do
|
110
|
-
field :created_at
|
111
|
-
configure :email do
|
112
|
-
visible false
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
create do
|
117
|
-
field :password do
|
118
|
-
required true
|
119
|
-
end
|
120
|
-
field :password_confirmation do
|
121
|
-
required true
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
edit do
|
126
|
-
field :password do
|
127
|
-
required false
|
128
|
-
end
|
129
|
-
field :password_confirmation do
|
130
|
-
required false
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
#has_paper_trail
|
136
|
-
|
137
|
-
private
|
138
|
-
|
139
|
-
def generate_authentication_token
|
140
|
-
loop do
|
141
|
-
self.authentication_token = SecureRandom.base64(64)
|
142
|
-
break unless User.find_by(authentication_token: authentication_token)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
2
|
def up
|
149
3
|
puts "Generating admin user"
|
150
4
|
User.reset_column_information
|
@@ -160,6 +14,6 @@ class AddAdminUser < ActiveRecord::Migration[4.2]
|
|
160
14
|
u.password_confirmation = psswd
|
161
15
|
u.admin = true
|
162
16
|
# u.skip_confirmation!
|
163
|
-
u.save
|
17
|
+
u.save
|
164
18
|
end
|
165
19
|
end
|
data/lib/thecore/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thecore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|