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
f6bda794
Commit
f6bda794
authored
Feb 23, 2022
by
Doug Stull
Committed by
Alper Akgun
Feb 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add free user cap feature flag and availability check
- foundation work for free user cap project
parent
b50ade79
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
129 additions
and
3 deletions
+129
-3
ee/app/controllers/groups/usage_quotas_controller.rb
ee/app/controllers/groups/usage_quotas_controller.rb
+1
-1
ee/app/models/ee/namespace.rb
ee/app/models/ee/namespace.rb
+23
-0
ee/app/views/groups/usage_quotas/index.html.haml
ee/app/views/groups/usage_quotas/index.html.haml
+1
-1
ee/config/feature_flags/development/free_user_cap.yml
ee/config/feature_flags/development/free_user_cap.yml
+8
-0
ee/spec/controllers/groups/usage_quotas_controller_spec.rb
ee/spec/controllers/groups/usage_quotas_controller_spec.rb
+1
-1
ee/spec/models/ee/namespace_spec.rb
ee/spec/models/ee/namespace_spec.rb
+95
-0
No files found.
ee/app/controllers/groups/usage_quotas_controller.rb
View file @
f6bda794
...
@@ -15,7 +15,7 @@ class Groups::UsageQuotasController < Groups::ApplicationController
...
@@ -15,7 +15,7 @@ class Groups::UsageQuotasController < Groups::ApplicationController
end
end
def
pending_members
def
pending_members
render_404
unless
@group
.
user_cap_available
?
render_404
unless
@group
.
apply_user_cap
?
@hide_search_settings
=
true
@hide_search_settings
=
true
end
end
...
...
ee/app/models/ee/namespace.rb
View file @
f6bda794
...
@@ -301,6 +301,18 @@ module EE
...
@@ -301,6 +301,18 @@ module EE
end
end
end
end
def
on_existing_free_subscription?
# this is a side-effect free version of checking if a namespace
# is on a free plan - see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/80839#note_851566461
strong_memoize
(
:on_existing_free_subscription
)
do
::
Plan
.
joins
(
:hosted_subscriptions
)
.
where
(
name:
::
Plan
::
FREE
)
.
where
(
gitlab_subscriptions:
{
namespace_id:
id
})
.
exists?
end
end
# When a purchasing a GL.com plan for a User namespace
# When a purchasing a GL.com plan for a User namespace
# we only charge for a single user.
# we only charge for a single user.
# This method is overwritten in Group where we made the calculation
# This method is overwritten in Group where we made the calculation
...
@@ -458,6 +470,17 @@ module EE
...
@@ -458,6 +470,17 @@ module EE
::
Feature
.
enabled?
(
:saas_user_caps
,
root_ancestor
,
default_enabled: :yaml
)
::
Feature
.
enabled?
(
:saas_user_caps
,
root_ancestor
,
default_enabled: :yaml
)
end
end
def
apply_free_user_cap?
return
false
unless
::
Gitlab
.
com?
return
false
unless
root_ancestor
.
on_existing_free_subscription?
::
Feature
.
enabled?
(
:free_user_cap
,
root_ancestor
,
default_enabled: :yaml
)
end
def
apply_user_cap?
user_cap_available?
||
apply_free_user_cap?
end
private
private
def
any_project_with_shared_runners_enabled_with_cte?
def
any_project_with_shared_runners_enabled_with_cte?
...
...
ee/app/views/groups/usage_quotas/index.html.haml
View file @
f6bda794
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
-
page_title
s_
(
"UsageQuota|Usage"
)
-
page_title
s_
(
"UsageQuota|Usage"
)
-
url_to_purchase_storage
=
buy_storage_path
(
@group
)
if
purchase_storage_link_enabled?
(
@group
)
-
url_to_purchase_storage
=
buy_storage_path
(
@group
)
if
purchase_storage_link_enabled?
(
@group
)
-
buy_addon_target_attr
=
buy_addon_target_attr
(
@group
)
if
purchase_storage_link_enabled?
(
@group
)
-
buy_addon_target_attr
=
buy_addon_target_attr
(
@group
)
if
purchase_storage_link_enabled?
(
@group
)
-
pending_members_page_path
=
pending_members_group_usage_quotas_path
(
@group
)
if
@group
.
user_cap_available
?
-
pending_members_page_path
=
pending_members_group_usage_quotas_path
(
@group
)
if
@group
.
apply_user_cap
?
-
pending_members_count
=
Member
.
in_hierarchy
(
@group
).
with_state
(
"awaiting"
).
count
-
pending_members_count
=
Member
.
in_hierarchy
(
@group
).
with_state
(
"awaiting"
).
count
-
if
show_product_purchase_success_alert?
-
if
show_product_purchase_success_alert?
...
...
ee/config/feature_flags/development/free_user_cap.yml
0 → 100644
View file @
f6bda794
---
name
:
free_user_cap
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/80839
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/352633
milestone
:
'
14.9'
type
:
development
group
:
group::conversion
default_enabled
:
false
ee/spec/controllers/groups/usage_quotas_controller_spec.rb
View file @
f6bda794
...
@@ -43,7 +43,7 @@ RSpec.describe Groups::UsageQuotasController do
...
@@ -43,7 +43,7 @@ RSpec.describe Groups::UsageQuotasController do
before
do
before
do
allow_next_found_instance_of
(
Group
)
do
|
group
|
allow_next_found_instance_of
(
Group
)
do
|
group
|
allow
(
group
).
to
receive
(
:
user_cap_available
?
).
and_return
(
feature_available
)
allow
(
group
).
to
receive
(
:
apply_user_cap
?
).
and_return
(
feature_available
)
end
end
end
end
...
...
ee/spec/models/ee/namespace_spec.rb
View file @
f6bda794
...
@@ -2207,6 +2207,101 @@ RSpec.describe Namespace do
...
@@ -2207,6 +2207,101 @@ RSpec.describe Namespace do
end
end
end
end
describe
'#apply_free_user_cap?'
,
:saas
do
let_it_be
(
:namespace
)
{
create
(
:group_with_plan
,
plan: :free_plan
)
}
let_it_be
(
:subgroup
)
{
create
(
:group
,
parent:
namespace
)
}
subject
(
:apply_free_user_cap?
)
{
namespace
.
apply_free_user_cap?
}
context
'when not on Gitlab.com'
do
before
do
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
false
)
end
it
{
is_expected
.
to
be
false
}
end
context
'when :free_user_cap is disabled'
do
before
do
stub_feature_flags
(
free_user_cap:
false
)
end
it
{
is_expected
.
to
be
false
}
end
context
'when :free_user_cap is enabled'
do
before
do
stub_feature_flags
(
free_user_cap:
true
)
end
it
{
is_expected
.
to
be
true
}
context
'when the namespace is not a group'
do
let_it_be
(
:namespace
)
do
namespace
=
create
(
:user
).
namespace
create
(
:gitlab_subscription
,
hosted_plan:
create
(
:free_plan
),
namespace:
namespace
)
namespace
end
it
{
is_expected
.
to
be
true
}
end
context
'when it is a non free plan'
do
let_it_be
(
:namespace
)
{
create
(
:group_with_plan
,
plan: :ultimate_plan
)
}
it
{
is_expected
.
to
be
false
}
end
context
'when no plan exists'
do
let_it_be
(
:namespace
)
{
create
(
:group
)
}
it
{
is_expected
.
to
be
false
}
end
end
end
describe
'#apply_user_cap?'
do
let
(
:namespace
)
{
build
(
:namespace
)
}
where
(
:user_cap_available
,
:apply_free_user_cap
,
:result
)
do
false
|
false
|
false
false
|
true
|
true
true
|
false
|
true
true
|
true
|
true
end
subject
{
namespace
.
apply_user_cap?
}
with_them
do
before
do
allow
(
namespace
).
to
receive
(
:user_cap_available?
).
and_return
(
user_cap_available
)
allow
(
namespace
).
to
receive
(
:apply_free_user_cap?
).
and_return
(
apply_free_user_cap
)
end
it
{
is_expected
.
to
eq
(
result
)
}
end
end
describe
'#on_existing_free_subscription?'
,
:saas
do
it
'returns true with a free plan'
do
namespace
=
create
(
:group_with_plan
,
plan: :free_plan
)
expect
(
namespace
.
on_existing_free_subscription?
).
to
be
(
true
)
end
it
'returns false when the plan is not free'
do
namespace
=
create
(
:group_with_plan
,
plan: :ultimate_plan
)
expect
(
namespace
.
on_existing_free_subscription?
).
to
be
(
false
)
end
it
'returns false when there is no plan'
do
namespace
=
create
(
:namespace
)
expect
(
namespace
.
on_existing_free_subscription?
).
to
be
(
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
)
...
...
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