arpa 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/arpa.gemspec +0 -1
  3. data/lib/arpa/services/verifier.rb +1 -1
  4. data/lib/arpa/version.rb +1 -1
  5. data/lib/generators/arpa/controllers_generator.rb +59 -0
  6. data/lib/generators/arpa/install_generator.rb +20 -48
  7. data/lib/{arpa → generators/arpa/templates}/assets/stylesheets/arpa_accordion.scss +0 -0
  8. data/lib/{arpa → generators/arpa/templates}/controllers/profiles_controller.rb +0 -2
  9. data/lib/{arpa → generators/arpa/templates}/controllers/resources_controller.rb +0 -2
  10. data/lib/{arpa → generators/arpa/templates}/controllers/roles_controller.rb +0 -2
  11. data/lib/generators/arpa/templates/migration.rb +4 -2
  12. data/lib/{arpa → generators/arpa/templates}/views/profiles/_form.html.erb +0 -0
  13. data/lib/{arpa → generators/arpa/templates}/views/profiles/edit.html.erb +0 -0
  14. data/lib/{arpa → generators/arpa/templates}/views/profiles/index.html.erb +0 -0
  15. data/lib/{arpa → generators/arpa/templates}/views/profiles/new.html.erb +0 -0
  16. data/lib/{arpa → generators/arpa/templates}/views/profiles/show.html.erb +0 -0
  17. data/lib/{arpa → generators/arpa/templates}/views/resources/index.html.erb +0 -0
  18. data/lib/{arpa → generators/arpa/templates}/views/resources/show.html.erb +0 -0
  19. data/lib/{arpa → generators/arpa/templates}/views/roles/_form.html.erb +0 -0
  20. data/lib/{arpa → generators/arpa/templates}/views/roles/edit.html.erb +0 -0
  21. data/lib/{arpa → generators/arpa/templates}/views/roles/index.html.erb +0 -0
  22. data/lib/{arpa → generators/arpa/templates}/views/roles/new.html.erb +0 -0
  23. data/lib/{arpa → generators/arpa/templates}/views/roles/show.html.erb +0 -0
  24. data/spec/lib/ar/services/verifier_spec.rb +10 -1
  25. metadata +19 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e222788d3061cf1fb09f3285f2781c7e6e595ea7
4
- data.tar.gz: 9260e3311202810408e671555bc4e25d8bc9765e
3
+ metadata.gz: 931f0491ce2453cff1606cdc0f2cd5991a7921c6
4
+ data.tar.gz: 6ed81530f8cc41943e1b9683c4676e60db6d697e
5
5
  SHA512:
6
- metadata.gz: e0dc1b3734844fb94c895ece8ed933b2aea924093c441de369dd0aa17d44993619d7beaccf76ff16ca21e52a367ce5829bf250f5603869901ba458695871a14e
7
- data.tar.gz: 7c7a9cc23e14c15f9402a67e7d80c9f2209b1cf9c097c3b5a5fc09a748b017705a9e1723d711296df030b312b0625cffcebfd70c3631f3c55825d763f658dcef
6
+ metadata.gz: 3a7cf1f28d58a0406abe0ff35ae3ab121bc8e209b5f807f287f2ca3e5309bbb5fc446a4799be6f034a7e6a80d61939c99b224ead2784a3d8dd26dbe5a7314068
7
+ data.tar.gz: f0481f9001e29f74fa20db57c016270de9b4538a430691d67bfe727adda6190458d7216f691a169f78d2d84f8fd4b6ee14c8b9073fdea9e7234e12157bd7a822
@@ -28,6 +28,5 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_dependency "activerecord", ">= 4.2.0"
30
30
  spec.add_dependency "railties", ">= 4.2.0", "< 5"
31
- spec.add_dependency "responders", "~> 2.0"
32
31
 
33
32
  end
@@ -9,7 +9,7 @@ module Arpa
9
9
 
10
10
  def has_access?(resource, action)
11
11
  free_access_action = action.to_s.split('_')[0]
