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
2b33f1cd
Commit
2b33f1cd
authored
Jul 21, 2020
by
jejacks0n
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow nested gitlab_subscription on namespace api
parent
4eeb6114
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
4 deletions
+77
-4
ee/changelogs/unreleased/jj-allow-namespace-nested-attributes.yml
...elogs/unreleased/jj-allow-namespace-nested-attributes.yml
+5
-0
ee/lib/ee/api/namespaces.rb
ee/lib/ee/api/namespaces.rb
+6
-4
ee/spec/requests/api/namespaces_spec.rb
ee/spec/requests/api/namespaces_spec.rb
+66
-0
No files found.
ee/changelogs/unreleased/jj-allow-namespace-nested-attributes.yml
0 → 100644
View file @
2b33f1cd
---
title
:
Allow nested gitlab_subscription on namespace api
merge_request
:
37397
author
:
jejacks0n
type
:
changed
ee/lib/ee/api/namespaces.rb
View file @
2b33f1cd
...
...
@@ -36,6 +36,7 @@ module EE
resource
:namespaces
,
requirements:
::
API
::
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
do
helpers
do
params
:gitlab_subscription_optional_attributes
do
optional
:start_date
,
type:
Date
,
desc:
'The date when subscription was started'
optional
:seats
,
type:
Integer
,
desc:
'The number of seats purchased'
optional
:max_seats_used
,
type:
Integer
,
desc:
'The max number of active users detected in the last month'
optional
:plan_code
,
type:
String
,
desc:
'The code of the purchased plan'
...
...
@@ -55,6 +56,9 @@ module EE
optional
:extra_shared_runners_minutes_limit
,
type:
Integer
,
desc:
"Extra pipeline minutes for this namespace"
optional
:additional_purchased_storage_size
,
type:
Integer
,
desc:
"Additional storage size for this namespace"
optional
:additional_purchased_storage_ends_on
,
type:
Date
,
desc:
"End of subscription of the additional purchased storage"
optional
:gitlab_subscription_attributes
,
type:
Hash
do
use
:gitlab_subscription_optional_attributes
end
end
put
':id'
do
authenticated_as_admin!
...
...
@@ -74,9 +78,9 @@ module EE
success
::
EE
::
API
::
Entities
::
GitlabSubscription
end
params
do
requires
:start_date
,
type:
Date
,
desc:
'The date when subscription was started'
use
:gitlab_subscription_optional_attributes
requires
:start_date
,
type:
Date
,
desc:
'The date when subscription was started'
end
post
":id/gitlab_subscription"
do
authenticated_as_admin!
...
...
@@ -107,8 +111,6 @@ module EE
success
::
EE
::
API
::
Entities
::
GitlabSubscription
end
params
do
optional
:start_date
,
type:
Date
,
desc:
'The date when subscription was started'
use
:gitlab_subscription_optional_attributes
end
put
":id/gitlab_subscription"
do
...
...
ee/spec/requests/api/namespaces_spec.rb
View file @
2b33f1cd
...
...
@@ -209,6 +209,66 @@ RSpec.describe API::Namespaces do
expect
(
runners
).
to
all
(
receive
(
:tick_runner_queue
))
end
end
context
"when passing attributes for gitlab_subscription"
do
let
(
:gitlab_subscription
)
do
{
start_date:
'2019-06-01'
,
end_date:
'2020-06-01'
,
plan_code:
'gold'
,
seats:
20
,
max_seats_used:
10
,
auto_renew:
true
,
trial:
true
,
trial_ends_on:
'2019-05-01'
,
trial_starts_on:
'2019-06-01'
}
end
it
"creates the gitlab_subscription record"
do
expect
(
group1
.
gitlab_subscription
).
to
be_nil
put
api
(
"/namespaces/
#{
group1
.
id
}
"
,
admin
),
params:
{
gitlab_subscription_attributes:
gitlab_subscription
}
expect
(
group1
.
reload
.
gitlab_subscription
).
to
have_attributes
(
start_date:
Date
.
parse
(
gitlab_subscription
[
:start_date
]),
end_date:
Date
.
parse
(
gitlab_subscription
[
:end_date
]),
hosted_plan:
instance_of
(
Plan
),
seats:
20
,
max_seats_used:
10
,
auto_renew:
true
,
trial:
true
,
trial_starts_on:
Date
.
parse
(
gitlab_subscription
[
:trial_starts_on
]),
trial_ends_on:
Date
.
parse
(
gitlab_subscription
[
:trial_ends_on
])
)
end
it
"updates the gitlab_subscription record"
do
group1
.
create_gitlab_subscription!
put
api
(
"/namespaces/
#{
group1
.
id
}
"
,
admin
),
params:
{
gitlab_subscription_attributes:
gitlab_subscription
}
expect
(
group1
.
reload
.
gitlab_subscription
.
reload
.
seats
).
to
eq
20
end
context
'when params are invalid'
do
it
'returns a 400 error'
do
put
api
(
"/namespaces/
#{
group1
.
id
}
"
,
admin
),
params:
{
gitlab_subscription_attributes:
{
start_date:
nil
,
seats:
nil
}
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'message'
]).
to
eq
(
"gitlab_subscription.seats"
=>
[
"can't be blank"
],
"gitlab_subscription.start_date"
=>
[
"can't be blank"
]
)
end
end
end
end
describe
'POST :id/gitlab_subscription'
do
...
...
@@ -238,6 +298,12 @@ RSpec.describe API::Namespaces do
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it
'fails when the record is invalid'
do
do_post
(
admin
,
params
.
merge
(
start_date:
nil
))
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it
'creates a subscription for the Group'
do
do_post
(
admin
,
params
)
...
...
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