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
246100d6
Commit
246100d6
authored
Aug 13, 2021
by
Sashi Kumar Kumaresan
Committed by
Andy Soiron
Aug 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add developers and maintainers to security policy project
parent
9a0f518f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
3 deletions
+42
-3
app/models/project_team.rb
app/models/project_team.rb
+4
-0
ee/app/services/security/security_orchestration_policies/project_create_service.rb
...security_orchestration_policies/project_create_service.rb
+4
-1
ee/spec/services/security/security_orchestration_policies/project_create_service_spec.rb
...ity_orchestration_policies/project_create_service_spec.rb
+4
-2
spec/models/project_team_spec.rb
spec/models/project_team_spec.rb
+30
-0
No files found.
app/models/project_team.rb
View file @
246100d6
...
...
@@ -78,6 +78,10 @@ class ProjectTeam
members
.
where
(
id:
member_user_ids
)
end
def
members_with_access_levels
(
access_levels
=
[])
fetch_members
(
access_levels
)
end
def
guests
@guests
||=
fetch_members
(
Gitlab
::
Access
::
GUEST
)
end
...
...
ee/app/services/security/security_orchestration_policies/project_create_service.rb
View file @
246100d6
...
...
@@ -3,6 +3,8 @@
module
Security
module
SecurityOrchestrationPolicies
class
ProjectCreateService
<
::
BaseProjectService
ACCESS_LEVELS_TO_ADD
=
[
Gitlab
::
Access
::
MAINTAINER
,
Gitlab
::
Access
::
DEVELOPER
].
freeze
def
execute
return
error
(
'Security Policy project already exists.'
)
if
project
.
security_orchestration_policy_configuration
.
present?
...
...
@@ -21,7 +23,8 @@ module Security
private
def
add_members
(
policy_project
)
members_to_add
=
project
.
team
.
maintainers
-
policy_project
.
team
.
members
developers_and_maintainers
=
project
.
team
.
members_with_access_levels
(
ACCESS_LEVELS_TO_ADD
)
members_to_add
=
developers_and_maintainers
-
policy_project
.
team
.
members
policy_project
.
add_users
(
members_to_add
,
:developer
)
end
...
...
ee/spec/services/security/security_orchestration_policies/project_create_service_spec.rb
View file @
246100d6
...
...
@@ -11,18 +11,20 @@ RSpec.describe Security::SecurityOrchestrationPolicies::ProjectCreateService do
context
'when security_orchestration_policies_configuration does not exist for project'
do
let_it_be
(
:maintainer
)
{
create
(
:user
)
}
let_it_be
(
:developer
)
{
create
(
:user
)
}
before
do
project
.
add_maintainer
(
maintainer
)
project
.
add_developer
(
developer
)
end
it
'creates
new project
'
do
it
'creates
policy project with maintainers and developers from target project as developers
'
do
response
=
service
.
execute
policy_project
=
response
[
:policy_project
]
expect
(
project
.
reload
.
security_orchestration_policy_configuration
.
security_policy_management_project
).
to
eq
(
policy_project
)
expect
(
policy_project
.
namespace
).
to
eq
(
project
.
namespace
)
expect
(
policy_project
.
team
.
developers
).
to
contain_exactly
(
maintainer
)
expect
(
policy_project
.
team
.
developers
).
to
contain_exactly
(
maintainer
,
developer
)
expect
(
policy_project
.
container_registry_access_level
).
to
eq
(
ProjectFeature
::
DISABLED
)
end
end
...
...
spec/models/project_team_spec.rb
View file @
246100d6
...
...
@@ -193,6 +193,36 @@ RSpec.describe ProjectTeam do
end
end
describe
'#members_with_access_levels'
do
let_it_be
(
:maintainer
)
{
create
(
:user
)
}
let_it_be
(
:developer
)
{
create
(
:user
)
}
let_it_be
(
:guest
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
namespace:
maintainer
.
namespace
)
}
let_it_be
(
:access_levels
)
{
[
Gitlab
::
Access
::
DEVELOPER
,
Gitlab
::
Access
::
MAINTAINER
]
}
subject
(
:members_with_access_levels
)
{
project
.
team
.
members_with_access_levels
(
access_levels
)
}
before
do
project
.
team
.
add_developer
(
developer
)
project
.
team
.
add_maintainer
(
maintainer
)
project
.
team
.
add_guest
(
guest
)
end
context
'with access_levels'
do
it
'filters members who have given access levels'
do
expect
(
members_with_access_levels
).
to
contain_exactly
(
developer
,
maintainer
)
end
end
context
'without access_levels'
do
let_it_be
(
:access_levels
)
{
[]
}
it
'returns empty array'
do
expect
(
members_with_access_levels
).
to
be_empty
end
end
end
describe
'#add_users'
do
let
(
:user1
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
...
...
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