openproject-global_roles 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +15 -0
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +89 -0
  4. data/app/assets/javascripts/global_roles/global_roles.js +91 -0
  5. data/app/assets/javascripts/global_roles/principal_roles.js +51 -0
  6. data/app/assets/stylesheets/global_roles/global_roles.css +18 -0
  7. data/app/controllers/principal_roles_controller.rb +139 -0
  8. data/app/models/global_role.rb +46 -0
  9. data/app/models/principal_role.rb +29 -0
  10. data/app/views/principal_roles/_errors.html.erb +13 -0
  11. data/app/views/principal_roles/_show_table_row.html.erb +28 -0
  12. data/app/views/principal_roles/index.html.erb +47 -0
  13. data/app/views/roles/_form.html.erb +52 -0
  14. data/app/views/roles/_global_attributes.html.erb +12 -0
  15. data/app/views/roles/_global_form.html.erb +12 -0
  16. data/app/views/roles/_member_attributes.html.erb +17 -0
  17. data/app/views/roles/_member_form.html.erb +39 -0
  18. data/app/views/roles/_permissions.html.erb +27 -0
  19. data/app/views/roles/edit.html.erb +20 -0
  20. data/app/views/roles/index.html.erb +57 -0
  21. data/app/views/roles/new.html.erb +18 -0
  22. data/app/views/shared/_global_roles_header.html.erb +16 -0
  23. data/app/views/users/_available_global_role.html.erb +14 -0
  24. data/app/views/users/_available_global_roles.html.erb +32 -0
  25. data/app/views/users/_global_roles.html.erb +33 -0
  26. data/config/locales/de.yml +11 -0
  27. data/config/locales/en.yml +11 -0
  28. data/config/routes.rb +14 -0
  29. data/db/migrate/001_sti_for_roles.rb +34 -0
  30. data/doc/COPYRIGHT.rdoc +16 -0
  31. data/doc/GPL.txt +674 -0
  32. data/lib/open_project/global_roles.rb +16 -0
  33. data/lib/open_project/global_roles/engine.rb +89 -0
  34. data/lib/open_project/global_roles/patches.rb +13 -0
  35. data/lib/open_project/global_roles/patches/access_control_patch.rb +41 -0
  36. data/lib/open_project/global_roles/patches/permission_patch.rb +49 -0
  37. data/lib/open_project/global_roles/patches/principal_patch.rb +24 -0
  38. data/lib/open_project/global_roles/patches/role_patch.rb +47 -0
  39. data/lib/open_project/global_roles/patches/roles_controller_patch.rb +62 -0
  40. data/lib/open_project/global_roles/patches/roles_helper_patch.rb +27 -0
  41. data/lib/open_project/global_roles/patches/user_patch.rb +24 -0
  42. data/lib/open_project/global_roles/patches/users_controller_patch.rb +34 -0
  43. data/lib/open_project/global_roles/patches/users_helper_patch.rb +39 -0
  44. data/lib/open_project/global_roles/principal_allowance_evaluator/global.rb +24 -0
  45. data/lib/open_project/global_roles/version.rb +16 -0
  46. data/lib/openproject-global_roles.rb +12 -0
  47. data/spec/controllers/principal_roles_controller_spec.rb +163 -0
  48. data/spec/controllers/roles_controller_spec.rb +315 -0
  49. data/spec/controllers/users_controller_spec.rb +57 -0
  50. data/spec/factories/global_role_factory.rb +16 -0
  51. data/spec/factories/principal_role_factory.rb +17 -0
  52. data/spec/lib/access_control_spec.rb +56 -0
  53. data/spec/lib/global_roles/principal_allowance_evaluator/global_spec.rb +84 -0
  54. data/spec/lib/loader_spec.rb +40 -0
  55. data/spec/lib/permission_spec.rb +41 -0
  56. data/spec/models/global_role_spec.rb +175 -0
  57. data/spec/models/principal_role_spec.rb +48 -0
  58. data/spec/models/principal_spec.rb +38 -0
  59. data/spec/models/role_spec.rb +43 -0
  60. data/spec/models/user_spec.rb +20 -0
  61. data/spec/plugin_spec_helper.rb +152 -0
  62. data/spec/spec_helper.rb +15 -0
  63. metadata +152 -0
