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
8fd684b1
Commit
8fd684b1
authored
Jul 02, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent creating access level for users & groups
When the feature isn't available
parent
f59a7f28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
app/models/ee/protected_ref_access.rb
app/models/ee/protected_ref_access.rb
+3
-0
spec/models/ee/protected_ref_access_spec.rb
spec/models/ee/protected_ref_access_spec.rb
+58
-0
No files found.
app/models/ee/protected_ref_access.rb
View file @
8fd684b1
...
...
@@ -18,6 +18,9 @@ module EE
validates
:user_id
,
uniqueness:
{
scope:
protected_type
,
allow_nil:
true
}
validates
:access_level
,
uniqueness:
{
scope:
protected_type
,
if: :role?
,
conditions:
->
{
where
(
user_id:
nil
,
group_id:
nil
)
}
}
validates
:group
,
:user
,
absence:
true
,
unless:
proc
{
|
access
|
access
.
type
!=
:role
&&
access
.
project
.
feature_available?
(
:ref_permissions_for_users
)
}
scope
:by_user
,
->
(
user
)
{
where
(
user:
user
)
}
scope
:by_group
,
->
(
group
)
{
where
(
group:
group
)
}
...
...
spec/models/ee/protected_ref_access_spec.rb
0 → 100644
View file @
8fd684b1
require
'spec_helper'
describe
EE
::
ProtectedRefAccess
do
included_in_classes
=
[
ProtectedBranch
::
MergeAccessLevel
,
ProtectedBranch
::
PushAccessLevel
,
ProtectedTag
::
CreateAccessLevel
]
included_in_classes
.
each
do
|
included_in_class
|
context
"in
#{
included_in_class
}
"
do
let
(
:access_level
)
do
factory_name
=
included_in_class
.
name
.
underscore
.
tr
(
'/'
,
'_'
)
build
(
factory_name
)
end
it
"
#{
included_in_class
}
includes {described_class}"
do
expect
(
included_in_class
.
included_modules
).
to
include
(
described_class
)
end
context
'with the `ref_permissions_for_users` feature disabled'
do
before
do
stub_licensed_features
(
ref_permissions_for_users:
false
)
end
it
"allows creating an
#{
included_in_class
}
with a group"
do
access_level
.
group
=
create
(
:group
)
expect
(
access_level
).
not_to
be_valid
expect
(
access_level
.
errors
).
to
include
(
:group
)
end
it
"allows creating an
#{
included_in_class
}
with a group"
do
access_level
.
user
=
create
(
:user
)
expect
(
access_level
).
not_to
be_valid
expect
(
access_level
.
errors
).
to
include
(
:user
)
end
end
context
'with the `ref_permissions_for_users` feature enabled'
do
before
do
stub_licensed_features
(
ref_permissions_for_users:
true
)
end
it
"allows creating an
#{
included_in_class
}
with a group"
do
access_level
.
group
=
create
(
:group
)
expect
(
access_level
).
to
be_valid
end
it
"allows creating an
#{
included_in_class
}
with a group"
do
access_level
.
user
=
create
(
:user
)
expect
(
access_level
).
to
be_valid
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