curupira 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of curupira might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 629cf0ce02edf0ffc9eac62be232bcbed54f7761
4
- data.tar.gz: 422e25f7a5554fde550ae3cea1708e740f1facf6
3
+ metadata.gz: 2f14fa682e08b79b040066b77987f1e349d6f7fc
4
+ data.tar.gz: 1e079aeade659aa49a9a845685bb729ab32fd547
5
5
  SHA512:
6
- metadata.gz: 2fd99c051f4be4ce32c9063b9dc163acbd29f7db11d383b1269ec076231ae0286dc8388e9bd3add8f90b40eb321b25d996c53f8d302b74907f0871198973cffe
7
- data.tar.gz: a0bc4d7597fdd0af5810ad735a7d8588dffff4f524d6cfba4119b020a1d9dd6f3db11e0066ca3b9f8f554f8393c80dc2b407161d6f4125fb4b61ba7079942128
6
+ metadata.gz: 4d0748f95cd07df56e5c71e7010a6d5c8c0fc3ee87431916e7892ef623b7d2acc49e06871044ab302739a5bdebd86c51eb1131ac4b9bc875be19cc87f1b29b31
7
+ data.tar.gz: d22e13945075d7f2e9cd8c5725140c6f2884e57bc4134bd5c0bd654dbf5506770c68c8cb737a6d2735438ee565f7cdc8c49350684b39a72cbe71612739497597
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- curupira (0.1.1)
4
+ curupira (0.1.2)
5
5
  cocoon
6
6
  jquery-rails
7
7
  rails (~> 4.2.0)
@@ -14,7 +14,7 @@
14
14
 
15
15
  <ul>
16
16
  <% @role.features.each do |feature| %>
17
- <li><%= link_to feature.name, feature %></li>
17
+ <li><%= feature.name %></li>
18
18
  <% end %>
19
19
  </ul>
20
20
  </div>
@@ -35,7 +35,7 @@ module Curupira
35
35
  )
36
36
  .where(
37
37
  features: { controller: params[:controller] },
38
- action_labels: { name: params[:action] },
38
+ action_labels: { name: [params[:action], 'manage'] },
39
39
  id: current_user
40
40
  )
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module Curupira
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require 'rails_helper'
2
+ require "curupira/authorizer"
3
+
4
+ describe Curupira::Authorizer do
5
+ include Curupira::Authorizer
6
+
7
+ describe "#has_authorization?" do
8
+ let!(:current_user) { FactoryGirl.create(:user) }
9
+ let(:params) do
10
+ {
11
+ controller: "users",
12
+ action: "create"
13
+ }
14
+ end
15
+
16
+ before do
17
+ setup_authorization(current_user, "users", "manage")
18
+ end
19
+
20
+ it "have authorization" do
21
+ expect(has_authorization?).to be true
22
+ end
23
+ end
24
+ end
@@ -20,4 +20,24 @@
20
20
  # available at http://guides.rubyonrails.org/i18n.html.
21
21
 
22
22
  en:
