thecore_auth_commons 0 → 2.1.5

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: e94769e7d262d850b7c5531f9bebe433fe00dd934d9b593264605bd92c153d0d
4
- data.tar.gz: e37f8a876f911fb9cf40723d5bda436125829de14fc85b91816e12dc56be2768
3
+ metadata.gz: 61ed8fcc4bce9d24788eba743ea4380956af397fe082b2b1f4a1e77bb032931c
4
+ data.tar.gz: 741d82ad26067fd57749b76cc935c162ad1706d7f3ca1eaead3a8994877ded7c
5
5
  SHA512:
6
- metadata.gz: f28ae34cec6fbe45be080c1b1da3d2b346bafd5c4cc1bc2d33830351e94d0207d34e710768405ad97c36f3653c457d2d214fee32a451d93bd59054d97bd7fcf4
7
- data.tar.gz: e6fea2a4ddcd36efaae3e0867ad2d673d9412e71df1fd1088ec1cb4161dcbc1d034d6b326baf43ac33e4f908d986d082e7bc934e124775a972ce65284046a2d8
6
+ metadata.gz: 235c4579bf07af34e3ebed23b28e2c1830047496de62ab04c4bcda0d68a7f65881305945ec72512e6d5f05385b988af1d02f773b9726d867d58bfe9f9909c287
7
+ data.tar.gz: ad249f078467efad19281d836a871b703ef345e93aa182bb3e507403ebfb6486cc8aac83da10182da19136393a71bfc4e58b3cde1696a68a4b338084f9615de5
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require 'abilities/thecore_auth_commons'
2
3
 
3
4
  class Ability
4
5
  include CanCan::Ability
@@ -40,10 +41,5 @@ class Ability
40
41
  self.merge const.new(user) if const.is_a? Class
41
42
  end
42
43
  end
43
- # Overrides from the database defined permissions
44
- ::Permission.joins(roles: :users).where(users: {id: user.id}).order(:id).each do |permission|
45
- # E.g. can :manage, :all
46
- self.send(permission.predicate.name.to_sym, permission.action.name.to_sym, (permission.target.name.classify.constantize rescue permission.target.name.to_sym))
47
- end
48
44
  end
49
45
  end
data/app/models/role.rb CHANGED
@@ -4,10 +4,8 @@ class Role < ApplicationRecord
4
4
  # REFERENCES
5
5
  has_many :role_users, dependent: :destroy, inverse_of: :role
6
6
  has_many :users, through: :role_users, inverse_of: :roles
7
- has_many :permission_roles, dependent: :destroy, inverse_of: :role
8
- has_many :permissions, through: :permission_roles, inverse_of: :roles
9
7
 
10
8
  def display_name
11
- (I18n.t name.parameterize.underscore, default: name.titleize rescue nil)
9
+ I18n.t name.parameterize.underscore, default: name.titleize
12
10
  end
13
11
  end
data/app/models/user.rb CHANGED
@@ -2,8 +2,6 @@ class User < ApplicationRecord
2
2
  # Include default devise modules. Others available are:
3
3
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
4
4
  devise :database_authenticatable
5
- devise :trackable
6
- devise :validatable
7
5
  # TODO: If it works, these must be added to another gem one which deal
8
6
  # more with sessions
9
7
  # devise :database_authenticatable
@@ -23,25 +21,17 @@ class User < ApplicationRecord
23
21
  # Don't want admin == false if the current user is the only admin
24
22
  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
25
23
  end
26
- validates_each :locked do |record, attr, value|
27
- # Don't want locked == true if the current user is the only admin
28
- 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
29
- end
30
-
24
+
31
25
  def display_name
32
26
  email
33
27
  end
34
-
28
+
35
29
  def has_role? role
36
- roles.include? role.to_s
37
- end
38
-
39
- def authenticate password
40
- self&.valid_password?(password) ? self : nil
30
+ roles.include? role
41
31
  end
42
-
32
+
43
33
  protected
44
-
34
+
45
35
  def check_password_and_confirmation_equal
46
36
  errors.add(:password, I18n.t("validation.errors.password_and_confirm_must_be_the_same")) unless password == password_confirmation
47
37
  end
@@ -1,6 +1,3 @@
1
- require 'thecore_auth_commons_actioncontroller_concerns'
2
-
3
- # App Config
4
1
  Rails.application.configure do
5
2
  config.after_initialize do
6
3
  # In development be sure to load all the namespaces
