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
2480f26c
Commit
2480f26c
authored
Oct 03, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/project_share_api' of /home/git/repositories/gitlab/gitlab-ee
parents
09b1f305
5bd00257
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
6 deletions
+79
-6
app/models/project_group_link.rb
app/models/project_group_link.rb
+3
-6
doc/api/projects.md
doc/api/projects.md
+17
-0
lib/api/entities.rb
lib/api/entities.rb
+4
-0
lib/api/projects.rb
lib/api/projects.rb
+23
-0
spec/models/project_group_link_spec.rb
spec/models/project_group_link_spec.rb
+1
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+31
-0
No files found.
app/models/project_group_link.rb
View file @
2480f26c
...
...
@@ -16,14 +16,11 @@ class ProjectGroupLink < ActiveRecord::Base
validates
:project_id
,
presence:
true
validates
:group_id
,
presence:
true
validates
:group_id
,
uniqueness:
{
scope:
[
:project_id
],
message:
"already shared with this group"
}
validates
:group_access
,
presence:
true
validates
:group_access
,
inclusion:
{
in:
Gitlab
::
Access
.
values
},
presence:
true
def
self
.
access_options
{
"Guest"
=>
GUEST
,
"Reporter"
=>
REPORTER
,
"Developer"
=>
DEVELOPER
,
"Master"
=>
MASTER
}
Gitlab
::
Access
.
options
end
def
self
.
default_access
...
...
doc/api/projects.md
View file @
2480f26c
...
...
@@ -484,3 +484,20 @@ DELETE /projects/:id/fork
Parameter:
+
`id`
(required) - The ID of the project
### Share project with group
Shares project with group. In order to share project with several groups - do several requests.
You must be a master or owner of project in order to perform action
```
POST /projects/:id/share
```
Parameters:
+
`id`
(required) - The ID of a project
+
`group_id`
(required) - The ID of a group to share with
+
`group_access`
(required) - Group access level
lib/api/entities.rb
View file @
2480f26c
...
...
@@ -140,5 +140,9 @@ module API
class
LdapGroup
<
Grape
::
Entity
expose
:cn
end
class
ProjectGroupLink
<
Grape
::
Entity
expose
:id
,
:project_id
,
:group_id
,
:group_access
end
end
end
lib/api/projects.rb
View file @
2480f26c
...
...
@@ -262,6 +262,29 @@ module API
{
message:
"Access revoked"
,
id:
params
[
:user_id
].
to_i
}
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
]
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
end
end
end
spec/models/project_group_link_spec.rb
View file @
2480f26c
...
...
@@ -17,5 +17,6 @@ describe ProjectGroupLink do
it
{
should
validate_presence_of
(
:project_id
)
}
it
{
should
validate_uniqueness_of
(
:group_id
).
scoped_to
(
:project_id
).
with_message
(
/already shared/
)
}
it
{
should
validate_presence_of
(
:group_id
)
}
it
{
should
validate_presence_of
(
:group_access
)
}
end
end
spec/requests/api/projects_spec.rb
View file @
2480f26c
...
...
@@ -692,4 +692,35 @@ describe API::API do
end
end
end
describe
"POST /projects/:id/share"
do
let
(
:group
)
{
create
(
:group
)
}
it
"should share project with group"
do
expect
{
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
}.
to
change
{
ProjectGroupLink
.
count
}.
by
(
1
)
response
.
status
.
should
==
201
json_response
[
'group_id'
].
should
==
group
.
id
json_response
[
'group_access'
].
should
==
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
response
.
status
.
should
==
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
response
.
status
.
should
==
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
response
.
status
.
should
==
409
json_response
[
'message'
].
should
==
'Group access is not included in the list'
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