thecore_auth_commons 2.3.2 → 2.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7820a25717ab5c4d9ff19a5dea6e7ab02c54a497348eef6d27e53dc459204f4
4
- data.tar.gz: 22775ef09abefa8bbe2cbdbff7dc3d3e48a097153bd3af1f73ab584d149e9dab
3
+ metadata.gz: 50b41bd961e584ec0ec2aa0e47ac5d7ec17671c7f523559dd928c4cc76e9694e
4
+ data.tar.gz: fe1566aeab26f20fd8194cf49017536c4cfde26ac6ef7c2dcc45bef544db2fd5
5
5
  SHA512:
6
- metadata.gz: cbf7e8777abfdbea0deee34773d812a1dca5adc48dfcb3a5bacda983f489c18cd0cff586c6dad777ed59a1b0ccca3988296bddb12c9262d03bd4a20b3a44e163
7
- data.tar.gz: ade3d82b997977aa4710e89ee9d77fda100b4c9ea2de2c812898afaa774c9936634b4b3218e1ee05ab11c8624113eb9d0e494b38f2b93d4274ca4812144cb178
6
+ metadata.gz: c2a6cfbd265adbc2f8e3e6293b02bf7ef06e69b092f33db4e89a7b4ee4bf525d8dd8c4c35172b64f84e8238c00a77e3368093c2c427d71ae5a349af9363c5652
7
+ data.tar.gz: a99b60ded5a87765de4a2a03d570de6d13463d8b7d7d81593ac42ca8da89317d2b548b15fba34a495b7614f8e79a28180f3c1d7da26b5f3cccb57380e72ce46e
data/app/models/user.rb CHANGED
@@ -10,7 +10,15 @@ class User < ApplicationRecord
10
10
  # devise :rememberable
11
11
  # devise :trackable
12
12
  # devise :validatable
13
- # devise :timeoutable, timeout_in: 30.minutes
13
+ # devise :timeoutable, timeout_in: 30.minutes
14
+
15
+ before_validation on: :create do
16
+ # If the generated uuid is not already present, then create the user with the proposed uuid
17
+ # Otherwise, try to generate another one
18
+ begin
19
+ self.access_token = SecureRandom.uuid #urlsafe_base64(32)
20
+ end while ::User.exists?(access_token: self.access_token)
21
+ end
14
22
  # REFERENCES
15
23
  has_many :role_users, dependent: :destroy, inverse_of: :user
16
24
  has_many :roles, through: :role_users, inverse_of: :users
@@ -19,6 +27,7 @@ class User < ApplicationRecord
19
27
  validates :password, presence: true, on: :create
20
28
  validates :password_confirmation, presence: true, on: :create
21
29
  validate :check_password_and_confirmation_equal
30
+ validates :access_token, uniqueness: true
22
31
  validates_each :admin do |record, attr, value|
23
32
  # Don't want admin == false if the current user is the only admin
24
33
  record.errors.add(attr, I18n.t("validation.errors.cannot_unadmin_last_admin")) if record.admin_changed? && record.admin_was == true && User.where(admin: true).count == 1
@@ -0,0 +1,5 @@
1
+ class AddAccessTokenToUser < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :users, :access_token, :uuid
4
+ end
5
+ end
data/db/seeds.rb CHANGED
@@ -2,12 +2,23 @@ puts "Loading ThecoreAuthCommons seeds"
2
2
  email = ENV["ADMIN_EMAIL"].presence || "admin@example.com"
3
3
  psswd = ENV["ADMIN_PASSWORD"].presence || "changeme"
4
4
 
5
- u = User.find_or_initialize_by(email: email)
6
- u.username = "Administrator"
7
- u.password = u.password_confirmation = psswd
8
- u.admin = true
9
- u.save(validate: false)
5
+ unless User.where(admin: true).exists?
6
+ u = User.find_or_initialize_by(email: email)
7
+ u.username = "Administrator"
8
+ u.password = u.password_confirmation = psswd
9
+ u.admin = true
10
+ u.save(validate: false)
11
+ end
10
12
 
13
+ # If there are previous users without the access_token, create it:
14
+ User.all.each do |u|
15
+ if u.access_token.blank?
16
+ begin
17
+ u.access_token = SecureRandom.uuid #urlsafe_base64(32)
18
+ end while ::User.exists?(access_token: self.access_token)
19
+ u.save(validate: false)
20
+ end
21
+ end
11
22
 
12
23
  @values = {
13
24
  predicates: %i[can cannot],
@@ -1,6 +1,7 @@
1
1
  require 'devise'
2
2
  require 'cancancan'
3
3
  require 'kaminari'
4
+ require 'activerecord-nulldb-adapter'
4
5
  require 'abilities/thecore_auth_commons'
5
6
 
6
7
  require "thecore_auth_commons/engine"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_auth_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-16 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.2
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 6.0.2.1
19
+ version: '6.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 6.0.2
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 6.0.2.1
26
+ version: '6.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: devise
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +66,20 @@ dependencies:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
68
  version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord-nulldb-adapter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
75
83
  - !ruby/object:Gem::Dependency
76
84
  name: sqlite3
77
85
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +128,7 @@ files:
120
128
  - db/migrate/20200306153136_add_lock_version_to_role.rb
121
129
  - db/migrate/20200516215346_add_locked_to_user.rb
122
130
  - db/migrate/20200518082821_create_permissions.rb
131
+ - db/migrate/20210415154152_add_access_token_to_user.rb
123
132
  - db/seeds.rb
124
133
  - lib/abilities/thecore_auth_commons.rb
125
134
  - lib/tasks/thecore_auth_commons_tasks.rake
@@ -147,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
156
  - !ruby/object:Gem::Version
148
157
  version: '0'
149
158
  requirements: []
150
- rubygems_version: 3.0.3
159
+ rubygems_version: 3.0.3.1
151
160
  signing_key:
152
161
  specification_version: 4
153
162
  summary: Common Auth methods and models to be used in thecore components.