authentication-zero 2.16.30 → 2.16.32

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: 4d24c61ab47e57ff3f4e61f6871063cc0eddd0bae159bad0a6033c13b6d11d27
4
- data.tar.gz: 5603c75ec12c501b2e4de8165c79fa98011a1509ad9728911a71a2ea5f1ed823
3
+ metadata.gz: c282c63840e3d6072f86c899f4a477296f2d5145317b715c00e2a434a2c2a565
4
+ data.tar.gz: 6f45065151e320e21a01c58a6daf2cf4101780428d6fd6d14341722aaec1bbd1
5
5
  SHA512:
6
- metadata.gz: ef99f6854ac55716a68f6439c14f33d9ad073c87374a2aa5434377d0fdefda107e6311692362c00e0ca9cb6a9b6b304f10a0ffd33b2373b27af0e3a1d32d8584
7
- data.tar.gz: d0d7a47777f70acb660bf9c8865967d6eda63147f764ab15abd3e0f41d119a31ed51553fe2ce132a56c7b3abf0221e82d7f22b4814d54214aae90db332fc71ea
6
+ metadata.gz: 25ff1fc4f8822b6edaad54cd754b1b14ecfe89bfd6afb195942fce0974e3907852aea9a6fef643cffcd01351f992eaf3524bf0a92e773ff7ed97669de11ff0d6
7
+ data.tar.gz: c1d3fa6bc16f41f0826edd2121910ead50c01137cdbf42a7140dd1625eaadab5606678986022d28a9972ca1aef0669e7bb4ab2f1fa5dacdf2b130365963cd6f2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authentication-zero (2.16.30)
4
+ authentication-zero (2.16.32)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -68,13 +68,16 @@ Use `before_action :require_sudo` in controllers with sensitive information, it
68
68
 
69
69
  Some artifacts are generated in the application, which makes it possible to implement row-level multitenancy applications. You should follow some steps to make it work.
70
70
 
71
- - Add `account_id` to each scoped table, ex. `rails g migration projects account:references`.
72
- - Add `include AccountScoped` to scoped models. It set up the relationship with the account and default scope using the current account.
73
- - The `Current.account` is set according to the url ex: `http://mywebsite.com/1234/projects`.
74
- - You should customize the sign-in flow yourself, it means:
75
- - Add the `account_id` column and scope your user model.
76
- - Assign the account when the user is created.
77
- - After sign-in redirect to the correct url, including the `account_id`.
71
+ - Add `account_id` to each scoped table using `rails g migration add_account_to_projects account:references`.
72
+ - Add `include AccountScoped` to scoped models. It set up the account relationship and default scope using the current account.
73
+ - The `Current.account` is set according to the url. `http://mywebsite.com/1234/projects`.
74
+ - You should customize the authentication flow yourself, it means:
75
+ - Add `account_id` to your users table using `rails g migration add_account_to_users account:references`.
76
+ - Add `include AccountScoped` to your user model.
77
+ - Use `joins(:user).find_by_id...` in the `authenticate` method.
78
+ - Use `redirect_to "/#{user.account_id}"` after sign-in.
79
+ - Override `Current#user=` to also set the account, `super; self.account = user.account`.
80
+ - etc...
78
81
 
79
82
  ## Development
80
83
 
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "2.16.30"
2
+ VERSION = "2.16.32"
3
3
  end
@@ -8,9 +8,9 @@ class AccountMiddleware
8
8
 
9
9
  _, account_id, request_path = request.path.split("/", 3)
10
10
 
11
- if is_number?(account_id)
11
+ if identifier?(account_id)
12
12
  set_current_account(account_id)
13
-
13
+
14
14
  request.script_name = "/#{account_id}"
15
15
  request.path_info = "/#{request_path}"
16
16
  @app.call(request.env)
@@ -20,11 +20,11 @@ class AccountMiddleware
20
20
  end
21
21
 
22
22
  private
23
- def is_number?(value)
24
- Integer(value, exception: false)
23
+ def identifier?(value)
24
+ Integer(value, exception: false) != nil
25
25
  end
26
26
 
27
27
  def set_current_account(account_id)
28
- Current.account = Account.find(account_id)
28
+ Current.account = Account.find_by_id(account_id)
29
29
  end
30
30
  end
@@ -2,10 +2,7 @@ module AccountScoped
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- belongs_to :account
6
-
7
- default_scope do
8
- where(account: Current.account || raise("You must set an account"))
9
- end
5
+ belongs_to :account
6
+ default_scope { where account: Current.account }
10
7
  end
11
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authentication-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.30
4
+ version: 2.16.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-01 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: