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
6acc1ff3
Commit
6acc1ff3
authored
Feb 22, 2022
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update service and response codes
- Simplify checks in service
parent
06638bf5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
15 deletions
+16
-15
ee/app/models/ee/alert_management/alert.rb
ee/app/models/ee/alert_management/alert.rb
+1
-3
ee/app/services/alert_management/metric_images/upload_service.rb
...services/alert_management/metric_images/upload_service.rb
+3
-3
ee/lib/api/alert_management_alerts.rb
ee/lib/api/alert_management_alerts.rb
+3
-3
ee/spec/requests/api/alert_management_alerts_spec.rb
ee/spec/requests/api/alert_management_alerts_spec.rb
+3
-3
ee/spec/services/alert_management/metric_images/upload_service_spec.rb
...ces/alert_management/metric_images/upload_service_spec.rb
+3
-3
locale/gitlab.pot
locale/gitlab.pot
+3
-0
No files found.
ee/app/models/ee/alert_management/alert.rb
View file @
6acc1ff3
...
...
@@ -23,9 +23,7 @@ module EE
end
def
metric_images_available?
return
false
unless
::
AlertManagement
::
MetricImage
.
available_for?
(
project
)
true
::
AlertManagement
::
MetricImage
.
available_for?
(
project
)
end
end
end
...
...
ee/app/services/alert_management/metric_images/upload_service.rb
View file @
6acc1ff3
...
...
@@ -15,7 +15,7 @@ module AlertManagement
end
def
execute
return
ServiceResponse
.
error
(
message:
"Not allowed!"
)
unless
alert
.
metric_images_available?
&&
can_upload_metrics?
return
ServiceResponse
.
error
(
message:
_
(
"You are not authorized to upload metric images"
),
http_status: :forbidden
)
unless
can_upload_metrics?
metric
=
AlertManagement
::
MetricImage
.
new
(
alert:
alert
,
...
...
@@ -27,14 +27,14 @@ module AlertManagement
if
metric
.
save
ServiceResponse
.
success
(
payload:
{
metric:
metric
,
alert:
alert
})
else
ServiceResponse
.
error
(
message:
metric
.
errors
.
full_messages
.
join
(
', '
))
ServiceResponse
.
error
(
message:
metric
.
errors
.
full_messages
.
join
(
', '
)
,
http_status: :bad_request
)
end
end
private
def
can_upload_metrics?
current_user
&
.
can?
(
:upload_alert_management_metric_image
,
alert
)
alert
.
metric_images_available?
&&
current_user
&
.
can?
(
:upload_alert_management_metric_image
,
alert
)
end
end
end
...
...
ee/lib/api/alert_management_alerts.rb
View file @
6acc1ff3
...
...
@@ -52,7 +52,7 @@ module API
if
upload
.
success?
present
upload
.
payload
[
:metric
],
with:
Entities
::
MetricImage
,
current_user:
current_user
,
project:
user_project
else
render_api_error!
(
upload
.
message
,
400
)
render_api_error!
(
upload
.
message
,
upload
.
http_status
)
end
end
...
...
@@ -80,7 +80,7 @@ module API
authorize!
(
:update_alert_management_metric_image
,
alert
)
render_api_error!
(
'
Not allowed!
'
,
400
)
unless
alert
.
metric_images_available?
render_api_error!
(
'
Feature not available
'
,
400
)
unless
alert
.
metric_images_available?
metric_image
=
alert
.
metric_images
.
find_by_id
(
params
[
:metric_image_id
])
...
...
@@ -89,7 +89,7 @@ module API
if
metric_image
&
.
update
(
params
.
slice
(
:url
,
:url_text
))
present
metric_image
,
with:
Entities
::
MetricImage
,
current_user:
current_user
,
project:
user_project
else
render_api_error!
(
'Metric image could not be updated'
,
4
00
)
render_api_error!
(
'Metric image could not be updated'
,
4
22
)
end
end
end
...
...
ee/spec/requests/api/alert_management_alerts_spec.rb
View file @
6acc1ff3
...
...
@@ -161,7 +161,7 @@ RSpec.describe API::AlertManagementAlerts do
project
.
add_developer
(
user
)
allow_next_instance_of
(
::
AlertManagement
::
MetricImages
::
UploadService
)
do
|
service
|
error
=
double
(
success?:
false
,
message:
'some error'
)
error
=
double
(
success?:
false
,
message:
'some error'
,
http_status: :bad_request
)
allow
(
service
).
to
receive
(
:execute
).
and_return
(
error
)
end
end
...
...
@@ -321,7 +321,7 @@ RSpec.describe API::AlertManagementAlerts do
it
'returns an error'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:
bad_request
)
expect
(
response
).
to
have_gitlab_http_status
(
:
unprocessable_entity
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Metric image could not be updated'
)
end
end
...
...
@@ -336,7 +336,7 @@ RSpec.describe API::AlertManagementAlerts do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'message'
]).
to
eq
(
'
Not allowed!
'
)
expect
(
json_response
[
'message'
]).
to
eq
(
'
Feature not available
'
)
end
end
end
...
...
ee/spec/services/alert_management/metric_images/upload_service_spec.rb
View file @
6acc1ff3
...
...
@@ -36,7 +36,7 @@ RSpec.describe AlertManagement::MetricImages::UploadService do
end
context
'user does not have permissions'
do
it_behaves_like
'no metric saved, an error given'
,
'
Not allowed!
'
it_behaves_like
'no metric saved, an error given'
,
'
You are not authorized to upload metric images
'
end
context
'user has permissions'
do
...
...
@@ -44,7 +44,7 @@ RSpec.describe AlertManagement::MetricImages::UploadService do
project
.
add_developer
(
current_user
)
end
it_behaves_like
'no metric saved, an error given'
,
'
Not allowed!
'
it_behaves_like
'no metric saved, an error given'
,
'
You are not authorized to upload metric images
'
context
'with license'
do
before
do
...
...
@@ -79,7 +79,7 @@ RSpec.describe AlertManagement::MetricImages::UploadService do
project
.
add_guest
(
current_user
)
end
it_behaves_like
'no metric saved, an error given'
,
'
Not allowed!
'
it_behaves_like
'no metric saved, an error given'
,
'
You are not authorized to upload metric images
'
end
end
end
...
...
locale/gitlab.pot
View file @
6acc1ff3
...
...
@@ -41693,6 +41693,9 @@ msgstr ""
msgid "You are not authorized to update this scanner profile"
msgstr ""
msgid "You are not authorized to upload metric images"
msgstr ""
msgid "You are now impersonating %{username}"
msgstr ""
...
...
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