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
45ab4d10
Commit
45ab4d10
authored
May 07, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate historical active user count when uploading license.
parent
85c04a8a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
20 deletions
+70
-20
app/controllers/admin/licenses_controller.rb
app/controllers/admin/licenses_controller.rb
+1
-0
app/models/license.rb
app/models/license.rb
+19
-5
app/views/admin/licenses/show.html.haml
app/views/admin/licenses/show.html.haml
+14
-12
spec/factories.rb
spec/factories.rb
+1
-1
spec/models/license_spec.rb
spec/models/license_spec.rb
+35
-2
No files found.
app/controllers/admin/licenses_controller.rb
View file @
45ab4d10
...
@@ -5,6 +5,7 @@ class Admin::LicensesController < Admin::ApplicationController
...
@@ -5,6 +5,7 @@ class Admin::LicensesController < Admin::ApplicationController
respond_to
:html
respond_to
:html
def
show
def
show
@historical_active_user_count
=
HistoricalData
.
during
(
license
.
issued_at
..
Date
.
today
).
maximum
(
:active_user_count
)
@previous_licenses
=
License
.
previous
@previous_licenses
=
License
.
previous
end
end
...
...
app/models/license.rb
View file @
45ab4d10
...
@@ -96,12 +96,26 @@ class License < ActiveRecord::Base
...
@@ -96,12 +96,26 @@ class License < ActiveRecord::Base
restricted_user_count
=
self
.
restrictions
[
:active_user_count
]
restricted_user_count
=
self
.
restrictions
[
:active_user_count
]
active_user_count
=
User
.
active
.
count
active_user_count
=
User
.
active
.
count
return
if
active_user_count
<=
restricted_user_count
if
active_user_count
>
restricted_user_count
message
=
"This license allows
#{
restricted_user_count
}
active users. "
message
<<
"This GitLab installation currently has
#{
active_user_count
}
, "
message
<<
"i.e.
#{
active_user_count
-
restricted_user_count
}
too many."
message
=
"This license allows
#{
restricted_user_count
}
active users. "
self
.
errors
.
add
(
:base
,
message
)
message
<<
"This GitLab installation currently has
#{
active_user_count
}
, "
return
message
<<
"i.e.
#{
active_user_count
-
restricted_user_count
}
too many."
end
self
.
errors
.
add
(
:base
,
message
)
if
License
.
current
historical_active_user_count
=
HistoricalData
.
during
(
License
.
current
.
issued_at
..
Date
.
today
).
maximum
(
:active_user_count
)
if
historical_active_user_count
&&
historical_active_user_count
>
restricted_user_count
message
=
"This license allows
#{
restricted_user_count
}
active users. "
message
<<
"At one point during the life of the previous license, this GitLab installation had "
message
<<
"
#{
historical_active_user_count
}
active users, "
message
<<
"i.e.
#{
historical_active_user_count
-
restricted_user_count
}
too many."
self
.
errors
.
add
(
:base
,
message
)
end
end
end
end
def
not_expired
def
not_expired
...
...
app/views/admin/licenses/show.html.haml
View file @
45ab4d10
...
@@ -49,19 +49,21 @@
...
@@ -49,19 +49,21 @@
%span
.light
Active users:
%span
.light
Active users:
%strong
%strong
-
if
@license
.
restricted?
(
:active_user_count
)
-
if
@license
.
restricted?
(
:active_user_count
)
-
restricted
_user_count
=
@license
.
restrictions
[
:active_user_count
]
-
restricted
=
@license
.
restrictions
[
:active_user_count
]
-
active_user_cou
nt
=
User
.
active
.
count
-
curre
nt
=
User
.
active
.
count
#{
restricted_user_count
}
users
-
historical
=
@historical_active_user_count
-
if
active_user_count
>
restricted_user_count
#{
restricted
}
users
%span
.label.label-danger.pull-right
%strong
Exceeded by
#{
active_user_count
-
restricted_user_count
}
users
-
if
historical
&&
historical
>
restricted
-
elsif
restricted_user_count
>
active_user_count
%span
.label.label-danger.pull-right.prepend-left-10
%span
.label.label-success.pull-right
%strong
%strong
#{
restricted_user_count
-
active_user_count
}
more allowed
Maximum during license life:
#{
historical
}
users
-
else
%span
.label.label-info.pull-right
-
label_class
=
current
>
restricted
?
"danger"
:
restricted
>
current
?
"success"
:
"info"
%strong
Right at the limit
%span
.label.pull-right
{
class:
"label-#{label_class}"
}
%strong
Current:
#{
current
}
users
-
else
-
else
Unlimited
Unlimited
...
...
spec/factories.rb
View file @
45ab4d10
...
@@ -204,7 +204,7 @@ FactoryGirl.define do
...
@@ -204,7 +204,7 @@ FactoryGirl.define do
end
end
factory
:gitlab_license
,
class:
"Gitlab::License"
do
factory
:gitlab_license
,
class:
"Gitlab::License"
do
issued_at
{
Date
.
today
}
issued_at
{
Date
.
today
-
1
.
month
}
licensee
do
licensee
do
{
"Name"
=>
Faker
::
Name
.
name
}
{
"Name"
=>
Faker
::
Name
.
name
}
end
end
...
...
spec/models/license_spec.rb
View file @
45ab4d10
...
@@ -24,6 +24,39 @@ describe License do
...
@@ -24,6 +24,39 @@ describe License do
end
end
describe
"Active user count"
do
describe
"Active user count"
do
let
(
:active_user_count
)
{
User
.
active
.
count
}
context
"when there is no active user count restriction"
do
it
"is valid"
do
expect
(
license
).
to
be_valid
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
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
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
"when there is no active user count restriction"
do
context
"when there is no active user count restriction"
do
it
"is valid"
do
it
"is valid"
do
expect
(
license
).
to
be_valid
expect
(
license
).
to
be_valid
...
@@ -32,7 +65,7 @@ describe License do
...
@@ -32,7 +65,7 @@ describe License do
context
"when the active user count restriction is exceeded"
do
context
"when the active user count restriction is exceeded"
do
before
do
before
do
gl_license
.
restrictions
=
{
active_user_count:
User
.
active
.
count
-
1
}
gl_license
.
restrictions
=
{
active_user_count:
active_user_
count
-
1
}
end
end
it
"is invalid"
do
it
"is invalid"
do
...
@@ -42,7 +75,7 @@ describe License do
...
@@ -42,7 +75,7 @@ describe License do
context
"when the active user count restriction is not exceeded"
do
context
"when the active user count restriction is not exceeded"
do
before
do
before
do
gl_license
.
restrictions
=
{
active_user_count:
User
.
active
.
count
+
1
}
gl_license
.
restrictions
=
{
active_user_count:
active_user_
count
+
1
}
end
end
it
"is valid"
do
it
"is valid"
do
...
...
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