12
- return true if free_access_action.empty?
12
+ return true if @current_user.is_arpa_admin? || free_access_action.empty?
13
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
@@ -1,3 +1,3 @@
1
1
  module Arpa
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,59 @@
1
+ module Arpa
2
+ module Generators
3
+ class ControllersGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ def copy_resources_views_files
7
+ copy_file 'views/resources/index.html.erb', 'app/views/arpa/resources/index.html.erb'
8
+ copy_file 'views/resources/show.html.erb', 'app/views/arpa/resources/show.html.erb'
9
+
10
+ copy_file 'views/roles/index.html.erb', 'app/views/arpa/roles/index.html.erb'
11
+ copy_file 'views/roles/show.html.erb', 'app/views/arpa/roles/show.html.erb'
12
+ copy_file 'views/roles/new.html.erb', 'app/views/arpa/roles/new.html.erb'
13
+ copy_file 'views/roles/edit.html.erb', 'app/views/arpa/roles/edit.html.erb'
14
+ copy_file 'views/roles/_form.html.erb', 'app/views/arpa/roles/_form.html.erb'
15
+
16
+ copy_file 'views/profiles/index.html.erb', 'app/views/arpa/profiles/index.html.erb'
17
+ copy_file 'views/profiles/show.html.erb', 'app/views/arpa/profiles/show.html.erb'
18
+ copy_file 'views/profiles/new.html.erb', 'app/views/arpa/profiles/new.html.erb'
19
+ copy_file 'views/profiles/edit.html.erb', 'app/views/arpa/profiles/edit.html.erb'
20
+ copy_file 'views/profiles/_form.html.erb', 'app/views/arpa/profiles/_form.html.erb'
21
+ end
22
+
23
+ def copy_stylesheet_files
24
+ copy_file 'assets/stylesheets/arpa_accordion.scss', 'app/assets/stylesheets/arpa/arpa_accordion.scss'
25
+ end
26
+
27
+ def add_controllers
28
+ copy_file 'controllers/resources_controller.rb', 'app/controllers/arpa/resources_controller.rb'
29
+ copy_file 'controllers/roles_controller.rb', 'app/controllers/arpa/roles_controller.rb'
30
+ copy_file 'controllers/profiles_controller.rb', 'app/controllers/arpa/profiles_controller.rb'
31
+ end
32
+
33
+ def add_routes
34
+ route <<-RUBY
35
+ scope module: :arpa do
36
+ resources :resources do
37
+ collection do
38
+ get 'generate_resources_and_actions'
39
+ end
40
+ end
41
+
42
+ resources :roles do
43
+ collection do
44
+ delete ':id', to: 'roles#remove'
45
+ end
46
+ end
47
+
48
+ resources :profiles do
49
+ collection do
50
+ delete ':id', to: 'profiles#remove'
51
+ end
52
+ end
53
+ end
54
+ RUBY
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -5,64 +5,36 @@ module Arpa
5
5
 
6
6
  source_root File.expand_path("..", __FILE__)
7
7
 
8
- def self.next_migration_number(dirname)
9
- return Time.new.utc.strftime("%Y%m%d%H%M%S") if ActiveRecord::Base.timestamped_migrations
10
- "%.3d" % (current_migration_number(dirname) + 1)
11
- end
8
+ desc <<-DESC.strip_heredoc
9
+ The Name of table to create the associate table.
12
10
 
13
- def create_migrate_files
14
- migration_template 'templates/migration.rb', 'db/migrate/create_arpa_tables.rb'
15
- end
11
+ E.g. users, admins.
16
12
 
17
- def copy_resources_views_files
18
- copy_file '../../arpa/views/resources/index.html.erb', 'app/views/arpa/resources/index.html.erb'
19
- copy_file '../../arpa/views/resources/show.html.erb', 'app/views/arpa/resources/show.html.erb'
13
+ By default is 'users'
14
+ DESC
20
15
 
21
- copy_file '../../arpa/views/roles/index.html.erb', 'app/views/arpa/roles/index.html.erb'
22
- copy_file '../../arpa/views/roles/show.html.erb', 'app/views/arpa/roles/show.html.erb'
23
- copy_file '../../arpa/views/roles/new.html.erb', 'app/views/arpa/roles/new.html.erb'
24
- copy_file '../../arpa/views/roles/edit.html.erb', 'app/views/arpa/roles/edit.html.erb'
25
- copy_file '../../arpa/views/roles/_form.html.erb', 'app/views/arpa/roles/_form.html.erb'
16
+ argument :associate_table, required: false
26
17
 
27
- copy_file '../../arpa/views/profiles/index.html.erb', 'app/views/arpa/profiles/index.html.erb'
28
- copy_file '../../arpa/views/profiles/show.html.erb', 'app/views/arpa/profiles/show.html.erb'
29
- copy_file '../../arpa/views/profiles/new.html.erb', 'app/views/arpa/profiles/new.html.erb'
30
- copy_file '../../arpa/views/profiles/edit.html.erb', 'app/views/arpa/profiles/edit.html.erb'
31
- copy_file '../../arpa/views/profiles/_form.html.erb', 'app/views/arpa/profiles/_form.html.erb'
32
- end
18
+ desc <<-DESC.strip_heredoc
19
+ The Primary key to create the associate table.
33
20
 
