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
d180f404
Commit
d180f404
authored
May 21, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate maximum active user count up until license issue date.
parent
064170d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
46 deletions
+36
-46
app/models/historical_data.rb
app/models/historical_data.rb
+2
-0
app/models/license.rb
app/models/license.rb
+7
-14
app/views/admin/licenses/show.html.haml
app/views/admin/licenses/show.html.haml
+1
-1
spec/models/historical_data_spec.rb
spec/models/historical_data_spec.rb
+8
-2
spec/models/license_spec.rb
spec/models/license_spec.rb
+18
-29
No files found.
app/models/historical_data.rb
View file @
d180f404
...
...
@@ -3,6 +3,8 @@ class HistoricalData < ActiveRecord::Base
# HistoricalData.during((Date.today - 1.year)..Date.today).average(:active_user_count)
scope
:during
,
->
(
range
)
{
where
(
date:
range
)
}
# HistoricalData.up_until(Date.today - 1.month).average(:active_user_count)
scope
:up_until
,
->
(
date
)
{
where
(
"date <= :date"
,
date:
date
)
}
class
<<
self
def
track!
...
...
app/models/license.rb
View file @
d180f404
...
...
@@ -96,27 +96,20 @@ class License < ActiveRecord::Base
return
unless
self
.
license?
&&
self
.
restricted?
(
:active_user_count
)
restricted_user_count
=
self
.
restrictions
[
:active_user_count
]
active_user_count
=
User
.
active
.
count
historical_active_user_count
=
HistoricalData
.
maximum
(
:active_user_count
)
||
0
active_user_count
=
HistoricalData
.
up_until
(
self
.
issued_at
)
.
maximum
(
:active_user_count
)
||
0
max_active_user_count
=
[
active_user_count
,
historical_active_user_count
].
max
return
if
active_user_count
<
restricted_user_count
return
if
max_active_user_count
<
restricted_user_count
overage
=
max_active_user_count
-
restricted_user_count
overage
=
active_user_count
-
restricted_user_count
message
=
""
message
<<
if
historical_active_user_count
>
active_user_count
"At one point, this GitLab installation had "
else
"This GitLab installation has "
end
message
<<
"
#{
number_with_delimiter
max_active_user_count
}
active
#{
"user"
.
pluralize
(
max_active_user_count
)
}
, "
message
<<
"At one point, this GitLab installation had "
message
<<
"
#{
number_with_delimiter
active_user_count
}
active
#{
"user"
.
pluralize
(
active_user_count
)
}
, "
message
<<
"exceeding this license's limit of
#{
number_with_delimiter
restricted_user_count
}
by "
message
<<
"
#{
number_with_delimiter
overage
}
#{
"user"
.
pluralize
(
overage
)
}
. "
message
<<
"Please upload a license for at least "
message
<<
"
#{
number_with_delimiter
max_active_user_count
}
#{
"user"
.
pluralize
(
max_
active_user_count
)
}
."
message
<<
"
#{
number_with_delimiter
active_user_count
}
#{
"user"
.
pluralize
(
active_user_count
)
}
."
self
.
errors
.
add
(
:base
,
message
)
end
...
...
app/views/admin/licenses/show.html.haml
View file @
d180f404
...
...
@@ -65,7 +65,7 @@
%strong
Exceeds license limit
-
historical
=
HistoricalData
.
maximum
(
:active_user_count
)
-
historical
=
HistoricalData
.
up_until
(
@license
.
issued_at
).
maximum
(
:active_user_count
)
-
if
historical
%li
%span
.light
Maximum active users:
...
...
spec/models/historical_data_spec.rb
View file @
d180f404
...
...
@@ -8,13 +8,19 @@ describe HistoricalData do
end
describe
".during"
do
it
"returns the historical data during the
given
period"
do
it
"returns the historical data during the
specified
period"
do
expect
(
HistoricalData
.
during
(
Date
.
new
(
2014
,
1
,
1
)
..
Date
.
new
(
2014
,
12
,
31
)).
average
(
:active_user_count
)).
to
eq
(
650
)
end
end
describe
".up_until"
do
it
"returns the historical data up until the specified date"
do
expect
(
HistoricalData
.
up_until
(
Date
.
new
(
2014
,
6
,
1
)).
average
(
:active_user_count
)).
to
eq
(
350
)
end
end
describe
".at"
do
it
"returns the historical data at the
given
date"
do
it
"returns the historical data at the
specified
date"
do
expect
(
HistoricalData
.
at
(
Date
.
new
(
2014
,
8
,
1
)).
active_user_count
).
to
eq
(
800
)
end
end
...
...
spec/models/license_spec.rb
View file @
d180f404
...
...
@@ -23,8 +23,10 @@ describe License do
end
end
describe
"Active user count"
do
let
(
:active_user_count
)
{
User
.
active
.
count
}
describe
"Historical active user count"
do
let
(
:active_user_count
)
{
User
.
active
.
count
+
10
}
let
(
:date
)
{
License
.
current
.
issued_at
}
let!
(
:historical_data
)
{
HistoricalData
.
create!
(
date:
date
,
active_user_count:
active_user_count
)
}
context
"when there is no active user count restriction"
do
it
"is valid"
do
...
...
@@ -37,39 +39,26 @@ describe License do
gl_license
.
restrictions
=
{
active_user_count:
active_user_count
-
1
}
end
it
"is invalid"
do
expect
(
license
).
to_not
be_valid
end
end
context
"when the active user count restriction is not exceeded"
do
before
do
gl_license
.
restrictions
=
{
active_user_count:
active_user_count
+
1
}
end
it
"is valid"
do
expect
(
license
).
to
be_valid
context
"when the license was issued"
do
it
"is invalid"
do
expect
(
license
).
to_not
be_valid
end
end
end
end
describe
"Historical active user count"
do
let
(
:active_user_count
)
{
User
.
active
.
count
+
10
}
let!
(
:historical_data
)
{
HistoricalData
.
create!
(
date:
License
.
current
.
issued_at
,
active_user_count:
active_user_count
)
}
context
"after the license was issued"
do
let
(
:date
)
{
Date
.
today
}
context
"when there is no active user count restriction
"
do
it
"is valid"
do
e
xpect
(
license
).
to
be_vali
d
it
"is valid
"
do
expect
(
license
).
to
be_valid
e
n
d
end
end
context
"when the active user count restriction is exceeded"
do
before
do
gl_license
.
restrictions
=
{
active_user_count:
active_user_count
-
1
}
end
context
"before the license was issued"
do
let
(
:date
)
{
License
.
current
.
issued_at
-
6
.
months
}
it
"is invalid"
do
expect
(
license
).
to_not
be_valid
it
"is invalid"
do
expect
(
license
).
to_not
be_valid
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