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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
e8b3b92d
Commit
e8b3b92d
authored
Mar 13, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bring share project with group API from EE
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
e1dffa32
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
0 deletions
+81
-0
doc/api/projects.md
doc/api/projects.md
+14
-0
lib/api/entities.rb
lib/api/entities.rb
+4
-0
lib/api/projects.rb
lib/api/projects.rb
+27
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+36
-0
No files found.
doc/api/projects.md
View file @
e8b3b92d
...
...
@@ -619,6 +619,20 @@ Revoking team membership for a user who is not currently a team member is consid
Please note that the returned JSON currently differs slightly. Thus you should not
rely on the returned JSON structure.
### Share project with group
Allow to share project with group.
```
POST /projects/:id/share
```
Parameters:
-
`id`
(required) - The ID of a project
-
`group_id`
(required) - The ID of a group
-
`group_access`
(required) - Level of permissions for sharing
## Hooks
Also called Project Hooks and Webhooks.
...
...
lib/api/entities.rb
View file @
e8b3b92d
...
...
@@ -243,6 +243,10 @@ module API
end
end
class
ProjectGroupLink
<
Grape
::
Entity
expose
:id
,
:project_id
,
:group_id
,
:group_access
end
class
Namespace
<
Grape
::
Entity
expose
:id
,
:path
,
:kind
end
...
...
lib/api/projects.rb
View file @
e8b3b92d
...
...
@@ -290,6 +290,33 @@ module API
end
end
# Share project with group
#
# Parameters:
# id (required) - The ID of a project
# group_id (required) - The ID of a group
# group_access (required) - Level of permissions for sharing
#
# Example Request:
# POST /projects/:id/share
post
":id/share"
do
authorize!
:admin_project
,
user_project
required_attributes!
[
:group_id
,
:group_access
]
unless
user_project
.
allowed_to_share_with_group?
return
render_api_error!
(
"The project sharing with group is disabled"
,
400
)
end
link
=
user_project
.
project_group_links
.
new
link
.
group_id
=
params
[
:group_id
]
link
.
group_access
=
params
[
:group_access
]
if
link
.
save
present
link
,
with:
Entities
::
ProjectGroupLink
else
render_api_error!
(
link
.
errors
.
full_messages
.
first
,
409
)
end
end
# Upload a file
#
# Parameters:
...
...
spec/requests/api/projects_spec.rb
View file @
e8b3b92d
...
...
@@ -747,6 +747,42 @@ describe API::API, api: true do
end
end
describe
"POST /projects/:id/share"
do
let
(
:group
)
{
create
(
:group
)
}
it
"should share project with group"
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
end
.
to
change
{
ProjectGroupLink
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
201
expect
(
json_response
[
'group_id'
]).
to
eq
group
.
id
expect
(
json_response
[
'group_access'
]).
to
eq
Gitlab
::
Access
::
DEVELOPER
end
it
"should return a 400 error when group id is not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_access:
Gitlab
::
Access
::
DEVELOPER
expect
(
response
.
status
).
to
eq
400
end
it
"should return a 400 error when access level is not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
expect
(
response
.
status
).
to
eq
400
end
it
"should return a 400 error when sharing is disabled"
do
project
.
namespace
.
update
(
share_with_group_lock:
true
)
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
expect
(
response
.
status
).
to
eq
400
end
it
"should return a 409 error when wrong params passed"
do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
1234
expect
(
response
.
status
).
to
eq
409
expect
(
json_response
[
'message'
]).
to
eq
'Group access is not included in the list'
end
end
describe
'GET /projects/search/:query'
do
let!
(
:query
)
{
'query'
}
let!
(
:search
)
{
create
(
:empty_project
,
name:
query
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
...
...
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