34
- def copy_stylesheet_files
35
- copy_file '../../arpa/assets/stylesheets/arpa_accordion.scss', 'app/assets/stylesheets/arpa/arpa_accordion.scss'
36
- end
21
+ E.g. user_id, admin_id.
37
22
 
38
- def add_controllers
39
- copy_file '../../arpa/controllers/resources_controller.rb', 'app/controllers/arpa/resources_controller.rb'
40
- copy_file '../../arpa/controllers/roles_controller.rb', 'app/controllers/arpa/roles_controller.rb'
41
- copy_file '../../arpa/controllers/profiles_controller.rb', 'app/controllers/arpa/profiles_controller.rb'
42
- end
23
+ By default is 'user_id'
24
+ DESC
25
+ argument :associate_primary_key, required: false
43
26
 
44
- def add_routes
45
- route <<-RUBY
46
- scope module: :arpa do
47
- resources :resources do
48
- collection do
49
- get 'generate_resources_and_actions'
27
+ def self.next_migration_number(dirname)
28
+ return Time.new.utc.strftime("%Y%m%d%H%M%S") if ActiveRecord::Base.timestamped_migrations
29
+ "%.3d" % (current_migration_number(dirname) + 1)
50
30
  end
51
- end
52
31
 
53
- resources :roles do
54
- collection do
55
- delete ':id', to: 'roles#remove'
56
- end
57
- end
32
+ desc "Create a migrate file with all necessery tables including the associate table."
58
33
 
59
- resources :profiles do
60
- collection do
61
- delete ':id', to: 'profiles#remove'
62
- end
63
- end
64
- end
65
- RUBY
34
+ def create_migrate_files
35
+ @associate_table ||= 'users'
36
+ @associate_primary_key ||= "#{@associate_table.singularize}_id"
37
+ migration_template 'templates/migration.rb', 'db/migrate/create_arpa_tables.rb'
66
38
  end
67
39
 
68
40
  def copy_locales
@@ -5,12 +5,10 @@ module Arpa
5
5
  # GET /profiles
6
6
  def index
7
7
  @profiles = profile_finder.all
8
- respond_with(@profiles)
9
8
  end
10
9
 
11
10
  # GET /profiles/1
12
11
  def show
13
- respond_with(@profile)
14
12
  end
15
13
 
16
14
  # GET /profiles/new
@@ -5,12 +5,10 @@ module Arpa
5
5
  # GET /resources
6
6
  def index
7
7
  @resources = resource_finder.all
8
- respond_with(@resources)
9
8
  end
10
9
 
11
10
  # GET /resources/1
12
11
  def show
13
- respond_with(@resource)
14
12
  end
15
13
 
16
14
  # GET /generate_resources_and_actions
@@ -5,12 +5,10 @@ module Arpa
5
5
  # GET /roles
6
6
  def index
7
7
  @roles = role_finder.all
8
- respond_with(@roles)
9
8
  end
10
9
 
11
10
  # GET /roles/1
12
11
  def show
13
- respond_with(@role)
14
12
  end
15
13
 
16
14
  # GET /roles/new
@@ -39,10 +39,12 @@ class CreateArpaTables < ActiveRecord::Migration
39
39
  t.index :repository_profile_id, name: 'profile_role_ids'
40
40
  end
41
41
 
42
- create_join_table :repository_profiles, :users, :force => true do |t|
42
+ create_join_table :repository_profiles, <%= ":#{@associate_table}" %>, :force => true do |t|
43
43
  t.index :repository_profile_id, name: 'profile_user_id'
44
- t.index :user_id, name: 'user_profile_id'
44
+ t.index <%= ":#{@associate_primary_key}" %>, name: 'user_profile_id'
45
45
  end
46
46
 
47
+ add_column <%= ":#{@associate_table}" %>, :is_arpa_admin, :boolean, default: false
48
+
47
49
  end
48
50
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Arpa::Services::Verifier do
4
4
  let(:session) { {} }
5
- let(:current_user) { double profile_ids: [1,2,3] }
5
+ let(:current_user) { double is_arpa_admin?: false, profile_ids: [1,2,3] }
6
6
 
7
7
  subject(:verifier) { Arpa::Services::Verifier.new(session, current_user) }
