strongbolt 0.3.12 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +56 -0
- data/.rubocop_todo.yml +91 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +18 -2
- data/Rakefile +1 -1
- data/app/controllers/strongbolt/capabilities_controller.rb +36 -45
- data/app/controllers/strongbolt/roles_controller.rb +39 -47
- data/app/controllers/strongbolt/security_controller.rb +2 -3
- data/app/controllers/strongbolt/user_groups_controller.rb +48 -54
- data/app/controllers/strongbolt/user_groups_users_controller.rb +2 -4
- data/app/controllers/strongbolt_controller.rb +1 -1
- data/circle.yml +13 -0
- data/lib/generators/strongbolt/fix_generator.rb +5 -6
- data/lib/generators/strongbolt/fix_unique_group_members_generator.rb +2 -3
- data/lib/generators/strongbolt/indexes_generator.rb +3 -4
- data/lib/generators/strongbolt/install_generator.rb +8 -9
- data/lib/generators/strongbolt/templates/fix_unique_group_members.rb +1 -1
- data/lib/generators/strongbolt/templates/indexes.rb +1 -1
- data/lib/generators/strongbolt/templates/migration.rb +11 -12
- data/lib/generators/strongbolt/templates/strongbolt.rb +1 -1
- data/lib/generators/strongbolt/views_generator.rb +4 -4
- data/lib/strongbolt.rb +51 -54
- data/lib/strongbolt/base.rb +1 -1
- data/lib/strongbolt/bolted.rb +12 -13
- data/lib/strongbolt/bolted_controller.rb +46 -57
- data/lib/strongbolt/capabilities_role.rb +5 -5
- data/lib/strongbolt/capability.rb +32 -31
- data/lib/strongbolt/configuration.rb +18 -19
- data/lib/strongbolt/controllers/url_helpers.rb +5 -5
- data/lib/strongbolt/engine.rb +9 -9
- data/lib/strongbolt/errors.rb +4 -4
- data/lib/strongbolt/generators/migration.rb +4 -6
- data/lib/strongbolt/helpers.rb +5 -7
- data/lib/strongbolt/rails/routes.rb +4 -4
- data/lib/strongbolt/role.rb +11 -12
- data/lib/strongbolt/roles_user_group.rb +5 -5
- data/lib/strongbolt/rspec.rb +2 -2
- data/lib/strongbolt/rspec/user.rb +13 -15
- data/lib/strongbolt/tenantable.rb +78 -80
- data/lib/strongbolt/user_abilities.rb +44 -54
- data/lib/strongbolt/user_group.rb +8 -10
- data/lib/strongbolt/user_groups_user.rb +6 -6
- data/lib/strongbolt/version.rb +1 -1
- data/lib/tasks/strongbolt_tasks.rake +4 -4
- data/spec/controllers/strongbolt/capabilities_controller_spec.rb +28 -45
- data/spec/controllers/strongbolt/roles_controller_spec.rb +39 -72
- data/spec/controllers/strongbolt/user_groups_controller_spec.rb +34 -65
- data/spec/controllers/strongbolt/user_groups_users_controller_spec.rb +11 -19
- data/spec/controllers/without_authorization_controller_spec.rb +5 -5
- data/spec/dummy/app/controllers/posts_controller.rb +2 -2
- data/spec/dummy/app/controllers/test_controller.rb +1 -1
- data/spec/dummy/app/controllers/without_authorization_controller.rb +1 -1
- data/spec/dummy/bin/rails +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/application.rb +4 -5
- data/spec/dummy/config/initializers/cookies_serializer.rb +1 -1
- data/spec/dummy/config/initializers/strongbolt.rb +2 -2
- data/spec/dummy/config/routes.rb +1 -3
- data/spec/dummy/db/migrate/20150630212236_create_strongbolt_tables.rb +9 -10
- data/spec/dummy/db/migrate/20150630212251_create_strongbolt_tables_indexes.rb +2 -2
- data/spec/dummy/db/migrate/20160531110509_fix_unique_group_members.rb +1 -1
- data/spec/fabricators/capability_fabricator.rb +4 -4
- data/spec/fabricators/role_fabricator.rb +3 -3
- data/spec/fabricators/user_fabricator.rb +2 -2
- data/spec/fabricators/user_group_fabricator.rb +3 -3
- data/spec/fixtures/application.rb +6 -3
- data/spec/fixtures/controllers.rb +1 -1
- data/spec/spec_helper.rb +7 -8
- data/spec/strongbolt/bolted_controller_spec.rb +110 -208
- data/spec/strongbolt/bolted_spec.rb +26 -40
- data/spec/strongbolt/capability_spec.rb +72 -86
- data/spec/strongbolt/configuration_spec.rb +33 -46
- data/spec/strongbolt/controllers/url_helpers_spec.rb +7 -9
- data/spec/strongbolt/helpers_spec.rb +14 -16
- data/spec/strongbolt/role_spec.rb +32 -35
- data/spec/strongbolt/tenantable_spec.rb +88 -86
- data/spec/strongbolt/user_abilities_multiple_tenants_spec.rb +29 -34
- data/spec/strongbolt/user_abilities_spec.rb +142 -188
- data/spec/strongbolt/user_group_spec.rb +14 -14
- data/spec/strongbolt/users_tenant_spec.rb +10 -12
- data/spec/strongbolt_spec.rb +53 -73
- data/spec/support/controller_macros.rb +1 -3
- data/spec/support/db_setup.rb +31 -25
- data/spec/support/helpers.rb +12 -12
- data/spec/support/transactional_specs.rb +1 -3
- data/strongbolt.gemspec +14 -12
- metadata +20 -3
@@ -1,22 +1,20 @@
|
|
1
1
|
module Strongbolt
|
2
2
|
class UserGroup < Base
|
3
|
-
|
4
3
|
has_many :user_groups_users,
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
has_many :users, :
|
4
|
+
class_name: 'Strongbolt::UserGroupsUser',
|
5
|
+
dependent: :restrict_with_exception,
|
6
|
+
inverse_of: :user_group
|
7
|
+
has_many :users, through: :user_groups_users
|
9
8
|
|
10
9
|
has_many :roles_user_groups,
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
class_name: 'Strongbolt::RolesUserGroup',
|
11
|
+
dependent: :delete_all,
|
12
|
+
inverse_of: :user_group
|
14
13
|
|
15
|
-
has_many :roles, :
|
14
|
+
has_many :roles, through: :roles_user_groups
|
16
15
|
|
17
16
|
has_many :capabilities, through: :roles
|
18
17
|
|
19
18
|
validates_presence_of :name
|
20
|
-
|
21
19
|
end
|
22
20
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Strongbolt
|
2
2
|
class UserGroupsUser < Base
|
3
|
-
authorize_as
|
3
|
+
authorize_as 'Strongbolt::UserGroup'
|
4
4
|
|
5
5
|
belongs_to :user_group,
|
6
|
-
|
7
|
-
|
6
|
+
class_name: 'Strongbolt::UserGroup',
|
7
|
+
inverse_of: :user_groups_users
|
8
8
|
|
9
9
|
belongs_to :user,
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
class_name: Configuration.user_class,
|
11
|
+
foreign_key: :user_id,
|
12
|
+
inverse_of: :user_groups_users
|
13
13
|
|
14
14
|
validates_presence_of :user_group, :user
|
15
15
|
end
|
data/lib/strongbolt/version.rb
CHANGED
@@ -2,7 +2,7 @@ namespace :strongbolt do
|
|
2
2
|
#
|
3
3
|
# Create full authorization roles that allows to get started using StrongBolt
|
4
4
|
#
|
5
|
-
task :
|
5
|
+
task seed: :environment do
|
6
6
|
ActiveRecord::Base.transaction do
|
7
7
|
#
|
8
8
|
# Creates capabilities for all models/actions
|
@@ -10,16 +10,16 @@ namespace :strongbolt do
|
|
10
10
|
Strongbolt::Capability.models.each do |model|
|
11
11
|
Strongbolt::Capability::Actions.each do |action|
|
12
12
|
Strongbolt::Capability.where(model: model, action: action,
|
13
|
-
|
13
|
+
require_tenant_access: false).first_or_create
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
# The role
|
18
|
-
role = Strongbolt::Role.create! name:
|
18
|
+
role = Strongbolt::Role.create! name: 'FULL ACCESS (TEMPORARY)'
|
19
19
|
role.capabilities = Strongbolt::Capability.all
|
20
20
|
|
21
21
|
# The user group
|
22
|
-
ug = Strongbolt::UserGroup.create! name:
|
22
|
+
ug = Strongbolt::UserGroup.create! name: 'FULL ACCESS USERS (TEMPORARY)'
|
23
23
|
ug.roles << role
|
24
24
|
|
25
25
|
# Assign to all users
|
@@ -1,16 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Strongbolt
|
4
|
-
|
5
4
|
describe CapabilitiesController do
|
6
|
-
|
7
5
|
subject { response }
|
8
6
|
|
9
7
|
# #
|
10
8
|
# # GET #index
|
11
9
|
# #
|
12
10
|
# describe "GET #index" do
|
13
|
-
|
11
|
+
|
14
12
|
# before do
|
15
13
|
# Fabricate :capability
|
16
14
|
# get :index
|
@@ -27,7 +25,6 @@ module Strongbolt
|
|
27
25
|
|
28
26
|
# end # End GET #index
|
29
27
|
|
30
|
-
|
31
28
|
# #
|
32
29
|
# # GET #show
|
33
30
|
# #
|
@@ -48,10 +45,9 @@ module Strongbolt
|
|
48
45
|
#
|
49
46
|
# POST #create
|
50
47
|
#
|
51
|
-
describe
|
52
|
-
|
48
|
+
describe 'POST #create' do
|
53
49
|
let(:create) { post :create, capability: attributes }
|
54
|
-
|
50
|
+
|
55
51
|
# context "when valid attributes" do
|
56
52
|
# let(:attributes) { Fabricate.attributes_for :capability }
|
57
53
|
|
@@ -67,35 +63,34 @@ module Strongbolt
|
|
67
63
|
# end
|
68
64
|
# end
|
69
65
|
|
70
|
-
context
|
71
|
-
|
66
|
+
context 'when valid attributes and role id present' do
|
72
67
|
let(:role) { Fabricate :role }
|
73
68
|
let(:attributes) { Fabricate.attributes_for :capability }
|
74
69
|
|
75
|
-
context
|
70
|
+
context 'html' do
|
76
71
|
let(:create) { post :create, capability: attributes, role_id: role.id }
|
77
72
|
|
78
|
-
it
|
73
|
+
it 'should redirect to role' do
|
79
74
|
create
|
80
75
|
expect(response).to redirect_to role_path(role)
|
81
76
|
end
|
82
77
|
|
83
|
-
it
|
78
|
+
it 'should add a capability to the role' do
|
84
79
|
expect do
|
85
80
|
create
|
86
81
|
end.to change(role.capabilities, :count).by 1
|
87
82
|
end
|
88
83
|
end
|
89
84
|
|
90
|
-
context
|
85
|
+
context 'json' do |_variable|
|
91
86
|
let(:create) { post :create, capability: attributes, role_id: role.id, format: :json }
|
92
87
|
|
93
|
-
it
|
88
|
+
it 'should redirect to role' do
|
94
89
|
create
|
95
|
-
expect(response.code).to eq
|
90
|
+
expect(response.code).to eq '200'
|
96
91
|
end
|
97
92
|
|
98
|
-
it
|
93
|
+
it 'should add a capability to the role' do
|
99
94
|
expect do
|
100
95
|
create
|
101
96
|
end.to change(role.capabilities, :count).by 1
|
@@ -129,16 +124,12 @@ module Strongbolt
|
|
129
124
|
# expect(response).to redirect_to capabilities_path
|
130
125
|
# end
|
131
126
|
# end
|
132
|
-
|
133
127
|
end # END POST #create
|
134
128
|
|
135
|
-
|
136
|
-
|
137
129
|
#
|
138
130
|
# DELETE #destroy
|
139
131
|
#
|
140
|
-
describe
|
141
|
-
|
132
|
+
describe 'DELETE #destroy' do
|
142
133
|
before do
|
143
134
|
@capability = Fabricate :capability
|
144
135
|
end
|
@@ -167,7 +158,7 @@ module Strongbolt
|
|
167
158
|
# before do
|
168
159
|
# capability.roles << Fabricate(:role)
|
169
160
|
# end
|
170
|
-
|
161
|
+
|
171
162
|
# it "should redirect to capabilities list" do
|
172
163
|
# destroy
|
173
164
|
# expect(response).to redirect_to capability_path(capability)
|
@@ -186,69 +177,61 @@ module Strongbolt
|
|
186
177
|
|
187
178
|
# end
|
188
179
|
|
189
|
-
context
|
180
|
+
context 'when role_id given' do
|
190
181
|
let(:role) { Fabricate :role }
|
191
|
-
|
182
|
+
|
192
183
|
before do
|
193
184
|
role.capabilities << capability
|
194
185
|
end
|
195
186
|
|
196
|
-
context
|
197
|
-
|
187
|
+
context 'when capability id given' do
|
198
188
|
let(:destroy) { delete :destroy, id: capability.id, role_id: role.id }
|
199
189
|
|
200
|
-
|
201
|
-
it "should not delete a capability" do
|
190
|
+
it 'should not delete a capability' do
|
202
191
|
expect do
|
203
192
|
destroy
|
204
193
|
end.not_to change(Capability, :count)
|
205
194
|
end
|
206
195
|
|
207
|
-
it
|
196
|
+
it 'should remove the capability from role' do
|
208
197
|
destroy
|
209
198
|
role.reload
|
210
199
|
expect(role.capabilities).not_to include capability
|
211
200
|
end
|
212
201
|
|
213
|
-
it
|
202
|
+
it 'should redirect to role' do
|
214
203
|
destroy
|
215
204
|
expect(response).to redirect_to role_path(role)
|
216
205
|
end
|
217
|
-
|
218
206
|
end
|
219
207
|
|
220
|
-
context
|
208
|
+
context 'when capability data given and format json' do
|
221
209
|
let(:attributes) do
|
222
|
-
{model: capability.model, require_ownership: capability.require_ownership,
|
210
|
+
{ model: capability.model, require_ownership: capability.require_ownership,
|
223
211
|
require_tenant_access: capability.require_tenant_access,
|
224
|
-
action: capability.action}
|
212
|
+
action: capability.action }
|
225
213
|
end
|
226
214
|
|
227
215
|
let(:destroy) { delete :destroy, role_id: role.id, capability: capability.attributes, format: :json }
|
228
216
|
|
229
|
-
it
|
217
|
+
it 'should not delete a capability' do
|
230
218
|
expect do
|
231
219
|
destroy
|
232
220
|
end.not_to change(Capability, :count)
|
233
221
|
end
|
234
222
|
|
235
|
-
it
|
223
|
+
it 'should remove the capability from role' do
|
236
224
|
destroy
|
237
225
|
role.reload
|
238
226
|
expect(role.capabilities).not_to include capability
|
239
227
|
end
|
240
228
|
|
241
|
-
it
|
229
|
+
it 'should render 200' do
|
242
230
|
destroy
|
243
|
-
expect(response.code).to eq
|
231
|
+
expect(response.code).to eq '200'
|
244
232
|
end
|
245
233
|
end
|
246
234
|
end
|
247
|
-
|
248
|
-
|
249
235
|
end
|
250
|
-
|
251
|
-
|
252
236
|
end
|
253
|
-
|
254
|
-
end
|
237
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Strongbolt
|
4
|
-
|
5
4
|
describe RolesController do
|
6
|
-
|
7
5
|
let!(:role) { Fabricate :role }
|
8
6
|
|
9
7
|
let(:valid_attributes) { Fabricate.attributes_for :role }
|
@@ -15,214 +13,183 @@ module Strongbolt
|
|
15
13
|
#
|
16
14
|
# GET #index
|
17
15
|
#
|
18
|
-
describe
|
19
|
-
|
16
|
+
describe 'GET #index' do
|
20
17
|
before { get :index }
|
21
18
|
|
22
19
|
it { should be_success }
|
23
20
|
|
24
21
|
it { should render_template :index }
|
25
22
|
|
26
|
-
it
|
27
|
-
expect(assigns
|
23
|
+
it 'should assign roles' do
|
24
|
+
expect(assigns(:roles)).to eq [role]
|
28
25
|
end
|
29
|
-
|
30
26
|
end
|
31
27
|
|
32
28
|
#
|
33
29
|
# GET #new
|
34
30
|
#
|
35
|
-
describe
|
36
|
-
|
31
|
+
describe 'GET #new' do
|
37
32
|
before { get :new }
|
38
33
|
|
39
34
|
it { should be_success }
|
40
35
|
|
41
36
|
it { should render_template :new }
|
42
|
-
|
43
37
|
end
|
44
38
|
|
45
|
-
|
46
39
|
#
|
47
40
|
# GET #show
|
48
41
|
#
|
49
|
-
describe
|
50
|
-
|
42
|
+
describe 'GET #show' do
|
51
43
|
# Some children
|
52
44
|
let(:role2) { Fabricate :role, parent: role }
|
53
|
-
let!(:role3) { Fabricate :role, parent: role2 }
|
54
|
-
|
45
|
+
let!(:role3) { Fabricate :role, parent: role2 }
|
46
|
+
|
55
47
|
before { get :show, id: role.id }
|
56
48
|
|
57
49
|
it { should be_success }
|
58
50
|
|
59
|
-
it
|
60
|
-
expect(assigns
|
51
|
+
it 'should assign role' do
|
52
|
+
expect(assigns(:role)).to eq role
|
61
53
|
end
|
62
54
|
|
63
|
-
it
|
64
|
-
expect(assigns
|
55
|
+
it 'should assign children' do
|
56
|
+
expect(assigns(:descendants)).to eq [role2, role3]
|
65
57
|
end
|
66
58
|
|
67
59
|
it { should render_template :show }
|
68
|
-
|
69
60
|
end
|
70
61
|
|
71
62
|
#
|
72
63
|
# GET #edit
|
73
64
|
#
|
74
|
-
describe
|
75
|
-
|
65
|
+
describe 'GET #edit' do
|
76
66
|
before { get :edit, id: role.id }
|
77
67
|
|
78
68
|
it { should be_success }
|
79
69
|
|
80
|
-
it
|
81
|
-
expect(assigns
|
70
|
+
it 'should assign role' do
|
71
|
+
expect(assigns(:role)).to eq role
|
82
72
|
end
|
83
73
|
|
84
74
|
it { should render_template :edit }
|
85
|
-
|
86
75
|
end
|
87
76
|
|
88
77
|
#
|
89
78
|
# POST #create
|
90
79
|
#
|
91
|
-
describe
|
92
|
-
|
80
|
+
describe 'POST #create' do
|
93
81
|
let(:create) { post :create, role: attributes }
|
94
82
|
|
95
83
|
context 'when valid attributes' do
|
96
|
-
|
97
84
|
let(:attributes) { valid_attributes }
|
98
85
|
|
99
|
-
it
|
86
|
+
it 'should redirect to show' do
|
100
87
|
create
|
101
88
|
expect(response).to redirect_to role_path(Role.last)
|
102
89
|
end
|
103
90
|
|
104
|
-
it
|
91
|
+
it 'should create an role' do
|
105
92
|
expect do
|
106
93
|
create
|
107
94
|
end.to change(Role, :count).by 1
|
108
95
|
end
|
109
|
-
|
110
96
|
end
|
111
97
|
|
112
|
-
context
|
113
|
-
|
98
|
+
context 'when invalid attributes' do
|
114
99
|
let(:attributes) { {} }
|
115
100
|
|
116
|
-
it
|
101
|
+
it 'should redirect_to new' do
|
117
102
|
create
|
118
103
|
expect(response).to redirect_to new_role_path
|
119
104
|
end
|
120
105
|
|
121
|
-
it
|
106
|
+
it 'should not create a role' do
|
122
107
|
expect do
|
123
108
|
create
|
124
109
|
end.not_to change(Role, :count)
|
125
110
|
end
|
126
111
|
|
127
|
-
it
|
112
|
+
it 'should set flash danger' do
|
128
113
|
create
|
129
114
|
expect(flash[:danger]).to be_present
|
130
115
|
end
|
131
|
-
|
132
116
|
end
|
133
|
-
|
134
117
|
end
|
135
118
|
|
136
|
-
|
137
119
|
#
|
138
120
|
# PUT #update
|
139
121
|
#
|
140
|
-
describe
|
141
|
-
|
122
|
+
describe 'PUT #update' do
|
142
123
|
before { put :update, id: role.id, role: attributes }
|
143
124
|
|
144
125
|
context 'when valid attributes' do
|
145
|
-
|
146
126
|
let(:attributes) { valid_attributes }
|
147
127
|
|
148
128
|
it { should redirect_to role_path(role) }
|
149
129
|
|
150
|
-
it
|
130
|
+
it 'should update attributes' do
|
151
131
|
expect(role.reload.name).to eq valid_attributes[:name]
|
152
132
|
end
|
153
|
-
|
154
133
|
end
|
155
134
|
|
156
135
|
context 'when invalid attributes' do
|
157
|
-
|
158
|
-
let(:attributes) { {name: ""} }
|
136
|
+
let(:attributes) { { name: '' } }
|
159
137
|
|
160
138
|
it { should redirect_to edit_role_path(role) }
|
161
139
|
|
162
|
-
it
|
163
|
-
expect(role.reload.name).not_to eq
|
140
|
+
it 'should not update attributes' do
|
141
|
+
expect(role.reload.name).not_to eq ''
|
164
142
|
end
|
165
143
|
|
166
|
-
it
|
144
|
+
it 'should set flash danger' do
|
167
145
|
expect(flash[:danger]).to be_present
|
168
146
|
end
|
169
|
-
|
170
147
|
end
|
171
|
-
|
172
148
|
end
|
173
149
|
|
174
|
-
|
175
150
|
#
|
176
151
|
# DELETE #destroy
|
177
152
|
#
|
178
|
-
describe
|
179
|
-
|
153
|
+
describe 'DELETE #destroy' do
|
180
154
|
let(:destroy) { delete :destroy, id: role.id }
|
181
155
|
|
182
|
-
context
|
183
|
-
|
184
|
-
it "should redirect to index" do
|
156
|
+
context 'when no user' do
|
157
|
+
it 'should redirect to index' do
|
185
158
|
destroy
|
186
159
|
expect(response).to redirect_to roles_path
|
187
160
|
end
|
188
161
|
|
189
|
-
it
|
162
|
+
it 'should set flash success' do
|
190
163
|
destroy
|
191
164
|
expect(flash[:success]).to be_present
|
192
165
|
end
|
193
166
|
|
194
|
-
it
|
167
|
+
it 'should delete a role' do
|
195
168
|
expect do
|
196
169
|
destroy
|
197
|
-
end.to change(Role, :count).by
|
170
|
+
end.to change(Role, :count).by(-1)
|
198
171
|
end
|
199
|
-
|
200
172
|
end
|
201
173
|
|
202
|
-
context
|
203
|
-
|
174
|
+
context 'when has user groups' do
|
204
175
|
let(:role) { Fabricate :role_with_user_groups }
|
205
176
|
|
206
|
-
it
|
177
|
+
it 'should redirect to show' do
|
207
178
|
destroy
|
208
179
|
expect(response).to redirect_to role_path(role)
|
209
180
|
end
|
210
181
|
|
211
|
-
it
|
182
|
+
it 'should set flash danger' do
|
212
183
|
destroy
|
213
184
|
expect(flash[:danger]).to be_present
|
214
185
|
end
|
215
186
|
|
216
|
-
it
|
187
|
+
it 'should not delete a role' do
|
217
188
|
expect do
|
218
189
|
destroy
|
219
190
|
end.not_to change(Role, :count)
|
220
191
|
end
|
221
|
-
|
222
192
|
end
|
223
|
-
|
224
193
|
end
|
225
|
-
|
226
194
|
end
|
227
|
-
|
228
|
-
end
|
195
|
+
end
|