thecore_auth_commons 2.3.4 → 2.3.9

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: ef336ba07dfb2b7045b03c7c6ddd046cc57f9494563917a728877f9ee2830191
4
- data.tar.gz: e71c6255f11bca1c7c625e0eaf150d5ece5a38104285be9d15f3b7a95fdd3b3c
3
+ metadata.gz: 7cc83c087063b265fbfe2abdb852b0f494c194dff7964d55cab60a181f4e7ead
4
+ data.tar.gz: f2cee22705f90cef98d2d4b3a7d716835f67a356ff1c7c5a0856568d673b8627
5
5
  SHA512:
6
- metadata.gz: a5d025b7c10645755d7e550da428eff612e2fb8e671eeef0c0f711d725b7086312b63053e5880d75ec897ce82e177a56c6090786b9ba53b1cedd8f039f459c6a
7
- data.tar.gz: 037a7431dd095a9cd2452847aab62e08d7d7e34a643a1bb2b49870ff01d81dbbcef64ad740c08efab5e8c27abe7741c1dd1ca979a72816903763baf7a5395010
6
+ metadata.gz: 4375e7e47cdb1a6655b810d71d762f7c9173f732d3fdc3b3016e1ae8f7ff3578940a424ea7b6a498f3a6c41f177737d53a1c622c45d5ce7fe2aba61dffa0b8b2
7
+ data.tar.gz: 63be69b8c6df27abc45de8f9b091550d4a99a48d24bf5f525e6b93aa927cb0676823937a66d333da537428ab21466e5e5dce84a7fd5bd0d13a0ac290a72b1fc4
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
@@ -10,6 +10,16 @@ unless User.where(admin: true).exists?
10
10
  u.save(validate: false)
11
11
  end
12
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: u.access_token)
19
+ u.save(validate: false)
20
+ end
21
+ end
22
+
13
23
  @values = {
14
24
  predicates: %i[can cannot],
15
25
  actions: %i[manage create read update destroy],
@@ -1,6 +1,8 @@
1
1
  require 'devise'
2
2
  require 'cancancan'
3
3
  require 'kaminari'
4
+ require 'activerecord-nulldb-adapter'
5
+ require 'active_record/hierarchical_query'
4
6
  require 'abilities/thecore_auth_commons'
5
7
 
6
8
  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.4
4
+ version: 2.3.9
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-30 00:00:00.000000000 Z
11
+ date: 2021-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord-hierarchical_query
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: sqlite3
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +142,7 @@ files:
114
142
  - db/migrate/20200306153136_add_lock_version_to_role.rb
115
143
  - db/migrate/20200516215346_add_locked_to_user.rb
116
144
  - db/migrate/20200518082821_create_permissions.rb
145
+ - db/migrate/20210415154152_add_access_token_to_user.rb
117
146
  - db/seeds.rb
118
147
  - lib/abilities/thecore_auth_commons.rb
119
148
  - lib/tasks/thecore_auth_commons_tasks.rake
@@ -141,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
170
  - !ruby/object:Gem::Version
142
171
  version: '0'
143
172
  requirements: []
144
- rubygems_version: 3.0.3
173
+ rubygems_version: 3.0.3.1
145
174
  signing_key:
146
175
  specification_version: 4
147
176
  summary: Common Auth methods and models to be used in thecore components.