23
- hello: "Hello world"
23
+ hello: 'OLA'
24
+ curupira:
25
+ features:
26
+ curupira/users:
27
+ create: "Create Users"
28
+ show: "Show Users"
29
+ edit: "Edit User"
30
+ delete: "Remove User"
31
+ manage: "Manage User"
32
+ curupira/groups:
33
+ create: "Create Groups"
34
+ show: "Show Groups"
35
+ edit: "Edit Group"
36
+ delete: "Remove Group"
37
+ manage: "Manage Groups"
38
+ curupira/roles:
39
+ create: "Create Roles"
40
+ show: "Show Roles"
41
+ edit: "Edit Role"
42
+ delete: "Remove Role"
43
+ manage: "Manage Roles"
@@ -1,137 +1,37 @@
1
- feature = Feature.create name: "Cadastrar usuário", controller: "curupira/users"
2
-
3
- action_1 = ActionLabel.create name: "new"
4
- action_2 = ActionLabel.create name: "create"
5
-
6
- feature.action_labels = [action_1, action_2]
7
-
8
- feature.save
9
-
10
- feature = Feature.create name: "Visualizar usuário", controller: "curupira/users"
11
-
12
- action_1 = ActionLabel.create name: "index"
13
- action_2 = ActionLabel.create name: "show"
14
-
15
- feature.action_labels = [action_1, action_2]
16
-
17
- feature.save
18
-
19
- feature = Feature.create name: "Editar usuário", controller: "curupira/users"
20
-
21
- action_1 = ActionLabel.create name: "edit"
22
- action_2 = ActionLabel.create name: "update"
23
-
24
- feature.action_labels = [action_1, action_2]
25
-
26
- feature = Feature.create name: "Deletar usuário", controller: "curupira/users"
27
-
28
- action_1 = ActionLabel.create name: "destroy"
29
-
30
- feature.action_labels = [action_1]
31
-
32
- feature.save
33
-
34
- ###############################################
35
-
36
- feature = Feature.create name: "Cadastrar Perfis", controller: "curupira/roles"
37
-
38
- action_1 = ActionLabel.create name: "new"
39
- action_2 = ActionLabel.create name: "create"
40
-
41
- feature.action_labels = [action_1, action_2]
42
-
43
- feature.save
44
-
45
- feature = Feature.create name: "Visualizar Perfis", controller: "curupira/roles"
46
-
47
- action_1 = ActionLabel.create name: "index"
48
- action_2 = ActionLabel.create name: "show"
49
-
50
- feature.action_labels = [action_1, action_2]
51
-
52
- feature.save
53
-
54
- feature = Feature.create name: "Editar Perfis", controller: "curupira/roles"
55
-
56
- action_1 = ActionLabel.create name: "edit"
57
- action_2 = ActionLabel.create name: "update"
58
-
59
- feature.action_labels = [action_1, action_2]
60
-
61
- feature = Feature.create name: "Deletar Perfis", controller: "curupira/roles"
62
-
63
- action_1 = ActionLabel.create name: "destroy"
64
-
65
- feature.action_labels = [action_1]
66
-
67
- feature.save
68
-
69
- ###############################################
70
-
71
- feature = Feature.create name: "Cadastrar Grupos", controller: "curupira/groups"
72
-
73
- action_1 = ActionLabel.create name: "new"
74
- action_2 = ActionLabel.create name: "create"
75
-
76
- feature.action_labels = [action_1, action_2]
77
-
78
- feature.save
79
-
80
- feature = Feature.create name: "Visualizar Grupos", controller: "curupira/groups"
81
-
82
- action_1 = ActionLabel.create name: "index"
83
- action_2 = ActionLabel.create name: "show"
84
-
85
- feature.action_labels = [action_1, action_2]
86
-
87
- feature.save
88
-
89
- feature = Feature.create name: "Editar Grupos", controller: "curupira/groups"
90
-
91
- action_1 = ActionLabel.create name: "edit"
92
- action_2 = ActionLabel.create name: "update"
93
-
94
- feature.action_labels = [action_1, action_2]
95
-
96
- feature = Feature.create name: "Deletar Grupos", controller: "curupira/groups"
97
-
98
- action_1 = ActionLabel.create name: "destroy"
99
-
100
- feature.action_labels = [action_1]
101
-
102
- feature.save
103
-
104
- ###############################################
105
-
106
- feature = Feature.create name: "Cadastrar Grupos", controller: "curupira/groups"
107
-
108
- action_1 = ActionLabel.create name: "new"
109
- action_2 = ActionLabel.create name: "create"
110
-
111
- feature.action_labels = [action_1, action_2]
112
-
113
- feature.save
114
-
115
- feature = Feature.create name: "Visualizar Grupos", controller: "curupira/groups"
116
-
117
- action_1 = ActionLabel.create name: "index"
118
- action_2 = ActionLabel.create name: "show"
119
-
120
- feature.action_labels = [action_1, action_2]
121
-
122
- feature.save
123
-
124
- feature = Feature.create name: "Editar Grupos", controller: "curupira/groups"
125
-
126
- action_1 = ActionLabel.create name: "edit"
127
- action_2 = ActionLabel.create name: "update"
128
-
129
- feature.action_labels = [action_1, action_2]
130
-
131
- feature = Feature.create name: "Deletar Grupos", controller: "curupira/groups"
132
-
133
- action_1 = ActionLabel.create name: "destroy"
134
-
135
- feature.action_labels = [action_1]
136
-
137
- feature.save
1
+ Rails.application.eager_load!
2
+
3
+ def eval_curupira_action(controller, action)
4
+ case action.to_s
5
+ when "index", "show", "search"
6
+ feature_desc = I18n.t("curupira.features.#{controller}.show")
7
+ when "create", "new"
8
+ feature_desc = I18n.t("curupira.features.#{controller}.create")
9
+ when "edit", "update"
10
+ feature_desc = I18n.t("curupira.features.#{controller}.edit")
11
+ when "delete", "destroy"
12
+ feature_desc = I18n.t("curupira.features.#{controller}.delete")
13
+ else
14
+ feature_desc = "Other: " << action.to_s
15
+ end
16
+ return feature_desc
17
+ end
18
+
19
+ Curupira::AuthorizedController.subclasses.each do |controller|
20
+ p clazz = controller.to_s.underscore.gsub("_controller", "")
21
+
22
+ feature = Feature.create name: I18n.t("curupira.features.#{clazz}.manage"), controller: clazz
23
+ feature.action_labels << ActionLabel.create(name: "manage")
24
+
25
+ controller.action_methods.each do |action|
26
+ feature_description = eval_curupira_action(clazz, action)
27
+
28
+ feature = Feature.find_by(name: feature_description)
29
+
30
+ if feature.present?
31
+ feature.action_labels << ActionLabel.create(name: action)
32
+ else
33
+ feature = Feature.create name: feature_description, controller: clazz
34
+ feature.action_labels << ActionLabel.create(name: action)
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curupira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Moura
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-03-19 00:00:00.000000000 Z
14
+ date: 2015-03-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -217,6 +217,7 @@ files:
217
217
  - spec/controllers/sessions_controller_spec.rb
