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,10 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Strongbolt
|
4
|
-
|
5
4
|
describe UserGroup do
|
6
|
-
|
7
|
-
let(:user_group) { UserGroup.new name: "PCCC" }
|
5
|
+
let(:user_group) { UserGroup.new name: 'PCCC' }
|
8
6
|
|
9
7
|
subject { user_group }
|
10
8
|
|
@@ -12,26 +10,28 @@ module Strongbolt
|
|
12
10
|
|
13
11
|
it { is_expected.to validate_presence_of :name }
|
14
12
|
|
15
|
-
it {
|
16
|
-
.
|
13
|
+
it {
|
14
|
+
is_expected.to have_many(:user_groups_users).class_name('Strongbolt::UserGroupsUser')
|
15
|
+
.dependent :restrict_with_exception
|
16
|
+
}
|
17
17
|
it { is_expected.to have_many(:users).through :user_groups_users }
|
18
18
|
|
19
|
-
it {
|
20
|
-
.
|
19
|
+
it {
|
20
|
+
is_expected.to have_many(:roles_user_groups).class_name('Strongbolt::RolesUserGroup')
|
21
|
+
.dependent :delete_all
|
22
|
+
}
|
21
23
|
it { is_expected.to have_many(:roles).through :roles_user_groups }
|
22
|
-
|
24
|
+
|
23
25
|
it { is_expected.to have_many(:capabilities).through :roles }
|
24
26
|
|
25
|
-
context
|
27
|
+
context 'when there are users linked to it' do
|
26
28
|
before { user_group.users << User.create! }
|
27
29
|
|
28
|
-
it
|
30
|
+
it 'cannot delete' do
|
29
31
|
expect do
|
30
32
|
user_group.destroy
|
31
33
|
end.to raise_error ActiveRecord::DeleteRestrictionError
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
35
36
|
end
|
36
|
-
|
37
|
-
end
|
37
|
+
end
|
@@ -1,18 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Strongbolt::UsersTenant do
|
4
|
-
|
5
4
|
before(:all) do
|
6
|
-
define_model
|
7
|
-
self.table_name =
|
5
|
+
define_model 'TenantModel' do
|
6
|
+
self.table_name = 'models'
|
8
7
|
|
9
8
|
tenant
|
10
9
|
end
|
11
|
-
define_model
|
12
|
-
self.table_name =
|
10
|
+
define_model 'Model' do
|
11
|
+
self.table_name = 'models'
|
13
12
|
end
|
14
13
|
end
|
15
|
-
|
14
|
+
|
16
15
|
let(:user) { User.create! }
|
17
16
|
let(:tenant) { TenantModel.create! }
|
18
17
|
|
@@ -21,16 +20,15 @@ describe Strongbolt::UsersTenant do
|
|
21
20
|
subject { users_tenant }
|
22
21
|
|
23
22
|
it { is_expected.to belong_to :user }
|
24
|
-
it { is_expected.to belong_to(:tenant_model).class_name(
|
23
|
+
it { is_expected.to belong_to(:tenant_model).class_name('TenantModel') }
|
25
24
|
|
26
25
|
it { is_expected.to be_valid }
|
27
26
|
it { is_expected.to validate_presence_of :user }
|
28
27
|
it { is_expected.to validate_presence_of :tenant_model }
|
29
28
|
|
30
|
-
it
|
29
|
+
it 'should ensure tenant is a Tenant' do
|
31
30
|
expect do
|
32
|
-
|
31
|
+
Strongbolt::UsersTenantModel.new user: user, tenant_model: Model.create!
|
33
32
|
end.to raise_error ActiveRecord::AssociationTypeMismatch
|
34
33
|
end
|
35
|
-
|
36
|
-
end
|
34
|
+
end
|
data/spec/strongbolt_spec.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Strongbolt do
|
4
|
-
|
5
4
|
#
|
6
5
|
# Important included modules
|
7
6
|
#
|
8
|
-
it
|
7
|
+
it 'should have included Grant::Grantable in ActiveRecord::Base' do
|
9
8
|
expect(ActiveRecord::Base.included_modules).to include Grant::Grantable
|
10
9
|
end
|
11
10
|
|
12
|
-
it
|
11
|
+
it 'should have included Bolted in ActiveRecord::Base' do
|
13
12
|
expect(ActiveRecord::Base.included_modules).to include Strongbolt::Bolted
|
14
13
|
end
|
15
14
|
|
16
|
-
it
|
15
|
+
it 'should have included tentable' do
|
17
16
|
expect(ActiveRecord::Base.included_modules).to include Strongbolt::Tenantable
|
18
17
|
end
|
19
18
|
|
@@ -21,33 +20,30 @@ describe Strongbolt do
|
|
21
20
|
# Setting up
|
22
21
|
#
|
23
22
|
|
24
|
-
describe
|
23
|
+
describe 'it should include module' do
|
25
24
|
before do
|
26
|
-
define_model
|
25
|
+
define_model 'UserModel'
|
27
26
|
Strongbolt.setup do |config|
|
28
|
-
config.user_class =
|
27
|
+
config.user_class = 'UserModel'
|
29
28
|
end
|
30
29
|
end
|
31
30
|
after do
|
32
31
|
Strongbolt.setup do |config|
|
33
|
-
config.user_class =
|
32
|
+
config.user_class = 'User'
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
37
|
-
it
|
36
|
+
it 'should include UserAbilities' do
|
38
37
|
expect(UserModel.included_modules).to include Strongbolt::UserAbilities
|
39
38
|
end
|
40
|
-
|
41
|
-
|
42
39
|
end
|
43
40
|
|
44
41
|
#
|
45
42
|
# Access denied
|
46
43
|
#
|
47
|
-
describe
|
48
|
-
|
44
|
+
describe 'access denied' do
|
49
45
|
before do
|
50
|
-
block = double('block', :
|
46
|
+
block = double('block', call: nil)
|
51
47
|
expect(block).to receive(:call).with 'user', 'instance', 'action', 'request_path'
|
52
48
|
Strongbolt::Configuration.access_denied do |user, instance, action, request_path|
|
53
49
|
block.call user, instance, action, request_path
|
@@ -58,22 +54,19 @@ describe Strongbolt do
|
|
58
54
|
it "should call configuration's block" do
|
59
55
|
Strongbolt.access_denied 'user', 'instance', 'action', 'request_path'
|
60
56
|
end
|
61
|
-
|
62
57
|
end
|
63
58
|
|
64
|
-
|
65
|
-
|
66
59
|
#
|
67
60
|
# Without authorization
|
68
61
|
#
|
69
|
-
describe
|
70
|
-
it
|
62
|
+
describe 'without_authorization' do
|
63
|
+
it 'should not perform authorization' do
|
71
64
|
Strongbolt.without_authorization do
|
72
65
|
expect(Grant::Status.grant_disabled?).to eq true
|
73
66
|
end
|
74
67
|
end
|
75
68
|
|
76
|
-
describe
|
69
|
+
describe 'perform action' do
|
77
70
|
before do
|
78
71
|
@user = User.create!
|
79
72
|
Strongbolt.current_user = User.create!
|
@@ -83,73 +76,71 @@ describe Strongbolt do
|
|
83
76
|
let(:user) { @user }
|
84
77
|
|
85
78
|
context 'with authorization' do
|
86
|
-
it
|
79
|
+
it 'should call user can? when normal' do
|
87
80
|
expect_any_instance_of(User).to receive(:can?)
|
88
81
|
.with(:find, user).and_return true
|
89
82
|
User.find user.id
|
90
83
|
end
|
91
84
|
end
|
92
85
|
|
93
|
-
context
|
94
|
-
it
|
86
|
+
context 'when without_authorization' do
|
87
|
+
it 'should not call can?' do
|
95
88
|
Strongbolt.without_authorization do
|
96
89
|
expect_any_instance_of(User).not_to receive(:can?)
|
97
|
-
expect(User.find
|
90
|
+
expect(User.find(user.id)).to eq user
|
98
91
|
end
|
99
92
|
end
|
100
93
|
end
|
101
94
|
end
|
102
95
|
end
|
103
96
|
|
104
|
-
|
105
97
|
#
|
106
98
|
# Perform without authorization
|
107
99
|
#
|
108
|
-
describe
|
100
|
+
describe 'perform_without_authorization' do
|
109
101
|
before do
|
110
|
-
define(
|
111
|
-
def method
|
102
|
+
define('AnyClass', Object) do
|
103
|
+
def method(_arg1, _arg2)
|
112
104
|
raise StandardError if Grant::Status.grant_enabled?
|
113
105
|
end
|
114
106
|
end
|
115
107
|
end
|
116
108
|
|
117
|
-
context
|
118
|
-
it
|
109
|
+
context 'when not skipped' do
|
110
|
+
it 'should raise error' do
|
119
111
|
expect do
|
120
|
-
AnyClass.new.method(
|
112
|
+
AnyClass.new.method('ok', 'ok2') {}
|
121
113
|
end.to raise_error(StandardError)
|
122
114
|
end
|
123
115
|
end
|
124
116
|
|
125
|
-
context
|
117
|
+
context 'when skipped' do
|
126
118
|
before { AnyClass.perform_without_authorization :method }
|
127
119
|
|
128
|
-
it
|
120
|
+
it 'should skip authorization' do
|
129
121
|
expect do
|
130
|
-
AnyClass.new.method(
|
122
|
+
AnyClass.new.method('ok', 'ok2') {}
|
131
123
|
end.not_to raise_error
|
132
124
|
end
|
133
125
|
end
|
134
126
|
end
|
135
127
|
|
136
|
-
|
137
128
|
#
|
138
129
|
# Disable, enable
|
139
130
|
#
|
140
|
-
describe
|
131
|
+
describe 'disable/enable' do
|
141
132
|
before { Strongbolt.disable_authorization }
|
142
133
|
after { Strongbolt.enable_authorization }
|
143
134
|
|
144
|
-
context
|
145
|
-
it
|
135
|
+
context 'disabling' do
|
136
|
+
it 'should disable Grant' do
|
146
137
|
expect(Grant::Status.grant_enabled?).to eq false
|
147
138
|
expect(Strongbolt.enabled?).to eq false
|
148
139
|
end
|
149
140
|
end
|
150
141
|
|
151
|
-
context
|
152
|
-
it
|
142
|
+
context 'enabling' do
|
143
|
+
it 'should enable Grant' do
|
153
144
|
Strongbolt.enable_authorization
|
154
145
|
expect(Grant::Status.grant_disabled?).to eq false
|
155
146
|
expect(Strongbolt.disabled?).to eq false
|
@@ -157,34 +148,30 @@ describe Strongbolt do
|
|
157
148
|
end
|
158
149
|
end
|
159
150
|
|
160
|
-
|
161
|
-
|
162
151
|
#
|
163
152
|
# Setting the Grant user
|
164
153
|
#
|
165
154
|
describe 'setting the current user' do
|
166
|
-
|
167
|
-
context "when it is from the same class then defined (or default)" do
|
168
|
-
|
155
|
+
context 'when it is from the same class then defined (or default)' do
|
169
156
|
context "when the model doesn't have the module UserAbilities included" do
|
170
157
|
before do
|
171
|
-
define_model
|
158
|
+
define_model 'UserWithout' do
|
172
159
|
self.table_name = 'users'
|
173
160
|
end
|
174
161
|
|
175
162
|
# We configure the user class
|
176
163
|
Strongbolt::Configuration.user_class = 'UserWithout'
|
177
164
|
end
|
178
|
-
after { undefine_model
|
165
|
+
after { undefine_model 'UserWithout' }
|
179
166
|
|
180
167
|
let(:user) { UserWithout.new }
|
181
168
|
|
182
|
-
it
|
169
|
+
it 'should have included the module' do
|
183
170
|
Strongbolt.current_user = user
|
184
171
|
expect(UserWithout.included_modules).to include Strongbolt::UserAbilities
|
185
172
|
end
|
186
173
|
|
187
|
-
it
|
174
|
+
it 'should set the current user' do
|
188
175
|
Strongbolt.current_user = user
|
189
176
|
expect(Strongbolt.current_user).to eq user
|
190
177
|
expect(Grant::User.current_user).to eq user
|
@@ -192,9 +179,8 @@ describe Strongbolt do
|
|
192
179
|
end # End when User Class doesn't have the UserAbilities included
|
193
180
|
|
194
181
|
context 'when the model has the UserAbilities module included' do
|
195
|
-
|
196
182
|
before do
|
197
|
-
define_model
|
183
|
+
define_model 'UserWithAbilities' do
|
198
184
|
include Strongbolt::UserAbilities
|
199
185
|
self.table_name = 'users'
|
200
186
|
end
|
@@ -202,73 +188,67 @@ describe Strongbolt do
|
|
202
188
|
# We configure the user class
|
203
189
|
Strongbolt::Configuration.user_class = 'UserWithAbilities'
|
204
190
|
end
|
205
|
-
after { undefine_model
|
191
|
+
after { undefine_model 'UserWithAbilities' }
|
206
192
|
|
207
193
|
let(:user) { UserWithAbilities.new }
|
208
194
|
|
209
|
-
it
|
195
|
+
it 'should set the current user' do
|
210
196
|
Strongbolt.current_user = user
|
211
197
|
expect(Strongbolt.current_user).to eq user
|
212
198
|
expect(Grant::User.current_user).to eq user
|
213
199
|
end
|
214
|
-
|
215
200
|
end # End when User class has Abilities
|
216
201
|
|
217
|
-
context
|
202
|
+
context 'when the user model is the base class of a STI' do
|
218
203
|
before do
|
219
|
-
define_model
|
204
|
+
define_model 'BaseUser' do
|
220
205
|
self.table_name = 'users'
|
221
206
|
end
|
222
|
-
define
|
207
|
+
define 'UserWithSTI', BaseUser do
|
223
208
|
end
|
224
209
|
Strongbolt::Configuration.user_class = 'BaseUser'
|
225
210
|
end
|
226
211
|
|
227
212
|
let(:user) { UserWithSTI.new }
|
228
213
|
|
229
|
-
it
|
214
|
+
it 'should allow setting as user a subclass' do
|
230
215
|
Strongbolt.current_user = user
|
231
216
|
expect(Strongbolt.current_user).to eq user
|
232
217
|
end
|
233
|
-
end
|
218
|
+
end # / end when user model is the base class of a STI
|
234
219
|
|
235
|
-
context
|
220
|
+
context 'when the user model is a subclass of a STI' do
|
236
221
|
before do
|
237
|
-
define_model
|
222
|
+
define_model 'BaseUser' do
|
238
223
|
self.table_name = 'users'
|
239
224
|
end
|
240
|
-
define
|
225
|
+
define 'UserWithSTI', BaseUser do
|
241
226
|
end
|
242
|
-
Strongbolt::Configuration.user_class =
|
227
|
+
Strongbolt::Configuration.user_class = 'UserWithSTI'
|
243
228
|
end
|
244
229
|
|
245
230
|
let(:user) { UserWithSTI.new }
|
246
231
|
|
247
|
-
it
|
232
|
+
it 'should allow setting as user a subclass' do
|
248
233
|
Strongbolt.current_user = user
|
249
234
|
expect(Strongbolt.current_user).to eq user
|
250
235
|
end
|
251
236
|
|
252
|
-
it
|
237
|
+
it 'should not allos the base class' do
|
253
238
|
expect do
|
254
239
|
Strongbolt.current_user = BaseUser.new
|
255
240
|
end.to raise_error Strongbolt::WrongUserClass
|
256
241
|
end
|
257
|
-
end
|
258
|
-
|
242
|
+
end # / end when user model is the base class of a STI
|
259
243
|
end # End when user given is the right class
|
260
244
|
|
261
245
|
context "when the model isn't from the user class" do
|
262
|
-
|
263
|
-
it "should raise error" do
|
246
|
+
it 'should raise error' do
|
264
247
|
Strongbolt::Configuration.user_class = 'User'
|
265
248
|
expect do
|
266
249
|
Strongbolt.current_user = Model.new
|
267
250
|
end.to raise_error Strongbolt::WrongUserClass
|
268
251
|
end
|
269
|
-
|
270
252
|
end
|
271
|
-
|
272
253
|
end
|
273
|
-
|
274
254
|
end
|
data/spec/support/db_setup.rb
CHANGED
@@ -6,12 +6,12 @@ FileUtils.mkdir(tmpdir) unless File.exist?(tmpdir)
|
|
6
6
|
test_db = File.join(tmpdir, 'test.db')
|
7
7
|
|
8
8
|
connection_spec = {
|
9
|
-
:
|
10
|
-
:
|
9
|
+
adapter: 'sqlite3',
|
10
|
+
database: test_db
|
11
11
|
}
|
12
12
|
|
13
13
|
# Delete any existing instance of the test database
|
14
|
-
FileUtils.rm test_db, :
|
14
|
+
FileUtils.rm test_db, force: true
|
15
15
|
|
16
16
|
# Create a new test database
|
17
17
|
ActiveRecord::Base.establish_connection(connection_spec)
|
@@ -20,13 +20,13 @@ ActiveRecord::Base.establish_connection(connection_spec)
|
|
20
20
|
|
21
21
|
class TestsMigrations < ActiveRecord::Migration
|
22
22
|
def change
|
23
|
-
create_table :users, :
|
23
|
+
create_table :users, force: true do |t|
|
24
24
|
t.string :username
|
25
25
|
|
26
26
|
t.timestamps
|
27
27
|
end
|
28
28
|
|
29
|
-
create_table :models, :
|
29
|
+
create_table :models, force: true do |t|
|
30
30
|
t.string :name
|
31
31
|
t.string :value
|
32
32
|
t.integer :user_id
|
@@ -35,7 +35,7 @@ class TestsMigrations < ActiveRecord::Migration
|
|
35
35
|
t.timestamps
|
36
36
|
end
|
37
37
|
|
38
|
-
create_table :child_models, :
|
38
|
+
create_table :child_models, force: true do |t|
|
39
39
|
t.integer :model_id
|
40
40
|
t.string :model_type
|
41
41
|
t.integer :parent_id
|
@@ -43,31 +43,40 @@ class TestsMigrations < ActiveRecord::Migration
|
|
43
43
|
t.timestamps
|
44
44
|
end
|
45
45
|
|
46
|
-
create_table :
|
46
|
+
create_table :other_child_models, force: true do |t|
|
47
|
+
t.integer :model_id
|
48
|
+
t.string :model_type
|
49
|
+
t.integer :other_model_id
|
50
|
+
t.string :other_model_type
|
51
|
+
|
52
|
+
t.timestamps
|
53
|
+
end
|
54
|
+
|
55
|
+
create_table :unowned_models, force: true do |t|
|
47
56
|
t.string :name
|
48
57
|
t.string :value
|
49
58
|
|
50
59
|
t.timestamps
|
51
60
|
end
|
52
61
|
|
53
|
-
create_table :model_models, :
|
62
|
+
create_table :model_models, force: true do |t|
|
54
63
|
t.integer :parent_id
|
55
64
|
t.integer :child_id
|
56
65
|
end
|
57
66
|
|
58
|
-
create_table :tenant_a, :
|
67
|
+
create_table :tenant_a, force: true do |t|
|
59
68
|
t.string :name
|
60
69
|
|
61
70
|
t.timestamps
|
62
71
|
end
|
63
72
|
|
64
|
-
create_table :tenant_b, :
|
73
|
+
create_table :tenant_b, force: true do |t|
|
65
74
|
t.string :name
|
66
75
|
|
67
76
|
t.timestamps
|
68
77
|
end
|
69
78
|
|
70
|
-
create_table :model_with_tenants, :
|
79
|
+
create_table :model_with_tenants, force: true do |t|
|
71
80
|
t.string :name
|
72
81
|
t.integer :tenant_a_id
|
73
82
|
t.integer :tenant_b_id
|
@@ -75,19 +84,19 @@ class TestsMigrations < ActiveRecord::Migration
|
|
75
84
|
t.timestamps
|
76
85
|
end
|
77
86
|
|
78
|
-
create_table :strongbolt_capabilities, :
|
87
|
+
create_table :strongbolt_capabilities, force: true do |t|
|
79
88
|
t.string :name
|
80
89
|
t.string :description
|
81
90
|
t.string :model
|
82
91
|
t.string :action
|
83
92
|
t.string :attr
|
84
|
-
t.boolean :require_ownership, :
|
85
|
-
t.boolean :require_tenant_access, :
|
93
|
+
t.boolean :require_ownership, default: false, null: false
|
94
|
+
t.boolean :require_tenant_access, default: true, null: false
|
86
95
|
|
87
96
|
t.timestamps
|
88
97
|
end
|
89
98
|
|
90
|
-
create_table :strongbolt_roles, :
|
99
|
+
create_table :strongbolt_roles, force: true do |t|
|
91
100
|
t.string :name
|
92
101
|
t.integer :parent_id
|
93
102
|
t.integer :lft
|
@@ -97,29 +106,29 @@ class TestsMigrations < ActiveRecord::Migration
|
|
97
106
|
t.timestamps
|
98
107
|
end
|
99
108
|
|
100
|
-
create_table :strongbolt_user_groups, :
|
109
|
+
create_table :strongbolt_user_groups, force: true do |t|
|
101
110
|
t.string :name
|
102
111
|
t.text :description
|
103
112
|
|
104
113
|
t.timestamps
|
105
114
|
end
|
106
115
|
|
107
|
-
create_table :strongbolt_user_groups_users, :
|
116
|
+
create_table :strongbolt_user_groups_users, force: true do |t|
|
108
117
|
t.integer :user_group_id
|
109
118
|
t.integer :user_id
|
110
119
|
end
|
111
120
|
|
112
|
-
create_table :strongbolt_roles_user_groups, :
|
121
|
+
create_table :strongbolt_roles_user_groups, force: true do |t|
|
113
122
|
t.integer :user_group_id
|
114
123
|
t.integer :role_id
|
115
124
|
end
|
116
125
|
|
117
|
-
create_table :strongbolt_capabilities_roles, :
|
126
|
+
create_table :strongbolt_capabilities_roles, force: true do |t|
|
118
127
|
t.integer :role_id
|
119
128
|
t.integer :capability_id
|
120
129
|
end
|
121
130
|
|
122
|
-
create_table :strongbolt_users_tenants, :
|
131
|
+
create_table :strongbolt_users_tenants, force: true do |t|
|
123
132
|
t.integer :user_id
|
124
133
|
t.integer :tenant_id
|
125
134
|
t.string :type
|
@@ -142,15 +151,12 @@ class TestsMigrations < ActiveRecord::Migration
|
|
142
151
|
add_index :strongbolt_users_tenants, :user_id
|
143
152
|
add_index :strongbolt_users_tenants, :tenant_id
|
144
153
|
add_index :strongbolt_users_tenants, :type
|
145
|
-
add_index :strongbolt_users_tenants, [
|
154
|
+
add_index :strongbolt_users_tenants, %i[tenant_id type]
|
146
155
|
|
147
|
-
add_index :strongbolt_user_groups_users, [
|
156
|
+
add_index :strongbolt_user_groups_users, %i[user_group_id user_id], unique: true, name: :index_strongbolt_user_groups_users_unique
|
148
157
|
end
|
149
158
|
end
|
150
159
|
|
151
160
|
class User < ActiveRecord::Base; end
|
152
161
|
class Model < ActiveRecord::Base; end
|
153
162
|
class UnownedModel < ActiveRecord::Base; end
|
154
|
-
|
155
|
-
|
156
|
-
|