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
Show 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
# like for SyncSeatLinkRequestWorker, the params are passed because the values from when
# the job was enqueued are necessary.
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
@key
=
key
@max_users
=
max_users
||
default_max_count
...
...
@@ -25,18 +26,28 @@ module Gitlab
SyncSeatLinkWorker
.
perform_async
end
def
should_sync_seats?
return
false
unless
license
if
license
.
cloud?
!
license
.
trial?
&&
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.
def
should_sync_seats?
Gitlab
::
CurrentSettings
.
seat_link_enabled?
&&
!
license
&
.
trial?
&&
license
&
.
expires_at
&&
# Skip sync if license has no expiration
!
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
private
attr_reader
:current_time
def
data
{
timestamp:
timestamp
.
iso8601
,
...
...
@@ -67,10 +78,6 @@ module Gitlab
end
end
def
current_time
strong_memoize
(
:current_time
)
{
Time
.
current
}
end
def
default_active_count
historical_data
&
.
active_user_count
end
...
...
ee/spec/factories/licenses.rb
View file @
70d78a8f
...
...
@@ -15,6 +15,10 @@ FactoryBot.define do
expires_at
{
3
.
weeks
.
ago
.
to_date
}
end
trait
:cloud
do
type
{
'cloud'
}
end
transient
do
plan
{
License
::
STARTER_PLAN
}
end
...
...
@@ -48,10 +52,15 @@ FactoryBot.define do
trial
{
false
}
end
trait
:cloud
do
cloud
{
true
}
end
data
do
attrs
=
[
:gitlab_license
]
attrs
<<
:trial
if
trial
attrs
<<
:expired
if
expired
attrs
<<
:cloud
if
cloud
build
(
*
attrs
,
plan:
plan
).
export
end
...
...
ee/spec/models/gitlab/seat_link_data_spec.rb
View file @
70d78a8f
...
...
@@ -120,40 +120,82 @@ RSpec.describe Gitlab::SeatLinkData do
describe
'#should_sync_seats?'
do
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?
}
context
'when all the pre conditions are valid'
do
it
{
is_expected
.
to
eq
(
true
)
}
end
context
'when seat link is disabled'
do
before
do
allow
(
Settings
.
gitlab
).
to
receive
(
:seat_link_enabled
).
and_return
(
false
)
context
'when license key is missing'
do
let
(
:license
)
{
nil
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when expires_at is not set'
do
let
(
:license
)
{
build
(
:license
,
expires_at:
nil
)
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when license key is missing'
do
before
do
allow
(
License
).
to
receive
(
:current
).
and_return
(
nil
)
context
'cloud license'
do
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 license is trial'
do
context
'when historical data not found'
do
before
do
historical_data
.
destroy!
end
it
{
is_expected
.
to
eq
(
true
)
}
end
end
context
'legacy license'
do
let
(
:license
)
{
build
(
:license
)
}
context
'when seat link is disabled'
do
before
do
allow
(
License
).
to
receive
(
:current
).
and_return
(
create
(
:license
,
trial:
true
))
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
)
{
Time
.
iso8601
(
'2015-03-22T06:09:18Z'
)
}
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
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