@@ -0,0 +1,65 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ devise:
5
+ confirmations:
6
+ confirmed: "Your email address has been successfully confirmed."
7
+ send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
8
+ send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
9
+ failure:
10
+ already_authenticated: "You are already signed in."
11
+ inactive: "Your account is not activated yet."
12
+ invalid: "Invalid %{authentication_keys} or password."
13
+ locked: "Your account is locked."
14
+ last_attempt: "You have one more attempt before your account is locked."
15
+ not_found_in_database: "Invalid %{authentication_keys} or password."
16
+ timeout: "Your session expired. Please sign in again to continue."
17
+ unauthenticated: "You need to sign in or sign up before continuing."
18
+ unconfirmed: "You have to confirm your email address before continuing."
19
+ mailer:
20
+ confirmation_instructions:
21
+ subject: "Confirmation instructions"
22
+ reset_password_instructions:
23
+ subject: "Reset password instructions"
24
+ unlock_instructions:
25
+ subject: "Unlock instructions"
26
+ email_changed:
27
+ subject: "Email Changed"
28
+ password_change:
29
+ subject: "Password Changed"
30
+ omniauth_callbacks:
31
+ failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
32
+ success: "Successfully authenticated from %{kind} account."
33
+ passwords:
34
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
35
+ send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
36
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
37
+ updated: "Your password has been changed successfully. You are now signed in."
38
+ updated_not_active: "Your password has been changed successfully."
39
+ registrations:
40
+ destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
41
+ signed_up: "Welcome! You have signed up successfully."
42
+ signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
43
+ signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
44
+ signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
45
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
46
+ updated: "Your account has been updated successfully."
47
+ updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again"
48
+ sessions:
49
+ signed_in: "Signed in successfully."
50
+ signed_out: "Signed out successfully."
51
+ already_signed_out: "Signed out successfully."
52
+ unlocks:
53
+ send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
54
+ send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
55
+ unlocked: "Your account has been unlocked successfully. Please sign in to continue."
56
+ errors:
57
+ messages:
58
+ already_confirmed: "was already confirmed, please try signing in"
59
+ confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
60
+ expired: "has expired, please request a new one"
61
+ not_found: "not found"
62
+ not_locked: "was not locked"
63
+ not_saved:
64
+ one: "1 error prohibited this %{resource} from being saved:"
65
+ other: "%{count} errors prohibited this %{resource} from being saved:"
@@ -14,12 +14,12 @@ class CreateUsers < ActiveRecord::Migration[6.0]
14
14
  ## Rememberable
15
15
  # t.datetime :remember_created_at
16
16
 
17
- # Trackable
18
- t.integer :sign_in_count, default: 0, null: false
19
- t.datetime :current_sign_in_at
20
- t.datetime :last_sign_in_at
21
- t.string :current_sign_in_ip
22
- t.string :last_sign_in_ip
17
+ ## Trackable
18
+ # t.integer :sign_in_count, default: 0, null: false
19
+ # t.datetime :current_sign_in_at
20
+ # t.datetime :last_sign_in_at
21
+ # t.string :current_sign_in_ip
22
+ # t.string :last_sign_in_ip
23
23
 
24
24
  ## Confirmable
25
25
  # t.string :confirmation_token
@@ -34,7 +34,7 @@ class CreateUsers < ActiveRecord::Migration[6.0]
34
34
 
35
35
 
36
36
  # Uncomment below if timestamps were not included in your original model.
37
- t.timestamps null: false
37
+ # t.timestamps null: false
38
38
  end
39
39
 
40
40
  add_index :users, :email, unique: true
@@ -1,43 +1,4 @@
1
1
  class AddFirstAdminUser < ActiveRecord::Migration[6.0]
2
- class User < ApplicationRecord
3
- # Include default devise modules. Others available are:
4
- # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
5
- devise :database_authenticatable, :trackable, :validatable
6
- # TODO: If it works, these must be added to another gem one which deal
7
- # more with sessions
8
- # devise :database_authenticatable
9
- # devise :rememberable
10
- # devise :trackable
11
- # devise :validatable
12
- # devise :timeoutable, timeout_in: 30.minutes
13
- # REFERENCES
14
- has_many :role_users, dependent: :destroy, inverse_of: :user
15
- has_many :roles, through: :role_users, inverse_of: :users
16
- # VALIDATIONS
17
- validates :email, uniqueness: { case_sensitive: false }, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
18
- validates :password, presence: true, on: :create
19
- validates :password_confirmation, presence: true, on: :create
20
- validate :check_password_and_confirmation_equal
21
- validates_each :admin do |record, attr, value|
22
- # Don't want admin == false if the current user is the only admin
23
- 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
24
- end
25
-
26
- def display_name
27
- email
28
- end
29
-
30
- def has_role? role
31
- roles.include? role
32
- end
33
-
34
- protected
35
-
36
- def check_password_and_confirmation_equal
37
- errors.add(:password, I18n.t("validation.errors.password_and_confirm_must_be_the_same")) unless password == password_confirmation
38
- end
39
- end
40
-
41
2
  def up
42
3
  email = "admin@example.com"
43
4
  User.reset_column_information
@@ -1,3 +1,3 @@
1
1
  module ThecoreAuthCommons
