thecore_auth_commons 3.3.1 → 3.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 682d5dea983ef3b65ae55f50803c0d8810ce04b8357f22bf05a6ab0cf7bd83f8
4
- data.tar.gz: 4ed90e7731d83da42faa85231203ea7affe2f8a7f8890b26e77293ece0f75257
3
+ metadata.gz: bce6c783c7e44a377fb7b7dbf2305dd23b563eae7e2c8897200fc152c2be0884
4
+ data.tar.gz: e7c41b6d7a829023e02fff2f1f6fd194f1686576de3742665b502adc42461e08
5
5
  SHA512:
6
- metadata.gz: b7f02c82f2388cf594af33f6203a78b46f8d1a5d71be783d7606517daeca4321130bfb37ee9d1c3ebd70dc2a41f8014469f0f22b180dbe707ee56dfd43cfc4aa
7
- data.tar.gz: 490b7d2c7994c846bfba308ba22f71e21362de89c7d4ecc87e5f17905c491c9f158db90fdad8f3ad3033e2f93728ee6c7d5ee20e98358d01b8554a5a9102d579
6
+ metadata.gz: 6960fc5c2750f3bf78e59360a8d3b1ef10eaefb179148701d3fb9c53b9f1f917390fe9835e8b12d45185d1351373a6d7054bede15e66795e1668794c76b2930d
7
+ data.tar.gz: 5ff74462f5bdc2c9289e6c8c4201f92a74a3f4ca2377138bef0c7a5c76768896c05c64e931bdd2705a794c41ed983d922fdaf968771b7dcfe2055ec29a80ec0f
data/app/models/user.rb CHANGED
@@ -1,4 +1,41 @@
1
1
  class User < ApplicationRecord
2
- # Get the minimum password length from the Environemnt or set it to 8
3
- devise :database_authenticatable, :rememberable, :trackable, :timeoutable, :validatable, password_length: ENV.fetch('MIN_PASSWORD_LENGTH', 8).to_i..128, timeout_in: ENV.fetch('SESSION_TIMEOUT_IN_MINUTES', 31).to_i.minutes
2
+ # Get the minimum password length from the Environemnt or set it to 8
3
+ devise :database_authenticatable, :rememberable, :trackable, :timeoutable, :validatable, password_length: ENV.fetch('MIN_PASSWORD_LENGTH', 8).to_i..128, timeout_in: ENV.fetch('SESSION_TIMEOUT_IN_MINUTES', 31).to_i.minutes
4
+
5
+ # REFERENCES
6
+ has_many :role_users, dependent: :destroy, inverse_of: :user
7
+ has_many :roles, through: :role_users, inverse_of: :users
8
+ # VALIDATIONS
9
+ validates :email, uniqueness: { case_sensitive: false }, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
10
+ validates :password, presence: true, on: :create
11
+ validates :password_confirmation, presence: true, on: :create
12
+ validate :check_password_and_confirmation_equal
13
+ validates_each :password do |record, attr, value|
14
+ # Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character or be blank
15
+ record.errors.add(attr, I18n.t("validation.errors.password_must_contain_uppercase_lowercase_number_special_character")) unless value.blank? || (value =~ /[A-Z]/ && value =~ /[a-z]/ && value =~ /[0-9]/ && value =~ /[^A-Za-z0-9]/)
16
+ end
17
+ validates_each :admin do |record, attr, value|
18
+ # Don't want admin == false if the current user is the only admin
19
+ 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
20
+ end
21
+ validates_each :locked do |record, attr, value|
22
+ # Don't want locked == true if the current user is the only admin
23
+ record.errors.add(attr, I18n.t("validation.errors.cannot_lock_last_admin")) if record.locked_changed? && record.locked_was == false && User.where(locked: false).count == 1
24
+ end
25
+
26
+ def display_name
27
+ email
28
+ end
29
+
30
+ def has_role? role
31
+ roles.include? role.to_s
32
+ end
33
+
34
+ def authenticate password
35
+ self&.valid_password?(password) ? self : nil
36
+ end
37
+
38
+ def check_password_and_confirmation_equal
39
+ errors.add(:password, I18n.t("validation.errors.password_and_confirm_must_be_the_same")) unless password == password_confirmation
40
+ end
4
41
  end
