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
3be7421e
Commit
3be7421e
authored
Mar 24, 2021
by
Robert May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache storage alert banner
Caches the storage alert on a short TTL.
parent
760d6c5f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
27 deletions
+83
-27
ee/app/helpers/ee/namespace_storage_limit_alert_helper.rb
ee/app/helpers/ee/namespace_storage_limit_alert_helper.rb
+8
-2
ee/app/views/shared/_namespace_storage_limit_alert.html.haml
ee/app/views/shared/_namespace_storage_limit_alert.html.haml
+27
-25
ee/spec/helpers/ee/namespace_storage_limit_alert_helper_spec.rb
...c/helpers/ee/namespace_storage_limit_alert_helper_spec.rb
+47
-0
ee/spec/support/shared_examples/controllers/namespace_storage_limit_alert_shared_examples.rb
...trollers/namespace_storage_limit_alert_shared_examples.rb
+1
-0
No files found.
ee/app/helpers/ee/namespace_storage_limit_alert_helper.rb
View file @
3be7421e
...
...
@@ -10,11 +10,13 @@ module EE
end
def
display_namespace_storage_limit_alert?
(
namespace
)
@display_namespace_storage_limit_alert
&&
!
usage_quota_page?
(
namespace
)
@display_namespace_storage_limit_alert
&&
!
usage_quota_page?
(
namespace
)
&&
can?
(
current_user
,
:admin_namespace
,
namespace
.
root_ancestor
)
end
def
namespace_storage_alert
(
namespace
)
return
{}
if
current_user
.
nil?
return
{}
unless
can?
(
current_user
,
:admin_namespace
,
namespace
.
root_ancestor
)
payload
=
check_storage_size_service
(
namespace
).
execute
.
payload
...
...
@@ -54,6 +56,10 @@ module EE
EE
::
SUBSCRIPTIONS_MORE_STORAGE_URL
end
def
number_of_hidden_storage_alert_banners
cookies
.
count
{
|
key
,
value
|
key
.
starts_with?
(
"hide_storage_limit_alert"
)
&&
value
==
"true"
}
end
private
def
usage_quota_page?
(
namespace
)
...
...
ee/app/views/shared/_namespace_storage_limit_alert.html.haml
View file @
3be7421e
...
...
@@ -3,31 +3,33 @@
-
return
unless
namespace
.
present?
-
return
unless
display_namespace_storage_limit_alert?
(
namespace
)
-
payload
=
namespace_storage_alert
(
namespace
)
-
return
if
payload
.
empty?
=
cache
([
namespace
,
number_of_hidden_storage_alert_banners
],
expires_in:
1
.
minute
)
do
-
payload
=
namespace_storage_alert
(
namespace
)
-
unless
payload
.
empty?
-
alert_level
=
payload
[
:alert_level
]
-
root_namespace
=
payload
[
:root_namespace
]
-
style
=
namespace_storage_alert_style
(
alert_level
)
-
icon
=
namespace_storage_alert_icon
(
alert_level
)
-
purchase_link
=
purchase_storage_url
if
purchase_storage_link_enabled?
(
namespace
)
-
usage_link
=
usage_quotas_path
(
root_namespace
,
anchor:
'storage-quota-tab'
)
-
show_storage_banner_actions
=
purchase_link
||
usage_link
-
alert_level
=
payload
[
:alert_level
]
-
root_namespace
=
payload
[
:root_namespace
]
.gl-py-5
.gl-alert.js-namespace-storage-alert
{
class:
"gl-alert-#{style}"
,
role:
'alert'
}
=
sprite_icon
(
icon
,
css_class:
"gl-icon gl-alert-icon"
)
.gl-alert-title
%h4
.gl-alert-title
=
payload
[
:usage_message
]
-
style
=
namespace_storage_alert_style
(
alert_level
)
-
icon
=
namespace_storage_alert_icon
(
alert_level
)
-
purchase_link
=
purchase_storage_url
if
purchase_storage_link_enabled?
(
namespace
)
-
usage_link
=
usage_quotas_path
(
root_namespace
,
anchor:
'storage-quota-tab'
)
-
show_storage_banner_actions
=
purchase_link
||
usage_link
-
if
alert_level
!=
:error
%button
.js-namespace-storage-alert-dismiss.gl-alert-dismiss.gl-cursor-pointer
{
type:
'button'
,
'aria-label'
=>
_
(
'Dismiss'
),
data:
{
id:
root_namespace
.
id
,
level:
alert_level
}
}
=
sprite_icon
(
'close'
,
css_class:
'gl-icon'
)
.gl-py-5
.gl-alert.js-namespace-storage-alert
{
class:
"gl-alert-#{style}"
,
role:
'alert'
}
=
sprite_icon
(
icon
,
css_class:
"gl-icon gl-alert-icon"
)
.gl-alert-title
%h4
.gl-alert-title
=
payload
[
:usage_message
]
-
if
alert_level
!=
:error
%button
.js-namespace-storage-alert-dismiss.gl-alert-dismiss.gl-cursor-pointer
{
type:
'button'
,
'aria-label'
=>
_
(
'Dismiss'
),
data:
{
id:
root_namespace
.
id
,
level:
alert_level
}
}
=
sprite_icon
(
'close'
,
css_class:
'gl-icon'
)
.gl-alert-body
=
payload
[
:explanation_message
]
-
if
show_storage_banner_actions
.gl-alert-actions
-
if
purchase_link
=
link_to
(
_
(
'Purchase more storage'
),
purchase_link
,
class:
"btn gl-alert-action btn-md gl-button btn-success"
)
-
if
usage_link
=
link_to
(
_
(
'View usage details'
),
usage_link
,
class:
"btn gl-alert-action btn-md gl-button btn-default"
)
.gl-alert-body
=
payload
[
:explanation_message
]
-
if
show_storage_banner_actions
.gl-alert-actions
-
if
purchase_link
=
link_to
(
_
(
'Purchase more storage'
),
purchase_link
,
class:
"btn gl-alert-action btn-md gl-button btn-success"
)
-
if
usage_link
=
link_to
(
_
(
'View usage details'
),
usage_link
,
class:
"btn gl-alert-action btn-md gl-button btn-default"
)
ee/spec/helpers/ee/namespace_storage_limit_alert_helper_spec.rb
View file @
3be7421e
...
...
@@ -21,6 +21,9 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
before
do
assign
(
:display_namespace_storage_limit_alert
,
display_namespace_storage_limit_alert
)
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
admin
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
anything
,
:admin_namespace
,
namespace
.
root_ancestor
).
and_return
(
false
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
admin
,
:admin_namespace
,
namespace
.
root_ancestor
).
and_return
(
true
)
end
context
'when display_namespace_storage_limit_alert is true'
do
...
...
@@ -43,6 +46,12 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
expect
(
helper
.
display_namespace_storage_limit_alert?
(
namespace
)).
to
eq
(
true
)
end
it
'returns false when user is not an admin'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
admin
,
:admin_namespace
,
namespace
.
root_ancestor
).
and_return
(
false
)
expect
(
helper
.
display_namespace_storage_limit_alert?
(
namespace
)).
to
eq
(
false
)
end
end
context
'when display_namespace_storage_limit_alert is false'
do
...
...
@@ -90,6 +99,9 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
allow_next_instance_of
(
service_class_name
,
namespace
,
admin
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
and_return
(
ServiceResponse
.
success
(
payload:
payload
))
end
allow
(
helper
).
to
receive
(
:can?
).
with
(
nil
,
:admin_namespace
,
namespace
.
root_ancestor
).
and_return
(
false
)
allow
(
helper
).
to
receive
(
:can?
).
with
(
admin
,
:admin_namespace
,
namespace
.
root_ancestor
).
and_return
(
true
)
end
context
'when payload is not empty and no cookie is set'
do
...
...
@@ -104,6 +116,14 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
it
{
is_expected
.
to
eq
({})
}
end
context
'when current_user is not an admin of the namespace'
do
before
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
admin
,
:admin_namespace
,
namespace
.
root_ancestor
).
and_return
(
false
)
end
it
{
is_expected
.
to
eq
({})
}
end
context
'when payload is empty'
do
let
(
:payload
)
{
{}
}
...
...
@@ -179,4 +199,31 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
it
{
is_expected
.
to
eq
(
result
)
}
end
end
describe
'#number_of_hidden_storage_alert_banners'
do
subject
{
helper
.
number_of_hidden_storage_alert_banners
}
let_it_be
(
:namespace
)
{
create
(
:namespace
)
}
context
'when a cookie is set'
do
before
do
helper
.
request
.
cookies
[
"hide_storage_limit_alert_
#{
namespace
.
id
}
_info"
]
=
'true'
end
it
{
is_expected
.
to
eq
(
1
)
}
end
context
'when two cookies are set'
do
before
do
helper
.
request
.
cookies
[
"hide_storage_limit_alert_
#{
namespace
.
id
}
_info"
]
=
'true'
helper
.
request
.
cookies
[
"hide_storage_limit_alert_
#{
namespace
.
id
}
_danger"
]
=
'true'
end
it
{
is_expected
.
to
eq
(
2
)
}
end
context
'when no cookies are set'
do
it
{
is_expected
.
to
eq
(
0
)
}
end
end
end
ee/spec/support/shared_examples/controllers/namespace_storage_limit_alert_shared_examples.rb
View file @
3be7421e
...
...
@@ -18,6 +18,7 @@ RSpec.shared_examples 'namespace storage limit alert' do
end
allow
(
controller
).
to
receive
(
:current_user
).
and_return
(
user
)
namespace
.
add_owner
(
user
)
end
render_views
...
...
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