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
b740ff9a
Commit
b740ff9a
authored
Jul 17, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix merge request approvals for EE without license
Call FOSS method when EE doesn't have a license
parent
497620d5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
5 deletions
+53
-5
app/models/concerns/approvable_base.rb
app/models/concerns/approvable_base.rb
+4
-0
changelogs/unreleased/id-fix-approvals-for-ee-without-license.yml
...gs/unreleased/id-fix-approvals-for-ee-without-license.yml
+5
-0
ee/app/models/approval_state.rb
ee/app/models/approval_state.rb
+2
-0
ee/spec/models/approval_state_spec.rb
ee/spec/models/approval_state_spec.rb
+10
-0
lib/api/entities/merge_request_approvals.rb
lib/api/entities/merge_request_approvals.rb
+1
-2
spec/models/concerns/approvable_base_spec.rb
spec/models/concerns/approvable_base_spec.rb
+31
-3
No files found.
app/models/concerns/approvable_base.rb
View file @
b740ff9a
...
@@ -13,4 +13,8 @@ module ApprovableBase
...
@@ -13,4 +13,8 @@ module ApprovableBase
approved_by_users
.
include?
(
user
)
approved_by_users
.
include?
(
user
)
end
end
def
can_be_approved_by?
(
user
)
user
&&
!
approved_by?
(
user
)
&&
user
.
can?
(
:approve_merge_request
,
self
)
end
end
end
changelogs/unreleased/id-fix-approvals-for-ee-without-license.yml
0 → 100644
View file @
b740ff9a
---
title
:
Fix merge request approvals for EE without a license
merge_request
:
37246
author
:
type
:
fixed
ee/app/models/approval_state.rb
View file @
b740ff9a
...
@@ -114,6 +114,8 @@ class ApprovalState
...
@@ -114,6 +114,8 @@ class ApprovalState
end
end
def
can_approve?
(
user
)
def
can_approve?
(
user
)
return
merge_request
.
can_be_approved_by?
(
user
)
unless
merge_request
.
approval_feature_available?
return
false
unless
user
return
false
unless
user
return
false
unless
user
.
can?
(
:approve_merge_request
,
merge_request
)
return
false
unless
user
.
can?
(
:approve_merge_request
,
merge_request
)
...
...
ee/spec/models/approval_state_spec.rb
View file @
b740ff9a
...
@@ -760,6 +760,16 @@ RSpec.describe ApprovalState do
...
@@ -760,6 +760,16 @@ RSpec.describe ApprovalState do
end
end
end
end
end
end
context
'when approval feature is disabled'
do
it
'delegates the call to merge request'
do
stub_licensed_features
(
merge_request_approvers:
false
)
expect
(
merge_request
).
to
receive
(
:can_be_approved_by?
).
with
(
approver1
)
subject
.
can_approve?
(
approver1
)
end
end
end
end
describe
'#authors_can_approve?'
do
describe
'#authors_can_approve?'
do
...
...
lib/api/entities/merge_request_approvals.rb
View file @
b740ff9a
...
@@ -8,8 +8,7 @@ module API
...
@@ -8,8 +8,7 @@ module API
end
end
expose
:user_can_approve
do
|
merge_request
,
options
|
expose
:user_can_approve
do
|
merge_request
,
options
|
!
merge_request
.
approved_by?
(
options
[
:current_user
])
&&
merge_request
.
can_be_approved_by?
(
options
[
:current_user
])
options
[
:current_user
].
can?
(
:approve_merge_request
,
merge_request
)
end
end
expose
:approved
do
|
merge_request
|
expose
:approved
do
|
merge_request
|
...
...
spec/models/concerns/approvable_base_spec.rb
View file @
b740ff9a
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
ApprovableBase
do
RSpec
.
describe
ApprovableBase
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
)
}
describe
'#approved_by?'
do
subject
{
merge_request
.
approved_by?
(
user
)
}
subject
{
merge_request
.
approved_by?
(
user
)
}
context
'when a user has not approved'
do
context
'when a user has not approved'
do
...
@@ -31,4 +31,32 @@ RSpec.describe ApprovableBase do
...
@@ -31,4 +31,32 @@ RSpec.describe ApprovableBase do
end
end
end
end
end
end
describe
'#can_be_approved_by?'
do
subject
{
merge_request
.
can_be_approved_by?
(
user
)
}
before
do
merge_request
.
project
.
add_developer
(
user
)
end
it
'returns true'
do
is_expected
.
to
be_truthy
end
context
'when a user has approved'
do
let!
(
:approval
)
{
create
(
:approval
,
merge_request:
merge_request
,
user:
user
)
}
it
'returns false'
do
is_expected
.
to
be_falsy
end
end
context
'when a user is nil'
do
let
(
:user
)
{
nil
}
it
'returns false'
do
is_expected
.
to
be_falsy
end
end
end
end
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