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
b359aebc
Commit
b359aebc
authored
Dec 17, 2020
by
Jason Goodman
Committed by
Patrick Bajao
Dec 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display maximum users in admin dashboard for any license duration
Do not assume the license is for one year
parent
2c4280cf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
35 deletions
+122
-35
ee/app/models/license.rb
ee/app/models/license.rb
+2
-7
ee/changelogs/unreleased/change-max-user-calculation.yml
ee/changelogs/unreleased/change-max-user-calculation.yml
+5
-0
ee/spec/helpers/license_monitoring_helper_spec.rb
ee/spec/helpers/license_monitoring_helper_spec.rb
+34
-17
ee/spec/models/license_spec.rb
ee/spec/models/license_spec.rb
+81
-11
No files found.
ee/app/models/license.rb
View file @
b359aebc
...
@@ -473,7 +473,7 @@ class License < ApplicationRecord
...
@@ -473,7 +473,7 @@ class License < ApplicationRecord
end
end
def
overage_with_historical_max
def
overage_with_historical_max
overage
(
historical_max_with_default_period
)
overage
(
maximum_user_count
)
end
end
def
historical_max
(
from
=
nil
,
to
=
nil
)
def
historical_max
(
from
=
nil
,
to
=
nil
)
...
@@ -481,12 +481,7 @@ class License < ApplicationRecord
...
@@ -481,12 +481,7 @@ class License < ApplicationRecord
end
end
def
maximum_user_count
def
maximum_user_count
[
historical_max
,
daily_billable_users_count
].
max
[
historical_max
(
starts_at
),
daily_billable_users_count
].
max
end
def
historical_max_with_default_period
@historical_max_with_default_period
||=
historical_max
end
end
def
update_trial_setting
def
update_trial_setting
...
...
ee/changelogs/unreleased/change-max-user-calculation.yml
0 → 100644
View file @
b359aebc
---
title
:
Display correct maximum users in admin dashboard for license of any duration
merge_request
:
49861
author
:
type
:
changed
ee/spec/helpers/license_monitoring_helper_spec.rb
View file @
b359aebc
...
@@ -108,28 +108,45 @@ RSpec.describe LicenseMonitoringHelper do
...
@@ -108,28 +108,45 @@ RSpec.describe LicenseMonitoringHelper do
end
end
describe
'#users_over_license'
do
describe
'#users_over_license'
do
context
'with an user overage'
do
let
(
:now
)
{
Date
.
current
}
let
(
:license
)
{
build
(
:license
)
}
before
do
def
setup_license
(
starts_at
:,
expires_at
:,
max_users
:)
allow
(
helper
).
to
receive
(
:license_is_over_capacity?
).
and_return
true
license
=
build
(
:license
,
allow
(
License
).
to
receive
(
:current
).
and_return
(
license
)
starts_at:
starts_at
,
allow
(
license
).
to
receive
(
:overage_with_historical_max
)
{
5
}
expires_at:
expires_at
,
end
restrictions:
{
active_user_count:
max_users
})
allow
(
License
).
to
receive
(
:current
).
and_return
(
license
)
it
'shows overage as a number'
do
license
expect
(
helper
.
users_over_license
).
to
eq
5
end
end
end
context
'without an user overage'
do
it
'shows overage as a number when there is an overage'
do
before
do
license
=
setup_license
(
starts_at:
now
-
3
.
months
,
expires_at:
now
+
9
.
months
,
max_users:
10
)
allow
(
helper
).
to
receive
(
:license_is_over_capacity?
).
and_return
false
create
(
:historical_data
,
recorded_at:
license
.
starts_at
+
1
.
month
,
active_user_count:
15
)
end
it
'shows overage as a number'
do
expect
(
helper
.
users_over_license
).
to
eq
(
5
)
expect
(
helper
.
users_over_license
).
to
eq
0
end
end
it
'shows overage as a number when there is not an overage'
do
setup_license
(
starts_at:
now
-
3
.
months
,
expires_at:
now
+
9
.
months
,
max_users:
10
)
expect
(
helper
.
users_over_license
).
to
eq
(
0
)
end
it
'reports overage for a license of 6 months in duration'
do
license
=
setup_license
(
starts_at:
now
-
3
.
months
,
expires_at:
now
+
3
.
months
,
max_users:
15
)
create
(
:historical_data
,
recorded_at:
license
.
starts_at
-
2
.
months
,
active_user_count:
45
)
create
(
:historical_data
,
recorded_at:
license
.
starts_at
+
1
.
month
,
active_user_count:
25
)
expect
(
helper
.
users_over_license
).
to
eq
(
10
)
end
it
'reports overage when the most recent billable user count is higher than the historical max active users'
do
license
=
setup_license
(
starts_at:
now
-
3
.
months
,
expires_at:
now
+
9
.
months
,
max_users:
40
)
create
(
:historical_data
,
recorded_at:
license
.
expires_at
-
2
.
months
,
active_user_count:
45
)
create
(
:instance_statistics_measurement
,
recorded_at:
now
-
1
.
day
,
identifier: :billable_users
,
count:
70
)
expect
(
helper
.
users_over_license
).
to
eq
(
30
)
end
end
end
end
end
end
ee/spec/models/license_spec.rb
View file @
b359aebc
...
@@ -855,21 +855,91 @@ RSpec.describe License do
...
@@ -855,21 +855,91 @@ RSpec.describe License do
end
end
describe
'#maximum_user_count'
do
describe
'#maximum_user_count'
do
subject
{
license
.
maximum_user_cou
nt
}
let
(
:now
)
{
Date
.
curre
nt
}
where
(
:daily_billable_users_count
,
:historical_max
,
:expected
)
do
it
'returns zero when there is no data'
do
100
|
50
|
100
expect
(
license
.
maximum_user_count
).
to
eq
(
0
)
50
|
100
|
100
50
|
50
|
50
end
end
with_them
do
it
'returns historical data'
do
before
do
create
(
:historical_data
,
active_user_count:
1
)
allow
(
license
).
to
receive
(
:daily_billable_users_count
)
{
daily_billable_users_count
}
allow
(
license
).
to
receive
(
:historical_max
)
{
historical_max
}
end
it
{
is_expected
.
to
eq
(
expected
)
}
expect
(
license
.
maximum_user_count
).
to
eq
(
1
)
end
it
'returns the billable users count'
do
create
(
:instance_statistics_measurement
,
identifier: :billable_users
,
count:
2
)
expect
(
license
.
maximum_user_count
).
to
eq
(
2
)
end
it
'returns the daily billable users count when it is higher than historical data'
do
create
(
:historical_data
,
active_user_count:
50
)
create
(
:instance_statistics_measurement
,
identifier: :billable_users
,
count:
100
)
expect
(
license
.
maximum_user_count
).
to
eq
(
100
)
end
it
'returns historical data when it is higher than the billable users count'
do
create
(
:historical_data
,
active_user_count:
100
)
create
(
:instance_statistics_measurement
,
identifier: :billable_users
,
count:
50
)
expect
(
license
.
maximum_user_count
).
to
eq
(
100
)
end
it
'returns the correct value when historical data and billable users are equal'
do
create
(
:historical_data
,
active_user_count:
100
)
create
(
:instance_statistics_measurement
,
identifier: :billable_users
,
count:
100
)
expect
(
license
.
maximum_user_count
).
to
eq
(
100
)
end
it
'returns the highest value from historical data'
do
create
(
:historical_data
,
recorded_at:
license
.
expires_at
-
4
.
months
,
active_user_count:
130
)
create
(
:historical_data
,
recorded_at:
license
.
expires_at
-
3
.
months
,
active_user_count:
250
)
create
(
:historical_data
,
recorded_at:
license
.
expires_at
-
1
.
month
,
active_user_count:
215
)
expect
(
license
.
maximum_user_count
).
to
eq
(
250
)
end
it
'uses only the most recent billable users entry'
do
create
(
:instance_statistics_measurement
,
recorded_at:
license
.
expires_at
-
3
.
months
,
identifier: :billable_users
,
count:
150
)
create
(
:historical_data
,
recorded_at:
license
.
expires_at
-
3
.
months
,
active_user_count:
140
)
create
(
:instance_statistics_measurement
,
recorded_at:
license
.
expires_at
-
2
.
months
,
identifier: :billable_users
,
count:
100
)
expect
(
license
.
maximum_user_count
).
to
eq
(
140
)
end
it
'returns the highest historical data since the license started for a 1 year license'
do
license
=
build
(
:license
,
starts_at:
now
-
4
.
months
,
expires_at:
now
+
8
.
months
)
create
(
:historical_data
,
recorded_at:
license
.
starts_at
-
1
.
day
,
active_user_count:
100
)
create
(
:historical_data
,
recorded_at:
now
,
active_user_count:
40
)
expect
(
license
.
maximum_user_count
).
to
eq
(
40
)
end
it
'returns the highest historical data since the license started for a license that lasts 6 months'
do
license
=
build
(
:license
,
starts_at:
now
-
4
.
months
,
expires_at:
now
+
2
.
months
)
create
(
:historical_data
,
recorded_at:
license
.
starts_at
-
1
.
day
,
active_user_count:
80
)
create
(
:historical_data
,
recorded_at:
now
,
active_user_count:
30
)
expect
(
license
.
maximum_user_count
).
to
eq
(
30
)
end
it
'returns the highest historical data since the license started for a license that lasts two years'
do
license
=
build
(
:license
,
starts_at:
now
-
6
.
months
,
expires_at:
now
+
18
.
months
)
create
(
:historical_data
,
recorded_at:
license
.
starts_at
-
1
.
day
,
active_user_count:
400
)
create
(
:historical_data
,
recorded_at:
now
,
active_user_count:
300
)
expect
(
license
.
maximum_user_count
).
to
eq
(
300
)
end
it
'returns the highest historical data during the license period for an expired license'
do
license
=
build
(
:license
,
starts_at:
now
-
14
.
months
,
expires_at:
now
-
2
.
months
)
create
(
:historical_data
,
recorded_at:
license
.
expires_at
-
1
.
month
,
active_user_count:
400
)
create
(
:historical_data
,
recorded_at:
now
,
active_user_count:
500
)
expect
(
license
.
maximum_user_count
).
to
eq
(
400
)
end
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