arpa 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -8
- data/arpa.gemspec +9 -9
- data/lib/arpa.rb +0 -1
- data/lib/arpa/additions/resource.rb +4 -10
- data/lib/arpa/repositories/actions/finder.rb +9 -10
- data/lib/arpa/services/verifier.rb +2 -8
- data/lib/arpa/version.rb +1 -1
- data/spec/lib/{ar → arpa}/additions/resource_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/data_mappers/action_mapper_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/data_mappers/base_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/data_mappers/profile_mapper_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/data_mappers/resource_mapper_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/data_mappers/role_mapper_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/entities/action_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/entities/profile_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/entities/resource_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/entities/role_spec.rb +0 -0
- data/spec/lib/arpa/repositories/actions/finder_spec.rb +81 -0
- data/spec/lib/{ar → arpa}/repositories/base_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/repositories/profiles/finder_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/repositories/profiles/remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/repositories/resources/finder_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/repositories/resources/remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/repositories/roles/finder_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/repositories/roles/remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/requests/profiles/create_request_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/requests/profiles/remove_request_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/requests/resources/create_request_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/requests/roles/create_request_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/requests/roles/remove_request_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/requests/roles/update_request_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/actions/create/action_creator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/actions/remove/action_remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/base_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/profiles/create/profile_creator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/profiles/profile_manager_creator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/profiles/profile_manager_remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/profiles/profile_manager_updater_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/profiles/remove/profile_remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/profiles/update/profile_updater_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/resources/create/resource_creator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/resources/remove/resource_remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/resources/resource_manager_creator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/roles/create/role_creator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/roles/remove/role_remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/roles/role_manager_creator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/roles/role_manager_remover_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/roles/role_manager_updater_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/roles/update/role_updater_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/services/verifier_spec.rb +4 -20
- data/spec/lib/{ar → arpa}/validators/action_validator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/validators/profile_validator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/validators/resource_validator_spec.rb +0 -0
- data/spec/lib/{ar → arpa}/validators/role_validator_spec.rb +0 -0
- metadata +121 -105
- data/lib/arpa/entities/permissions.rb +0 -33
- data/spec/lib/ar/entities/permissions_spec.rb +0 -74
- data/spec/lib/ar/repositories/actions/finder_spec.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e186a7ffa777711f8abe3a488b43f3da45e74d69
|
4
|
+
data.tar.gz: fb3ac71b712d8a6d31b67f8242a7257cacbb4c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66b5b16cab66695d654fc2f4dff9ed97b2e780107658e7b86ba4905928af10a02316305d13e5a69803be42d980980e7335d498456304ef2081f8af6b2f1a4c27
|
7
|
+
data.tar.gz: aa5a31742a16330891c12017b61acfe6d72af273db195ec06ce651b7ec7a0c6ece5e5f106731c8080498fc08365efbd2edce25b6261cb16d993dac3266a79225
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -105,13 +105,8 @@ To verify if a user has access to some :controler and :action, use the following
|
|
105
105
|
has_access?('users', 'index')
|
106
106
|
```
|
107
107
|
|
108
|
-
To reset the session permissions created by Arpa, use the following helper:
|
109
108
|
|
110
|
-
|
111
|
-
reset_permissions
|
112
|
-
```
|
113
|
-
|
114
|
-
**Obs.:** To that helper method works. You must have **:session** (In Rails app already has) and **:current_user** attribute or method.
|
109
|
+
**Obs.:** To that helper method works. You must have **:current_user** attribute or method.
|
115
110
|
|
116
111
|
---
|
117
112
|
If you want use that methods inside another object you should use the **Arpa::Services::Verifier** class;
|
@@ -119,9 +114,8 @@ If you want use that methods inside another object you should use the **Arpa::Se
|
|
119
114
|
You just need pass as arguments the :session and :current_user:
|
120
115
|
|
121
116
|
```ruby
|
122
|
-
verifier = Arpa::Services::Verifier.new(
|
117
|
+
verifier = Arpa::Services::Verifier.new(current_user)
|
123
118
|
verifier.has_access?('users', 'index')
|
124
|
-
verifier.reset_permissions
|
125
119
|
```
|
126
120
|
|
127
121
|
### Controller Filter
|
data/arpa.gemspec
CHANGED
@@ -18,15 +18,15 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.3', '>= 3.3.0'
|
24
|
+
spec.add_development_dependency 'factory_girl', '~> 0'
|
25
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.3'
|
26
|
+
spec.add_development_dependency 'database_cleaner', '~> 0'
|
27
|
+
spec.add_development_dependency 'pry', '~> 0'
|
28
28
|
|
29
|
-
spec.add_dependency
|
30
|
-
spec.add_dependency
|
29
|
+
spec.add_dependency 'activerecord', '~> 4.2', '>= 4.2.0'
|
30
|
+
spec.add_dependency 'railties', '>= 4.2.0', '< 5'
|
31
31
|
|
32
32
|
end
|
data/lib/arpa.rb
CHANGED
@@ -7,26 +7,20 @@ module Arpa
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def has_access?(resource, action)
|
10
|
-
return unless
|
10
|
+
return unless has_current_user?
|
11
11
|
verifier.has_access?(resource, action)
|
12
12
|
end
|
13
13
|
|
14
|
-
def reset_permissions
|
15
|
-
verifier.reset_permissions
|
16
|
-
end
|
17
|
-
|
18
14
|
def verifier
|
19
|
-
@verifier ||= Arpa::Services::Verifier.new(
|
15
|
+
@verifier ||= Arpa::Services::Verifier.new(current_user)
|
20
16
|
end
|
21
17
|
|
22
18
|
private
|
23
19
|
|
24
|
-
def
|
25
|
-
verified_session = try(:session)
|
20
|
+
def has_current_user?
|
26
21
|
verified_current_user = try(:current_user)
|
27
|
-
return true if
|
22
|
+
return true if verified_current_user
|
28
23
|
log = Logger.new(STDOUT)
|
29
|
-
log.warn("The ApplicationController must has a attribute or method 'session'") unless verified_session
|
30
24
|
log.warn("The ApplicationController must has a attribute or method 'current_user'") unless verified_current_user
|
31
25
|
false
|
32
26
|
end
|
@@ -5,19 +5,18 @@ module Arpa
|
|
5
5
|
include Arpa::Repositories::Base
|
6
6
|
|
7
7
|
def by_name_and_resource(name, resource_id)
|
8
|
-
record = repository_class.
|
8
|
+
record = repository_class.find_by(name: name, repository_resource_id: resource_id)
|
9
9
|
mapper_instance.map_to_entity(record) if record
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Arpa::Entities::Permissions.new(actions)
|
12
|
+
def permission(resource_name, action_name, profile_ids)
|
13
|
+
record = repository_class
|
14
|
+
.distinct(true)
|
15
|
+
.joins(:resource, roles: :profiles)
|
16
|
+
.find_by(repository_profiles: {id: profile_ids},
|
17
|
+
repository_resources: {name: resource_name},
|
18
|
+
name: action_name)
|
19
|
+
mapper_instance.map_to_entity(record) if record
|
21
20
|
end
|
22
21
|
|
23
22
|
def mapper_instance
|
@@ -2,20 +2,14 @@ module Arpa
|
|
2
2
|
module Services
|
3
3
|
class Verifier
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@session = session
|
5
|
+
def initialize(current_user)
|
7
6
|
@current_user = current_user
|
8
7
|
end
|
9
8
|
|
10
9
|
def has_access?(resource, action)
|
11
10
|
free_access_action = action.to_s.split('_')[0]
|
12
11
|
return true if @current_user.is_arpa_admin? || free_access_action.empty?
|
13
|
-
|
14
|
-
@session[:entity_permissions].has_permission?(resource.to_s, action.to_s)
|
15
|
-
end
|
16
|
-
|
17
|
-
def reset_permissions
|
18
|
-
@session[:entity_permissions] = nil
|
12
|
+
action_finder.permission(resource.to_s, action.to_s, @current_user.profile_ids)
|
19
13
|
end
|
20
14
|
|
21
15
|
private
|
data/lib/arpa/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Arpa::Repositories::Actions::Finder, type: :repository, slow: true do
|
4
|
+
|
5
|
+
let(:resource_record) { create :repository_resource, :user }
|
6
|
+
let(:action_record_001) { create :repository_action, :index, resource: resource_record }
|
7
|
+
let(:action_record_002) { create :repository_action, :show, resource: resource_record}
|
8
|
+
|
9
|
+
before do
|
10
|
+
action_record_001
|
11
|
+
action_record_002
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#by_name_and_resource' do
|
15
|
+
|
16
|
+
context 'when exist with the params' do
|
17
|
+
|
18
|
+
let(:result) { subject.by_name_and_resource('index', resource_record) }
|
19
|
+
|
20
|
+
it 'should return a resource with name "index"' do
|
21
|
+
expect(result.name).to eql 'index'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'the result should be an instance of Arpa::Entities::Action' do
|
25
|
+
expect(result).to be_an Arpa::Entities::Action
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when nonexist with the params' do
|
30
|
+
|
31
|
+
let(:result) { subject.by_name_and_resource('nonexist_action', resource_record) }
|
32
|
+
|
33
|
+
it 'the result should return nil' do
|
34
|
+
expect(result).to be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'getting permission from action_name, resource_name and profile_ids' do
|
41
|
+
let(:resource_name) { '' }
|
42
|
+
let(:action_name) { '' }
|
43
|
+
let(:profile_ids) { [] }
|
44
|
+
|
45
|
+
let(:result) { subject.permission(resource_name, action_name, profile_ids) }
|
46
|
+
|
47
|
+
before { result }
|
48
|
+
|
49
|
+
context 'when action and resource belongs to some profile' do
|
50
|
+
let(:user_resource) { create :repository_resource, :user }
|
51
|
+
let(:index_action) { create :repository_action, :index, resource: user_resource }
|
52
|
+
let(:show_action) { create :repository_action, :show, resource: user_resource }
|
53
|
+
|
54
|
+
let(:user_resource_001) { create :repository_resource, :contact }
|
55
|
+
let(:index_action_001) { create :repository_action, :index, resource: user_resource }
|
56
|
+
|
57
|
+
let(:role_001) { create :repository_role, actions: [index_action] }
|
58
|
+
let(:role_002) { create :repository_role, actions: [index_action] }
|
59
|
+
let(:role_003) { create :repository_role, actions: [index_action_001] }
|
60
|
+
|
61
|
+
let(:profile_001) { create :repository_profile, roles: [role_001, role_002] }
|
62
|
+
let(:profile_002) { create :repository_profile, roles: [role_001, role_003] }
|
63
|
+
|
64
|
+
let(:resource_name) { 'users' }
|
65
|
+
let(:action_name) { 'index' }
|
66
|
+
let(:profile_ids) { [profile_001.id, profile_002.id] }
|
67
|
+
|
68
|
+
it 'should return some permission' do
|
69
|
+
expect(result).to be_an Arpa::Entities::Action
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when action and resource not belogns to any profile' do
|
74
|
+
|
75
|
+
it 'should not return any permission' do
|
76
|
+
expect(result).to be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,20 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Arpa::Services::Verifier do
|
4
|
-
let(:session) { {} }
|
5
4
|
let(:current_user) { double is_arpa_admin?: false, profile_ids: [1,2,3] }
|
6
5
|
|
7
|
-
subject(:verifier) { Arpa::Services::Verifier.new(
|
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
|
6
|
+
subject(:verifier) { Arpa::Services::Verifier.new(current_user) }
|
18
7
|
|
19
8
|
describe '#has_access?' do
|
20
9
|
|
@@ -35,12 +24,11 @@ describe Arpa::Services::Verifier do
|
|
35
24
|
context 'when pass a non free action' do
|
36
25
|
let(:action_finder_class) { Arpa::Repositories::Actions::Finder }
|
37
26
|
let(:action_finder) { instance_double action_finder_class }
|
38
|
-
let(:
|
27
|
+
let(:action) { double }
|
39
28
|
|
40
29
|
before do
|
41
30
|
allow(action_finder_class).to receive(:new).and_return(action_finder)
|
42
|
-
allow(action_finder).to receive(:
|
43
|
-
allow(entity_permissions).to receive(:has_permission?).with('users', 'index')
|
31
|
+
allow(action_finder).to receive(:permission).and_return(action)
|
44
32
|
|
45
33
|
subject.has_access?('users', 'index')
|
46
34
|
end
|
@@ -50,11 +38,7 @@ describe Arpa::Services::Verifier do
|
|
50
38
|
end
|
51
39
|
|
52
40
|
it 'should be called :permissions from Arpa::Repositories::Actions::Finder' do
|
53
|
-
expect(action_finder).to have_received(:
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should be called :has_permission? from session[:entity_permissions]' do
|
57
|
-
expect(entity_permissions).to have_received(:has_permission?).with('users', 'index').once
|
41
|
+
expect(action_finder).to have_received(:permission).with('users', 'index', [1,2,3]).once
|
58
42
|
end
|
59
43
|
|
60
44
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rachid Calazans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -43,6 +43,9 @@ dependencies:
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
- - ">="
|
46
49
|
- !ruby/object:Gem::Version
|
47
50
|
version: 3.3.0
|
48
51
|
type: :development
|
@@ -50,20 +53,23 @@ dependencies:
|
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.3'
|
58
|
+
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: 3.3.0
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: factory_girl
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - "
|
65
|
+
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: '0'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- - "
|
72
|
+
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '0'
|
69
75
|
- !ruby/object:Gem::Dependency
|
@@ -71,6 +77,9 @@ dependencies:
|
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
79
|
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.3'
|
82
|
+
- - ">="
|
74
83
|
- !ruby/object:Gem::Version
|
75
84
|
version: 1.3.3
|
76
85
|
type: :development
|
@@ -78,40 +87,46 @@ dependencies:
|
|
78
87
|
version_requirements: !ruby/object:Gem::Requirement
|
79
88
|
requirements:
|
80
89
|
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1.3'
|
92
|
+
- - ">="
|
81
93
|
- !ruby/object:Gem::Version
|
82
94
|
version: 1.3.3
|
83
95
|
- !ruby/object:Gem::Dependency
|
84
96
|
name: database_cleaner
|
85
97
|
requirement: !ruby/object:Gem::Requirement
|
86
98
|
requirements:
|
87
|
-
- - "
|
99
|
+
- - "~>"
|
88
100
|
- !ruby/object:Gem::Version
|
89
101
|
version: '0'
|
90
102
|
type: :development
|
91
103
|
prerelease: false
|
92
104
|
version_requirements: !ruby/object:Gem::Requirement
|
93
105
|
requirements:
|
94
|
-
- - "
|
106
|
+
- - "~>"
|
95
107
|
- !ruby/object:Gem::Version
|
96
108
|
version: '0'
|
97
109
|
- !ruby/object:Gem::Dependency
|
98
110
|
name: pry
|
99
111
|
requirement: !ruby/object:Gem::Requirement
|
100
112
|
requirements:
|
101
|
-
- - "
|
113
|
+
- - "~>"
|
102
114
|
- !ruby/object:Gem::Version
|
103
115
|
version: '0'
|
104
116
|
type: :development
|
105
117
|
prerelease: false
|
106
118
|
version_requirements: !ruby/object:Gem::Requirement
|
107
119
|
requirements:
|
108
|
-
- - "
|
120
|
+
- - "~>"
|
109
121
|
- !ruby/object:Gem::Version
|
110
122
|
version: '0'
|
111
123
|
- !ruby/object:Gem::Dependency
|
112
124
|
name: activerecord
|
113
125
|
requirement: !ruby/object:Gem::Requirement
|
114
126
|
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '4.2'
|
115
130
|
- - ">="
|
116
131
|
- !ruby/object:Gem::Version
|
117
132
|
version: 4.2.0
|
@@ -119,6 +134,9 @@ dependencies:
|
|
119
134
|
prerelease: false
|
120
135
|
version_requirements: !ruby/object:Gem::Requirement
|
121
136
|
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '4.2'
|
122
140
|
- - ">="
|
123
141
|
- !ruby/object:Gem::Version
|
124
142
|
version: 4.2.0
|
@@ -152,6 +170,7 @@ files:
|
|
152
170
|
- ".gitignore"
|
153
171
|
- ".ruby-gemset"
|
154
172
|
- ".ruby-version"
|
173
|
+
- CHANGELOG.md
|
155
174
|
- Gemfile
|
156
175
|
- LICENSE.txt
|
157
176
|
- README.md
|
@@ -165,7 +184,6 @@ files:
|
|
165
184
|
- lib/arpa/data_mappers/resource_mapper.rb
|
166
185
|
- lib/arpa/data_mappers/role_mapper.rb
|
167
186
|
- lib/arpa/entities/action.rb
|
168
|
-
- lib/arpa/entities/permissions.rb
|
169
187
|
- lib/arpa/entities/profile.rb
|
170
188
|
- lib/arpa/entities/resource.rb
|
171
189
|
- lib/arpa/entities/role.rb
|
@@ -238,54 +256,53 @@ files:
|
|
238
256
|
- spec/factories/repository_profiles.rb
|
239
257
|
- spec/factories/repository_resources.rb
|
240
258
|
- spec/factories/repository_roles.rb
|
241
|
-
- spec/lib/
|
242
|
-
- spec/lib/
|
243
|
-
- spec/lib/
|
244
|
-
- spec/lib/
|
245
|
-
- spec/lib/
|
246
|
-
- spec/lib/
|
247
|
-
- spec/lib/
|
248
|
-
- spec/lib/
|
249
|
-
- spec/lib/
|
250
|
-
- spec/lib/
|
251
|
-
- spec/lib/
|
252
|
-
- spec/lib/
|
253
|
-
- spec/lib/
|
254
|
-
- spec/lib/
|
255
|
-
- spec/lib/
|
256
|
-
- spec/lib/
|
257
|
-
- spec/lib/
|
258
|
-
- spec/lib/
|
259
|
-
- spec/lib/
|
260
|
-
- spec/lib/
|
261
|
-
- spec/lib/
|
262
|
-
- spec/lib/
|
263
|
-
- spec/lib/
|
264
|
-
- spec/lib/
|
265
|
-
- spec/lib/
|
266
|
-
- spec/lib/
|
267
|
-
- spec/lib/
|
268
|
-
- spec/lib/
|
269
|
-
- spec/lib/
|
270
|
-
- spec/lib/
|
271
|
-
- spec/lib/
|
272
|
-
- spec/lib/
|
273
|
-
- spec/lib/
|
274
|
-
- spec/lib/
|
275
|
-
- spec/lib/
|
276
|
-
- spec/lib/
|
277
|
-
- spec/lib/
|
278
|
-
- spec/lib/
|
279
|
-
- spec/lib/
|
280
|
-
- spec/lib/
|
281
|
-
- spec/lib/
|
282
|
-
- spec/lib/
|
283
|
-
- spec/lib/
|
284
|
-
- spec/lib/
|
285
|
-
- spec/lib/
|
286
|
-
- spec/lib/
|
287
|
-
- spec/lib/
|
288
|
-
- spec/lib/ar/validators/role_validator_spec.rb
|
259
|
+
- spec/lib/arpa/additions/resource_spec.rb
|
260
|
+
- spec/lib/arpa/data_mappers/action_mapper_spec.rb
|
261
|
+
- spec/lib/arpa/data_mappers/base_spec.rb
|
262
|
+
- spec/lib/arpa/data_mappers/profile_mapper_spec.rb
|
263
|
+
- spec/lib/arpa/data_mappers/resource_mapper_spec.rb
|
264
|
+
- spec/lib/arpa/data_mappers/role_mapper_spec.rb
|
265
|
+
- spec/lib/arpa/entities/action_spec.rb
|
266
|
+
- spec/lib/arpa/entities/profile_spec.rb
|
267
|
+
- spec/lib/arpa/entities/resource_spec.rb
|
268
|
+
- spec/lib/arpa/entities/role_spec.rb
|
269
|
+
- spec/lib/arpa/repositories/actions/finder_spec.rb
|
270
|
+
- spec/lib/arpa/repositories/base_spec.rb
|
271
|
+
- spec/lib/arpa/repositories/profiles/finder_spec.rb
|
272
|
+
- spec/lib/arpa/repositories/profiles/remover_spec.rb
|
273
|
+
- spec/lib/arpa/repositories/resources/finder_spec.rb
|
274
|
+
- spec/lib/arpa/repositories/resources/remover_spec.rb
|
275
|
+
- spec/lib/arpa/repositories/roles/finder_spec.rb
|
276
|
+
- spec/lib/arpa/repositories/roles/remover_spec.rb
|
277
|
+
- spec/lib/arpa/requests/profiles/create_request_spec.rb
|
278
|
+
- spec/lib/arpa/requests/profiles/remove_request_spec.rb
|
279
|
+
- spec/lib/arpa/requests/resources/create_request_spec.rb
|
280
|
+
- spec/lib/arpa/requests/roles/create_request_spec.rb
|
281
|
+
- spec/lib/arpa/requests/roles/remove_request_spec.rb
|
282
|
+
- spec/lib/arpa/requests/roles/update_request_spec.rb
|
283
|
+
- spec/lib/arpa/services/actions/create/action_creator_spec.rb
|
284
|
+
- spec/lib/arpa/services/actions/remove/action_remover_spec.rb
|
285
|
+
- spec/lib/arpa/services/base_spec.rb
|
286
|
+
- spec/lib/arpa/services/profiles/create/profile_creator_spec.rb
|
287
|
+
- spec/lib/arpa/services/profiles/profile_manager_creator_spec.rb
|
288
|
+
- spec/lib/arpa/services/profiles/profile_manager_remover_spec.rb
|
289
|
+
- spec/lib/arpa/services/profiles/profile_manager_updater_spec.rb
|
290
|
+
- spec/lib/arpa/services/profiles/remove/profile_remover_spec.rb
|
291
|
+
- spec/lib/arpa/services/profiles/update/profile_updater_spec.rb
|
292
|
+
- spec/lib/arpa/services/resources/create/resource_creator_spec.rb
|
293
|
+
- spec/lib/arpa/services/resources/remove/resource_remover_spec.rb
|
294
|
+
- spec/lib/arpa/services/resources/resource_manager_creator_spec.rb
|
295
|
+
- spec/lib/arpa/services/roles/create/role_creator_spec.rb
|
296
|
+
- spec/lib/arpa/services/roles/remove/role_remover_spec.rb
|
297
|
+
- spec/lib/arpa/services/roles/role_manager_creator_spec.rb
|
298
|
+
- spec/lib/arpa/services/roles/role_manager_remover_spec.rb
|
299
|
+
- spec/lib/arpa/services/roles/role_manager_updater_spec.rb
|
300
|
+
- spec/lib/arpa/services/roles/update/role_updater_spec.rb
|
301
|
+
- spec/lib/arpa/services/verifier_spec.rb
|
302
|
+
- spec/lib/arpa/validators/action_validator_spec.rb
|
303
|
+
- spec/lib/arpa/validators/profile_validator_spec.rb
|
304
|
+
- spec/lib/arpa/validators/resource_validator_spec.rb
|
305
|
+
- spec/lib/arpa/validators/role_validator_spec.rb
|
289
306
|
- spec/spec_helper.rb
|
290
307
|
- spec/support/repositories/test_repository.rb
|
291
308
|
- spec/support/schema.rb
|
@@ -318,54 +335,53 @@ test_files:
|
|
318
335
|
- spec/factories/repository_profiles.rb
|
319
336
|
- spec/factories/repository_resources.rb
|
320
337
|
- spec/factories/repository_roles.rb
|
321
|
-
- spec/lib/
|
322
|
-
- spec/lib/
|
323
|
-
- spec/lib/
|
324
|
-
- spec/lib/
|
325
|
-
- spec/lib/
|
326
|
-
- spec/lib/
|
327
|
-
- spec/lib/
|
328
|
-
- spec/lib/
|
329
|
-
- spec/lib/
|
330
|
-
- spec/lib/
|
331
|
-
- spec/lib/
|
332
|
-
- spec/lib/
|
333
|
-
- spec/lib/
|
334
|
-
- spec/lib/
|
335
|
-
- spec/lib/
|
336
|
-
- spec/lib/
|
337
|
-
- spec/lib/
|
338
|
-
- spec/lib/
|
339
|
-
- spec/lib/
|
340
|
-
- spec/lib/
|
341
|
-
- spec/lib/
|
342
|
-
- spec/lib/
|
343
|
-
- spec/lib/
|
344
|
-
- spec/lib/
|
345
|
-
- spec/lib/
|
346
|
-
- spec/lib/
|
347
|
-
- spec/lib/
|
348
|
-
- spec/lib/
|
349
|
-
- spec/lib/
|
350
|
-
- spec/lib/
|
351
|
-
- spec/lib/
|
352
|
-
- spec/lib/
|
353
|
-
- spec/lib/
|
354
|
-
- spec/lib/
|
355
|
-
- spec/lib/
|
356
|
-
- spec/lib/
|
357
|
-
- spec/lib/
|
358
|
-
- spec/lib/
|
359
|
-
- spec/lib/
|
360
|
-
- spec/lib/
|
361
|
-
- spec/lib/
|
362
|
-
- spec/lib/
|
363
|
-
- spec/lib/
|
364
|
-
- spec/lib/
|
365
|
-
- spec/lib/
|
366
|
-
- spec/lib/
|
367
|
-
- spec/lib/
|
368
|
-
- spec/lib/ar/validators/role_validator_spec.rb
|
338
|
+
- spec/lib/arpa/additions/resource_spec.rb
|
339
|
+
- spec/lib/arpa/data_mappers/action_mapper_spec.rb
|
340
|
+
- spec/lib/arpa/data_mappers/base_spec.rb
|
341
|
+
- spec/lib/arpa/data_mappers/profile_mapper_spec.rb
|
342
|
+
- spec/lib/arpa/data_mappers/resource_mapper_spec.rb
|
343
|
+
- spec/lib/arpa/data_mappers/role_mapper_spec.rb
|
344
|
+
- spec/lib/arpa/entities/action_spec.rb
|
345
|
+
- spec/lib/arpa/entities/profile_spec.rb
|
346
|
+
- spec/lib/arpa/entities/resource_spec.rb
|
347
|
+
- spec/lib/arpa/entities/role_spec.rb
|
348
|
+
- spec/lib/arpa/repositories/actions/finder_spec.rb
|
349
|
+
- spec/lib/arpa/repositories/base_spec.rb
|
350
|
+
- spec/lib/arpa/repositories/profiles/finder_spec.rb
|
351
|
+
- spec/lib/arpa/repositories/profiles/remover_spec.rb
|
352
|
+
- spec/lib/arpa/repositories/resources/finder_spec.rb
|
353
|
+
- spec/lib/arpa/repositories/resources/remover_spec.rb
|
354
|
+
- spec/lib/arpa/repositories/roles/finder_spec.rb
|
355
|
+
- spec/lib/arpa/repositories/roles/remover_spec.rb
|
356
|
+
- spec/lib/arpa/requests/profiles/create_request_spec.rb
|
357
|
+
- spec/lib/arpa/requests/profiles/remove_request_spec.rb
|
358
|
+
- spec/lib/arpa/requests/resources/create_request_spec.rb
|
359
|
+
- spec/lib/arpa/requests/roles/create_request_spec.rb
|
360
|
+
- spec/lib/arpa/requests/roles/remove_request_spec.rb
|
361
|
+
- spec/lib/arpa/requests/roles/update_request_spec.rb
|
362
|
+
- spec/lib/arpa/services/actions/create/action_creator_spec.rb
|
363
|
+
- spec/lib/arpa/services/actions/remove/action_remover_spec.rb
|
364
|
+
- spec/lib/arpa/services/base_spec.rb
|
365
|
+
- spec/lib/arpa/services/profiles/create/profile_creator_spec.rb
|
366
|
+
- spec/lib/arpa/services/profiles/profile_manager_creator_spec.rb
|
367
|
+
- spec/lib/arpa/services/profiles/profile_manager_remover_spec.rb
|
368
|
+
- spec/lib/arpa/services/profiles/profile_manager_updater_spec.rb
|
369
|
+
- spec/lib/arpa/services/profiles/remove/profile_remover_spec.rb
|
370
|
+
- spec/lib/arpa/services/profiles/update/profile_updater_spec.rb
|
371
|
+
- spec/lib/arpa/services/resources/create/resource_creator_spec.rb
|
372
|
+
- spec/lib/arpa/services/resources/remove/resource_remover_spec.rb
|
373
|
+
- spec/lib/arpa/services/resources/resource_manager_creator_spec.rb
|
374
|
+
- spec/lib/arpa/services/roles/create/role_creator_spec.rb
|
375
|
+
- spec/lib/arpa/services/roles/remove/role_remover_spec.rb
|
376
|
+
- spec/lib/arpa/services/roles/role_manager_creator_spec.rb
|
377
|
+
- spec/lib/arpa/services/roles/role_manager_remover_spec.rb
|
378
|
+
- spec/lib/arpa/services/roles/role_manager_updater_spec.rb
|
379
|
+
- spec/lib/arpa/services/roles/update/role_updater_spec.rb
|
380
|
+
- spec/lib/arpa/services/verifier_spec.rb
|
381
|
+
- spec/lib/arpa/validators/action_validator_spec.rb
|
382
|
+
- spec/lib/arpa/validators/profile_validator_spec.rb
|
383
|
+
- spec/lib/arpa/validators/resource_validator_spec.rb
|
384
|
+
- spec/lib/arpa/validators/role_validator_spec.rb
|
369
385
|
- spec/spec_helper.rb
|
370
386
|
- spec/support/repositories/test_repository.rb
|
371
387
|
- spec/support/schema.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Arpa
|
2
|
-
module Entities
|
3
|
-
class Permissions
|
4
|
-
|
5
|
-
attr_reader :permissions
|
6
|
-
|
7
|
-
def initialize(actions)
|
8
|
-
@actions = actions
|
9
|
-
@permissions = Array.new
|
10
|
-
build_permissions
|
11
|
-
end
|
12
|
-
|
13
|
-
def has_permission?(resource_name, action_name)
|
14
|
-
hash_permission = build_hash_permission(resource_name, action_name)
|
15
|
-
permissions.include?(hash_permission)
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def build_permissions
|
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)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def build_hash_permission(resource_name, action_name)
|
27
|
-
{'resource' => resource_name, 'action' => action_name }
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arpa::Entities::Permissions, type: :entity, fast: true do
|
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
|
-
|
9
|
-
subject { Arpa::Entities::Permissions.new(actions)}
|
10
|
-
|
11
|
-
describe 'intializing' do
|
12
|
-
let(:result) { subject.permissions }
|
13
|
-
|
14
|
-
it 'attr :permissions should be an Array' do
|
15
|
-
expect(result).to be_an Array
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should fill attr :permissions as an Array of Hash with keys :resource and :action' do
|
19
|
-
first = result.first
|
20
|
-
|
21
|
-
expect(first).to be_a Hash
|
22
|
-
expect(first.has_key?('resource')).to be_truthy
|
23
|
-
expect(first.has_key?('action')).to be_truthy
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when try fill permissions with duplicate resource and action' do
|
27
|
-
|
28
|
-
it 'should has only one Hash with that duplicated resource and action' do
|
29
|
-
duplicated_hash_permission = result.detect{ |e| result.count(e) > 1 }
|
30
|
-
expect(duplicated_hash_permission).to be_nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#has_permission?' do
|
37
|
-
let(:result) { subject.has_permission?(resource_name, action_name) }
|
38
|
-
|
39
|
-
context 'when pass a resource name with permission' do
|
40
|
-
let(:resource_name) { 'users' }
|
41
|
-
|
42
|
-
context 'when pass an action with permission' do
|
43
|
-
let(:action_name) { 'index' }
|
44
|
-
|
45
|
-
it 'should return true' do
|
46
|
-
expect(result).to be_truthy
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when pass an action with no permission' do
|
51
|
-
let(:action_name) { 'index_old' }
|
52
|
-
|
53
|
-
it 'should return false' do
|
54
|
-
expect(result).to be_falsey
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'when pass a resource name with no permission' do
|
60
|
-
let(:resource_name) { 'users_2' }
|
61
|
-
|
62
|
-
context 'when pass some action' do
|
63
|
-
let(:action_name) { 'index' }
|
64
|
-
|
65
|
-
it 'should return false' do
|
66
|
-
expect(result).to be_falsey
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arpa::Repositories::Actions::Finder, type: :repository, slow: true do
|
4
|
-
|
5
|
-
let(:resource_record) { create :repository_resource, :user }
|
6
|
-
let(:action_record_001) { create :repository_action, :index, resource: resource_record }
|
7
|
-
let(:action_record_002) { create :repository_action, :show, resource: resource_record}
|
8
|
-
|
9
|
-
before do
|
10
|
-
action_record_001
|
11
|
-
action_record_002
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#by_name_and_resource' do
|
15
|
-
|
16
|
-
context 'when exist with the params' do
|
17
|
-
|
18
|
-
let(:result) { subject.by_name_and_resource('index', resource_record) }
|
19
|
-
|
20
|
-
it 'should return a resource with name "index"' do
|
21
|
-
expect(result.name).to eql 'index'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'the result should be an instance of Arpa::Entities::Action' do
|
25
|
-
expect(result).to be_an Arpa::Entities::Action
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'when nonexist with the params' do
|
30
|
-
|
31
|
-
let(:result) { subject.by_name_and_resource('nonexist_action', resource_record) }
|
32
|
-
|
33
|
-
it 'the result should return nil' do
|
34
|
-
expect(result).to be_nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
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
|
-
|
58
|
-
end
|