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
72a518fe
Commit
72a518fe
authored
Sep 28, 2020
by
Gary Holtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using a method that was already there to simplify comparison
Also cleaning up the migration stubbed classes per review
parent
9d12db03
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
62 deletions
+15
-62
ee/app/models/approval_merge_request_rule.rb
ee/app/models/approval_merge_request_rule.rb
+1
-26
ee/spec/lib/ee/gitlab/usage_data_spec.rb
ee/spec/lib/ee/gitlab/usage_data_spec.rb
+2
-2
ee/spec/models/approval_merge_request_rule_spec.rb
ee/spec/models/approval_merge_request_rule_spec.rb
+0
-26
lib/gitlab/background_migration/add_modified_to_approval_merge_request_rule.rb
..._migration/add_modified_to_approval_merge_request_rule.rb
+12
-8
No files found.
ee/app/models/approval_merge_request_rule.rb
View file @
72a518fe
...
...
@@ -131,35 +131,10 @@ class ApprovalMergeRequestRule < ApplicationRecord
refresh_license_scanning_approvals
(
project_approval_rule
)
if
license_scanning?
end
def
different_from_project_rule?
return
unless
approval_project_rule
different_groups?
||
different_users?
||
different_name_or_approvals_required?
?
true
:
false
end
private
def
different_groups?
group_ids
=
groups
.
collect
(
&
:id
)
apr_group_ids
=
approval_project_rule
.
groups
.
pluck
(
:id
)
group_ids
&
apr_group_ids
==
group_ids
end
def
different_users?
user_ids
=
users
.
collect
(
&
:id
)
apr_user_ids
=
approval_project_rule
.
users
.
pluck
(
:id
)
user_ids
&
apr_user_ids
==
user_ids
end
def
different_name_or_approvals_required?
true
if
approvals_required
!=
approval_project_rule
.
approvals_required
||
name
!=
approval_project_rule
.
name
end
def
compare_with_project_rule
self
.
modified_from_project_rule
=
different_from_project_rule?
?
true
:
false
self
.
modified_from_project_rule
=
overridden?
?
true
:
false
end
def
validate_approval_project_rule
...
...
ee/spec/lib/ee/gitlab/usage_data_spec.rb
View file @
72a518fe
...
...
@@ -321,7 +321,7 @@ RSpec.describe Gitlab::UsageData do
end
expect
(
described_class
.
usage_activity_by_stage_create
({})).
to
include
(
approval_project_rules:
8
,
approval_project_rules:
10
,
approval_project_rules_with_target_branch:
2
,
approval_project_rules_with_more_approvers_than_required:
2
,
approval_project_rules_with_less_approvers_than_required:
2
,
...
...
@@ -342,7 +342,7 @@ RSpec.describe Gitlab::UsageData do
total_number_of_locked_files:
14
)
expect
(
described_class
.
usage_activity_by_stage_create
(
described_class
.
last_28_days_time_period
)).
to
include
(
approval_project_rules:
8
,
approval_project_rules:
10
,
approval_project_rules_with_target_branch:
2
,
approval_project_rules_with_more_approvers_than_required:
2
,
approval_project_rules_with_less_approvers_than_required:
2
,
...
...
ee/spec/models/approval_merge_request_rule_spec.rb
View file @
72a518fe
...
...
@@ -36,32 +36,6 @@ RSpec.describe ApprovalMergeRequestRule do
it
'is valid'
do
expect
(
merge_request_rule
).
to
be_valid
end
context
'the MR rule shows that its modified from the original'
do
it
'by having different groups'
do
first_group
=
create
(
:group
)
second_group
=
create
(
:group
)
third_group
=
create
(
:group
)
approval_project_rule
.
groups
=
[
first_group
,
second_group
]
approval_project_rule
.
save!
merge_request_rule
.
groups
=
[
first_group
,
third_group
]
expect
(
merge_request_rule
.
different_from_project_rule?
).
to
be
true
end
it
'by having different users'
do
first_user
=
create
(
:user
)
second_user
=
create
(
:user
)
third_user
=
create
(
:user
)
approval_project_rule
.
users
=
[
first_user
,
second_user
]
approval_project_rule
.
save!
merge_request_rule
.
users
=
[
first_user
,
third_user
]
expect
(
merge_request_rule
.
different_from_project_rule?
).
to
be
true
end
end
end
context
'when the project of approval_project_rule and merge request does not match'
do
...
...
lib/gitlab/background_migration/add_modified_to_approval_merge_request_rule.rb
View file @
72a518fe
...
...
@@ -4,33 +4,37 @@ module Gitlab
module
BackgroundMigration
# Compare all current rules to project rules
class
AddModifiedToApprovalMergeRequestRule
# Stubbed class to access the Group table
class
Group
<
ActiveRecord
::
Base
self
.
table_name
=
'namespaces'
self
.
inheritance_column
=
:_type_disabled
end
# Stubbed class to access the ApprovalMergeRequestRule table
class
ApprovalMergeRequestRule
<
ActiveRecord
::
Base
self
.
table_name
=
'approval_merge_request_rules'
has_one
:approval_merge_request_rule_source
has_one
:approval_merge_request_rule_source
,
class_name:
'AddModifiedToApprovalMergeRequestRule::ApprovalMergeRequestRuleSource'
has_one
:approval_project_rule
,
through: :approval_merge_request_rule_source
has_and_belongs_to_many
:users
has_and_belongs_to_many
:groups
,
class_name:
'Group'
,
join_table:
"
#{
self
.
table_name
}
_groups"
class_name:
'
AddModifiedToApprovalMergeRequestRule::
Group'
,
join_table:
"
#{
self
.
table_name
}
_groups"
end
# Stubbed class to access the ApprovalProjectRule table
class
ApprovalProjectRule
<
ActiveRecord
::
Base
self
.
table_name
=
'approval_project_rules'
has_many
:approval_merge_request_rule_sources
has_and_belongs_to_many
:users
has_many
:approval_merge_request_rule_sources
,
class_name:
'AddModifiedToApprovalMergeRequestRule::ApprovalMergeRequestRuleSource'
has_and_belongs_to_many
:groups
,
class_name:
'Group'
,
join_table:
"
#{
self
.
table_name
}
_groups"
class_name:
'
AddModifiedToApprovalMergeRequestRule::
Group'
,
join_table:
"
#{
self
.
table_name
}
_groups"
end
# Stubbed class to access the ApprovalMergeRequestRuleSource table
class
ApprovalMergeRequestRuleSource
<
ActiveRecord
::
Base
self
.
table_name
=
'approval_merge_request_rule_sources'
belongs_to
:approval_merge_request_rule
belongs_to
:approval_project_rule
belongs_to
:approval_merge_request_rule
,
class_name:
'AddModifiedToApprovalMergeRequestRule::ApprovalMergeRequestRule'
belongs_to
:approval_project_rule
,
class_name:
'AddModifiedToApprovalMergeRequestRule::ApprovalProjectRule'
end
def
perform
(
start_id
,
stop_id
)
...
...
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