2
- VERSION = "#{`git describe --tags $(git rev-list --tags --max-count=1)`}"
2
+ VERSION = '2.1.5'.freeze
3
3
  end
@@ -1,9 +1,7 @@
1
+ require "thecore_auth_commons/engine"
2
+
1
3
  require 'devise'
2
4
  require 'cancancan'
3
- require 'kaminari'
4
- require 'abilities/thecore_auth_commons'
5
-
6
- require "thecore_auth_commons/engine"
7
5
 
8
6
  module ThecoreAuthCommons
9
7
  # Your code goes here...
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: '0'
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
- - Gabriele Tassoni
7
+ - ''
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-16 00:00:00.000000000 Z
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,34 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '3.1'
61
- - !ruby/object:Gem::Dependency
62
- name: kaminari
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1.1'
68
- type: :runtime
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1.1'
75
61
  - !ruby/object:Gem::Dependency
76
62
  name: sqlite3
77
63
  requirement: !ruby/object:Gem::Requirement
78
64
  requirements:
79
- - - "~>"
65
+ - - ">="
80
66
  - !ruby/object:Gem::Version
81
- version: '1.4'
67
+ version: '0'
82
68
  type: :development
83
69
  prerelease: false
84
70
  version_requirements: !ruby/object:Gem::Requirement
85
71
  requirements:
86
- - - "~>"
72
+ - - ">="
87
73
  - !ruby/object:Gem::Version
88
- version: '1.4'
74
+ version: '0'
89
75
  description: Provides common User and Role models to attach Authentication and Authorization
90
76
  via your preferred gem.
91
77
  email:
@@ -98,19 +84,12 @@ files:
98
84
  - README.md
99
85
  - Rakefile
100
86
  - app/models/ability.rb
101
- - app/models/action.rb
102
- - app/models/permission.rb
103
- - app/models/permission_role.rb
104
- - app/models/predicate.rb
105
87
  - app/models/role.rb
106
88
  - app/models/role_user.rb
107
- - app/models/target.rb
108
89
  - app/models/user.rb
109
90
  - config/initializers/after_initialize_thecore_auth_commons.rb
110
91
  - config/initializers/devise.rb
111
- - config/locales/en.activerecord.yml
112
- - config/locales/it.activerecord.yml
113
- - config/locales/it.permissions.yml
92
+ - config/locales/devise.en.yml
114
93
  - config/routes.rb
115
94
  - db/migrate/20200306143408_create_users.rb
116
95
  - db/migrate/20200306151046_add_admin_field_to_user.rb
@@ -119,14 +98,11 @@ files:
119
98
  - db/migrate/20200306152816_create_role_users.rb
120
99
  - db/migrate/20200306153125_add_lock_version_to_user.rb
121
100
  - db/migrate/20200306153136_add_lock_version_to_role.rb
122
- - db/migrate/20200516215346_add_locked_to_user.rb
123
- - db/migrate/20200518082821_create_permissions.rb
124
101
  - lib/abilities/thecore_auth_commons.rb
125
102
  - lib/tasks/thecore_auth_commons_tasks.rake
126
103
  - lib/thecore_auth_commons.rb
127
104
  - lib/thecore_auth_commons/engine.rb
128
105
  - lib/thecore_auth_commons/version.rb
129
- - lib/thecore_auth_commons_actioncontroller_concerns.rb
130
106
  homepage: https://github.com/gabrieletassoni/thecore_auth_commons
131
107
  licenses:
132
108
  - MIT
@@ -147,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
123
  - !ruby/object:Gem::Version
148
124
  version: '0'
149
125
  requirements: []
150
- rubygems_version: 3.0.3
126
+ rubygems_version: 3.1.2
151
127
  signing_key:
152
128
  specification_version: 4
153
129
  summary: Common Auth methods and models to be used in thecore components.
