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
8c1215f3
Commit
8c1215f3
authored
Jul 12, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds mirror params to POST #create project endpoint parameters
parent
0e92a772
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
2 deletions
+127
-2
ee/lib/ee/api/entities.rb
ee/lib/ee/api/entities.rb
+5
-0
ee/lib/ee/api/helpers.rb
ee/lib/ee/api/helpers.rb
+10
-0
ee/spec/requests/api/projects_spec.rb
ee/spec/requests/api/projects_spec.rb
+99
-1
lib/api/helpers/projects_helpers.rb
lib/api/helpers/projects_helpers.rb
+3
-0
lib/api/projects.rb
lib/api/projects.rb
+10
-1
No files found.
ee/lib/ee/api/entities.rb
View file @
8c1215f3
...
...
@@ -18,6 +18,11 @@ module EE
prepended
do
expose
:repository_storage
,
if:
->
(
_project
,
options
)
{
options
[
:current_user
].
try
(
:admin?
)
}
expose
:approvals_before_merge
,
if:
->
(
project
,
_
)
{
project
.
feature_available?
(
:merge_request_approvers
)
}
expose
:mirror
,
if:
->
(
project
,
_
)
{
project
.
feature_available?
(
:repository_mirrors
)
}
expose
:mirror_user_id
,
if:
->
(
project
,
_
)
{
project
.
feature_available?
(
:repository_mirrors
)
}
expose
:mirror_trigger_builds
,
if:
->
(
project
,
_
)
{
project
.
feature_available?
(
:repository_mirrors
)
}
expose
:only_mirror_protected_branches
,
if:
->
(
project
,
_
)
{
project
.
feature_available?
(
:repository_mirrors
)
}
expose
:mirror_overwrites_diverged_branches
,
if:
->
(
project
,
_
)
{
project
.
feature_available?
(
:repository_mirrors
)
}
end
end
...
...
ee/lib/ee/api/helpers.rb
View file @
8c1215f3
...
...
@@ -61,6 +61,16 @@ module EE
::
Gitlab
::
CurrentSettings
.
current_application_settings
.
allow_group_owners_to_manage_ldap
end
def
valid_mirror_user?
(
mirror_params
)
return
true
unless
mirror_params
[
:mirror_user_id
].
present?
default_mirror_users
.
map
(
&
:id
).
include?
(
mirror_params
[
:mirror_user_id
].
to_i
)
end
def
default_mirror_users
[
current_user
,
user_project
.
mirror_user
].
compact
.
uniq
end
end
end
end
ee/spec/requests/api/projects_spec.rb
View file @
8c1215f3
...
...
@@ -4,9 +4,52 @@ describe API::Projects do
include
ExternalAuthorizationServiceHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
describe
'POST /projects'
do
context
'when importing with mirror attributes'
do
let
(
:import_url
)
{
generate
(
:url
)
}
let
(
:mirror_params
)
do
{
name:
"Foo"
,
mirror:
true
,
import_url:
import_url
,
mirror_user_id:
user
.
id
,
mirror_trigger_builds:
true
}
end
it
'creates new project with pull mirroring setup'
do
post
api
(
'/projects'
,
user
),
mirror_params
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
Project
.
first
).
to
have_attributes
(
mirror:
true
,
import_url:
import_url
,
mirror_user_id:
user
.
id
,
mirror_trigger_builds:
true
)
end
it
'creates project without mirror settings when repository mirroring feature is disabled'
do
stub_licensed_features
(
repository_mirrors:
false
)
expect
{
post
api
(
'/projects'
,
user
),
mirror_params
}
.
to
change
{
Project
.
count
}.
by
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
Project
.
first
).
to
have_attributes
(
mirror:
false
,
import_url:
import_url
,
mirror_user_id:
nil
,
mirror_trigger_builds:
false
)
end
end
end
describe
'PUT /projects/:id'
do
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
before
do
enable_external_authorization_service_check
end
...
...
@@ -18,6 +61,61 @@ describe API::Projects do
expect
(
project
.
reload
.
external_authorization_classification_label
).
to
eq
(
'new label'
)
end
context
'when updating mirror related attributes'
do
let
(
:import_url
)
{
generate
(
:url
)
}
let
(
:mirror_params
)
do
{
mirror:
true
,
import_url:
import_url
,
mirror_user_id:
user
.
id
,
mirror_trigger_builds:
true
,
only_mirror_protected_branches:
true
,
mirror_overwrites_diverged_branches:
true
}
end
it
'updates mirror related attributes'
do
put
(
api
(
"/projects/
#{
project
.
id
}
"
,
user
),
mirror_params
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
project
.
reload
).
to
have_attributes
(
mirror:
true
,
import_url:
import_url
,
mirror_user_id:
user
.
id
,
mirror_trigger_builds:
true
,
only_mirror_protected_branches:
true
,
mirror_overwrites_diverged_branches:
true
)
end
it
'reverts to current user when mirror_user_id is invalid'
do
invalid_mirror_user
=
create
(
:user
)
project
.
add_developer
(
invalid_mirror_user
)
mirror_params
[
:mirror_user_id
]
=
invalid_mirror_user
.
id
put
(
api
(
"/projects/
#{
project
.
id
}
"
,
user
),
mirror_params
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
project
.
reload
).
to
have_attributes
(
mirror:
true
,
import_url:
import_url
,
mirror_user_id:
user
.
id
,
mirror_trigger_builds:
true
,
only_mirror_protected_branches:
true
,
mirror_overwrites_diverged_branches:
true
)
end
it
'returns 403 when the user does not have access to mirror settings'
do
developer
=
create
(
:user
)
project
.
add_developer
(
developer
)
put
(
api
(
"/projects/
#{
project
.
id
}
"
,
developer
),
mirror_params
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
end
describe
'GET /projects'
do
...
...
lib/api/helpers/projects_helpers.rb
View file @
8c1215f3
...
...
@@ -32,6 +32,9 @@ module API
optional
:repository_storage
,
type:
String
,
desc:
'Which storage shard the repository is on. Available only to admins'
optional
:approvals_before_merge
,
type:
Integer
,
desc:
'How many approvers should approve merge request by default'
optional
:external_authorization_classification_label
,
type:
String
,
desc:
'The classification label for the project'
optional
:mirror
,
type:
Boolean
,
desc:
'Enables pull mirroring in a project'
optional
:mirror_user_id
,
type:
Integer
,
desc:
'User responsible for all the activity surrounding a pull mirror event'
optional
:mirror_trigger_builds
,
type:
Boolean
,
desc:
'Pull mirroring triggers builds'
end
params
:optional_project_params
do
...
...
lib/api/projects.rb
View file @
8c1215f3
...
...
@@ -140,6 +140,8 @@ module API
post
do
attrs
=
declared_params
(
include_missing:
false
)
attrs
=
translate_params_for_compatibility
(
attrs
)
attrs
[
:mirror_user_id
]
=
current_user
.
id
if
attrs
[
:import_url
].
present?
project
=
::
Projects
::
CreateService
.
new
(
current_user
,
attrs
).
execute
if
project
.
saved?
...
...
@@ -172,6 +174,8 @@ module API
attrs
=
declared_params
(
include_missing:
false
)
attrs
=
translate_params_for_compatibility
(
attrs
)
attrs
[
:mirror_user_id
]
=
user
.
id
if
attrs
[
:import_url
].
present?
project
=
::
Projects
::
CreateService
.
new
(
user
,
attrs
).
execute
if
project
.
saved?
...
...
@@ -284,13 +288,17 @@ module API
optional
:name
,
type:
String
,
desc:
'The name of the project'
optional
:default_branch
,
type:
String
,
desc:
'The default branch of the project'
optional
:path
,
type:
String
,
desc:
'The path of the repository'
optional
:import_url
,
type:
String
,
desc:
'URL from which the project is imported'
# EE
at_least_one_of_ee
=
[
:approvals_before_merge
,
:repository_storage
,
:external_authorization_classification_label
:external_authorization_classification_label
,
:import_url
]
optional
:only_mirror_protected_branches
,
type:
Boolean
,
desc:
'Only mirror protected branches'
optional
:mirror_overwrites_diverged_branches
,
type:
Boolean
,
desc:
'Pull mirror overwrites diverged branches'
use
:optional_project_params
at_least_one_of
(
*
(
at_least_one_of_ce
+
at_least_one_of_ee
))
...
...
@@ -302,6 +310,7 @@ module API
authorize!
:change_visibility_level
,
user_project
if
attrs
[
:visibility
].
present?
attrs
=
translate_params_for_compatibility
(
attrs
)
attrs
[
:mirror_user_id
]
=
current_user
.
id
unless
valid_mirror_user?
(
attrs
)
result
=
::
Projects
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
...
...
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