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
ccd8cb79
Commit
ccd8cb79
authored
Jan 25, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add approval rule policies
Only allow updating if user can update project/MR
parent
08a35292
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
0 deletions
+76
-0
ee/app/policies/approval_merge_request_rule_policy.rb
ee/app/policies/approval_merge_request_rule_policy.rb
+11
-0
ee/app/policies/approval_project_rule_policy.rb
ee/app/policies/approval_project_rule_policy.rb
+11
-0
ee/spec/policies/approval_merge_request_rule_policy_spec.rb
ee/spec/policies/approval_merge_request_rule_policy_spec.rb
+24
-0
ee/spec/policies/approval_project_rule_policy_spec.rb
ee/spec/policies/approval_project_rule_policy_spec.rb
+30
-0
No files found.
ee/app/policies/approval_merge_request_rule_policy.rb
0 → 100644
View file @
ccd8cb79
# frozen_string_literal: true
class
ApprovalMergeRequestRulePolicy
<
BasePolicy
delegate
{
@subject
.
merge_request
}
condition
(
:editable
)
do
can?
(
:update_merge_request
,
@subject
.
merge_request
)
end
rule
{
editable
}.
enable
:edit_approval_rule
end
ee/app/policies/approval_project_rule_policy.rb
0 → 100644
View file @
ccd8cb79
# frozen_string_literal: true
class
ApprovalProjectRulePolicy
<
BasePolicy
delegate
{
@subject
.
project
}
condition
(
:editable
)
do
can?
(
:admin_project
,
@subject
.
project
)
end
rule
{
editable
}.
enable
:edit_approval_rule
end
ee/spec/policies/approval_merge_request_rule_policy_spec.rb
0 → 100644
View file @
ccd8cb79
# frozen_string_literal: true
require
'spec_helper'
describe
ApprovalMergeRequestRulePolicy
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let!
(
:approval_rule
)
{
create
(
:approval_merge_request_rule
,
merge_request:
merge_request
)
}
def
permissions
(
user
,
approval_rule
)
described_class
.
new
(
user
,
approval_rule
)
end
context
'when user can update merge request'
do
it
'allows updating approval rule'
do
expect
(
permissions
(
merge_request
.
author
,
approval_rule
)).
to
be_allowed
(
:edit_approval_rule
)
end
end
context
'when user cannot update merge request'
do
it
'disallow updating approval rule'
do
expect
(
permissions
(
create
(
:user
),
approval_rule
)).
to
be_disallowed
(
:edit_approval_rule
)
end
end
end
ee/spec/policies/approval_project_rule_policy_spec.rb
0 → 100644
View file @
ccd8cb79
# frozen_string_literal: true
require
'spec_helper'
describe
ApprovalProjectRulePolicy
do
let
(
:project
)
{
create
(
:project
)
}
let!
(
:approval_rule
)
{
create
(
:approval_project_rule
,
project:
project
)
}
def
permissions
(
user
,
approval_rule
)
described_class
.
new
(
user
,
approval_rule
)
end
context
'when user can admin project'
do
it
'allows updating approval rule'
do
expect
(
permissions
(
project
.
creator
,
approval_rule
)).
to
be_allowed
(
:edit_approval_rule
)
end
end
context
'when user cannot admin project'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_developer
(
user
)
end
it
'disallow updating approval rule'
do
expect
(
permissions
(
user
,
approval_rule
)).
to
be_disallowed
(
:edit_approval_rule
)
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