account_authz 0.1.1 → 0.1.2

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: f6bf1ede17936361eb69db9ddee70b962284bacf76ff5118230b15c12426a3af
4
- data.tar.gz: 0af940aed74493eda52f69ee2889dd03771bc29364d4424610c9528a3973d2e1
3
+ metadata.gz: 349b6e1097c3f9cd3f4211488f800e5132418138e0785573f2810dde8e87287d
4
+ data.tar.gz: 9cf6c1e7593dc3bd6e814df1df72d5f0caa488bd868407cf3098e6f189a3950d
5
5
  SHA512:
6
- metadata.gz: e5c79cf5b28c21c94ac5c141fe06c999712b2f13c363a31aae570c204c810be2c648435af1313ab0748fcad5a89425527b6d9e9579633448869e286ce064eacb
7
- data.tar.gz: 470a22bd1bc503c93d15e69618c3c0db9ca57b1cfc8c24e4d5a4ba2aba891797ab45ee7d65239ac45ac524c46f320f14545c6693e3b14583bff58f88eff361e6
6
+ metadata.gz: 02b2a2acf869db601b2cf5470565ef64920543c01c027f21575b22d5e16d98f1ac8e679d9759d9f9f0698f17ee65acc719bd01a147a428ca087aec4d0620e6fa
7
+ data.tar.gz: 403e200dd7e81b20319415fbce054f10dd4cbfa9327faa7ddccf399c042fd91c70c03f16f7ecb18269cc86315a56087d942b161127776f6224c68a5361d75ea6
@@ -3,5 +3,6 @@
3
3
  module AccountAuthz
4
4
  class Current < ActiveSupport::CurrentAttributes
5
5
  attribute :account_id
6
+ attribute :capabilities, default: -> { {} }
6
7
  end
7
8
  end
@@ -4,6 +4,7 @@ module AccountAuthz
4
4
  class Role < ApplicationRecord
5
5
  validates :name, presence: true
6
6
  validate :capabilities_within_catalog
7
+ after_save { Current.capabilities = {} }
7
8
 
8
9
  scope :in_account, ->(account_id) { where(account_id: account_id) }
9
10
 
@@ -10,16 +10,20 @@ module AccountAuthz
10
10
  end
11
11
 
12
12
  def assign_role(role)
13
+ Current.capabilities = {}
13
14
  account_authz_assignments.find_or_create_by(role: role)
14
15
  end
15
16
 
16
17
  def revoke_role(role)
18
+ Current.capabilities = {}
17
19
  account_authz_assignments.where(role: role).destroy_all
18
20
  end
19
21
 
20
22
  def capabilities(account_id: nil)
21
- roles = account_id ? account_authz_roles.where(account_id: account_id) : account_authz_roles
22
- roles.flat_map(&:capabilities).uniq.map(&:to_sym)
23
+ Current.capabilities[[ self.class.name, id, account_id ]] ||= begin
24
+ roles = account_id ? account_authz_roles.where(account_id: account_id) : account_authz_roles
25
+ roles.flat_map(&:capabilities).uniq.map(&:to_sym)
26
+ end
23
27
  end
24
28
 
25
29
  def can?(capability, account_id: nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AccountAuthz
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: account_authz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider