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
585deba6
Commit
585deba6
authored
Apr 14, 2021
by
Corinna Wiesner
Committed by
Miguel Rincon
Apr 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return license with activation mutation
parent
b3b3c59b
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
79 additions
and
17 deletions
+79
-17
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
ee/app/assets/javascripts/pages/admin/cloud_licenses/graphql/mutations/activate_subscription.mutation.graphql
.../graphql/mutations/activate_subscription.mutation.graphql
+16
-1
ee/app/graphql/mutations/gitlab_subscriptions/activate.rb
ee/app/graphql/mutations/gitlab_subscriptions/activate.rb
+5
-1
ee/app/services/gitlab_subscriptions/activate_service.rb
ee/app/services/gitlab_subscriptions/activate_service.rb
+1
-1
ee/spec/frontend/admin/cloud_licenses/mock_data.js
ee/spec/frontend/admin/cloud_licenses/mock_data.js
+17
-2
ee/spec/graphql/mutations/gitlab_subscriptions/activate_spec.rb
...c/graphql/mutations/gitlab_subscriptions/activate_spec.rb
+4
-3
ee/spec/requests/api/graphql/mutations/gitlab_subscriptions/activate_spec.rb
...i/graphql/mutations/gitlab_subscriptions/activate_spec.rb
+23
-2
ee/spec/services/gitlab_subscriptions/activate_service_spec.rb
...ec/services/gitlab_subscriptions/activate_service_spec.rb
+12
-7
No files found.
doc/api/graphql/reference/index.md
View file @
585deba6
...
...
@@ -3148,6 +3148,7 @@ Autogenerated return type of GitlabSubscriptionActivate.
| ----- | ---- | ----------- |
|
`clientMutationId`
|
[
`String`
](
#string
)
| A unique identifier for the client performing the mutation. |
|
`errors`
|
[
`[String!]!`
](
#string
)
| Errors encountered during execution of the mutation. |
|
`license`
|
[
`CurrentLicense`
](
#currentlicense
)
| The current license. |
### `GrafanaIntegration`
...
...
ee/app/assets/javascripts/pages/admin/cloud_licenses/graphql/mutations/activate_subscription.mutation.graphql
View file @
585deba6
mutation
(
$gitlabSubscriptionActivateInput
:
GitlabSubscriptionActivateInput
!)
{
gitlabSubscriptionActivate
(
input
:
$gitlabSubscriptionActivateInput
)
{
clientMutationId
errors
license
{
id
type
plan
name
email
company
startsAt
expiresAt
activatedAt
lastSync
usersInLicenseCount
billableUsersCount
maximumUserCount
usersOverLicenseCount
}
}
}
ee/app/graphql/mutations/gitlab_subscriptions/activate.rb
View file @
585deba6
...
...
@@ -11,12 +11,16 @@ module Mutations
required:
true
,
description:
'Activation code received after purchasing a GitLab subscription.'
field
:license
,
Types
::
Admin
::
CloudLicenses
::
CurrentLicenseType
,
null:
true
,
description:
'The current license.'
def
resolve
(
activation_code
:)
authorize!
:global
result
=
::
GitlabSubscriptions
::
ActivateService
.
new
.
execute
(
activation_code
)
{
errors:
Array
(
result
[
:errors
])
}
{
errors:
Array
(
result
[
:errors
])
,
license:
result
[
:license
]
}
end
end
end
...
...
ee/app/services/gitlab_subscriptions/activate_service.rb
View file @
585deba6
...
...
@@ -20,7 +20,7 @@ module GitlabSubscriptions
license
=
License
.
new
(
data:
response
[
:license_key
])
if
license
.
save
{
success:
true
}
{
success:
true
,
license:
license
}
else
error
(
license
.
errors
.
full_messages
)
end
...
...
ee/spec/frontend/admin/cloud_licenses/mock_data.js
View file @
585deba6
...
...
@@ -75,7 +75,7 @@ export const activateLicenseMutationResponse = {
FAILURE_IN_DISGUISE
:
{
data
:
{
gitlabSubscriptionActivate
:
{
clientMutationId
:
null
,
license
:
null
,
errors
:
[
"
undefined method `[]' for nil:NilClass
"
],
__typename
:
'
GitlabSubscriptionActivatePayload
'
,
},
...
...
@@ -84,7 +84,22 @@ export const activateLicenseMutationResponse = {
SUCCESS
:
{
data
:
{
gitlabSubscriptionActivate
:
{
clientMutationId
:
null
,
license
:
{
id
:
'
gid://gitlab/License/3
'
,
type
:
'
legacy
'
,
plan
:
'
ultimate
'
,
name
:
'
Test license
'
,
email
:
'
user@example.com
'
,
company
:
'
Example Inc
'
,
startsAt
:
'
2020-01-01
'
,
expiresAt
:
'
2022-01-01
'
,
activatedAt
:
'
2021-01-02
'
,
lastSync
:
null
,
usersInLicenseCount
:
100
,
billableUsersCount
:
50
,
maximumUserCount
:
50
,
usersOverLicenseCount
:
0
,
},
errors
:
[],
},
},
...
...
ee/spec/graphql/mutations/gitlab_subscriptions/activate_spec.rb
View file @
585deba6
...
...
@@ -8,8 +8,9 @@ RSpec.describe Mutations::GitlabSubscriptions::Activate do
subject
(
:mutation
)
{
described_class
.
new
(
object:
nil
,
context:
{
current_user:
user
},
field:
nil
)
}
let_it_be
(
:user
)
{
create
(
:admin
)
}
let_it_be
(
:created_license
)
{
License
.
last
}
let
(
:activation_code
)
{
'activation_code'
}
let
(
:result
)
{
{
success:
true
}
}
let
(
:result
)
{
{
success:
true
,
license:
created_license
}
}
describe
'#resolve'
do
before
do
...
...
@@ -24,7 +25,7 @@ RSpec.describe Mutations::GitlabSubscriptions::Activate do
it
'adds the issue to the epic'
do
result
=
mutation
.
resolve
(
activation_code:
activation_code
)
expect
(
result
).
to
eq
({
errors:
[]
})
expect
(
result
).
to
eq
({
errors:
[]
,
license:
created_license
})
end
end
...
...
@@ -34,7 +35,7 @@ RSpec.describe Mutations::GitlabSubscriptions::Activate do
it
'returns errors'
do
result
=
mutation
.
resolve
(
activation_code:
activation_code
)
expect
(
result
).
to
eq
({
errors:
[
'foo'
]
})
expect
(
result
).
to
eq
({
errors:
[
'foo'
]
,
license:
nil
})
end
end
...
...
ee/spec/requests/api/graphql/mutations/gitlab_subscriptions/activate_spec.rb
View file @
585deba6
...
...
@@ -45,8 +45,29 @@ RSpec.describe 'Activate a subscription' do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
mutation_response
=
graphql_mutation_response
(
:gitlab_subscription_activate
)
created_license
=
License
.
last
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
graphql_mutation_response
(
:gitlab_subscription_activate
)[
'errors'
]).
to
be_empty
expect
(
License
.
last
.
data
).
to
eq
(
license_key
)
expect
(
mutation_response
[
'errors'
]).
to
be_empty
expect
(
mutation_response
[
'license'
]).
to
eq
(
{
'id'
=>
"gid://gitlab/License/
#{
created_license
.
id
}
"
,
'type'
=>
License
::
LEGACY_LICENSE_TYPE
,
'plan'
=>
created_license
.
plan
,
'name'
=>
created_license
.
licensee_name
,
'email'
=>
created_license
.
licensee_email
,
'company'
=>
created_license
.
licensee_company
,
'startsAt'
=>
created_license
.
starts_at
.
to_s
,
'expiresAt'
=>
created_license
.
expires_at
.
to_s
,
'activatedAt'
=>
created_license
.
created_at
.
to_date
.
to_s
,
'lastSync'
=>
nil
,
'usersInLicenseCount'
=>
nil
,
'billableUsersCount'
=>
1
,
'maximumUserCount'
=>
1
,
'usersOverLicenseCount'
=>
0
}
)
expect
(
created_license
.
data
).
to
eq
(
license_key
)
end
end
ee/spec/services/gitlab_subscriptions/activate_service_spec.rb
View file @
585deba6
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
GitlabSubscriptions
::
ActivateService
do
subject
(
:execute_service
)
{
described_class
.
new
.
execute
(
activation_code
)
}
let!
(
:application_settings
)
do
stub_env
(
'IN_MEMORY_APPLICATION_SETTINGS'
,
'false'
)
create
(
:application_setting
,
cloud_license_enabled:
cloud_license_enabled
)
...
...
@@ -30,16 +32,19 @@ RSpec.describe GitlabSubscriptions::ActivateService do
end
it
'persists license'
do
expect
(
subject
.
execute
(
activation_code
)).
to
eq
({
success:
true
})
result
=
execute_service
created_license
=
License
.
last
expect
(
result
).
to
eq
({
success:
true
,
license:
created_license
})
expect
(
License
.
last
.
data
).
to
eq
(
license_key
)
expect
(
created_license
.
data
).
to
eq
(
license_key
)
end
context
'when persisting fails'
do
let
(
:license_key
)
{
'invalid key'
}
it
'returns error'
do
expect
(
subject
.
execute
(
activation_code
)
).
to
match
({
errors:
[
be_a_kind_of
(
String
)],
success:
false
})
expect
(
execute_service
).
to
match
({
errors:
[
be_a_kind_of
(
String
)],
success:
false
})
end
end
end
...
...
@@ -50,7 +55,7 @@ RSpec.describe GitlabSubscriptions::ActivateService do
it
'returns error'
do
stub_client_activate
expect
(
subject
.
execute
(
activation_code
)
).
to
eq
(
customer_dot_response
)
expect
(
execute_service
).
to
eq
(
customer_dot_response
)
expect
(
License
.
last
&
.
data
).
not_to
eq
(
license_key
)
end
...
...
@@ -63,7 +68,7 @@ RSpec.describe GitlabSubscriptions::ActivateService do
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
expect
(
Gitlab
::
SubscriptionPortal
::
Client
).
not_to
receive
(
:activate
)
expect
(
subject
.
execute
(
activation_code
)
).
to
eq
(
customer_dot_response
)
expect
(
execute_service
).
to
eq
(
customer_dot_response
)
end
end
...
...
@@ -74,7 +79,7 @@ RSpec.describe GitlabSubscriptions::ActivateService do
it
'returns error'
do
expect
(
Gitlab
::
SubscriptionPortal
::
Client
).
not_to
receive
(
:activate
)
expect
(
subject
.
execute
(
activation_code
)
).
to
eq
(
customer_dot_response
)
expect
(
execute_service
).
to
eq
(
customer_dot_response
)
end
end
...
...
@@ -82,7 +87,7 @@ RSpec.describe GitlabSubscriptions::ActivateService do
it
'captures error'
do
expect
(
Gitlab
::
SubscriptionPortal
::
Client
).
to
receive
(
:activate
).
and_raise
(
'foo'
)
expect
(
subject
.
execute
(
activation_code
)
).
to
eq
({
success:
false
,
errors:
[
'foo'
]
})
expect
(
execute_service
).
to
eq
({
success:
false
,
errors:
[
'foo'
]
})
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