218
218
  - spec/controllers/users_controller_spec.rb
219
219
  - spec/curupira/authorization_spec.rb
220
+ - spec/curupira/full_feature_spec.rb
220
221
  - spec/dummy/README.rdoc
221
222
  - spec/dummy/Rakefile
222
223
  - spec/dummy/app/assets/images/.keep
@@ -349,15 +350,15 @@ files:
349
350
  - spec/tmp/app/models/user.rb
350
351
  - spec/tmp/config/initializers/sorcery.rb
351
352
  - spec/tmp/config/routes.rb
352
- - spec/tmp/db/migrate/20150319143755_create_role_group_users.rb
353
- - spec/tmp/db/migrate/20150319143756_create_authorizations.rb
354
- - spec/tmp/db/migrate/20150319143757_create_features.rb
355
- - spec/tmp/db/migrate/20150319143758_create_groups.rb
356
- - spec/tmp/db/migrate/20150319143759_create_roles.rb
357
- - spec/tmp/db/migrate/20150319143760_sorcery_core.rb
358
- - spec/tmp/db/migrate/20150319143761_create_group_users.rb
359
- - spec/tmp/db/migrate/20150319143762_create_role_groups.rb
360
- - spec/tmp/db/migrate/20150319143763_create_action_labels.rb
353
+ - spec/tmp/db/migrate/20150320032239_create_role_group_users.rb
354
+ - spec/tmp/db/migrate/20150320032240_create_authorizations.rb
355
+ - spec/tmp/db/migrate/20150320032241_create_features.rb
356
+ - spec/tmp/db/migrate/20150320032242_create_groups.rb
357
+ - spec/tmp/db/migrate/20150320032243_create_roles.rb
358
+ - spec/tmp/db/migrate/20150320032244_sorcery_core.rb
359
+ - spec/tmp/db/migrate/20150320032245_create_group_users.rb
360
+ - spec/tmp/db/migrate/20150320032246_create_role_groups.rb
361
+ - spec/tmp/db/migrate/20150320032247_create_action_labels.rb
361
362
  homepage: https://rubygems.org/gems/curupira
362
363
  licenses:
363
364
  - MIT
@@ -402,6 +403,7 @@ test_files:
402
403
  - spec/controllers/sessions_controller_spec.rb
403
404
  - spec/controllers/users_controller_spec.rb
404
405
  - spec/curupira/authorization_spec.rb
406
+ - spec/curupira/full_feature_spec.rb
405
407
  - spec/dummy/app/assets/javascripts/application.js
406
408
  - spec/dummy/app/assets/stylesheets/application.css
407
409
  - spec/dummy/app/controllers/application_controller.rb
@@ -528,12 +530,12 @@ test_files:
528
530
  - spec/tmp/app/models/user.rb
529
531
  - spec/tmp/config/initializers/sorcery.rb
530
532
  - spec/tmp/config/routes.rb
531
- - spec/tmp/db/migrate/20150319143755_create_role_group_users.rb
532
- - spec/tmp/db/migrate/20150319143756_create_authorizations.rb
533
- - spec/tmp/db/migrate/20150319143757_create_features.rb
534
- - spec/tmp/db/migrate/20150319143758_create_groups.rb
535
- - spec/tmp/db/migrate/20150319143759_create_roles.rb
536
- - spec/tmp/db/migrate/20150319143760_sorcery_core.rb
537
- - spec/tmp/db/migrate/20150319143761_create_group_users.rb
538
- - spec/tmp/db/migrate/20150319143762_create_role_groups.rb
539
- - spec/tmp/db/migrate/20150319143763_create_action_labels.rb
533
+ - spec/tmp/db/migrate/20150320032239_create_role_group_users.rb
534
+ - spec/tmp/db/migrate/20150320032240_create_authorizations.rb
535
+ - spec/tmp/db/migrate/20150320032241_create_features.rb
536
+ - spec/tmp/db/migrate/20150320032242_create_groups.rb
537
+ - spec/tmp/db/migrate/20150320032243_create_roles.rb
538
+ - spec/tmp/db/migrate/20150320032244_sorcery_core.rb
539
+ - spec/tmp/db/migrate/20150320032245_create_group_users.rb
540
+ - spec/tmp/db/migrate/20150320032246_create_role_groups.rb
541
+ - spec/tmp/db/migrate/20150320032247_create_action_labels.rb