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
c7df1373
Commit
c7df1373
authored
Jul 16, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename has_approved? methods to approved_by?
Remove duplicated definitions of the method as well
parent
59b0dcc4
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
11 additions
and
44 deletions
+11
-44
app/models/concerns/approvable_base.rb
app/models/concerns/approvable_base.rb
+1
-1
app/services/merge_requests/remove_approval_service.rb
app/services/merge_requests/remove_approval_service.rb
+1
-1
ee/app/controllers/ee/projects/merge_requests_controller.rb
ee/app/controllers/ee/projects/merge_requests_controller.rb
+1
-1
ee/app/models/approval_state.rb
ee/app/models/approval_state.rb
+0
-6
ee/app/models/concerns/approvable.rb
ee/app/models/concerns/approvable.rb
+0
-1
ee/app/views/projects/merge_requests/_approvals_count.html.haml
.../views/projects/merge_requests/_approvals_count.html.haml
+1
-1
ee/lib/ee/api/entities/approval_state.rb
ee/lib/ee/api/entities/approval_state.rb
+1
-1
ee/spec/models/approval_state_spec.rb
ee/spec/models/approval_state_spec.rb
+2
-28
lib/api/entities/merge_request_approvals.rb
lib/api/entities/merge_request_approvals.rb
+2
-2
spec/models/concerns/approvable_base_spec.rb
spec/models/concerns/approvable_base_spec.rb
+2
-2
No files found.
app/models/concerns/approvable_base.rb
View file @
c7df1373
...
@@ -8,7 +8,7 @@ module ApprovableBase
...
@@ -8,7 +8,7 @@ module ApprovableBase
has_many
:approved_by_users
,
through: :approvals
,
source: :user
has_many
:approved_by_users
,
through: :approvals
,
source: :user
end
end
def
has_approved
?
(
user
)
def
approved_by
?
(
user
)
return
false
unless
user
return
false
unless
user
approved_by_users
.
include?
(
user
)
approved_by_users
.
include?
(
user
)
...
...
app/services/merge_requests/remove_approval_service.rb
View file @
c7df1373
...
@@ -4,7 +4,7 @@ module MergeRequests
...
@@ -4,7 +4,7 @@ module MergeRequests
class
RemoveApprovalService
<
MergeRequests
::
BaseService
class
RemoveApprovalService
<
MergeRequests
::
BaseService
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
execute
(
merge_request
)
def
execute
(
merge_request
)
return
unless
merge_request
.
has_approved
?
(
current_user
)
return
unless
merge_request
.
approved_by
?
(
current_user
)
# paranoid protection against running wrong deletes
# paranoid protection against running wrong deletes
return
unless
merge_request
.
id
&&
current_user
.
id
return
unless
merge_request
.
id
&&
current_user
.
id
...
...
ee/app/controllers/ee/projects/merge_requests_controller.rb
View file @
c7df1373
...
@@ -45,7 +45,7 @@ module EE
...
@@ -45,7 +45,7 @@ module EE
end
end
def
unapprove
def
unapprove
if
merge_request
.
has_approved
?
(
current_user
)
if
merge_request
.
approved_by
?
(
current_user
)
::
MergeRequests
::
RemoveApprovalService
::
MergeRequests
::
RemoveApprovalService
.
new
(
project
,
current_user
)
.
new
(
project
,
current_user
)
.
execute
(
merge_request
)
.
execute
(
merge_request
)
...
...
ee/app/models/approval_state.rb
View file @
c7df1373
...
@@ -128,12 +128,6 @@ class ApprovalState
...
@@ -128,12 +128,6 @@ class ApprovalState
true
true
end
end
def
has_approved?
(
user
)
return
false
unless
user
approved_approvers
.
include?
(
user
)
end
def
authors_can_approve?
def
authors_can_approve?
project
.
merge_requests_author_approval?
project
.
merge_requests_author_approval?
end
end
...
...
ee/app/models/concerns/approvable.rb
View file @
c7df1373
...
@@ -13,7 +13,6 @@ module Approvable
...
@@ -13,7 +13,6 @@ module Approvable
approvals_left
approvals_left
approvals_required
approvals_required
can_approve?
can_approve?
has_approved?
authors_can_approve?
authors_can_approve?
committers_can_approve?
committers_can_approve?
approvers_overwritten?
approvers_overwritten?
...
...
ee/app/views/projects/merge_requests/_approvals_count.html.haml
View file @
c7df1373
-
if
merge_request
.
approval_needed?
-
if
merge_request
.
approval_needed?
-
approved
=
merge_request
.
approved?
-
approved
=
merge_request
.
approved?
-
self_approved
=
merge_request
.
has_approved
?
(
current_user
)
-
self_approved
=
merge_request
.
approved_by
?
(
current_user
)
-
given
=
merge_request
.
approvals_given
-
given
=
merge_request
.
approvals_given
-
total
=
merge_request
.
total_approvals_count
-
total
=
merge_request
.
total_approvals_count
...
...
ee/lib/ee/api/entities/approval_state.rb
View file @
c7df1373
...
@@ -51,7 +51,7 @@ module EE
...
@@ -51,7 +51,7 @@ module EE
end
end
expose
:user_has_approved
do
|
approval_state
,
options
|
expose
:user_has_approved
do
|
approval_state
,
options
|
approval_state
.
has_approved
?
(
options
[
:current_user
])
approval_state
.
merge_request
.
approved_by
?
(
options
[
:current_user
])
end
end
expose
:user_can_approve
do
|
approval_state
,
options
|
expose
:user_can_approve
do
|
approval_state
,
options
|
...
...
ee/spec/models/approval_state_spec.rb
View file @
c7df1373
...
@@ -744,7 +744,7 @@ RSpec.describe ApprovalState do
...
@@ -744,7 +744,7 @@ RSpec.describe ApprovalState do
end
end
it
'requires 1 approval'
do
it
'requires 1 approval'
do
expect
(
subject
.
has_approved
?
(
approver
)).
to
eq
(
true
)
expect
(
merge_request
.
approved_by
?
(
approver
)).
to
eq
(
true
)
expect
(
subject
.
approvals_left
).
to
eq
(
1
)
expect
(
subject
.
approvals_left
).
to
eq
(
1
)
end
end
...
@@ -754,7 +754,7 @@ RSpec.describe ApprovalState do
...
@@ -754,7 +754,7 @@ RSpec.describe ApprovalState do
end
end
it
'becomes approved'
do
it
'becomes approved'
do
expect
(
subject
.
has_approved
?
(
approver1
)).
to
eq
(
true
)
expect
(
merge_request
.
approved_by
?
(
approver1
)).
to
eq
(
true
)
expect
(
subject
.
approved?
).
to
eq
(
true
)
expect
(
subject
.
approved?
).
to
eq
(
true
)
end
end
end
end
...
@@ -762,19 +762,6 @@ RSpec.describe ApprovalState do
...
@@ -762,19 +762,6 @@ RSpec.describe ApprovalState do
end
end
end
end
describe
'#has_approved?'
do
it
'returns false if user is nil'
do
expect
(
subject
.
has_approved?
(
nil
)).
to
eq
(
false
)
end
it
'returns true if user has approved'
do
create
(
:approval
,
merge_request:
merge_request
,
user:
approver1
)
expect
(
subject
.
has_approved?
(
approver1
)).
to
eq
(
true
)
expect
(
subject
.
has_approved?
(
approver2
)).
to
eq
(
false
)
end
end
describe
'#authors_can_approve?'
do
describe
'#authors_can_approve?'
do
context
'when project allows author approval'
do
context
'when project allows author approval'
do
before
do
before
do
...
@@ -1353,19 +1340,6 @@ RSpec.describe ApprovalState do
...
@@ -1353,19 +1340,6 @@ RSpec.describe ApprovalState do
end
end
end
end
describe
'#has_approved?'
do
it
'returns false if user is nil'
do
expect
(
subject
.
has_approved?
(
nil
)).
to
eq
(
false
)
end
it
'returns true if user has approved'
do
create
(
:approval
,
merge_request:
merge_request
,
user:
approver1
)
expect
(
subject
.
has_approved?
(
approver1
)).
to
eq
(
true
)
expect
(
subject
.
has_approved?
(
approver2
)).
to
eq
(
false
)
end
end
describe
'#authors_can_approve?'
do
describe
'#authors_can_approve?'
do
context
'when project allows author approval'
do
context
'when project allows author approval'
do
before
do
before
do
...
...
lib/api/entities/merge_request_approvals.rb
View file @
c7df1373
...
@@ -4,11 +4,11 @@ module API
...
@@ -4,11 +4,11 @@ module API
module
Entities
module
Entities
class
MergeRequestApprovals
<
Grape
::
Entity
class
MergeRequestApprovals
<
Grape
::
Entity
expose
:user_has_approved
do
|
merge_request
,
options
|
expose
:user_has_approved
do
|
merge_request
,
options
|
merge_request
.
has_approved
?
(
options
[
:current_user
])
merge_request
.
approved_by
?
(
options
[
:current_user
])
end
end
expose
:user_can_approve
do
|
merge_request
,
options
|
expose
:user_can_approve
do
|
merge_request
,
options
|
!
merge_request
.
has_approved
?
(
options
[
:current_user
])
&&
!
merge_request
.
approved_by
?
(
options
[
:current_user
])
&&
options
[
:current_user
].
can?
(
:approve_merge_request
,
merge_request
)
options
[
:current_user
].
can?
(
:approve_merge_request
,
merge_request
)
end
end
...
...
spec/models/concerns/approvable_base_spec.rb
View file @
c7df1373
...
@@ -3,11 +3,11 @@
...
@@ -3,11 +3,11 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
ApprovableBase
do
RSpec
.
describe
ApprovableBase
do
describe
'#
has_approved
?'
do
describe
'#
approved_by
?'
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
subject
{
merge_request
.
has_approved
?
(
user
)
}
subject
{
merge_request
.
approved_by
?
(
user
)
}
context
'when a user has not approved'
do
context
'when a user has not approved'
do
it
'returns false'
do
it
'returns false'
do
...
...
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