arpa 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/arpa-0.0.2.gem +0 -0
- data/arpa-0.0.3.gem +0 -0
- data/arpa-0.0.4.gem +0 -0
- data/lib/arpa/additions/resource.rb +8 -1
- data/lib/arpa/entities/action.rb +5 -1
- data/lib/arpa/entities/permissions.rb +5 -7
- data/lib/arpa/repositories/actions/finder.rb +11 -0
- data/lib/arpa/repositories/resources/finder.rb +0 -11
- data/lib/arpa/services/verifier.rb +7 -3
- data/lib/arpa/version.rb +1 -1
- data/spec/lib/ar/additions/resource_spec.rb +26 -5
- data/spec/lib/ar/entities/permissions_spec.rb +7 -8
- data/spec/lib/ar/repositories/actions/finder_spec.rb +18 -0
- data/spec/lib/ar/repositories/resources/finder_spec.rb +0 -18
- data/spec/lib/ar/services/verifier_spec.rb +19 -9
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aed68f2437222532064f2a8edbff5caf37bf9c8
|
4
|
+
data.tar.gz: 02ce1a1c1deb60c086bb0bcdfab56389f1927a14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d130875b378e74eeb65141f715e976365f5c790d74531ca87934bd45090a24a70e8086952482ad55d351d7fe3fcb5f4fce3a79281ec531c0ac127c710ad4381b
|
7
|
+
data.tar.gz: fb3c39a4ce49b9238dc7ae6c587aa556982776bae00beec2338a74374d05a1939eec135ca11e38edf6bfd3591db08fa4fa2b575b00afb8d3fee817fb7ceae3c3
|
data/arpa-0.0.2.gem
ADDED
Binary file
|
data/arpa-0.0.3.gem
ADDED
Binary file
|
data/arpa-0.0.4.gem
ADDED
Binary file
|
@@ -8,8 +8,15 @@ module Arpa
|
|
8
8
|
|
9
9
|
def has_access?(resource, action)
|
10
10
|
return unless has_session_or_current_user?
|
11
|
+
verifier.has_access?(resource, action)
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset_permissions
|
15
|
+
verifier.reset_permissions
|
16
|
+
end
|
17
|
+
|
18
|
+
def verifier
|
11
19
|
@verifier ||= Arpa::Services::Verifier.new(session, current_user)
|
12
|
-
@verifier.has_access?(resource, action)
|
13
20
|
end
|
14
21
|
|
15
22
|
private
|
data/lib/arpa/entities/action.rb
CHANGED
@@ -15,8 +15,12 @@ module Arpa
|
|
15
15
|
@updated_at = attrs[:updated_at]
|
16
16
|
end
|
17
17
|
|
18
|
+
def resource_name
|
19
|
+
resource.name
|
20
|
+
end
|
21
|
+
|
18
22
|
def description
|
19
|
-
I18n.t(name.to_sym, scope: "entities.resources.#{
|
23
|
+
I18n.t(name.to_sym, scope: "entities.resources.#{resource_name}.actions.description")
|
20
24
|
end
|
21
25
|
|
22
26
|
end
|
@@ -4,8 +4,8 @@ module Arpa
|
|
4
4
|
|
5
5
|
attr_reader :permissions
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(actions)
|
8
|
+
@actions = actions
|
9
9
|
@permissions = Array.new
|
10
10
|
build_permissions
|
11
11
|
end
|
@@ -17,11 +17,9 @@ module Arpa
|
|
17
17
|
|
18
18
|
private
|
19
19
|
def build_permissions
|
20
|
-
@
|
21
|
-
|
22
|
-
|
23
|
-
@permissions << hash_permission unless permissions.include?(hash_permission)
|
24
|
-
end
|
20
|
+
@actions.collect do |action|
|
21
|
+
hash_permission = build_hash_permission(action.resource_name, action.name)
|
22
|
+
@permissions << hash_permission unless permissions.include?(hash_permission)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
@@ -9,6 +9,17 @@ module Arpa
|
|
9
9
|
mapper_instance.map_to_entity(record) if record
|
10
10
|
end
|
11
11
|
|
12
|
+
def permissions(profile_ids)
|
13
|
+
records = repository_class.joins(roles: :profiles)
|
14
|
+
.where(repository_profiles: {id: profile_ids})
|
15
|
+
|
16
|
+
actions = records.collect do |action|
|
17
|
+
mapper_instance.map_to_entity(action)
|
18
|
+
end
|
19
|
+
|
20
|
+
Arpa::Entities::Permissions.new(actions)
|
21
|
+
end
|
22
|
+
|
12
23
|
def mapper_instance
|
13
24
|
Arpa::DataMappers::ActionMapper.instance
|
14
25
|
end
|
@@ -20,17 +20,6 @@ module Arpa
|
|
20
20
|
mapper_instance.map_to_entity(record) if record
|
21
21
|
end
|
22
22
|
|
23
|
-
def permissions(profile_ids)
|
24
|
-
records = repository_class.joins(actions: [roles: :profiles])
|
25
|
-
.where(repository_profiles: {id: profile_ids})
|
26
|
-
|
27
|
-
resources = records.collect do |record|
|
28
|
-
mapper_instance.map_to_entity(record)
|
29
|
-
end
|
30
|
-
|
31
|
-
Arpa::Entities::Permissions.new(resources)
|
32
|
-
end
|
33
|
-
|
34
23
|
def mapper_instance
|
35
24
|
Arpa::DataMappers::ResourceMapper.instance
|
36
25
|
end
|
@@ -10,14 +10,18 @@ module Arpa
|
|
10
10
|
def has_access?(resource, action)
|
11
11
|
free_access_action = action.to_s.split('_')[0]
|
12
12
|
return true if free_access_action.empty?
|
13
|
-
@session[:entity_permissions] ||=
|
13
|
+
@session[:entity_permissions] ||= action_finder.permissions(@current_user.profile_ids)
|
14
14
|
@session[:entity_permissions].has_permission?(resource.to_s, action.to_s)
|
15
15
|
end
|
16
16
|
|
17
|
+
def reset_permissions
|
18
|
+
@session[:entity_permissions] = nil
|
19
|
+
end
|
20
|
+
|
17
21
|
private
|
18
22
|
|
19
|
-
def
|
20
|
-
@
|
23
|
+
def action_finder
|
24
|
+
@action_finder ||= Arpa::Repositories::Actions::Finder.new
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/arpa/version.rb
CHANGED
@@ -11,13 +11,18 @@ describe Arpa::Additions::Resource, type: :addition, fast: true do
|
|
11
11
|
|
12
12
|
let(:resource_implementation) { ResourceImplementation.new }
|
13
13
|
|
14
|
+
let(:verifier) { double }
|
15
|
+
let(:resource) { double }
|
16
|
+
let(:action) { double }
|
17
|
+
|
18
|
+
before do
|
19
|
+
allow(Arpa::Services::Verifier).to receive(:new).and_return(verifier)
|
20
|
+
setup
|
21
|
+
end
|
22
|
+
|
14
23
|
describe '#has_access?' do
|
15
|
-
let(:verifier) { double }
|
16
|
-
let(:resource) { double }
|
17
|
-
let(:action) { double }
|
18
24
|
|
19
|
-
|
20
|
-
allow(Arpa::Services::Verifier).to receive(:new).and_return(verifier)
|
25
|
+
let(:setup) do
|
21
26
|
allow(verifier).to receive(:has_access?)
|
22
27
|
resource_implementation.has_access?(resource, action)
|
23
28
|
end
|
@@ -31,4 +36,20 @@ describe Arpa::Additions::Resource, type: :addition, fast: true do
|
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
39
|
+
describe '#reset_permissions' do
|
40
|
+
|
41
|
+
let(:setup) do
|
42
|
+
allow(verifier).to receive(:reset_permissions)
|
43
|
+
resource_implementation.reset_permissions
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should call :new from Arpa::Services::Verifier' do
|
47
|
+
expect(Arpa::Services::Verifier).to have_received(:new).once
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'verifier should call :reset_permissions once' do
|
51
|
+
expect(verifier).to have_received(:reset_permissions).once
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
34
55
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Arpa::Entities::Permissions, type: :presenter, fast: true do
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
4
|
+
let(:action_001) { double name: 'index', resource_name: 'users' }
|
5
|
+
let(:action_002) { double name: 'show', resource_name: 'users' }
|
6
|
+
let(:action_003) { double name: 'show', resource_name: 'users' }
|
7
|
+
let(:actions) { [action_001, action_002, action_003] }
|
8
8
|
|
9
|
-
subject { Arpa::Entities::Permissions.new(
|
9
|
+
subject { Arpa::Entities::Permissions.new(actions)}
|
10
10
|
|
11
11
|
describe 'intializing' do
|
12
12
|
let(:result) { subject.permissions }
|
@@ -24,7 +24,6 @@ describe Arpa::Entities::Permissions, type: :presenter, fast: true do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'when try fill permissions with duplicate resource and action' do
|
27
|
-
let(:hash_permission) { {'resource' => 'users', 'action' => 'index_new' } }
|
28
27
|
|
29
28
|
it 'should has only one Hash with that duplicated resource and action' do
|
30
29
|
duplicated_hash_permission = result.detect{ |e| result.count(e) > 1 }
|
@@ -39,7 +38,7 @@ describe Arpa::Entities::Permissions, type: :presenter, fast: true do
|
|
39
38
|
let(:result) { subject.has_permission?(resource_name, action_name) }
|
40
39
|
|
41
40
|
context 'when has' do
|
42
|
-
let(:action_name) { '
|
41
|
+
let(:action_name) { 'index' }
|
43
42
|
|
44
43
|
it 'should return true' do
|
45
44
|
expect(result).to be_truthy
|
@@ -48,7 +47,7 @@ describe Arpa::Entities::Permissions, type: :presenter, fast: true do
|
|
48
47
|
end
|
49
48
|
|
50
49
|
context 'when has not' do
|
51
|
-
let(:action_name) { '
|
50
|
+
let(:action_name) { 'index_old' }
|
52
51
|
|
53
52
|
it 'should return false' do
|
54
53
|
expect(result).to be_falsey
|
@@ -37,4 +37,22 @@ describe Arpa::Repositories::Actions::Finder, type: :repository, slow: true do
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
+
describe 'getting permissions from profile_ids' do
|
41
|
+
let(:profile_001) { create :repository_profile, :with_complete_association, name: 'prof_001' }
|
42
|
+
let(:profile_002) { create :repository_profile, :with_complete_association, name: 'prof_002' }
|
43
|
+
let(:profile_ids) { [profile_001.id, profile_002.id] }
|
44
|
+
|
45
|
+
let(:result) { subject.permissions(profile_ids) }
|
46
|
+
let(:first) { result.first }
|
47
|
+
|
48
|
+
it 'should return an Arpa::Entities::Permissions' do
|
49
|
+
expect(result).to be_an Arpa::Entities::Permissions
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should has just one permission' do
|
53
|
+
expect(result.permissions.size).to be == 1
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
40
58
|
end
|
@@ -71,22 +71,4 @@ describe Arpa::Repositories::Resources::Finder, type: :repository, slow: true do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
74
|
-
|
75
|
-
describe 'getting permissions from profile_ids' do
|
76
|
-
let(:profile_001) { create :repository_profile, :with_complete_association, name: 'prof_001' }
|
77
|
-
let(:profile_002) { create :repository_profile, :with_complete_association, name: 'prof_002' }
|
78
|
-
let(:profile_ids) { [profile_001.id, profile_002.id] }
|
79
|
-
|
80
|
-
let(:result) { subject.permissions(profile_ids) }
|
81
|
-
let(:first) { result.first }
|
82
|
-
|
83
|
-
it 'should return an Arpa::Entities::Permissions' do
|
84
|
-
expect(result).to be_an Arpa::Entities::Permissions
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should has just one permission' do
|
88
|
-
expect(result.permissions.size).to be == 1
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
74
|
end
|
@@ -6,6 +6,16 @@ describe Arpa::Services::Verifier do
|
|
6
6
|
|
7
7
|
subject(:verifier) { Arpa::Services::Verifier.new(session, current_user) }
|
8
8
|
|
9
|
+
describe 'cleaning session of permissions' do
|
10
|
+
let(:session) { {entity_permissions: [ {'resource': 'users', 'action': 'index'} ] } }
|
11
|
+
|
12
|
+
before { verifier.reset_permissions }
|
13
|
+
|
14
|
+
it 'session[:entity_permissions] should be set to nil' do
|
15
|
+
expect(session[:entity_permissions]).to be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
describe '#has_access?' do
|
10
20
|
context 'when pass a free action which begin with "_"' do
|
11
21
|
it 'should has access' do
|
@@ -14,24 +24,24 @@ describe Arpa::Services::Verifier do
|
|
14
24
|
end
|
15
25
|
|
16
26
|
context 'when pass a non free action' do
|
17
|
-
let(:
|
18
|
-
let(:
|
19
|
-
let(:entity_permissions)
|
27
|
+
let(:action_finder_class) { Arpa::Repositories::Actions::Finder }
|
28
|
+
let(:action_finder) { instance_double action_finder_class }
|
29
|
+
let(:entity_permissions) { double }
|
20
30
|
|
21
31
|
before do
|
22
|
-
allow(
|
23
|
-
allow(
|
32
|
+
allow(action_finder_class).to receive(:new).and_return(action_finder)
|
33
|
+
allow(action_finder).to receive(:permissions).with([1,2,3]).and_return(entity_permissions)
|
24
34
|
allow(entity_permissions).to receive(:has_permission?).with('users', 'index')
|
25
35
|
|
26
36
|
subject.has_access?('users', 'index')
|
27
37
|
end
|
28
38
|
|
29
|
-
it 'should be called :new from Arpa::Repositories::
|
30
|
-
expect(
|
39
|
+
it 'should be called :new from Arpa::Repositories::Actions::Finder' do
|
40
|
+
expect(action_finder_class).to have_received(:new).once
|
31
41
|
end
|
32
42
|
|
33
|
-
it 'should be called :permissions from Arpa::Repositories::
|
34
|
-
expect(
|
43
|
+
it 'should be called :permissions from Arpa::Repositories::Actions::Finder' do
|
44
|
+
expect(action_finder).to have_received(:permissions).with([1,2,3]).once
|
35
45
|
end
|
36
46
|
|
37
47
|
it 'should be called :has_permission? from session[:entity_permissions]' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arpa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rachid Calazans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,6 +170,9 @@ files:
|
|
170
170
|
- LICENSE.txt
|
171
171
|
- README.md
|
172
172
|
- Rakefile
|
173
|
+
- arpa-0.0.2.gem
|
174
|
+
- arpa-0.0.3.gem
|
175
|
+
- arpa-0.0.4.gem
|
173
176
|
- arpa.gemspec
|
174
177
|
- lib/arpa.rb
|
175
178
|
- lib/arpa/additions/resource.rb
|