@@ -0,0 +1,24 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ class OpenProject::GlobalRoles::PrincipalAllowanceEvaluator::Global < ChiliProject::PrincipalAllowanceEvaluator::Base
13
+
14
+ def granted_for_global? membership, action, options
15
+ return false unless membership.is_a?(PrincipalRole)
16
+ granted = super
17
+
18
+ granted ||= membership.role.allowed_to?(action).present?
19
+ end
20
+
21
+ def global_granting_candidates
22
+ @user.principal_roles
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject
13
+ module GlobalRoles
14
+ VERSION = "1.0.0"
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ require 'open_project/global_roles'
@@ -0,0 +1,163 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ require File.dirname(__FILE__) + '/../spec_helper'
13
+
14
+ describe PrincipalRolesController do
15
+ before(:each) do
16
+ @controller.stub!(:require_admin).and_return(true)
17
+ @controller.stub!(:check_if_login_required).and_return(true)
18
+ @controller.stub!(:set_localization).and_return(true)
19
+
20
+ @principal_role = mock_model PrincipalRole
21
+
22
+ if privacy_plugin_loaded?
23
+ @principal_role.stub!(:privacy_unnecessary=)
24
+ @principal_role.stub!(:valid?).and_return(true)
25
+ @principal_role.stub!(:privacy_statement_necessary?).and_return(false)
26
+ end
27
+
28
+ @principal_role.stub!(:id).and_return(23)
29
+ PrincipalRole.stub!(:find).and_return @principal_role
30
+ disable_flash_sweep
31
+ disable_log_requesting_user
32
+ end
33
+
34
+ describe :post do
35
+ before :each do
36
+ @params = {"principal_role"=>{"principal_id"=>"3", "role_ids"=>["7"]}}
37
+ end
38
+
39
+ unless privacy_plugin_loaded? #tests than are defined in privacy_plugin
40
+
41
+ describe :create do
42
+ before :each do
43
+
44
+ end
45
+
46
+ describe "SUCCESS" do
47
+ before :each do
48
+ @global_role = mock_model(GlobalRole)
49
+ @global_role.stub!(:id).and_return(42)
50
+ Role.stub!(:find).and_return([@global_role])
51
+ PrincipalRole.stub!(:new).and_return(@principal_role)
52
+ @user = mock_model User
53
+ @user.stub!(:valid?).and_return(true)
54
+ @user.stub!(:logged?).and_return(true)
55
+ Principal.stub!(:find).and_return(@user)
56
+ @principal_role.stub!(:role=)
57
+ @principal_role.stub!(:role).and_return(@global_role)
58
+ @principal_role.stub!(:principal_id=)
59
+ @principal_role.stub!(:save)
60
+ @principal_role.stub!(:role_id).and_return(@global_role.id)
61
+ @principal_role.stub!(:valid?).and_return(true)
62
+ end
63
+
64
+ describe "js" do
65
+ before :each do
66
+ response_should_render :replace,
67
+ "available_principal_roles",
68
+ :partial => "users/available_global_roles",
69
+ :locals => {:global_roles => anything(),
70
+ :user => anything()}
71
+ response_should_render :insert_html,
72
+ :top, 'table_principal_roles_body',
73
+ :partial => "principal_roles/show_table_row",
74
+ :locals => {:principal_role => anything()}
75
+
76
+ #post :create, { "format" => "js", "principal_role"=>{"principal_id"=>"3", "role_ids"=>["7"]}}
77
+ xhr :post, :create, @params
78
+ end
79
+
80
+ it { response.should be_success }
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ describe :put do
88
+ before :each do
89
+ @params = {"principal_role"=>{"id"=>"6", "role_id" => "5"}}
90
+ end
91
+
92
+ describe :update do
93
+ before(:each) do
94
+ @principal_role.stub!(:update_attributes)
95
+ end
96
+
97
+ describe "SUCCESS" do
98
+ describe "js" do
99
+ before :each do
100
+ @principal_role.stub!(:valid?).and_return(true)
101
+
102
+ response_should_render :replace,
103
+ "principal_role-#{@principal_role.id}",
104
+ :partial => "principal_roles/show_table_row",
105
+ :locals => {:principal_role => anything()}
106
+
107
+ xhr :put, :update, @params
108
+ end
109
+
110
+ it {response.should be_success}
111
+ end
112
+ end
113
+
114
+ describe "FAILURE" do
115
+ describe "js" do
116
+ before :each do
117
+ @principal_role.stub!(:valid?).and_return(false)
118
+ response_should_render :insert_html,
119
+ :top,
120
+ "tab-content-global_roles",
121
+ :partial => 'errors'
122
+
123
+ xhr :put, :update, @params
124
+ end
125
+
126
+ it {response.should be_success}
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ describe :delete do
133
+ before :each do
134
+ @principal_role.stub!(:principal_id).and_return(1)
135
+ @user = mock_model User
136
+ @user.stub!(:logged?).and_return(true)
137
+ Principal.stub(:find).and_return(@user)
138
+ @principal_role.stub!(:destroy)
139
+ @params = {"id" => "1"}
140
+ end
141
+
142
+ describe :destroy do
143
+ describe "SUCCESS" do
144
+ before :each do
145
+ response_should_render :remove, "principal_role-#{@principal_role.id}"
146
+ response_should_render :replace,
147
+ "available_principal_roles",
148
+ :partial => "users/available_global_roles",
149
+ :locals => {:global_roles => anything(),
150
+ :user => anything()}
151
+ end
152
+
153
+ describe "js" do
154
+ before :each do
155
+ xhr :delete, :destroy, @params
156
+ end
157
+
158
+ it { response.should be_success }
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,315 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
13
+
14
+ describe RolesController do
15
+ before (:each) do
16
+ @controller.stub!(:check_if_login_required)
17
+ @controller.should_receive(:require_admin)
18
+ disable_flash_sweep
19
+ end
20
+
21
+ after (:each) do
22
+ User.current = nil
23
+ end
24
+
25
+ shared_examples_for "index" do
26
+ it {response.should be_success}
27
+ it {assigns(:roles).should eql(@roles)}
28
+ it {response.should render_template "roles/index"}
29
+ end
30
+
31
+ shared_examples_for "global assigns" do
32
+ it {assigns(:global_permissions).should eql @global_role.setable_permissions}
33
+ it {assigns(:global_roles).should eql @global_roles}
34
+ it {assigns(:global_role).should eql @global_role}
35
+ end
36
+
37
+ shared_examples_for "permission assigns" do
38
+ it {assigns(:member_permissions).should eql @member_role.setable_permissions}
39
+ it {assigns(:global_permissions).should eql GlobalRole.setable_permissions}
40
+ end
41
+
42
+ shared_examples_for "successful create" do
43
+ it {response.should be_redirect}
44
+ it {response.should redirect_to "/admin/roles"}
45
+ it {flash[:notice].should eql I18n.t(:notice_successful_create)}
46
+ end
47
+
48
+ shared_examples_for "failed create" do
49
+ it {response.should be_success}
50
+ it {response.should render_template "new"}
51
+ end
52
+
53
+
54
+
55
+ describe "WITH get" do
56
+ describe "VERB", :index do
57
+ before (:each) do
58
+ mock_role_find
59
+ end
60
+
61
+ describe "html" do
62
+ before {get "index"}
63
+
64
+ it_should_behave_like "index"
65
+
66
+ end
67
+
68
+ describe "xhr" do
69
+ before {xhr :get, "index"}
70
+
71
+ it_should_behave_like "index"
72
+ end
73
+ end
74
+
75
+ describe "VERB", :new do
76
+ before (:each) do
77
+ @member_role = mocks_for_creating Role
78
+ GlobalRole.stub!(:setable_permissions).and_return([:perm1, :perm2, :perm3])
79
+ @non_member_role = mock_model Role
80
+ mock_permissions_on @non_member_role
81
+ Role.stub!(:non_member).and_return(@non_member_role)
82
+
83
+ mock_role_find
84
+ get "new"
85
+ end
86
+
87
+ it {response.should be_success}
88
+ it {response.should render_template "roles/new"}
89
+ it {assigns(:member_permissions).should eql @member_role.setable_permissions}
90
+ it {assigns(:roles).should eql @roles}
91
+ it {assigns(:role).should eql @member_role}
92
+ it {assigns(:global_permissions).should eql GlobalRole.setable_permissions}
93
+ end
94
+
95
+ describe "VERB", :edit do
96
+ before(:each) do
97
+ @member_role = mocks_for_creating Role
98
+ @global_role = mocks_for_creating GlobalRole
99
+ mock_role_find
100
+ end
101
+
102
+ describe "WITH member_role id" do
103
+ before (:each) do
104
+ @params = {"id" => "1"}
105
+ Role.stub!(:find).and_return(@member_role)
106
+ end
107
+
108
+ describe "RESULT" do
109
+ describe "success" do
110
+ describe "html" do
111
+ before {get :edit, @params}
112
+
113
+ it {response.should be_success}
114
+ it {response.should render_template "roles/edit"}
115
+ it {assigns(:role).should eql @member_role}
116
+ it {assigns(:permissions).should eql @member_role.setable_permissions}
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "WITH post" do
125
+ before(:each) do
126
+ @member_role = mocks_for_creating Role
127
+ @global_role = mocks_for_creating GlobalRole
128
+ mock_role_find
129
+ Role.stub!(:find).with("1").and_return(@member_role)
130
+ Role.stub!(:find).with("2").and_return(@global_role)
131
+ end
132
+
133
+ describe "VERB", :create do
134
+
135
+ describe "WITH member_role params" do
136
+ before (:each) do
137
+ @params = {"role"=>{"name"=>"role",
138
+ "permissions"=>["perm1", "perm2", "perm3"],
139
+ "assignable"=>"1"}}
140
+ end
141
+
142
+ describe "RESULT" do
143
+ describe "success" do
144
+ before(:each) do
145
+ Role.should_receive(:new).with(@params["role"]).and_return(@member_role)
146
+ @member_role.stub!(:save).and_return(true)
147
+ @member_role.stub!(:errors).and_return([])
148
+ end
149
+
150
+ describe "html" do
151
+ before (:each) do
152
+ post "create", @params
153
+ end
154
+
155
+ it_should_behave_like "successful create"
156
+ it {assigns(:role).should eql @member_role}
157
+ end
158
+ end
159
+
160
+ describe "failure" do
161
+ before(:each) do
162
+ Role.should_receive(:new).with(@params["role"]).and_return(@member_role)
163
+ @member_role.stub!(:save).and_return(false)
164
+ @member_role.stub!(:errors).and_return(["something is wrong"])
165
+ end
166
+
167
+ describe "html" do
168
+ before {post "create", @params}
169
+
170
+ it_should_behave_like "failed create"
171
+ it {assigns(:role).should eql @member_role}
172
+ it {assigns(:roles).should eql Role.all}
173
+ it_should_behave_like "permission assigns"
174
+ end
175
+ end
176
+ end
177
+ end
178
+
179
+ describe "WITH global_role params" do
180
+ before (:each) do
181
+ @params = {"role"=>{"name"=>"role",
182
+ "permissions"=>["perm1", "perm2", "perm3"]
183
+ },
184
+ "global_role" => "1"}
185
+ end
186
+
187
+ describe "RESULTS" do
188
+ describe "success" do
189
+ before(:each) do
190
+ GlobalRole.should_receive(:new).with(@params["role"]).and_return(@global_role)
191
+ @global_role.stub!(:save).and_return(true)
192
+ end
193
+
194
+ describe "html" do
195
+ before {post "create", @params}
196
+
197
+ it_should_behave_like "successful create"
198
+ end
199
+ end
200
+
201
+ describe "failure" do
202
+ before(:each) do
203
+ GlobalRole.should_receive(:new).with(@params["role"]).and_return(@global_role)
204
+ @global_role.stub!(:save).and_return(false)
205
+ end
206
+
207
+ describe "html" do
208
+ before {post "create", @params}
209
+
210
+ it_should_behave_like "failed create"
211
+ it {assigns(:role).should eql @global_role}
212
+ it {assigns(:roles).should eql Role.all}
213
+ it_should_behave_like "permission assigns"
214
+ end
215
+ end
216
+ end
217
+ end
218
+ end
219
+
220
+
221
+
222
+ describe "VERB", :destroy do
223
+ shared_examples_for "destroy results" do
224
+ describe "success" do
225
+ before (:each) do
226
+ @role.should_receive(:destroy)
227
+ post "destroy", @params
228
+ end
229
+
230
+ it {response.should be_redirect}
231
+ it {response.should redirect_to "/admin/roles"}
232
+ end
233
+ end
234
+
235
+ describe "WITH member_role params" do
236
+ before (:each) do
237
+ @params = {"class" => "Role", "id" => "1"}
238
+ @role = @member_role
239
+ end
240
+
241
+ describe "RESULTS" do
242
+ it_should_behave_like "destroy results"
243
+ end
244
+ end
245
+
246
+ describe "WITH global_role params" do
247
+ before (:each) do
248
+ @params = {"class" => "Role", "id" => "2"}
249
+ @role = @global_role
250
+ end
251
+
252
+ describe "RESULTS" do
253
+ it_should_behave_like "destroy results"
254
+ end
255
+ end
256
+ end
257
+
258
+
259
+ describe "VERB", :update do
260
+ shared_examples_for "update results" do
261
+ describe "success" do
262
+ describe "html" do
263
+ before (:each) do
264
+ @role.should_receive(:update_attributes).with(@params["role"]).and_return(true)
265
+ @role.stub!(:errors).and_return([])
266
+ post :update, @params
267
+ end
268
+
269
+ it {response.should be_redirect}
270
+ it {response.should redirect_to "/admin/roles"}
271
+ it {flash[:notice].should eql I18n.t(:notice_successful_update)}
272
+ end
273
+ end
274
+
275
+ describe "failure" do
276
+ describe "html" do
277
+ before(:each) do
278
+ @role.should_receive(:update_attributes).with(@params["role"]).and_return(false)
279
+ @role.stub!(:errors).and_return(["something is wrong"])
280
+ post :update, @params
281
+ end
282
+
283
+ it { response.should render_template "roles/edit" }
284
+ end
285
+ end
286
+ end
287
+
288
+ describe "WITH member_role params" do
289
+ before (:each) do
290
+ @params = {"role" => {"permissions" => ["permA", "permB"],
291
+ "name" => "schmu"},
292
+ "id" => "1"}
293
+ @role = @member_role
294
+ end
295
+
296
+ describe "RESULT" do
297
+ it_should_behave_like "update results"
298
+ end
299
+ end
300
+
301
+ describe "WITH global_role params" do
302
+ before (:each) do
303
+ @params = {"role" => {"permissions" => ["permA", "permB"],
304
+ "name" => "schmu"},
305
+ "id" => "2"}
306
+ @role = @global_role
307
+ end
308
+
309
+ describe "RESULT" do
310
+ it_should_behave_like "update results"
311
+ end
312
+ end
313
+ end
314
+ end
315
+ end