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
fc8902d2
Commit
fc8902d2
authored
Nov 05, 2021
by
Vijay Hawoldar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only refresh max_seats_used and use DB value
parent
78dae45f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
31 deletions
+10
-31
ee/app/models/gitlab_subscription.rb
ee/app/models/gitlab_subscription.rb
+6
-5
ee/spec/models/gitlab_subscription_spec.rb
ee/spec/models/gitlab_subscription_spec.rb
+3
-25
ee/spec/requests/api/namespaces_spec.rb
ee/spec/requests/api/namespaces_spec.rb
+1
-1
No files found.
ee/app/models/gitlab_subscription.rb
View file @
fc8902d2
...
...
@@ -71,9 +71,9 @@ class GitlabSubscription < ApplicationRecord
end
# Refresh seat related attribute (without persisting them)
def
refresh_seat_attributes!
(
new_term_reset:
false
)
def
refresh_seat_attributes!
self
.
seats_in_use
=
calculate_seats_in_use
self
.
max_seats_used
=
new_term_reset
?
seats_in_use
:
[
max_seats_used
,
seats_in_use
].
max
self
.
max_seats_used
=
[
max_seats_used
,
seats_in_use
].
max
self
.
seats_owed
=
calculate_seats_owed
end
...
...
@@ -179,12 +179,13 @@ class GitlabSubscription < ApplicationRecord
ElasticsearchIndexedNamespace
.
safe_find_or_create_by!
(
namespace_id:
namespace_id
)
end
# If the subscription starts a new term, the dates will change. We reset
seat counts
#
so that we don't carry over max_seats_used/owed
from the previous term
# If the subscription starts a new term, the dates will change. We reset
max_seats_used
#
and seats_owed so that we don't carry it over
from the previous term
def
reset_seats_for_new_term
return
unless
new_term?
refresh_seat_attributes!
(
new_term_reset:
true
)
self
.
max_seats_used
=
attributes
[
'seats_in_use'
]
self
.
seats_owed
=
calculate_seats_owed
end
def
new_term?
...
...
ee/spec/models/gitlab_subscription_spec.rb
View file @
fc8902d2
...
...
@@ -179,16 +179,6 @@ RSpec.describe GitlabSubscription, :saas do
.
and
not_change
(
gitlab_subscription
,
:max_seats_used
)
.
and
not_change
(
gitlab_subscription
,
:seats_owed
)
end
context
'when resetting for a new term'
do
it
'sets max_seats_used to seats_in_use'
do
expect
do
gitlab_subscription
.
refresh_seat_attributes!
(
new_term_reset:
true
)
end
.
to
change
(
gitlab_subscription
,
:seats_in_use
).
from
(
0
).
to
(
1
)
.
and
change
(
gitlab_subscription
,
:max_seats_used
).
from
(
2
).
to
(
1
)
.
and
not_change
(
gitlab_subscription
,
:seats_owed
)
end
end
end
context
'when current seats in use is higher than seats and max_seats_used'
do
...
...
@@ -201,16 +191,6 @@ RSpec.describe GitlabSubscription, :saas do
.
and
change
(
gitlab_subscription
,
:max_seats_used
).
from
(
2
).
to
(
4
)
.
and
change
(
gitlab_subscription
,
:seats_owed
).
from
(
0
).
to
(
1
)
end
context
'when resetting for a new term'
do
it
'sets max_seats_used to seats_in_use'
do
expect
do
gitlab_subscription
.
refresh_seat_attributes!
(
new_term_reset:
true
)
end
.
to
change
(
gitlab_subscription
,
:seats_in_use
).
from
(
0
).
to
(
4
)
.
and
change
(
gitlab_subscription
,
:max_seats_used
).
from
(
2
).
to
(
4
)
.
and
change
(
gitlab_subscription
,
:seats_owed
).
from
(
0
).
to
(
1
)
end
end
end
end
...
...
@@ -454,7 +434,7 @@ RSpec.describe GitlabSubscription, :saas do
context
'before_update'
,
:freeze_time
do
let
(
:gitlab_subscription
)
do
create
(
:gitlab_subscription
,
max_seats_used:
42
,
seats:
13
,
seats_owed:
29
,
start_date:
Date
.
today
-
1
.
year
)
create
(
:gitlab_subscription
,
seats_in_use:
20
,
max_seats_used:
42
,
seats:
13
,
seats_owed:
29
,
start_date:
Date
.
today
-
1
.
year
)
end
it
'logs previous state to gitlab subscription history'
do
...
...
@@ -470,10 +450,6 @@ RSpec.describe GitlabSubscription, :saas do
end
context
'when start and end dates change'
do
before
do
allow
(
gitlab_subscription
).
to
receive
(
:seats_in_use
).
and_return
(
20
)
end
context
'when start_date is after the old end_date'
do
it
'resets seats attributes'
do
new_start
=
gitlab_subscription
.
end_date
+
1
.
year
...
...
@@ -485,6 +461,7 @@ RSpec.describe GitlabSubscription, :saas do
.
and
change
(
gitlab_subscription
,
:end_date
).
to
(
new_end
)
.
and
change
(
gitlab_subscription
,
:max_seats_used
).
from
(
42
).
to
(
20
)
.
and
change
(
gitlab_subscription
,
:seats_owed
).
from
(
29
).
to
(
7
)
.
and
not_change
(
gitlab_subscription
,
:seats_in_use
)
end
end
...
...
@@ -501,6 +478,7 @@ RSpec.describe GitlabSubscription, :saas do
.
and
change
(
gitlab_subscription
,
:end_date
).
to
(
new_end
)
.
and
change
(
gitlab_subscription
,
:max_seats_used
).
from
(
42
).
to
(
20
)
.
and
change
(
gitlab_subscription
,
:seats_owed
).
from
(
29
).
to
(
7
)
.
and
not_change
(
gitlab_subscription
,
:seats_in_use
)
end
end
...
...
ee/spec/requests/api/namespaces_spec.rb
View file @
fc8902d2
...
...
@@ -685,7 +685,7 @@ RSpec.describe API::Namespaces do
gitlab_subscription
.
update!
(
seats:
20
,
max_seats_used:
42
,
seats_owed:
22
)
new_start
=
gitlab_subscription
.
end_date
+
1
.
year
new_end
=
gitlab_subscription
.
end_date
+
1
.
year
new_end
=
new_start
+
1
.
year
new_term_params
=
params
.
merge
(
start_date:
new_start
,
end_date:
new_end
)
expect
(
gitlab_subscription
.
seats_in_use
).
to
eq
0
...
...
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