data/app/models/action.rb DELETED
@@ -1,3 +0,0 @@
1
- class Action < ApplicationRecord
2
- has_many :permissions, dependent: :destroy, inverse_of: :action
3
- end
@@ -1,20 +0,0 @@
1
- class Permission < ApplicationRecord
2
- # REFERENCES
3
- has_many :permission_roles, dependent: :destroy, inverse_of: :permission
4
- has_many :roles, through: :permission_roles, inverse_of: :permissions
5
- belongs_to :predicate, inverse_of: :permissions
6
- belongs_to :action, inverse_of: :permissions
7
- belongs_to :target, inverse_of: :permissions
8
-
9
- # VALIDATIONS
10
- validates :predicate_id, presence: true, uniqueness: {scope: [:action_id, :target_id]}
11
- validates :action_id, presence: true
12
- validates :target_id, presence: true
13
-
14
- def display_name
15
- p = (I18n.t "permissions.predicates.#{predicate.name}", default: predicate.name.titleize rescue nil)
16
- a = (I18n.t "permissions.actions.#{action.name}", default: action.name.titleize rescue nil)
17
- m = (I18n.t "activerecord.models.#{target.name}", default: target.name.titleize rescue nil)
18
- [ p, a, m ].join(" ")
19
- end
20
- end
@@ -1,4 +0,0 @@
1
- class PermissionRole < ApplicationRecord
2
- belongs_to :role, inverse_of: :permission_roles
3
- belongs_to :permission, inverse_of: :permission_roles
4
- end
@@ -1,3 +0,0 @@
1
- class Predicate < ApplicationRecord
2
- has_many :permissions, dependent: :destroy, inverse_of: :predicate
3
- end
data/app/models/target.rb DELETED
@@ -1,3 +0,0 @@
1
- class Target < ApplicationRecord
2
- has_many :permissions, dependent: :destroy, inverse_of: :target
3
- end
@@ -1,11 +0,0 @@
1
- en:
2
- activerecord:
3
- models:
4
- user:
5
- one: User
6
- other: Users
7
- descriptions:
8
- user: Section to manage users.
9
- role: Section to manage Roles
10
- permission: Section to manage Permissions
11
-
@@ -1,36 +0,0 @@
1
- it:
2
- activerecord:
3
- models:
4
- user:
5
- one: Utente
6
- other: Utenti
7
- role:
8
- one: Ruolo
9
- other: Ruoli
10
- permission:
11
- one: Permesso
12
- other: Permessi
13
- attributes:
14
- user:
15
- email: E-Mail
16
- username: Nome Utente
17
- code: Codice
18
- roles: Ruoli
19
- admin: Amministratore?
20
- created_at: Data di Creazione
21
- locked: Bloccato?
22
- third_party: Ente Terzo?
23
- password: Password
24
- password_confirmation: Conferma Password
25
- role:
26
- users: Utenti
27
- name: Nome
28
- permissions: Permessi
29
- permission:
30
- predicate: Predicato
31
- action: Azione
32
- model: Modello
33
- descriptions:
34
- user: In questa sezione dell'applicazione potete cercare nella lista degli utenti in diversi modi usando i filtri o ordinare la lista secondo diversi campi.
35
- role: In questa sezione si possono creare dei ruoli da usare nell'RBAC gestito dai file abilities, per definire le autorizzazioni CRUD e non solo.
36
- permission: Il predicato definisce se è un permesso di poter fare o non fare, l'azione è il tipo definisce cosa si possa fare o non fare, mentre il modello definisce su chi.
@@ -1,10 +0,0 @@
1
- it:
2
- permissions:
3
- predicates:
4
- can: Può
5
- cannot: Non può
6
- actions:
7
- manage: Gestire
8
- read: Leggere
9
- update: Modificare
10
- destroy: Eliminare
@@ -1,5 +0,0 @@
1
- class AddLockedToUser < ActiveRecord::Migration[6.0]
2
- def change
3
- add_column :users, :locked, :boolean, null: false, default: false
4
- end
5
- end
@@ -1,48 +0,0 @@
1
- class CreatePermissions < ActiveRecord::Migration[6.0]
2
- def change
3
- @values = {
4
- predicates: %i[can cannot],
5
- actions: %i[manage create read update destroy],
6
- targets: ApplicationRecord.subclasses.map {|d| d.to_s.underscore}.to_a.unshift(:all)
7
- }
8
-
9
- def create_and_fill table
10
- create_table table do |t|
11
- t.string :name
12
- t.bigint :lock_version
13
-
14
- t.timestamps
15
- end
16
- add_index table, :name, unique: true
17
- model = table.to_s.classify.constantize
18
- model.reset_column_information
19
- model.upsert_all @values[table].map { |p| {name: p, created_at: Time.now, updated_at: Time.now} }, unique_by: [:name]
20
- end
21
-
22
- # Predicates
23
- create_and_fill :predicates
24
-
25
- # Actions
26
- create_and_fill :actions
27
-
28
- # Targets
29
- create_and_fill :targets
30
-
31
- create_table :permissions do |t|
32
- t.references :predicate, null: false, foreign_key: true
33
- t.references :action, null: false, foreign_key: true
34
- t.references :target, null: false, foreign_key: true
35
- t.bigint :lock_version
36
-
37
- t.timestamps
38
- end
39
- # Association table
40
- create_table :permission_roles do |t|
41
- t.references :role, null: false, foreign_key: true
42
- t.references :permission, null: false, foreign_key: true
43
- t.bigint :lock_version
44
-
45
- t.timestamps
46
- end
47
- end
48
- end
@@ -1,7 +0,0 @@
1
- module ThecoreAuthCommonsActioncontrollerConcerns
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- include HttpAcceptLanguage::AutoLocale
6
- end
7
- end