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
c1d6d65e
Commit
c1d6d65e
authored
Jun 03, 2020
by
Petar Prokic
Committed by
Douglas Barbosa Alexandre
Jun 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add optional expires_at param to Users API endpoint Add SSH key
parent
a45b8ff8
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
57 deletions
+80
-57
doc/api/users.md
doc/api/users.md
+58
-57
lib/api/users.rb
lib/api/users.rb
+2
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+20
-0
No files found.
doc/api/users.md
View file @
c1d6d65e
This diff is collapsed.
Click to expand it.
lib/api/users.rb
View file @
c1d6d65e
...
...
@@ -255,6 +255,7 @@ module API
requires
:id
,
type:
Integer
,
desc:
'The ID of the user'
requires
:key
,
type:
String
,
desc:
'The new SSH key'
requires
:title
,
type:
String
,
desc:
'The title of the new SSH key'
optional
:expires_at
,
type:
DateTime
,
desc:
'The expiration date of the SSH key in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)'
end
# rubocop: disable CodeReuse/ActiveRecord
post
":id/keys"
do
...
...
@@ -720,6 +721,7 @@ module API
params
do
requires
:key
,
type:
String
,
desc:
'The new SSH key'
requires
:title
,
type:
String
,
desc:
'The title of the new SSH key'
optional
:expires_at
,
type:
DateTime
,
desc:
'The expiration date of the SSH key in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)'
end
post
"keys"
do
key
=
current_user
.
keys
.
new
(
declared_params
)
...
...
spec/requests/api/users_spec.rb
View file @
c1d6d65e
...
...
@@ -1242,6 +1242,16 @@ describe API::Users, :do_not_mock_admin_mode do
end
.
to
change
{
user
.
keys
.
count
}.
by
(
1
)
end
it
'creates SSH key with `expires_at` attribute'
do
optional_attributes
=
{
expires_at:
'2016-01-21T00:00:00.000Z'
}
attributes
=
attributes_for
(
:key
).
merge
(
optional_attributes
)
post
api
(
"/users/
#{
user
.
id
}
/keys"
,
admin
),
params:
attributes
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
json_response
[
'expires_at'
]).
to
eq
(
optional_attributes
[
:expires_at
])
end
it
"returns 400 for invalid ID"
do
post
api
(
"/users/0/keys"
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
...
...
@@ -1798,6 +1808,16 @@ describe API::Users, :do_not_mock_admin_mode do
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
end
it
'creates SSH key with `expires_at` attribute'
do
optional_attributes
=
{
expires_at:
'2016-01-21T00:00:00.000Z'
}
attributes
=
attributes_for
(
:key
).
merge
(
optional_attributes
)
post
api
(
"/user/keys"
,
user
),
params:
attributes
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
json_response
[
'expires_at'
]).
to
eq
(
optional_attributes
[
:expires_at
])
end
it
"returns a 401 error if unauthorized"
do
post
api
(
"/user/keys"
),
params:
{
title:
'some title'
,
key:
'some key'
}
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
...
...
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