permisi 0.1.3 → 0.1.4

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: '082297c3c88cb77bf0fe05e8c855d27d8bd5293c7db4d55cc3f0a6e0b982ac84'
4
- data.tar.gz: caa2bef94cfaba331a10e5f27ee45c0d8256690139f3de39447d1d515ad3daa0
3
+ metadata.gz: 4b56c15224ab819fd173b51ce3cd341836a9edcbf6d2a0c0496813826c168f4c
4
+ data.tar.gz: 1eb2ef335b4fa1a2790573ca118c9178cff6d96ef6d3334cc165650c216bbc97
5
5
  SHA512:
6
- metadata.gz: c06509c2a113376920a1f41f6382f2542642c5ca83a1f37b330b28474f426566a3a526942417345a6ba7c4860dc87cd4744c669f2535f15f25f216cec61cf5b6
7
- data.tar.gz: 2f497885ec26787708b26900576d95c5ee2ff127b1d48f14560ddd5826edfcc0c01bbd6018a06bc05212e8ab73495cdbe1d1979902acefcfa88c34d9e819ddbe
6
+ metadata.gz: 9e099b2453555f7da80bfef2c4948a80523625271ba9666d2c053e455b0c42dc90d53f7f4a7233e1572696d58c7f1553dbdcaf38f9a4d6e351432a98de21d3ae
7
+ data.tar.gz: ea49a2fa692188d5864da2322a37c01de5856fb3d5bb4529966328f45e2ccc0114119c07289fa12c68afffc7f9e2030db99a10815480f180f3ea17fccd082218
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ # 0.1.4
4
+
5
+ [_View the docs._](https://github.com/ukazap/permisi/blob/v0.1.4/README.md)
6
+
7
+ - Add actor-role uniqueness constraint (previously it was possible to append the same role to an actor many times), if you are upgrading from previous versions, please create the following migration: `add_index :permisi_actor_roles, [:actor_id, :role_id], unique: true`
8
+ - Show warning when calling "roles.delete" because it won't invalidate the cache
9
+
3
10
  # 0.1.3
4
11
 
5
12
  [_View the docs._](https://github.com/ukazap/permisi/blob/v0.1.3/README.md)
data/Gemfile CHANGED
@@ -6,9 +6,9 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "byebug", "~> 11.1"
9
+ gem "codecov", "~> 0.4.3"
9
10
  gem "rake", "~> 13.0"
10
11
  gem "rspec", "~> 3.0"
11
12
  gem "rubocop", "~> 1.9"
12
13
  gem "simplecov", "~> 0.21.2"
13
14
  gem "sqlite3", "~> 1.4"
14
- gem "codecov", "~> 0.4.3"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- permisi (0.1.3)
4
+ permisi (0.1.4)
5
5
  activemodel (>= 3.2.0)
6
6
  activerecord (>= 3.2.0)
7
7
  activesupport (>= 3.2.0)
@@ -18,6 +18,8 @@ class CreatePermisiTables < ActiveRecord::Migration<%= migration_version %>
18
18
  t.belongs_to :actor
19
19
  t.belongs_to :role
20
20
  end
21
+
22
+ add_index :permisi_actor_roles, [:actor_id, :role_id], unique: true
21
23
  end
22
24
 
23
25
  def down
@@ -6,10 +6,14 @@ module Permisi
6
6
  class Actor < ::ActiveRecord::Base
7
7
  belongs_to :aka, polymorphic: true, touch: true
8
8
  has_many :actor_roles, dependent: :destroy
9
- has_many :roles, through: :actor_roles
9
+ has_many :roles, -> { distinct }, through: :actor_roles
10
10
 
11
11
  after_commit :reset_permissions
12
12
 
13
+ def roles
14
+ super.extend(ActorRolesCollectionProxy)
15
+ end
16
+
13
17
  def role?(role_slug)
14
18
  roles.load.any? { |role| role.slug == role_slug.to_s }
15
19
  end
@@ -38,6 +42,19 @@ module Permisi
38
42
 
39
43
  alias may? may_i?
40
44
  alias has_role? role?
45
+
46
+ module ActorRolesCollectionProxy
47
+ def <<(new_role)
48
+ super
49
+ rescue ::ActiveRecord::RecordNotUnique
50
+ self
51
+ end
52
+
53
+ def delete(*records)
54
+ warn "WARNING: `#delete(*records)` won't invalidate the cache, use `#destroy(*records)` instead."
55
+ super
56
+ end
57
+ end
41
58
  end
42
59
  end
43
60
  end
@@ -15,6 +15,16 @@ module Permisi
15
15
 
16
16
  def backend=(chosen_backend)
17
17
  chosen_backend = "::Permisi::Backend::#{chosen_backend.to_s.classify}".constantize if chosen_backend.is_a? Symbol
18
+
19
+ if chosen_backend == Backend::ActiveRecord && VERSION == "0.1.4"
20
+ warn <<~MESSAGE
21
+
22
+ WARNING: If you are upgrading from Permisi >v0.1.4, please create the following migration:
23
+ `add_index :permisi_actor_roles, [:actor_id, :role_id], unique: true`
24
+
25
+ MESSAGE
26
+ end
27
+
18
28
  @backend = chosen_backend
19
29
  rescue NameError
20
30
  raise Backend::InvalidBackend
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Permisi
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: permisi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ukaza Perdana
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-22 00:00:00.000000000 Z
11
+ date: 2021-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel