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
ea5eedfc
Commit
ea5eedfc
authored
Apr 05, 2022
by
Diana Zubova
Committed by
Doug Stull
Apr 05, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend namespace gitlab_subscription API
Added exclude_guests field Changelog: changed EE: true
parent
2ba1442e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
70 additions
and
7 deletions
+70
-7
doc/development/internal_api/index.md
doc/development/internal_api/index.md
+4
-3
ee/app/models/ee/group.rb
ee/app/models/ee/group.rb
+6
-3
ee/app/models/ee/namespace.rb
ee/app/models/ee/namespace.rb
+4
-0
ee/app/models/gitlab_subscription.rb
ee/app/models/gitlab_subscription.rb
+1
-0
ee/lib/ee/api/entities/gitlab_subscription.rb
ee/lib/ee/api/entities/gitlab_subscription.rb
+1
-0
ee/spec/models/ee/group_spec.rb
ee/spec/models/ee/group_spec.rb
+27
-0
ee/spec/models/ee/namespace_spec.rb
ee/spec/models/ee/namespace_spec.rb
+8
-0
ee/spec/models/gitlab_subscription_spec.rb
ee/spec/models/gitlab_subscription_spec.rb
+2
-0
ee/spec/requests/api/namespaces_spec.rb
ee/spec/requests/api/namespaces_spec.rb
+17
-1
No files found.
doc/development/internal_api/index.md
View file @
ea5eedfc
...
@@ -621,7 +621,7 @@ Example response:
...
@@ -621,7 +621,7 @@ Example response:
"name"
:
"premium"
,
"name"
:
"premium"
,
"trial"
:
false
,
"trial"
:
false
,
"auto_renew"
:
null
,
"auto_renew"
:
null
,
"upgradable"
:
false
"upgradable"
:
false
,
},
},
"usage"
:
{
"usage"
:
{
"seats_in_subscription"
:
10
,
"seats_in_subscription"
:
10
,
...
@@ -672,7 +672,7 @@ Example response:
...
@@ -672,7 +672,7 @@ Example response:
"name"
:
"premium"
,
"name"
:
"premium"
,
"trial"
:
false
,
"trial"
:
false
,
"auto_renew"
:
null
,
"auto_renew"
:
null
,
"upgradable"
:
false
"upgradable"
:
false
,
},
},
"usage"
:
{
"usage"
:
{
"seats_in_subscription"
:
80
,
"seats_in_subscription"
:
80
,
...
@@ -711,7 +711,8 @@ Example response:
...
@@ -711,7 +711,8 @@ Example response:
"name"
:
"premium"
,
"name"
:
"premium"
,
"trial"
:
false
,
"trial"
:
false
,
"auto_renew"
:
null
,
"auto_renew"
:
null
,
"upgradable"
:
false
"upgradable"
:
false
,
"exclude_guests"
:
false
,
},
},
"usage"
:
{
"usage"
:
{
"seats_in_subscription"
:
80
,
"seats_in_subscription"
:
80
,
...
...
ee/app/models/ee/group.rb
View file @
ea5eedfc
...
@@ -357,9 +357,7 @@ module EE
...
@@ -357,9 +357,7 @@ module EE
# converting the array of user_ids to a Set which will have unique user_ids.
# converting the array of user_ids to a Set which will have unique user_ids.
override
:billed_user_ids
override
:billed_user_ids
def
billed_user_ids
(
requested_hosted_plan
=
nil
)
def
billed_user_ids
(
requested_hosted_plan
=
nil
)
exclude_guests
=
([
actual_plan_name
,
requested_hosted_plan
]
&
[
::
Plan
::
GOLD
,
::
Plan
::
ULTIMATE
,
::
Plan
::
ULTIMATE_TRIAL
]).
any?
exclude_guests?
(
requested_hosted_plan
)
?
billed_user_ids_excluding_guests
:
billed_user_ids_including_guests
exclude_guests
?
billed_user_ids_excluding_guests
:
billed_user_ids_including_guests
end
end
override
:supports_events?
override
:supports_events?
...
@@ -367,6 +365,11 @@ module EE
...
@@ -367,6 +365,11 @@ module EE
feature_available?
(
:epics
)
feature_available?
(
:epics
)
end
end
override
:exclude_guests?
def
exclude_guests?
(
requested_hosted_plan
=
nil
)
([
actual_plan_name
,
requested_hosted_plan
]
&
[
::
Plan
::
GOLD
,
::
Plan
::
ULTIMATE
,
::
Plan
::
ULTIMATE_TRIAL
]).
any?
end
def
marked_for_deletion?
def
marked_for_deletion?
marked_for_deletion_on
.
present?
&&
marked_for_deletion_on
.
present?
&&
feature_available?
(
:adjourned_deletion_for_projects_and_groups
)
feature_available?
(
:adjourned_deletion_for_projects_and_groups
)
...
...
ee/app/models/ee/namespace.rb
View file @
ea5eedfc
...
@@ -472,6 +472,10 @@ module EE
...
@@ -472,6 +472,10 @@ module EE
end
end
end
end
def
exclude_guests?
false
end
private
private
def
free_user_cap
def
free_user_cap
...
...
ee/app/models/gitlab_subscription.rb
View file @
ea5eedfc
...
@@ -23,6 +23,7 @@ class GitlabSubscription < ApplicationRecord
...
@@ -23,6 +23,7 @@ class GitlabSubscription < ApplicationRecord
validates
:namespace_id
,
uniqueness:
true
,
presence:
true
validates
:namespace_id
,
uniqueness:
true
,
presence:
true
delegate
:name
,
:title
,
to: :hosted_plan
,
prefix: :plan
,
allow_nil:
true
delegate
:name
,
:title
,
to: :hosted_plan
,
prefix: :plan
,
allow_nil:
true
delegate
:exclude_guests?
,
to: :namespace
scope
:with_hosted_plan
,
->
(
plan_name
)
do
scope
:with_hosted_plan
,
->
(
plan_name
)
do
joins
(
:hosted_plan
).
where
(
trial:
false
,
'plans.name'
=>
plan_name
)
joins
(
:hosted_plan
).
where
(
trial:
false
,
'plans.name'
=>
plan_name
)
...
...
ee/lib/ee/api/entities/gitlab_subscription.rb
View file @
ea5eedfc
...
@@ -10,6 +10,7 @@ module EE
...
@@ -10,6 +10,7 @@ module EE
expose
:trial
expose
:trial
expose
:auto_renew
expose
:auto_renew
expose
:upgradable?
,
as: :upgradable
expose
:upgradable?
,
as: :upgradable
expose
:exclude_guests?
,
as: :exclude_guests
end
end
expose
:usage
do
expose
:usage
do
...
...
ee/spec/models/ee/group_spec.rb
View file @
ea5eedfc
...
@@ -1320,6 +1320,33 @@ RSpec.describe Group do
...
@@ -1320,6 +1320,33 @@ RSpec.describe Group do
end
end
end
end
describe
'#exclude_guests?'
,
:saas
do
using
RSpec
::
Parameterized
::
TableSyntax
let_it_be
(
:group
,
refind:
true
)
{
create
(
:group
)
}
where
(
:actual_plan_name
,
:requested_plan_name
,
:result
)
do
:free
|
nil
|
false
:premium
|
nil
|
false
:ultimate
|
nil
|
true
:ultimate_trial
|
nil
|
true
:gold
|
nil
|
true
:free
|
'premium'
|
false
:free
|
'ultimate'
|
true
:premium
|
'ultimate'
|
true
:ultimate
|
'ultimate'
|
true
end
with_them
do
let!
(
:subscription
)
{
build
(
:gitlab_subscription
,
actual_plan_name
,
namespace:
group
)
}
it
'returns the expected result'
do
expect
(
group
.
exclude_guests?
(
requested_plan_name
)).
to
eq
(
result
)
end
end
end
describe
'#users_count'
do
describe
'#users_count'
do
subject
{
group
.
users_count
}
subject
{
group
.
users_count
}
...
...
ee/spec/models/ee/namespace_spec.rb
View file @
ea5eedfc
...
@@ -1752,6 +1752,14 @@ RSpec.describe Namespace do
...
@@ -1752,6 +1752,14 @@ RSpec.describe Namespace do
end
end
end
end
describe
'#exclude_guests?'
do
let
(
:namespace
)
{
build
(
:namespace
)
}
it
'returns false'
do
expect
(
namespace
.
exclude_guests?
).
to
eq
(
false
)
end
end
def
create_project
(
repository_size
:,
lfs_objects_size
:,
repository_size_limit
:)
def
create_project
(
repository_size
:,
lfs_objects_size
:,
repository_size_limit
:)
create
(
:project
,
namespace:
namespace
,
repository_size_limit:
repository_size_limit
).
tap
do
|
project
|
create
(
:project
,
namespace:
namespace
,
repository_size_limit:
repository_size_limit
).
tap
do
|
project
|
create
(
:project_statistics
,
project:
project
,
repository_size:
repository_size
,
lfs_objects_size:
lfs_objects_size
)
create
(
:project_statistics
,
project:
project
,
repository_size:
repository_size
,
lfs_objects_size:
lfs_objects_size
)
...
...
ee/spec/models/gitlab_subscription_spec.rb
View file @
ea5eedfc
...
@@ -9,6 +9,8 @@ RSpec.describe GitlabSubscription, :saas do
...
@@ -9,6 +9,8 @@ RSpec.describe GitlabSubscription, :saas do
let_it_be
(
plan
)
{
create
(
plan
)
}
# rubocop:disable Rails/SaveBang
let_it_be
(
plan
)
{
create
(
plan
)
}
# rubocop:disable Rails/SaveBang
end
end
it
{
is_expected
.
to
delegate_method
(
:exclude_guests?
).
to
(
:namespace
)
}
describe
'default values'
,
:freeze_time
do
describe
'default values'
,
:freeze_time
do
it
'defaults start_date to the current date'
do
it
'defaults start_date to the current date'
do
expect
(
subject
.
start_date
).
to
eq
(
Date
.
today
)
expect
(
subject
.
start_date
).
to
eq
(
Date
.
today
)
...
...
ee/spec/requests/api/namespaces_spec.rb
View file @
ea5eedfc
...
@@ -563,16 +563,32 @@ RSpec.describe API::Namespaces do
...
@@ -563,16 +563,32 @@ RSpec.describe API::Namespaces do
do_get
(
owner
)
do_get
(
owner
)
expect
(
json_response
.
keys
).
to
match_array
(
%w[plan usage billing]
)
expect
(
json_response
.
keys
).
to
match_array
(
%w[plan usage billing]
)
expect
(
json_response
[
'plan'
].
keys
).
to
match_array
(
%w[name code trial upgradable auto_renew]
)
expect
(
json_response
[
'plan'
].
keys
).
to
match_array
(
%w[name code trial upgradable
exclude_guests
auto_renew]
)
expect
(
json_response
[
'plan'
][
'name'
]).
to
eq
(
'Premium'
)
expect
(
json_response
[
'plan'
][
'name'
]).
to
eq
(
'Premium'
)
expect
(
json_response
[
'plan'
][
'code'
]).
to
eq
(
'premium'
)
expect
(
json_response
[
'plan'
][
'code'
]).
to
eq
(
'premium'
)
expect
(
json_response
[
'plan'
][
'trial'
]).
to
eq
(
false
)
expect
(
json_response
[
'plan'
][
'trial'
]).
to
eq
(
false
)
expect
(
json_response
[
'plan'
][
'upgradable'
]).
to
eq
(
true
)
expect
(
json_response
[
'plan'
][
'upgradable'
]).
to
eq
(
true
)
expect
(
json_response
[
'plan'
][
'exclude_guests'
]).
to
eq
(
false
)
expect
(
json_response
[
'usage'
].
keys
).
to
match_array
(
%w[seats_in_subscription seats_in_use max_seats_used seats_owed]
)
expect
(
json_response
[
'usage'
].
keys
).
to
match_array
(
%w[seats_in_subscription seats_in_use max_seats_used seats_owed]
)
expect
(
json_response
[
'billing'
].
keys
).
to
match_array
(
%w[subscription_start_date subscription_end_date trial_ends_on]
)
expect
(
json_response
[
'billing'
].
keys
).
to
match_array
(
%w[subscription_start_date subscription_end_date trial_ends_on]
)
end
end
end
end
context
'for groups inherits exclude_guests'
do
let_it_be
(
:ultimate_namespace
)
{
create
(
:group
)
}
let_it_be
(
:gitlab_subscription
)
{
create
(
:gitlab_subscription
,
hosted_plan:
ultimate_plan
,
namespace:
ultimate_namespace
)
}
before
do
ultimate_namespace
.
add_owner
(
owner
)
end
it
'returns true for Ultimate-like plans'
do
get
api
(
"/namespaces/
#{
ultimate_namespace
.
id
}
/gitlab_subscription"
,
owner
)
expect
(
json_response
[
'plan'
][
'exclude_guests'
]).
to
eq
(
true
)
end
end
context
'when namespace is a project namespace'
do
context
'when namespace is a project namespace'
do
it
'returns a 404 error'
do
it
'returns a 404 error'
do
get
api
(
"/namespaces/
#{
project_namespace
.
id
}
/gitlab_subscription"
,
admin
)
get
api
(
"/namespaces/
#{
project_namespace
.
id
}
/gitlab_subscription"
,
admin
)
...
...
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