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
70d78a8f
Commit
70d78a8f
authored
Apr 08, 2021
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
License sync even if historical data absent
We want to update license regardless of data availablility.
parent
c457d53e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
26 deletions
+84
-26
ee/app/models/gitlab/seat_link_data.rb
ee/app/models/gitlab/seat_link_data.rb
+18
-11
ee/spec/factories/licenses.rb
ee/spec/factories/licenses.rb
+9
-0
ee/spec/models/gitlab/seat_link_data_spec.rb
ee/spec/models/gitlab/seat_link_data_spec.rb
+57
-15
No files found.
ee/app/models/gitlab/seat_link_data.rb
View file @
70d78a8f
...
@@ -13,6 +13,7 @@ module Gitlab
...
@@ -13,6 +13,7 @@ module Gitlab
# like for SyncSeatLinkRequestWorker, the params are passed because the values from when
# like for SyncSeatLinkRequestWorker, the params are passed because the values from when
# the job was enqueued are necessary.
# the job was enqueued are necessary.
def
initialize
(
timestamp:
nil
,
key:
default_key
,
max_users:
nil
,
active_users:
nil
)
def
initialize
(
timestamp:
nil
,
key:
default_key
,
max_users:
nil
,
active_users:
nil
)
@current_time
=
Time
.
current
@timestamp
=
timestamp
||
historical_data
&
.
recorded_at
||
current_time
@timestamp
=
timestamp
||
historical_data
&
.
recorded_at
||
current_time
@key
=
key
@key
=
key
@max_users
=
max_users
||
default_max_count
@max_users
=
max_users
||
default_max_count
...
@@ -25,18 +26,28 @@ module Gitlab
...
@@ -25,18 +26,28 @@ module Gitlab
SyncSeatLinkWorker
.
perform_async
SyncSeatLinkWorker
.
perform_async
end
end
# Only sync paid licenses from start date until 14 days after expiration
# when seat link feature is enabled.
def
should_sync_seats?
def
should_sync_seats?
Gitlab
::
CurrentSettings
.
seat_link_enabled?
&&
return
false
unless
license
!
license
&
.
trial?
&&
license
&
.
expires_at
&&
# Skip sync if license has no expiration
if
license
.
cloud?
historical_data
.
present?
&&
# Skip sync if there is no historical data
!
license
.
trial?
&&
timestamp
.
between?
(
license
.
starts_at
.
beginning_of_day
,
license
.
expires_at
.
end_of_day
+
14
.
days
)
license
.
expires_at
&&
# Skip sync if license has no expiration
timestamp
.
between?
(
license
.
starts_at
.
beginning_of_day
,
license
.
expires_at
.
end_of_day
+
14
.
days
)
else
# Only sync paid licenses from start date until 14 days after expiration
# when seat link feature is enabled.
Gitlab
::
CurrentSettings
.
seat_link_enabled?
&&
!
license
.
trial?
&&
license
.
expires_at
&&
# Skip sync if license has no expiration
historical_data
.
present?
&&
# Skip sync if there is no historical data
timestamp
.
between?
(
license
.
starts_at
.
beginning_of_day
,
license
.
expires_at
.
end_of_day
+
14
.
days
)
end
end
end
private
private
attr_reader
:current_time
def
data
def
data
{
{
timestamp:
timestamp
.
iso8601
,
timestamp:
timestamp
.
iso8601
,
...
@@ -67,10 +78,6 @@ module Gitlab
...
@@ -67,10 +78,6 @@ module Gitlab
end
end
end
end
def
current_time
strong_memoize
(
:current_time
)
{
Time
.
current
}
end
def
default_active_count
def
default_active_count
historical_data
&
.
active_user_count
historical_data
&
.
active_user_count
end
end
...
...
ee/spec/factories/licenses.rb
View file @
70d78a8f
...
@@ -15,6 +15,10 @@ FactoryBot.define do
...
@@ -15,6 +15,10 @@ FactoryBot.define do
expires_at
{
3
.
weeks
.
ago
.
to_date
}
expires_at
{
3
.
weeks
.
ago
.
to_date
}
end
end
trait
:cloud
do
type
{
'cloud'
}
end
transient
do
transient
do
plan
{
License
::
STARTER_PLAN
}
plan
{
License
::
STARTER_PLAN
}
end
end
...
@@ -48,10 +52,15 @@ FactoryBot.define do
...
@@ -48,10 +52,15 @@ FactoryBot.define do
trial
{
false
}
trial
{
false
}
end
end
trait
:cloud
do
cloud
{
true
}
end
data
do
data
do
attrs
=
[
:gitlab_license
]
attrs
=
[
:gitlab_license
]
attrs
<<
:trial
if
trial
attrs
<<
:trial
if
trial
attrs
<<
:expired
if
expired
attrs
<<
:expired
if
expired
attrs
<<
:cloud
if
cloud
build
(
*
attrs
,
plan:
plan
).
export
build
(
*
attrs
,
plan:
plan
).
export
end
end
...
...
ee/spec/models/gitlab/seat_link_data_spec.rb
View file @
70d78a8f
...
@@ -120,40 +120,82 @@ RSpec.describe Gitlab::SeatLinkData do
...
@@ -120,40 +120,82 @@ RSpec.describe Gitlab::SeatLinkData do
describe
'#should_sync_seats?'
do
describe
'#should_sync_seats?'
do
let_it_be
(
:historical_data
)
{
create
(
:historical_data
,
recorded_at:
timestamp
)
}
let_it_be
(
:historical_data
)
{
create
(
:historical_data
,
recorded_at:
timestamp
)
}
let
(
:license
)
{
build
(
:license
,
:cloud
)
}
before
do
allow
(
License
).
to
receive
(
:current
).
and_return
(
license
)
end
subject
{
super
().
should_sync_seats?
}
subject
{
super
().
should_sync_seats?
}
context
'when all the pre conditions are valid'
do
context
'when all the pre conditions are valid'
do
it
{
is_expected
.
to
eq
(
true
)
}
it
{
is_expected
.
to
eq
(
true
)
}
end
end
context
'when seat link is disabled'
do
context
'when license key is missing'
do
before
do
let
(
:license
)
{
nil
}
allow
(
Settings
.
gitlab
).
to
receive
(
:seat_link_enabled
).
and_return
(
false
)
end
it
{
is_expected
.
to
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
context
'when license key is missing'
do
context
'when expires_at is not set'
do
before
do
let
(
:license
)
{
build
(
:license
,
expires_at:
nil
)
}
allow
(
License
).
to
receive
(
:current
).
and_return
(
nil
)
end
it
{
is_expected
.
to
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
context
'when license is trial'
do
context
'cloud license'
do
before
do
context
'when license is trial'
do
allow
(
License
).
to
receive
(
:current
).
and_return
(
create
(
:license
,
trial:
true
))
let
(
:license
)
{
build
(
:license
,
trial:
true
)
}
it
{
is_expected
.
to
be_falsey
}
end
end
it
{
is_expected
.
to
be_falsey
}
context
'when timestamp is out of the range'
do
let
(
:timestamp
)
{
license
.
starts_at
-
1
.
day
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when historical data not found'
do
before
do
historical_data
.
destroy!
end
it
{
is_expected
.
to
eq
(
true
)
}
end
end
end
context
'
when timestamp is out of the rang
e'
do
context
'
legacy licens
e'
do
let
(
:
timestamp
)
{
Time
.
iso8601
(
'2015-03-22T06:09:18Z'
)
}
let
(
:
license
)
{
build
(
:license
)
}
it
{
is_expected
.
to
be_falsey
}
context
'when seat link is disabled'
do
before
do
allow
(
Settings
.
gitlab
).
to
receive
(
:seat_link_enabled
).
and_return
(
false
)
end
it
{
is_expected
.
to
be_falsey
}
end
context
'when license is trial'
do
let
(
:license
)
{
build
(
:license
,
trial:
true
)
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when timestamp is out of the range'
do
let
(
:timestamp
)
{
license
.
starts_at
-
1
.
day
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when historical data not found'
do
before
do
historical_data
.
destroy!
end
it
{
is_expected
.
to
eq
(
false
)
}
end
end
end
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