Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
380a73cc
Commit
380a73cc
authored
Oct 07, 2020
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for workers
Add new workers to queues Fix
parent
0b215f47
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
12 deletions
+57
-12
app/models/group.rb
app/models/group.rb
+1
-1
app/services/groups/update_service.rb
app/services/groups/update_service.rb
+3
-1
app/workers/all_queues.yml
app/workers/all_queues.yml
+16
-0
app/workers/disallow_two_fa_for_subgroups_worker.rb
app/workers/disallow_two_fa_for_subgroups_worker.rb
+1
-1
app/workers/disallow_two_fa_worker.rb
app/workers/disallow_two_fa_worker.rb
+6
-5
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+4
-0
spec/services/groups/update_service_spec.rb
spec/services/groups/update_service_spec.rb
+1
-1
spec/workers/disallow_two_fa_for_subgroups_worker_spec.rb
spec/workers/disallow_two_fa_for_subgroups_worker_spec.rb
+22
-0
spec/workers/disallow_two_fa_worker_spec.rb
spec/workers/disallow_two_fa_worker_spec.rb
+3
-3
No files found.
app/models/group.rb
View file @
380a73cc
...
...
@@ -564,7 +564,7 @@ class Group < Namespace
def
update_two_factor_requirement
return
unless
saved_change_to_require_two_factor_authentication?
||
saved_change_to_two_factor_grace_period?
binding
.
pry
members_with_descendants
.
find_each
(
&
:update_two_factor_requirement
)
end
...
...
app/services/groups/update_service.rb
View file @
380a73cc
...
...
@@ -22,7 +22,9 @@ module Groups
return
false
unless
valid_path_change_with_npm_packages?
return
false
unless
update_shared_runners
handle_changes
before_assignment_hook
(
group
,
params
)
handle_namespace_settings
...
...
@@ -101,7 +103,7 @@ module Groups
if
settings
.
previous_changes
.
include?
(
:allow_mfa_for_subgroups
)
# enque in batches members update
Disallow
2FA
Worker
.
perform_async
(
group
.
id
)
Disallow
TwoFa
Worker
.
perform_async
(
group
.
id
)
end
end
...
...
app/workers/all_queues.yml
View file @
380a73cc
...
...
@@ -1393,6 +1393,22 @@
:weight:
1
:idempotent:
:tags: []
-
:name: disallow_two_fa
:feature_category: :subgroups
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight:
1
:idempotent:
:tags: []
-
:name: disallow_two_fa_for_subgroups
:feature_category: :subgroups
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight:
1
:idempotent:
:tags: []
-
:name: email_receiver
:feature_category: :issue_tracking
:has_external_dependencies:
...
...
app/workers/disallow_
2
fa_for_subgroups_worker.rb
→
app/workers/disallow_
two_
fa_for_subgroups_worker.rb
View file @
380a73cc
# frozen_string_literal: true
class
Disallow
2FA
ForSubgroupsWorker
# rubocop:disable Scalability/IdempotentWorker
class
Disallow
TwoFa
ForSubgroupsWorker
# rubocop:disable Scalability/IdempotentWorker
include
ApplicationWorker
include
ExceptionBacktrace
...
...
app/workers/disallow_
2
fa_worker.rb
→
app/workers/disallow_
two_
fa_worker.rb
View file @
380a73cc
# frozen_string_literal: true
class
Disallow
2FA
Worker
# rubocop:disable Scalability/IdempotentWorker
class
Disallow
TwoFa
Worker
# rubocop:disable Scalability/IdempotentWorker
include
ApplicationWorker
include
ExceptionBacktrace
...
...
@@ -9,20 +9,21 @@ class Disallow2FAWorker # rubocop:disable Scalability/IdempotentWorker
feature_category
:subgroups
def
perform
(
group_id
)
binding
.
pry
begin
group
=
Group
.
find
(
group_id
)
rescue
ActiveRecord
::
RecordNotFound
return
end
subgroups
=
group
.
descendants
.
where
(
require_two_factor_authentication:
true
)
subgroups
.
find_each
(
batch_size:
100
).
with_index
do
|
subgroup
,
index
|
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
subgroups
=
group
.
descendants
.
where
(
require_two_factor_authentication:
true
)
# rubocop: disable CodeReuse/ActiveRecord
subgroups
.
find_each
(
batch_size:
100
).
with_index
do
|
subgroup
,
index
|
delay
=
index
*
INTERVAL
with_context
(
namespace:
subgroup
)
do
Disallow
2FA
ForSubgroupsWorker
.
perform_in
(
delay
,
subgroup
.
id
)
Disallow
TwoFa
ForSubgroupsWorker
.
perform_in
(
delay
,
subgroup
.
id
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
config/sidekiq_queues.yml
View file @
380a73cc
...
...
@@ -84,6 +84,10 @@
-
1
-
-
detect_repository_languages
-
1
-
-
disallow_two_fa
-
1
-
-
disallow_two_fa_for_subgroups
-
1
-
-
elastic_commit_indexer
-
1
-
-
elastic_delete_project
...
...
spec/services/groups/update_service_spec.rb
View file @
380a73cc
...
...
@@ -321,7 +321,7 @@ RSpec.describe Groups::UpdateService do
end
it
'enqueues update subgroups and its members'
do
expect
(
Disallow
2FA
Worker
).
to
receive
(
:perform_async
).
with
(
group
.
id
)
expect
(
Disallow
TwoFa
Worker
).
to
receive
(
:perform_async
).
with
(
group
.
id
)
subject
end
...
...
spec/workers/disallow_
2
fa_for_subgroups_worker_spec.rb
→
spec/workers/disallow_
two_
fa_for_subgroups_worker_spec.rb
View file @
380a73cc
...
...
@@ -2,11 +2,9 @@
require
'spec_helper'
RSpec
.
describe
Disallow
2FA
ForSubgroupsWorker
do
RSpec
.
describe
Disallow
TwoFa
ForSubgroupsWorker
do
let_it_be
(
:group
)
{
create
(
:group
,
require_two_factor_authentication:
true
)
}
let_it_be
(
:subgroup
)
{
create
(
:group
,
parent:
group
,
require_two_factor_authentication:
true
)
}
let_it_be
(
:user
)
{
create
(
:user
,
:two_factor
,
require_two_factor_authentication_from_group:
true
)
}
let_it_be
(
:user_for_subgroup
)
{
create
(
:user
,
:two_factor
,
require_two_factor_authentication_from_group:
true
)
}
let_it_be
(
:user
)
{
create
(
:user
,
require_two_factor_authentication_from_group:
true
)
}
it
"updates group"
do
described_class
.
new
.
perform
(
group
.
id
)
...
...
@@ -16,17 +14,9 @@ RSpec.describe Disallow2FAForSubgroupsWorker do
it
"updates group members"
do
group
.
add_user
(
user
,
GroupMember
::
DEVELOPER
)
binding
.
pry
described_class
.
new
.
perform
(
group
.
id
)
expect
(
user
.
reload
.
require_two_factor_authentication_from_group
).
to
eq
(
false
)
end
it
"updates descendant members"
do
subgroup
.
add_user
(
user_for_subgroup
,
GroupMember
::
DEVELOPER
)
described_class
.
new
.
perform
(
group
.
id
)
expect
(
user
_for_subgroup
.
reload
.
require_two_factor_authentication_from_group
).
to
eq
(
false
)
expect
(
user
.
reload
.
require_two_factor_authentication_from_group
).
to
eq
(
false
)
end
end
spec/workers/disallow_
2
fa_worker_spec.rb
→
spec/workers/disallow_
two_
fa_worker_spec.rb
View file @
380a73cc
...
...
@@ -2,15 +2,15 @@
require
'spec_helper'
RSpec
.
describe
Disallow
2FA
Worker
do
RSpec
.
describe
Disallow
TwoFa
Worker
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:subgroup_with_2fa
)
{
create
(
:group
,
parent:
group
,
require_two_factor_authentication:
true
)
}
let_it_be
(
:subgroup_without_2fa
)
{
create
(
:group
,
parent:
group
,
require_two_factor_authentication:
false
)
}
let_it_be
(
:subsubgroup_with_2fa
)
{
create
(
:group
,
parent:
subgroup_with_2fa
,
require_two_factor_authentication:
true
)
}
it
"schedules updating subgroups"
do
expect
(
Disallow
2FA
ForSubgroupsWorker
).
to
receive
(
:perform_in
).
with
(
0
,
subgroup_with_2fa
.
id
)
expect
(
Disallow
2FA
ForSubgroupsWorker
).
to
receive
(
:perform_in
).
with
(
2
,
subsubgroup_with_2fa
.
id
)
expect
(
Disallow
TwoFa
ForSubgroupsWorker
).
to
receive
(
:perform_in
).
with
(
0
,
subgroup_with_2fa
.
id
)
expect
(
Disallow
TwoFa
ForSubgroupsWorker
).
to
receive
(
:perform_in
).
with
(
2
,
subsubgroup_with_2fa
.
id
)
described_class
.
new
.
perform
(
group
.
id
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment