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
6d892244
Commit
6d892244
authored
Aug 06, 2016
by
Adam Niedzielski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API support for expires_at.
parent
9accb302
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
5 deletions
+18
-5
lib/api/entities.rb
lib/api/entities.rb
+3
-0
lib/api/project_members.rb
lib/api/project_members.rb
+6
-3
spec/requests/api/project_members_spec.rb
spec/requests/api/project_members_spec.rb
+9
-2
No files found.
lib/api/entities.rb
View file @
6d892244
...
@@ -95,6 +95,9 @@ module API
...
@@ -95,6 +95,9 @@ module API
expose
:access_level
do
|
user
,
options
|
expose
:access_level
do
|
user
,
options
|
options
[
:project
].
project_members
.
find_by
(
user_id:
user
.
id
).
access_level
options
[
:project
].
project_members
.
find_by
(
user_id:
user
.
id
).
access_level
end
end
expose
:expires_at
do
|
user
,
options
|
options
[
:project
].
project_members
.
find_by
(
user_id:
user
.
id
).
expires_at
end
end
end
class
Group
<
Grape
::
Entity
class
Group
<
Grape
::
Entity
...
...
lib/api/project_members.rb
View file @
6d892244
...
@@ -38,6 +38,7 @@ module API
...
@@ -38,6 +38,7 @@ module API
# id (required) - The ID of a project
# id (required) - The ID of a project
# user_id (required) - The ID of a user
# user_id (required) - The ID of a user
# access_level (required) - Project access level
# access_level (required) - Project access level
# expires_at (optional) - Date string in the format YEAR-MONTH-DAY
# Example Request:
# Example Request:
# POST /projects/:id/members
# POST /projects/:id/members
post
":id/members"
do
post
":id/members"
do
...
@@ -49,7 +50,8 @@ module API
...
@@ -49,7 +50,8 @@ module API
if
project_member
.
nil?
if
project_member
.
nil?
project_member
=
user_project
.
project_members
.
new
(
project_member
=
user_project
.
project_members
.
new
(
user_id:
params
[
:user_id
],
user_id:
params
[
:user_id
],
access_level:
params
[
:access_level
]
access_level:
params
[
:access_level
],
expires_at:
params
[
:expires_at
]
)
)
end
end
...
@@ -67,16 +69,17 @@ module API
...
@@ -67,16 +69,17 @@ module API
# id (required) - The ID of a project
# id (required) - The ID of a project
# user_id (required) - The ID of a team member
# user_id (required) - The ID of a team member
# access_level (required) - Project access level
# access_level (required) - Project access level
# expires_at (optional) - Date string in the format YEAR-MONTH-DAY
# Example Request:
# Example Request:
# PUT /projects/:id/members/:user_id
# PUT /projects/:id/members/:user_id
put
":id/members/:user_id"
do
put
":id/members/:user_id"
do
authorize!
:admin_project
,
user_project
authorize!
:admin_project
,
user_project
required_attributes!
[
:access_level
]
required_attributes!
[
:access_level
]
attrs
=
attributes_for_keys
[
:access_level
,
:expires_at
]
project_member
=
user_project
.
project_members
.
find_by
(
user_id:
params
[
:user_id
])
project_member
=
user_project
.
project_members
.
find_by
(
user_id:
params
[
:user_id
])
not_found!
(
"User can not be found"
)
if
project_member
.
nil?
not_found!
(
"User can not be found"
)
if
project_member
.
nil?
if
project_member
.
update_attributes
(
a
ccess_level:
params
[
:access_level
]
)
if
project_member
.
update_attributes
(
a
ttrs
)
@member
=
project_member
.
user
@member
=
project_member
.
user
present
@member
,
with:
Entities
::
ProjectMember
,
project:
user_project
present
@member
,
with:
Entities
::
ProjectMember
,
project:
user_project
else
else
...
...
spec/requests/api/project_members_spec.rb
View file @
6d892244
...
@@ -54,12 +54,16 @@ describe API::API, api: true do
...
@@ -54,12 +54,16 @@ describe API::API, api: true do
describe
"POST /projects/:id/members"
do
describe
"POST /projects/:id/members"
do
it
"should add user to project team"
do
it
"should add user to project team"
do
expect
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
user_id:
user2
.
id
,
access_level:
ProjectMember
::
DEVELOPER
post
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
user_id:
user2
.
id
,
access_level:
ProjectMember
::
DEVELOPER
,
expires_at:
'2016-08-05'
end
.
to
change
{
ProjectMember
.
count
}.
by
(
1
)
end
.
to
change
{
ProjectMember
.
count
}.
by
(
1
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'username'
]).
to
eq
(
user2
.
username
)
expect
(
json_response
[
'username'
]).
to
eq
(
user2
.
username
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
ProjectMember
::
DEVELOPER
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
ProjectMember
::
DEVELOPER
)
expect
(
json_response
[
'expires_at'
]).
to
eq
(
'2016-08-05'
)
end
end
it
"should return a 201 status if user is already project member"
do
it
"should return a 201 status if user is already project member"
do
...
@@ -95,10 +99,13 @@ describe API::API, api: true do
...
@@ -95,10 +99,13 @@ describe API::API, api: true do
before
{
project_member2
}
before
{
project_member2
}
it
"should update project team member"
do
it
"should update project team member"
do
put
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
),
access_level:
ProjectMember
::
MASTER
put
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
),
access_level:
ProjectMember
::
MASTER
,
expires_at:
'2016-08-05'
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'username'
]).
to
eq
(
user3
.
username
)
expect
(
json_response
[
'username'
]).
to
eq
(
user3
.
username
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
ProjectMember
::
MASTER
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
ProjectMember
::
MASTER
)
expect
(
json_response
[
'expires_at'
]).
to
eq
(
'2016-08-05'
)
end
end
it
"should return a 404 error if user_id is not found"
do
it
"should return a 404 error if user_id is not found"
do
...
...
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