arpa 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +17 -0
- data/.ruby-version +1 -1
- data/.travis.yml +5 -0
- data/CHANGELOG.md +4 -0
- data/README.md +4 -4
- data/Rakefile +1 -2
- data/arpa.gemspec +17 -18
- data/lib/arpa.rb +65 -67
- data/lib/arpa/additions/resource.rb +0 -2
- data/lib/arpa/data_mappers/action_mapper.rb +1 -2
- data/lib/arpa/data_mappers/base.rb +15 -16
- data/lib/arpa/data_mappers/profile_mapper.rb +3 -4
- data/lib/arpa/data_mappers/resource_mapper.rb +1 -1
- data/lib/arpa/data_mappers/role_mapper.rb +2 -2
- data/lib/arpa/entities/action.rb +0 -2
- data/lib/arpa/entities/profile.rb +2 -3
- data/lib/arpa/entities/resource.rb +4 -6
- data/lib/arpa/entities/role.rb +2 -3
- data/lib/arpa/exceptions/record_invalid.rb +0 -1
- data/lib/arpa/repositories/actions/creator.rb +0 -1
- data/lib/arpa/repositories/actions/finder.rb +5 -6
- data/lib/arpa/repositories/actions/remover.rb +0 -1
- data/lib/arpa/repositories/actions/repository_action.rb +1 -2
- data/lib/arpa/repositories/base.rb +0 -2
- data/lib/arpa/repositories/profiles/creator.rb +0 -1
- data/lib/arpa/repositories/profiles/finder.rb +2 -3
- data/lib/arpa/repositories/profiles/remover.rb +0 -1
- data/lib/arpa/repositories/profiles/repository_profile.rb +1 -2
- data/lib/arpa/repositories/profiles/updater.rb +0 -1
- data/lib/arpa/repositories/registrator.rb +5 -10
- data/lib/arpa/repositories/resources/creator.rb +0 -1
- data/lib/arpa/repositories/resources/finder.rb +0 -1
- data/lib/arpa/repositories/resources/remover.rb +0 -1
- data/lib/arpa/repositories/resources/repository_resource.rb +1 -2
- data/lib/arpa/repositories/roles/creator.rb +0 -1
- data/lib/arpa/repositories/roles/finder.rb +0 -1
- data/lib/arpa/repositories/roles/remover.rb +0 -1
- data/lib/arpa/repositories/roles/repository_role.rb +1 -2
- data/lib/arpa/repositories/roles/updater.rb +0 -1
- data/lib/arpa/services/actions/create/action_creator.rb +1 -3
- data/lib/arpa/services/actions/remove/action_remover.rb +0 -2
- data/lib/arpa/services/base.rb +6 -10
- data/lib/arpa/services/profiles/create/profile_creator.rb +0 -2
- data/lib/arpa/services/profiles/profile_manager_creator.rb +0 -1
- data/lib/arpa/services/profiles/profile_manager_remover.rb +0 -1
- data/lib/arpa/services/profiles/profile_manager_updater.rb +0 -1
- data/lib/arpa/services/profiles/remove/profile_remover.rb +0 -2
- data/lib/arpa/services/profiles/update/profile_updater.rb +0 -2
- data/lib/arpa/services/resources/create/resource_creator.rb +0 -2
- data/lib/arpa/services/resources/remove/resource_remover.rb +1 -4
- data/lib/arpa/services/resources/resource_manager_creator.rb +1 -2
- data/lib/arpa/services/roles/create/role_creator.rb +0 -3
- data/lib/arpa/services/roles/remove/role_remover.rb +0 -2
- data/lib/arpa/services/roles/role_manager_creator.rb +0 -2
- data/lib/arpa/services/roles/role_manager_remover.rb +0 -1
- data/lib/arpa/services/roles/role_manager_updater.rb +0 -1
- data/lib/arpa/services/roles/update/role_updater.rb +0 -2
- data/lib/arpa/services/verifier.rb +0 -1
- data/lib/arpa/validators/action_validator.rb +0 -1
- data/lib/arpa/validators/profile_validator.rb +0 -1
- data/lib/arpa/validators/resource_validator.rb +0 -1
- data/lib/arpa/validators/role_validator.rb +0 -2
- data/lib/arpa/version.rb +1 -1
- data/lib/generators/arpa/controllers_generator.rb +21 -22
- data/lib/generators/arpa/install_generator.rb +5 -6
- data/lib/generators/arpa/templates/controllers/profiles_controller.rb +31 -37
- data/lib/generators/arpa/templates/controllers/resources_controller.rb +20 -11
- data/lib/generators/arpa/templates/controllers/roles_controller.rb +31 -37
- data/lib/generators/arpa/templates/migration.rb +1 -1
- data/spec/factories/repository_actions.rb +4 -5
- data/spec/factories/repository_profiles.rb +4 -5
- data/spec/factories/repository_resources.rb +1 -3
- data/spec/factories/repository_roles.rb +2 -3
- data/spec/factories/repository_test.rb +1 -1
- data/spec/lib/arpa/additions/resource_spec.rb +8 -6
- data/spec/lib/arpa/data_mappers/action_mapper_spec.rb +1 -3
- data/spec/lib/arpa/data_mappers/base_spec.rb +0 -2
- data/spec/lib/arpa/data_mappers/profile_mapper_spec.rb +1 -3
- data/spec/lib/arpa/data_mappers/resource_mapper_spec.rb +1 -3
- data/spec/lib/arpa/data_mappers/role_mapper_spec.rb +1 -3
- data/spec/lib/arpa/entities/action_spec.rb +3 -6
- data/spec/lib/arpa/entities/profile_spec.rb +1 -7
- data/spec/lib/arpa/entities/resource_spec.rb +1 -9
- data/spec/lib/arpa/entities/role_spec.rb +1 -7
- data/spec/lib/arpa/repositories/actions/finder_spec.rb +1 -8
- data/spec/lib/arpa/repositories/base_spec.rb +1 -9
- data/spec/lib/arpa/repositories/profiles/finder_spec.rb +0 -6
- data/spec/lib/arpa/repositories/profiles/remover_spec.rb +0 -4
- data/spec/lib/arpa/repositories/resources/finder_spec.rb +0 -8
- data/spec/lib/arpa/repositories/resources/remover_spec.rb +0 -4
- data/spec/lib/arpa/repositories/roles/finder_spec.rb +0 -4
- data/spec/lib/arpa/repositories/roles/remover_spec.rb +0 -4
- data/spec/lib/arpa/requests/profiles/create_request_spec.rb +10 -12
- data/spec/lib/arpa/requests/profiles/remove_request_spec.rb +4 -9
- data/spec/lib/arpa/requests/resources/create_request_spec.rb +18 -21
- data/spec/lib/arpa/requests/roles/create_request_spec.rb +7 -9
- data/spec/lib/arpa/requests/roles/remove_request_spec.rb +3 -6
- data/spec/lib/arpa/requests/roles/update_request_spec.rb +7 -9
- data/spec/lib/arpa/services/actions/create/action_creator_spec.rb +5 -14
- data/spec/lib/arpa/services/actions/remove/action_remover_spec.rb +3 -6
- data/spec/lib/arpa/services/base_spec.rb +8 -15
- data/spec/lib/arpa/services/profiles/create/profile_creator_spec.rb +0 -7
- data/spec/lib/arpa/services/profiles/profile_manager_creator_spec.rb +2 -4
- data/spec/lib/arpa/services/profiles/profile_manager_remover_spec.rb +3 -6
- data/spec/lib/arpa/services/profiles/profile_manager_updater_spec.rb +2 -4
- data/spec/lib/arpa/services/profiles/remove/profile_remover_spec.rb +0 -5
- data/spec/lib/arpa/services/profiles/update/profile_updater_spec.rb +0 -7
- data/spec/lib/arpa/services/resources/create/resource_creator_spec.rb +1 -7
- data/spec/lib/arpa/services/resources/remove/resource_remover_spec.rb +2 -6
- data/spec/lib/arpa/services/resources/resource_manager_creator_spec.rb +5 -7
- data/spec/lib/arpa/services/roles/create/role_creator_spec.rb +0 -7
- data/spec/lib/arpa/services/roles/remove/role_remover_spec.rb +1 -8
- data/spec/lib/arpa/services/roles/role_manager_creator_spec.rb +2 -4
- data/spec/lib/arpa/services/roles/role_manager_remover_spec.rb +2 -4
- data/spec/lib/arpa/services/roles/role_manager_updater_spec.rb +2 -4
- data/spec/lib/arpa/services/roles/update/role_updater_spec.rb +0 -7
- data/spec/lib/arpa/services/verifier_spec.rb +3 -6
- data/spec/lib/arpa/validators/action_validator_spec.rb +0 -1
- data/spec/lib/arpa/validators/profile_validator_spec.rb +1 -2
- data/spec/lib/arpa/validators/resource_validator_spec.rb +0 -1
- data/spec/lib/arpa/validators/role_validator_spec.rb +1 -2
- data/spec/spec_helper.rb +4 -6
- data/spec/support/schema.rb +9 -10
- metadata +40 -36
@@ -1,9 +1,8 @@
|
|
1
1
|
module Arpa
|
2
2
|
module Entities
|
3
3
|
class Profile
|
4
|
-
|
5
4
|
attr_reader :id, :name, :description, :role_ids, :roles, :entity_id, :entity_class,
|
6
|
-
|
5
|
+
:created_at, :updated_at, :removed
|
7
6
|
|
8
7
|
def initialize(attrs = {})
|
9
8
|
attrs = attrs.with_indifferent_access
|
@@ -21,11 +20,11 @@ module Arpa
|
|
21
20
|
end
|
22
21
|
|
23
22
|
private
|
23
|
+
|
24
24
|
def default_value_to_nil_or_empty(attr_value, default_value)
|
25
25
|
return attr_value if attr_value.present?
|
26
26
|
default_value
|
27
27
|
end
|
28
|
-
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Arpa
|
2
2
|
module Entities
|
3
3
|
class Resource
|
4
|
-
|
5
4
|
attr_reader :id, :full_name, :name, :created_at, :updated_at, :actions
|
6
5
|
|
7
6
|
def initialize(attrs = {})
|
@@ -24,10 +23,10 @@ module Arpa
|
|
24
23
|
|
25
24
|
def adjust_name(name)
|
26
25
|
parts_of_name = name.split '::'
|
27
|
-
refactored_name =
|
26
|
+
refactored_name = ''
|
28
27
|
|
29
28
|
parts_of_name.each_with_index do |part, index|
|
30
|
-
refactored_name << '/' if index
|
29
|
+
refactored_name << '/' if index.positive?
|
31
30
|
refactored_name << change_to_snake_case(part)
|
32
31
|
end
|
33
32
|
|
@@ -42,17 +41,16 @@ module Arpa
|
|
42
41
|
|
43
42
|
def change_to_snake_case(name)
|
44
43
|
parts_of_name = name.split(/(?=[A-Z])/) # Split at CamelCase
|
45
|
-
refactored_name =
|
44
|
+
refactored_name = ''
|
46
45
|
|
47
46
|
parts_of_name.each_with_index do |part, index|
|
48
47
|
part.downcase!
|
49
|
-
refactored_name << '_' if index
|
48
|
+
refactored_name << '_' if index.positive?
|
50
49
|
refactored_name << part
|
51
50
|
end
|
52
51
|
|
53
52
|
refactored_name
|
54
53
|
end
|
55
|
-
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
data/lib/arpa/entities/role.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module Arpa
|
2
2
|
module Entities
|
3
3
|
class Role
|
4
|
-
|
5
4
|
attr_reader :id, :name, :description, :created_at, :updated_at, :removed,
|
6
|
-
|
5
|
+
:action_ids, :actions, :profiles
|
7
6
|
|
8
7
|
def initialize(attrs = {})
|
9
8
|
attrs = attrs.with_indifferent_access
|
@@ -24,11 +23,11 @@ module Arpa
|
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
26
|
+
|
27
27
|
def default_value_to_nil_or_empty(attr_value, default_value)
|
28
28
|
return attr_value if attr_value.present?
|
29
29
|
default_value
|
30
30
|
end
|
31
|
-
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
@@ -11,11 +11,11 @@ module Arpa
|
|
11
11
|
|
12
12
|
def permission(resource_name, action_name, profile_ids)
|
13
13
|
record = repository_class
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
19
|
mapper_instance.map_to_entity(record) if record
|
20
20
|
end
|
21
21
|
|
@@ -26,7 +26,6 @@ module Arpa
|
|
26
26
|
def repository_class
|
27
27
|
RepositoryAction
|
28
28
|
end
|
29
|
-
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
@@ -2,13 +2,12 @@ module Arpa
|
|
2
2
|
module Repositories
|
3
3
|
module Actions
|
4
4
|
class RepositoryAction < ActiveRecord::Base
|
5
|
-
default_scope {order(name: :asc)}
|
5
|
+
default_scope { order(name: :asc) }
|
6
6
|
|
7
7
|
alias_attribute :resource_id, :repository_resource_id
|
8
8
|
belongs_to :resource, foreign_key: 'repository_resource_id', class_name: 'Arpa::Repositories::Resources::RepositoryResource'
|
9
9
|
|
10
10
|
has_and_belongs_to_many :roles, class_name: 'Arpa::Repositories::Roles::RepositoryRole'
|
11
|
-
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Arpa
|
2
2
|
module Repositories
|
3
3
|
module Base
|
4
|
-
|
5
4
|
def mapper_instance
|
6
5
|
raise NotImplementedError, "This #{self.class} cannot respond :mapper_instance"
|
7
6
|
end
|
@@ -9,7 +8,6 @@ module Arpa
|
|
9
8
|
def repository_class
|
10
9
|
raise NotImplementedError, "This #{self.class} cannot respond :repository_class"
|
11
10
|
end
|
12
|
-
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
@@ -17,9 +17,9 @@ module Arpa
|
|
17
17
|
|
18
18
|
def all_by_entity(entity_id, entity_class)
|
19
19
|
repository_class
|
20
|
-
.where("( (entity_id is null AND entity_class is null) OR (entity_id = '#{entity_id}' AND entity_class = '#{entity_class}') )"
|
20
|
+
.where("( (entity_id is null AND entity_class is null) OR (entity_id = '#{entity_id}' AND entity_class = '#{entity_class}') )")
|
21
21
|
.collect do |record|
|
22
|
-
|
22
|
+
mapper_instance.map_to_entity(record)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -30,7 +30,6 @@ module Arpa
|
|
30
30
|
def repository_class
|
31
31
|
RepositoryProfile
|
32
32
|
end
|
33
|
-
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -2,10 +2,9 @@ module Arpa
|
|
2
2
|
module Repositories
|
3
3
|
module Profiles
|
4
4
|
class RepositoryProfile < ActiveRecord::Base
|
5
|
-
default_scope {where(removed: false).order(name: :asc)}
|
5
|
+
default_scope { where(removed: false).order(name: :asc) }
|
6
6
|
|
7
7
|
has_and_belongs_to_many :roles, class_name: 'Arpa::Repositories::Roles::RepositoryRole'
|
8
|
-
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
@@ -4,9 +4,7 @@ module Arpa
|
|
4
4
|
include Base
|
5
5
|
|
6
6
|
def create(entity)
|
7
|
-
save(entity)
|
8
|
-
record.save!
|
9
|
-
end
|
7
|
+
save(entity, &:save!)
|
10
8
|
end
|
11
9
|
|
12
10
|
def update(entity)
|
@@ -24,10 +22,10 @@ module Arpa
|
|
24
22
|
|
25
23
|
private
|
26
24
|
|
27
|
-
def save(entity
|
28
|
-
record = mapper_instance.map_to_record(
|
25
|
+
def save(entity)
|
26
|
+
record = mapper_instance.map_to_record(entity)
|
29
27
|
begin
|
30
|
-
|
28
|
+
yield(record)
|
31
29
|
rescue ActiveRecord::RecordInvalid => invalid
|
32
30
|
raise Arpa::Exceptions::RecordInvalid.new(message: invalid.message, errors: invalid.record.errors)
|
33
31
|
end
|
@@ -35,10 +33,7 @@ module Arpa
|
|
35
33
|
mapper_instance.map_to_entity(record)
|
36
34
|
end
|
37
35
|
|
38
|
-
def post_update(entity, record)
|
39
|
-
end
|
40
|
-
|
36
|
+
def post_update(entity, record); end
|
41
37
|
end
|
42
38
|
end
|
43
39
|
end
|
44
|
-
|
@@ -2,10 +2,9 @@ module Arpa
|
|
2
2
|
module Repositories
|
3
3
|
module Resources
|
4
4
|
class RepositoryResource < ActiveRecord::Base
|
5
|
-
default_scope {order(name: :asc)}
|
5
|
+
default_scope { order(name: :asc) }
|
6
6
|
|
7
7
|
has_many :actions, dependent: :destroy, class_name: 'Arpa::Repositories::Actions::RepositoryAction'
|
8
|
-
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
@@ -2,11 +2,10 @@ module Arpa
|
|
2
2
|
module Repositories
|
3
3
|
module Roles
|
4
4
|
class RepositoryRole < ActiveRecord::Base
|
5
|
-
default_scope {where(removed: false).order(name: :asc)}
|
5
|
+
default_scope { where(removed: false).order(name: :asc) }
|
6
6
|
|
7
7
|
has_and_belongs_to_many :actions, class_name: 'Arpa::Repositories::Actions::RepositoryAction'
|
8
8
|
has_and_belongs_to_many :profiles, class_name: 'Arpa::Repositories::Profiles::RepositoryProfile'
|
9
|
-
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
@@ -3,7 +3,6 @@ module Arpa
|
|
3
3
|
module Actions
|
4
4
|
module Create
|
5
5
|
class ActionCreator
|
6
|
-
|
7
6
|
def create_many(params)
|
8
7
|
params[:actions_names].collect do |action_name|
|
9
8
|
create(action_params(params, action_name))
|
@@ -23,7 +22,7 @@ module Arpa
|
|
23
22
|
private
|
24
23
|
|
25
24
|
def action_params(params, action_name)
|
26
|
-
{name: action_name, resource_id: params[:resource].id}
|
25
|
+
{ name: action_name, resource_id: params[:resource].id }
|
27
26
|
end
|
28
27
|
|
29
28
|
def action_instance(params)
|
@@ -42,7 +41,6 @@ module Arpa
|
|
42
41
|
def creator_repo
|
43
42
|
@creator_repo ||= Arpa::Repositories::Actions::Creator.new
|
44
43
|
end
|
45
|
-
|
46
44
|
end
|
47
45
|
end
|
48
46
|
end
|
@@ -3,7 +3,6 @@ module Arpa
|
|
3
3
|
module Actions
|
4
4
|
module Remove
|
5
5
|
class ActionRemover
|
6
|
-
|
7
6
|
def remove_nonexistent_actions(params)
|
8
7
|
params[:resource].actions.each do |action|
|
9
8
|
exist = params[:actions_names].include?(action.name)
|
@@ -16,7 +15,6 @@ module Arpa
|
|
16
15
|
def remover_repo
|
17
16
|
@remover_repo ||= Arpa::Repositories::Actions::Remover.new
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
data/lib/arpa/services/base.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
1
|
module Arpa
|
2
2
|
module Services
|
3
3
|
module Base
|
4
|
-
|
5
4
|
def self.included(base)
|
6
5
|
base.extend ClassMethods
|
7
6
|
end
|
8
7
|
|
9
|
-
def manager_action
|
8
|
+
def manager_action(callback)
|
10
9
|
begin_transaction do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
callback[:fail].call e
|
16
|
-
end
|
10
|
+
result = yield
|
11
|
+
callback[:success].call result
|
12
|
+
rescue StandardError => e
|
13
|
+
callback[:fail].call e
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
@@ -26,7 +23,7 @@ module Arpa
|
|
26
23
|
end
|
27
24
|
|
28
25
|
module ClassMethods
|
29
|
-
def repository_transaction
|
26
|
+
def repository_transaction(repository_transaction_class)
|
30
27
|
@repository_transaction = repository_transaction_class
|
31
28
|
end
|
32
29
|
|
@@ -34,7 +31,6 @@ module Arpa
|
|
34
31
|
@repository_transaction ||= 'ActiveRecord::Base'
|
35
32
|
@repository_transaction.constantize
|
36
33
|
end
|
37
|
-
|
38
34
|
end
|
39
35
|
end
|
40
36
|
end
|
@@ -3,7 +3,6 @@ module Arpa
|
|
3
3
|
module Profiles
|
4
4
|
module Create
|
5
5
|
class ProfileCreator
|
6
|
-
|
7
6
|
def create(params)
|
8
7
|
profile = profile_instance(params)
|
9
8
|
validate_profile(profile)
|
@@ -24,7 +23,6 @@ module Arpa
|
|
24
23
|
def creator_repo
|
25
24
|
@creator_repo ||= Arpa::Repositories::Profiles::Creator.new
|
26
25
|
end
|
27
|
-
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|