8
8
 
@@ -17,6 +17,15 @@ describe Arpa::Services::Verifier do
17
17
  end
18
18
 
19
19
  describe '#has_access?' do
20
+
21
+ context 'when current_user is a arpa admin' do
22
+ let(:current_user) { double is_arpa_admin?: true, profile_ids: [1,2,3] }
23
+
24
+ it 'should has access' do
25
+ expect(subject.has_access?('home', 'some_action')).to be_truthy
26
+ end
27
+ end
28
+
20
29
  context 'when pass a free action which begin with "_"' do
21
30
  it 'should has access' do
22
31
  expect(subject.has_access?('home', '_some_action')).to be_truthy
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.6
4
+ version: 0.0.7
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-27 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,20 +142,6 @@ dependencies:
142
142
  - - "<"
143
143
  - !ruby/object:Gem::Version
144
144
  version: '5'
145
- - !ruby/object:Gem::Dependency
146
- name: responders
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: '2.0'
152
- type: :runtime
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - "~>"
157
- - !ruby/object:Gem::Version
158
- version: '2.0'
159
145
  description: Authorization Gem for Ruby and Ruby on Rails projects
160
146
  email:
161
147
  - rachidcalazans@gmail.com
@@ -176,10 +162,6 @@ files:
176
162
  - arpa.gemspec
177
163
  - lib/arpa.rb
178
164
  - lib/arpa/additions/resource.rb
179
- - lib/arpa/assets/stylesheets/arpa_accordion.scss
180
- - lib/arpa/controllers/profiles_controller.rb
181
- - lib/arpa/controllers/resources_controller.rb
182
- - lib/arpa/controllers/roles_controller.rb
183
165
  - lib/arpa/data_mappers/action_mapper.rb
184
166
  - lib/arpa/data_mappers/base.rb
185
167
  - lib/arpa/data_mappers/profile_mapper.rb
@@ -235,21 +217,26 @@ files:
235
217
  - lib/arpa/validators/resource_validator.rb
236
218
  - lib/arpa/validators/role_validator.rb
237
219
  - lib/arpa/version.rb
238
- - lib/arpa/views/profiles/_form.html.erb
239
- - lib/arpa/views/profiles/edit.html.erb
240
- - lib/arpa/views/profiles/index.html.erb
241
- - lib/arpa/views/profiles/new.html.erb
242
- - lib/arpa/views/profiles/show.html.erb
243
- - lib/arpa/views/resources/index.html.erb
244
- - lib/arpa/views/resources/show.html.erb
245
- - lib/arpa/views/roles/_form.html.erb
246
- - lib/arpa/views/roles/edit.html.erb
247
- - lib/arpa/views/roles/index.html.erb
248
- - lib/arpa/views/roles/new.html.erb
249
- - lib/arpa/views/roles/show.html.erb
250
220
  - lib/config/locales/arpa.en.yml
221
+ - lib/generators/arpa/controllers_generator.rb
251
222
  - lib/generators/arpa/install_generator.rb
223
+ - lib/generators/arpa/templates/assets/stylesheets/arpa_accordion.scss
224
+ - lib/generators/arpa/templates/controllers/profiles_controller.rb
225
+ - lib/generators/arpa/templates/controllers/resources_controller.rb
226
+ - lib/generators/arpa/templates/controllers/roles_controller.rb
252
227
  - lib/generators/arpa/templates/migration.rb
228
+ - lib/generators/arpa/templates/views/profiles/_form.html.erb
229
+ - lib/generators/arpa/templates/views/profiles/edit.html.erb
230
+ - lib/generators/arpa/templates/views/profiles/index.html.erb
231
+ - lib/generators/arpa/templates/views/profiles/new.html.erb
232
+ - lib/generators/arpa/templates/views/profiles/show.html.erb
233
+ - lib/generators/arpa/templates/views/resources/index.html.erb
234
+ - lib/generators/arpa/templates/views/resources/show.html.erb
235
+ - lib/generators/arpa/templates/views/roles/_form.html.erb
236
+ - lib/generators/arpa/templates/views/roles/edit.html.erb
237
+ - lib/generators/arpa/templates/views/roles/index.html.erb
238
+ - lib/generators/arpa/templates/views/roles/new.html.erb
239
+ - lib/generators/arpa/templates/views/roles/show.html.erb
253
240
  - spec/factories/repository_actions.rb
254
241
  - spec/factories/repository_profiles.rb
255
242
  - spec/factories/repository_resources.rb