arpa 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +138 -0
- data/Rakefile +2 -0
- data/arpa.gemspec +33 -0
- data/lib/arpa.rb +91 -0
- data/lib/arpa/additions/resource.rb +29 -0
- data/lib/arpa/assets/stylesheets/ar_accordion.scss +80 -0
- data/lib/arpa/controllers/profiles_controller.rb +106 -0
- data/lib/arpa/controllers/resources_controller.rb +47 -0
- data/lib/arpa/controllers/roles_controller.rb +106 -0
- data/lib/arpa/data_mappers/action_mapper.rb +13 -0
- data/lib/arpa/data_mappers/base.rb +117 -0
- data/lib/arpa/data_mappers/profile_mapper.rb +14 -0
- data/lib/arpa/data_mappers/resource_mapper.rb +11 -0
- data/lib/arpa/data_mappers/role_mapper.rb +14 -0
- data/lib/arpa/entities/action.rb +24 -0
- data/lib/arpa/entities/permissions.rb +35 -0
- data/lib/arpa/entities/profile.rb +22 -0
- data/lib/arpa/entities/resource.rb +58 -0
- data/lib/arpa/entities/role.rb +28 -0
- data/lib/arpa/exceptions/record_invalid.rb +13 -0
- data/lib/arpa/repositories/actions/creator.rb +18 -0
- data/lib/arpa/repositories/actions/finder.rb +23 -0
- data/lib/arpa/repositories/actions/remover.rb +22 -0
- data/lib/arpa/repositories/actions/repository_action.rb +15 -0
- data/lib/arpa/repositories/base.rb +15 -0
- data/lib/arpa/repositories/profiles/creator.rb +18 -0
- data/lib/arpa/repositories/profiles/finder.rb +29 -0
- data/lib/arpa/repositories/profiles/remover.rb +29 -0
- data/lib/arpa/repositories/profiles/repository_profile.rb +12 -0
- data/lib/arpa/repositories/profiles/updater.rb +23 -0
- data/lib/arpa/repositories/registrator.rb +44 -0
- data/lib/arpa/repositories/resources/creator.rb +18 -0
- data/lib/arpa/repositories/resources/finder.rb +45 -0
- data/lib/arpa/repositories/resources/remover.rb +22 -0
- data/lib/arpa/repositories/resources/repository_resource.rb +12 -0
- data/lib/arpa/repositories/roles/creator.rb +18 -0
- data/lib/arpa/repositories/roles/finder.rb +29 -0
- data/lib/arpa/repositories/roles/remover.rb +29 -0
- data/lib/arpa/repositories/roles/repository_role.rb +13 -0
- data/lib/arpa/repositories/roles/updater.rb +23 -0
- data/lib/arpa/services/actions/create/action_creator.rb +50 -0
- data/lib/arpa/services/actions/remove/action_remover.rb +24 -0
- data/lib/arpa/services/base.rb +41 -0
- data/lib/arpa/services/profiles/create/profile_creator.rb +32 -0
- data/lib/arpa/services/profiles/profile_manager_creator.rb +22 -0
- data/lib/arpa/services/profiles/profile_manager_remover.rb +24 -0
- data/lib/arpa/services/profiles/profile_manager_updater.rb +22 -0
- data/lib/arpa/services/profiles/remove/profile_remover.rb +25 -0
- data/lib/arpa/services/profiles/update/profile_updater.rb +32 -0
- data/lib/arpa/services/resources/create/resource_creator.rb +42 -0
- data/lib/arpa/services/resources/remove/resource_remover.rb +31 -0
- data/lib/arpa/services/resources/resource_manager_creator.rb +50 -0
- data/lib/arpa/services/roles/create/role_creator.rb +33 -0
- data/lib/arpa/services/roles/remove/role_remover.rb +25 -0
- data/lib/arpa/services/roles/role_manager_creator.rb +23 -0
- data/lib/arpa/services/roles/role_manager_remover.rb +23 -0
- data/lib/arpa/services/roles/role_manager_updater.rb +22 -0
- data/lib/arpa/services/roles/update/role_updater.rb +32 -0
- data/lib/arpa/services/verifier.rb +24 -0
- data/lib/arpa/validators/action_validator.rb +17 -0
- data/lib/arpa/validators/profile_validator.rb +19 -0
- data/lib/arpa/validators/resource_validator.rb +17 -0
- data/lib/arpa/validators/role_validator.rb +20 -0
- data/lib/arpa/version.rb +3 -0
- data/lib/arpa/views/profiles/_form.html.erb +41 -0
- data/lib/arpa/views/profiles/edit.html.erb +6 -0
- data/lib/arpa/views/profiles/index.html.erb +29 -0
- data/lib/arpa/views/profiles/new.html.erb +5 -0
- data/lib/arpa/views/profiles/show.html.erb +37 -0
- data/lib/arpa/views/resources/index.html.erb +27 -0
- data/lib/arpa/views/resources/show.html.erb +33 -0
- data/lib/arpa/views/roles/_form.html.erb +55 -0
- data/lib/arpa/views/roles/edit.html.erb +6 -0
- data/lib/arpa/views/roles/index.html.erb +29 -0
- data/lib/arpa/views/roles/new.html.erb +5 -0
- data/lib/arpa/views/roles/show.html.erb +37 -0
- data/lib/config/locales/arpa.en.yml +38 -0
- data/lib/generators/ar/install_generator.rb +74 -0
- data/lib/generators/ar/templates/migration.rb +48 -0
- data/spec/factories/repository_actions.rb +19 -0
- data/spec/factories/repository_profiles.rb +11 -0
- data/spec/factories/repository_resources.rb +15 -0
- data/spec/factories/repository_roles.rb +11 -0
- data/spec/lib/ar/additions/resource_spec.rb +34 -0
- data/spec/lib/ar/data_mappers/action_mapper_spec.rb +46 -0
- data/spec/lib/ar/data_mappers/base_spec.rb +47 -0
- data/spec/lib/ar/data_mappers/profile_mapper_spec.rb +43 -0
- data/spec/lib/ar/data_mappers/resource_mapper_spec.rb +38 -0
- data/spec/lib/ar/data_mappers/role_mapper_spec.rb +47 -0
- data/spec/lib/ar/entities/action_spec.rb +19 -0
- data/spec/lib/ar/entities/permissions_spec.rb +61 -0
- data/spec/lib/ar/entities/resource_spec.rb +35 -0
- data/spec/lib/ar/repositories/actions/finder_spec.rb +40 -0
- data/spec/lib/ar/repositories/base_spec.rb +37 -0
- data/spec/lib/ar/repositories/profiles/finder_spec.rb +43 -0
- data/spec/lib/ar/repositories/profiles/remover_spec.rb +31 -0
- data/spec/lib/ar/repositories/resources/finder_spec.rb +92 -0
- data/spec/lib/ar/repositories/resources/remover_spec.rb +38 -0
- data/spec/lib/ar/repositories/roles/finder_spec.rb +43 -0
- data/spec/lib/ar/repositories/roles/remover_spec.rb +31 -0
- data/spec/lib/ar/requests/profiles/create_request_spec.rb +51 -0
- data/spec/lib/ar/requests/profiles/remove_request_spec.rb +36 -0
- data/spec/lib/ar/requests/resources/create_request_spec.rb +107 -0
- data/spec/lib/ar/requests/roles/create_request_spec.rb +40 -0
- data/spec/lib/ar/requests/roles/remove_request_spec.rb +23 -0
- data/spec/lib/ar/requests/roles/update_request_spec.rb +50 -0
- data/spec/lib/ar/services/actions/create/action_creator_spec.rb +88 -0
- data/spec/lib/ar/services/actions/remove/action_remover_spec.rb +36 -0
- data/spec/lib/ar/services/base_spec.rb +94 -0
- data/spec/lib/ar/services/profiles/create/profile_creator_spec.rb +68 -0
- data/spec/lib/ar/services/profiles/profile_manager_creator_spec.rb +31 -0
- data/spec/lib/ar/services/profiles/profile_manager_remover_spec.rb +44 -0
- data/spec/lib/ar/services/profiles/profile_manager_updater_spec.rb +31 -0
- data/spec/lib/ar/services/profiles/remove/profile_remover_spec.rb +45 -0
- data/spec/lib/ar/services/profiles/update/profile_updater_spec.rb +68 -0
- data/spec/lib/ar/services/resources/create/resource_creator_spec.rb +87 -0
- data/spec/lib/ar/services/resources/remove/resource_remover_spec.rb +50 -0
- data/spec/lib/ar/services/resources/resource_manager_creator_spec.rb +71 -0
- data/spec/lib/ar/services/roles/create/role_creator_spec.rb +68 -0
- data/spec/lib/ar/services/roles/remove/role_remover_spec.rb +50 -0
- data/spec/lib/ar/services/roles/role_manager_creator_spec.rb +31 -0
- data/spec/lib/ar/services/roles/role_manager_remover_spec.rb +32 -0
- data/spec/lib/ar/services/roles/role_manager_updater_spec.rb +31 -0
- data/spec/lib/ar/services/roles/update/role_updater_spec.rb +68 -0
- data/spec/lib/ar/services/verifier_spec.rb +44 -0
- data/spec/lib/ar/validators/action_validator_spec.rb +15 -0
- data/spec/lib/ar/validators/profile_validator_spec.rb +16 -0
- data/spec/lib/ar/validators/resource_validator_spec.rb +15 -0
- data/spec/lib/ar/validators/role_validator_spec.rb +16 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/repositories/test_repository.rb +2 -0
- data/spec/support/schema.rb +58 -0
- metadata +380 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b1918d1807d5e006ce34bcb7eae4c495a605930
|
4
|
+
data.tar.gz: 0e9320f97b278352163636d3b562aec0f81b1b3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93f5bd0a9df3c2c088c95dd337cf5c106d240149a138ab0373d44752f46988847286dff718a1f12b15c9093f39524ec7e9f325d268a9040fb46101e5320d13d9
|
7
|
+
data.tar.gz: c213426b20ee6c4b164a6be60a06f6af6656642c8363ccd6b3a07e3400781a4f86c0653ff9558ed9295f7c0e9970900c16aacb86bf945d13eab6a61abcfa58c4
|
data/.gitignore
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
*.sqlite3
|
10
|
+
/tmp/
|
11
|
+
*.bundle
|
12
|
+
*.so
|
13
|
+
*.o
|
14
|
+
*.a
|
15
|
+
mkmf.log
|
16
|
+
|
17
|
+
# scm revert files
|
18
|
+
**.orig
|
19
|
+
|
20
|
+
# Mac finder artifacts
|
21
|
+
.DS_Store
|
22
|
+
|
23
|
+
# RubyMine project files
|
24
|
+
.idea
|
25
|
+
|
26
|
+
# vim artifacts
|
27
|
+
**.swp
|
28
|
+
|
29
|
+
# Environment files that may contain sensitive data
|
30
|
+
.env
|
31
|
+
.powenv
|
32
|
+
|
33
|
+
# Ignoring .keep files
|
34
|
+
.keep
|
35
|
+
|
36
|
+
# Elastic Beanstalk Files
|
37
|
+
.elasticbeanstalk/*
|
38
|
+
!.elasticbeanstalk/*.cfg.yml
|
39
|
+
!.elasticbeanstalk/*.global.yml
|
40
|
+
|
41
|
+
Procfile
|
42
|
+
.vagrant
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
arpa
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Rachid Calazans
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
#Arpa
|
2
|
+
|
3
|
+
Authorization Gem for Ruby and Ruby on Rails projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'arpa'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install arpa
|
20
|
+
|
21
|
+
After you install Ar and add it to your Gemfile, you need to run the generator:
|
22
|
+
|
23
|
+
$ rails generate arpa:install
|
24
|
+
|
25
|
+
This command will create some files that are needed to run the Gem.
|
26
|
+
|
27
|
+
| File | Purpose |
|
28
|
+
|----------|:-------------:|
|
29
|
+
| db/migrate/20140120201010_create_arpa_tables.rb | Migration to create the all **Ar** tables in your database (your name will include a different timestamp) |
|
30
|
+
| config/locales/arpa.en.yml | Locales to use in Ar classes |
|
31
|
+
| app/assets/stylesheets/arpa/arpa_accordion.scss | Basic stylesheet to use with Ar views |
|
32
|
+
| app/controllers/arpa/resources_controller.rb app/controllers/arpa/roles_controller.rb app/controllers/arpa/profiles_controller.rb | Controllers to use the CRUD actions for each one |
|
33
|
+
| app/views/arpa/resources/ app/controllers/arpa/roles/ app/controllers/arpa/profiles/ | All views to use the CRUD actions for each controller above |
|
34
|
+
| config/routes.rb | Will add all routes into this file with all resources of Ar |
|
35
|
+
|
36
|
+
After generate, you need to run the migration to create all Ar tables:
|
37
|
+
|
38
|
+
$ rake db:migrate
|
39
|
+
|
40
|
+
**Obs.:** The migration file will create a associate table between **Profiles** and **Users** (the Users must exist in your Application before adding the Gem)
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
First of all you must create the Resources, Roles and Profiles (each is avaliable in the paths listed above). After that you need associate **Profiles** with **User** (to do this, you need create by your own the associate form view, saving some profiles in some user). Done that you can use some Helpers generated by Ar.
|
45
|
+
|
46
|
+
### Association between Profiles and Users
|
47
|
+
|
48
|
+
You just need have a method called **:profile_ids** inside the User model. This method should return a list of ids from profiles associated in the user.
|
49
|
+
|
50
|
+
You just add a HBTM association in User model:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
class User < ActiveRecord::Base
|
54
|
+
has_and_belongs_to_many :profiles, class_name: 'Ar::Repositories::Profiles::RepositoryProfile'
|
55
|
+
end
|
56
|
+
```
|
57
|
+
With this you will be able to use the :profile_ids method.
|
58
|
+
|
59
|
+
### Controller helpers
|
60
|
+
|
61
|
+
Ar will create some helpers to use inside your controllers and views.
|
62
|
+
|
63
|
+
To verify if a user has access to some :controler and :action, use the following helper:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
has_access?('users', 'index')
|
67
|
+
```
|
68
|
+
**Obs.:** To that helper method works. You must have **:session** (In Rails app already has) and **:current_user** attribute or method.
|
69
|
+
|
70
|
+
---
|
71
|
+
If you want use that method inside another object you should use the **Ar::Services::Verifier** class;
|
72
|
+
|
73
|
+
You just need pass as arguments the :session and :current_user:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
verifier = Ar::Services::Verifier.new(session, current_user)
|
77
|
+
verifier.has_access?('users', 'index')
|
78
|
+
```
|
79
|
+
|
80
|
+
### Controller Filter
|
81
|
+
|
82
|
+
If you want create a filter to verify if the current_user has access and if not redirect to another route you can do this:
|
83
|
+
|
84
|
+
Create a method in ApplicationController and add as a before_filter callback from rails:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class ApplicationController < ActionController::Base
|
88
|
+
before_filter :authorize_user
|
89
|
+
|
90
|
+
def authorize_user
|
91
|
+
controller = params[:controller]
|
92
|
+
action = params[:action]
|
93
|
+
redirect_to some_url unless has_access?(controller, action
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
**Obs.:** The **has_access?** method come from Controller Helper method which Ar gem has been created.
|
100
|
+
|
101
|
+
|
102
|
+
## Information
|
103
|
+
|
104
|
+
After generate, you will be able to access some paths for each Controller created:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
generate_resources_and_actions_resources GET /resources/generate_resources_and_actions(.:format) arpa/resources#generate_resources_and_actions
|
108
|
+
resources GET /resources(.:format) arpa/resources#index
|
109
|
+
POST /resources(.:format) arpa/resources#create
|
110
|
+
new_resource GET /resources/new(.:format) arpa/resources#new
|
111
|
+
edit_resource GET /resources/:id/edit(.:format) arpa/resources#edit
|
112
|
+
resource GET /resources/:id(.:format) arpa/resources#show
|
113
|
+
PATCH /resources/:id(.:format) arpa/resources#update
|
114
|
+
PUT /resources/:id(.:format) arpa/resources#update
|
115
|
+
DELETE /resources/:id(.:format) arpa/resources#destroy
|
116
|
+
DELETE /roles/:id(.:format) arpa/roles#remove
|
117
|
+
roles GET /roles(.:format) arpa/roles#index
|
118
|
+
POST /roles(.:format) arpa/roles#create
|
119
|
+
new_role GET /roles/new(.:format) arpa/roles#new
|
120
|
+
edit_role GET /roles/:id/edit(.:format) arpa/roles#edit
|
121
|
+
role GET /roles/:id(.:format) arpa/roles#show
|
122
|
+
PATCH /roles/:id(.:format) arpa/roles#update
|
123
|
+
PUT /roles/:id(.:format) arpa/roles#update
|
124
|
+
DELETE /roles/:id(.:format) arpa/roles#destroy
|
125
|
+
DELETE /profiles/:id(.:format) arpa/profiles#remove
|
126
|
+
profiles GET /profiles(.:format) arpa/profiles#index
|
127
|
+
POST /profiles(.:format) arpa/profiles#create
|
128
|
+
new_profile GET /profiles/new(.:format) arpa/profiles#new
|
129
|
+
edit_profile GET /profiles/:id/edit(.:format) arpa/profiles#edit
|
130
|
+
profile GET /profiles/:id(.:format) arpa/profiles#show
|
131
|
+
PATCH /profiles/:id(.:format) arpa/profiles#update
|
132
|
+
PUT /profiles/:id(.:format) arpa/profiles#update
|
133
|
+
DELETE /profiles/:id(.:format) arpa/profiles#destroy
|
134
|
+
```
|
135
|
+
|
136
|
+
## License
|
137
|
+
|
138
|
+
MIT License. Copyright Rachid Calazans.
|
data/Rakefile
ADDED
data/arpa.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arpa/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "arpa"
|
8
|
+
spec.version = Arpa::VERSION
|
9
|
+
spec.authors = ["Rachid Calazans"]
|
10
|
+
spec.summary = "Authorization Gem for Ruby and Ruby on Rails projects"
|
11
|
+
spec.email = ["rachidcalazans@gmail.com"]
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.homepage = "https://github.com/rachidcalazans/arpa"
|
14
|
+
spec.description = "Authorization Gem for Ruby and Ruby on Rails projects"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.3.0"
|
24
|
+
spec.add_development_dependency "factory_girl"
|
25
|
+
spec.add_development_dependency "sqlite3", "~> 1.3.3"
|
26
|
+
spec.add_development_dependency "database_cleaner"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
|
29
|
+
spec.add_dependency "activerecord", ">= 4.2.0"
|
30
|
+
spec.add_dependency "railties", ">= 4.2.0", "< 5"
|
31
|
+
spec.add_dependency "responders", "~> 2.0"
|
32
|
+
|
33
|
+
end
|
data/lib/arpa.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "arpa/version"
|
2
|
+
require "rails/railtie"
|
3
|
+
|
4
|
+
# Additions
|
5
|
+
require "arpa/additions/resource"
|
6
|
+
|
7
|
+
# Exceptions
|
8
|
+
require "arpa/exceptions/record_invalid"
|
9
|
+
|
10
|
+
# Entities
|
11
|
+
require "arpa/entities/resource"
|
12
|
+
require "arpa/entities/action"
|
13
|
+
require "arpa/entities/role"
|
14
|
+
require "arpa/entities/profile"
|
15
|
+
require "arpa/entities/permissions"
|
16
|
+
|
17
|
+
# Mappers
|
18
|
+
require "arpa/data_mappers/base"
|
19
|
+
require "arpa/data_mappers/resource_mapper"
|
20
|
+
require "arpa/data_mappers/action_mapper"
|
21
|
+
require "arpa/data_mappers/role_mapper"
|
22
|
+
require "arpa/data_mappers/profile_mapper"
|
23
|
+
|
24
|
+
# Validators
|
25
|
+
require "arpa/validators/resource_validator"
|
26
|
+
require "arpa/validators/action_validator"
|
27
|
+
require "arpa/validators/role_validator"
|
28
|
+
require "arpa/validators/profile_validator"
|
29
|
+
|
30
|
+
# Repositories
|
31
|
+
require "arpa/repositories/base"
|
32
|
+
require "arpa/repositories/registrator"
|
33
|
+
|
34
|
+
require "arpa/repositories/resources/repository_resource"
|
35
|
+
require "arpa/repositories/resources/finder"
|
36
|
+
require "arpa/repositories/resources/remover"
|
37
|
+
require "arpa/repositories/resources/creator"
|
38
|
+
|
39
|
+
require "arpa/repositories/actions/repository_action"
|
40
|
+
require "arpa/repositories/actions/finder"
|
41
|
+
require "arpa/repositories/actions/remover"
|
42
|
+
require "arpa/repositories/actions/creator"
|
43
|
+
|
44
|
+
require "arpa/repositories/roles/repository_role"
|
45
|
+
require "arpa/repositories/roles/finder"
|
46
|
+
require "arpa/repositories/roles/creator"
|
47
|
+
require "arpa/repositories/roles/updater"
|
48
|
+
require "arpa/repositories/roles/remover"
|
49
|
+
|
50
|
+
require "arpa/repositories/profiles/repository_profile"
|
51
|
+
require "arpa/repositories/profiles/finder"
|
52
|
+
require "arpa/repositories/profiles/creator"
|
53
|
+
require "arpa/repositories/profiles/updater"
|
54
|
+
require "arpa/repositories/profiles/remover"
|
55
|
+
|
56
|
+
# Services
|
57
|
+
require "arpa/services/base"
|
58
|
+
require "arpa/services/verifier"
|
59
|
+
|
60
|
+
require "arpa/services/actions/create/action_creator"
|
61
|
+
require "arpa/services/actions/remove/action_remover"
|
62
|
+
|
63
|
+
require "arpa/services/resources/create/resource_creator"
|
64
|
+
require "arpa/services/resources/remove/resource_remover"
|
65
|
+
require "arpa/services/resources/resource_manager_creator"
|
66
|
+
|
67
|
+
require "arpa/services/roles/role_manager_creator"
|
68
|
+
require "arpa/services/roles/role_manager_updater"
|
69
|
+
require "arpa/services/roles/role_manager_remover"
|
70
|
+
require "arpa/services/roles/create/role_creator"
|
71
|
+
require "arpa/services/roles/update/role_updater"
|
72
|
+
require "arpa/services/roles/remove/role_remover"
|
73
|
+
|
74
|
+
require "arpa/services/profiles/profile_manager_creator"
|
75
|
+
require "arpa/services/profiles/profile_manager_updater"
|
76
|
+
require "arpa/services/profiles/profile_manager_remover"
|
77
|
+
require "arpa/services/profiles/create/profile_creator"
|
78
|
+
require "arpa/services/profiles/update/profile_updater"
|
79
|
+
require "arpa/services/profiles/remove/profile_remover"
|
80
|
+
|
81
|
+
module Arpa
|
82
|
+
|
83
|
+
class Railtie < ::Rails::Railtie
|
84
|
+
initializer "arpa.configure_view_controller" do |app|
|
85
|
+
ActiveSupport.on_load :action_controller do
|
86
|
+
include Ar::Additions::Resource
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Arpa
|
2
|
+
module Additions
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.helper_method :has_access?
|
7
|
+
end
|
8
|
+
|
9
|
+
def has_access?(resource, action)
|
10
|
+
return unless has_session_or_current_user?
|
11
|
+
@verifier ||= Arpa::Services::Verifier.new(session, current_user)
|
12
|
+
@verifier.has_access?(resource, action)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def has_session_or_current_user?
|
18
|
+
sess = try(:session)
|
19
|
+
c_user = try(:current_user)
|
20
|
+
return true if sess && c_user
|
21
|
+
log = Logger.new(STDOUT)
|
22
|
+
log.warn("The ApplicationController must has a attribute or method 'session'") unless sess
|
23
|
+
log.warn("The ApplicationController must has a attribute or method 'current_user'") unless c_user
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
// ArpaAccordion
|
2
|
+
.arpa-accordion {
|
3
|
+
margin: 10px auto 30px auto;
|
4
|
+
text-align: left;
|
5
|
+
|
6
|
+
.arpa-accordion-title {
|
7
|
+
position: relative;
|
8
|
+
z-index: 20;
|
9
|
+
display: block;
|
10
|
+
padding: 10px 12px;
|
11
|
+
cursor: pointer;
|
12
|
+
color: #555;
|
13
|
+
font-size: 18px;
|
14
|
+
font-weight: bold;
|
15
|
+
background: #fff;
|
16
|
+
border: 1px solid #cfcfcf;
|
17
|
+
|
18
|
+
&:hover{
|
19
|
+
background: #fff;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
.arpa-accordion-input {
|
24
|
+
display: none;
|
25
|
+
|
26
|
+
&:checked + .arpa-accordion-item {
|
27
|
+
box-shadow: 3px 3px 3px red;
|
28
|
+
}
|
29
|
+
|
30
|
+
&:checked + .arpa-accordion-title,
|
31
|
+
&:checked + .arpa-accordion-title:hover {
|
32
|
+
margin-bottom: 0;
|
33
|
+
border-bottom: none;
|
34
|
+
}
|
35
|
+
|
36
|
+
&:checked + .arpa-accordion-title {
|
37
|
+
border-color: #bbb;
|
38
|
+
|
39
|
+
&:after {
|
40
|
+
background: none;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
&:checked ~ .arpa-accordion-content {
|
45
|
+
padding: 10px 20px 0;
|
46
|
+
margin-bottom: 10px;
|
47
|
+
max-height: 9999999px;
|
48
|
+
border: 1px solid #bbb;
|
49
|
+
opacity: 1;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
.arpa-accordion-title {
|
54
|
+
&:after {
|
55
|
+
content: '';
|
56
|
+
position: absolute;
|
57
|
+
width: 24px;
|
58
|
+
height: 24px;
|
59
|
+
right: 13px;
|
60
|
+
top: 7px;
|
61
|
+
// background: url(image-path("arpa-accordion-arrow.png")) -6px -6px;
|
62
|
+
}
|
63
|
+
|
64
|
+
&:hover {
|
65
|
+
&:after {
|
66
|
+
background-position: -6px -42px;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
.arpa-accordion-content {
|
72
|
+
z-index: 10;
|
73
|
+
position: relative;
|
74
|
+
padding: 0 20px;
|
75
|
+
max-height: 0px;
|
76
|
+
background: #fafafa;
|
77
|
+
overflow: hidden;
|
78
|
+
opacity: 0;
|
79
|
+
}
|
80
|
+
}
|