@@ -9,6 +9,7 @@ module Abilities
9
9
  if user.admin?
10
10
  # Admins' abiities
11
11
  can :manage, :all # only allow admin users to access Rails Admin
12
+ cannot :create, ::Action
12
13
  # prevents killing himself
13
14
  cannot :destroy, ::User do |u|
14
15
  u.id == user.id
@@ -3,11 +3,7 @@ Rails.application.configure do
3
3
  # In development be sure to load all the namespaces
4
4
  # in order to have working reflection
5
5
  Zeitwerk::Loader.eager_load_all if Rails.env.development?
6
-
7
- # Devise.timeout_in = ENV.fetch('SESSION_TIMEOUT_IN_MINUTES', 31).to_i.minutes
8
- # Devise.password_length = ENV.fetch('MIN_PASSWORD_LENGTH', 8).to_i..128
9
6
 
10
7
  Ability.send(:include, ThecoreAuthCommonsCanCanCanConcern)
11
- User.send(:include, ThecoreAuthCommonsUserConcern)
12
8
  end
13
9
  end
@@ -1,3 +1,3 @@
1
1
  module ThecoreAuthCommons
2
- VERSION = "3.3.1".freeze
2
+ VERSION = "3.3.3".freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_auth_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: devise
@@ -191,7 +191,6 @@ files:
191
191
  - config/initializers/add_to_db_migrations.rb
192
192
  - config/initializers/after_initialize.rb
193
193
  - config/initializers/concern_cancancan.rb
194
- - config/initializers/concern_user.rb
195
194
  - config/locales/en.permissions.yml
196
195
  - config/locales/en.thecore_auth_commons.yml
197
196
  - config/locales/it.permissions.yml
@@ -231,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
230
  - !ruby/object:Gem::Version
232
231
  version: '0'
233
232
  requirements: []
234
- rubygems_version: 3.6.2
233
+ rubygems_version: 3.6.7
235
234
  specification_version: 4
236
235
  summary: Common Auth methods and models to be used in thecore components.
237
236
  test_files: []
@@ -1,42 +0,0 @@
1
- module ThecoreAuthCommonsUserConcern
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- # REFERENCES
6
- has_many :role_users, dependent: :destroy, inverse_of: :user
7
- has_many :roles, through: :role_users, inverse_of: :users
8
- # VALIDATIONS
9
- validates :email, uniqueness: { case_sensitive: false }, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
10
- validates :password, presence: true, on: :create
11
- validates :password_confirmation, presence: true, on: :create
12
- validate :check_password_and_confirmation_equal
13
- validates_each :password do |record, attr, value|
14
- # Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character or be blank
15
- record.errors.add(attr, I18n.t("validation.errors.password_must_contain_uppercase_lowercase_number_special_character")) unless value.blank? || (value =~ /[A-Z]/ && value =~ /[a-z]/ && value =~ /[0-9]/ && value =~ /[^A-Za-z0-9]/)
16
- end
17
- validates_each :admin do |record, attr, value|
18
- # Don't want admin == false if the current user is the only admin
19
- 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
20
- end
21
- validates_each :locked do |record, attr, value|
22
- # Don't want locked == true if the current user is the only admin
23
- record.errors.add(attr, I18n.t("validation.errors.cannot_lock_last_admin")) if record.locked_changed? && record.locked_was == false && User.where(locked: false).count == 1
24
- end
25
-
26
- def display_name
27
- email
28
- end
29
-
30
- def has_role? role
31
- roles.include? role.to_s
32
- end
33
-
34
- def authenticate password
35
- self&.valid_password?(password) ? self : nil
36
- end
37
-
38
- def check_password_and_confirmation_equal
39
- errors.add(:password, I18n.t("validation.errors.password_and_confirm_must_be_the_same")) unless password == password_confirmation
40
- end
41
- end
42
- end