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
b1044aeb
Commit
b1044aeb
authored
Apr 13, 2022
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop using reference to feature
- Fix factory - Fix some specs
parent
16007fcd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
75 deletions
+40
-75
app/models/alert_management/metric_image.rb
app/models/alert_management/metric_image.rb
+1
-1
app/services/alert_management/metric_images/upload_service.rb
...services/alert_management/metric_images/upload_service.rb
+6
-1
ee/app/models/gitlab_subscriptions/features.rb
ee/app/models/gitlab_subscriptions/features.rb
+0
-1
lib/api/alert_management_alerts.rb
lib/api/alert_management_alerts.rb
+4
-1
spec/factories/alert_management/metric_images.rb
spec/factories/alert_management/metric_images.rb
+0
-0
spec/models/alert_management/metric_image_spec.rb
spec/models/alert_management/metric_image_spec.rb
+1
-17
spec/requests/api/alert_management_alerts_spec.rb
spec/requests/api/alert_management_alerts_spec.rb
+28
-54
No files found.
app/models/alert_management/metric_image.rb
View file @
b1044aeb
...
...
@@ -8,7 +8,7 @@ module AlertManagement
belongs_to
:alert
,
class_name:
'AlertManagement::Alert'
,
foreign_key:
'alert_id'
,
inverse_of: :metric_images
def
self
.
available_for?
(
project
)
project
&
.
feature_available?
(
:alert_metric_upload
)
true
end
private
...
...
app/services/alert_management/metric_images/upload_service.rb
View file @
b1044aeb
...
...
@@ -15,7 +15,12 @@ module AlertManagement
end
def
execute
return
ServiceResponse
.
error
(
message:
_
(
"You are not authorized to upload metric images"
),
http_status: :forbidden
)
unless
can_upload_metrics?
unless
can_upload_metrics?
return
ServiceResponse
.
error
(
message:
_
(
"You are not authorized to upload metric images"
),
http_status: :forbidden
)
end
metric
=
AlertManagement
::
MetricImage
.
new
(
alert:
alert
,
...
...
ee/app/models/gitlab_subscriptions/features.rb
View file @
b1044aeb
...
...
@@ -72,7 +72,6 @@ module GitlabSubscriptions
PREMIUM_FEATURES
=
%i[
adjourned_deletion_for_projects_and_groups
admin_audit_log
alert_metric_upload
auditor_user
blocking_merge_requests
board_assignee_lists
...
...
lib/api/alert_management_alerts.rb
View file @
b1044aeb
...
...
@@ -50,7 +50,10 @@ module API
).
execute
if
upload
.
success?
present
upload
.
payload
[
:metric
],
with:
Entities
::
MetricImage
,
current_user:
current_user
,
project:
user_project
present
upload
.
payload
[
:metric
],
with:
Entities
::
MetricImage
,
current_user:
current_user
,
project:
user_project
else
render_api_error!
(
upload
.
message
,
upload
.
http_status
)
end
...
...
ee/
spec/factories/alert_management/metric_images.rb
→
spec/factories/alert_management/metric_images.rb
View file @
b1044aeb
File moved
spec/models/alert_management/metric_image_spec.rb
View file @
b1044aeb
...
...
@@ -19,22 +19,6 @@ RSpec.describe AlertManagement::MetricImage do
describe
'.available_for?'
do
subject
{
described_class
.
available_for?
(
issue
.
project
)
}
before
do
stub_licensed_features
(
alert_metric_upload:
true
)
end
let_it_be_with_refind
(
:issue
)
{
create
(
:issue
)
}
context
'license enabled'
do
it
{
is_expected
.
to
eq
(
true
)
}
end
context
'license disabled'
do
before
do
stub_licensed_features
(
alert_metric_upload:
false
)
end
it
{
is_expected
.
to
eq
(
false
)
}
end
it
{
is_expected
.
to
eq
(
true
)
}
end
end
spec/requests/api/alert_management_alerts_spec.rb
View file @
b1044aeb
...
...
@@ -18,7 +18,10 @@ RSpec.describe API::AlertManagementAlerts do
project
.
add_developer
(
user
)
end
subject
{
post
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/authorize"
,
user
),
headers:
workhorse_headers
}
subject
do
post
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/authorize"
,
user
),
headers:
workhorse_headers
end
it
'authorizes uploading with workhorse header'
do
subject
...
...
@@ -104,9 +107,10 @@ RSpec.describe API::AlertManagementAlerts do
expect
(
json_response
[
'filename'
]).
to
eq
(
file_name
)
expect
(
json_response
[
'url'
]).
to
eq
(
url
)
expect
(
json_response
[
'url_text'
]).
to
eq
(
url_text
)
expect
(
json_response
[
'file_path'
]).
to
match
(
%r{/uploads/-/system/alert_management_metric_image/file/
\d
+/
#{
file_name
}
}
)
expect
(
json_response
[
'created_at'
]).
not_to
be_nil
expect
(
json_response
[
'id'
]).
not_to
be_nil
file_path_regex
=
%r{/uploads/-/system/alert_management_metric_image/file/
\d
+/
#{
file_name
}
}
expect
(
json_response
[
'file_path'
]).
to
match
(
file_path_regex
)
end
end
...
...
@@ -133,7 +137,6 @@ RSpec.describe API::AlertManagementAlerts do
allow
(
uploader
).
to
receive
(
:file_storage?
).
and_return
(
true
)
end
stub_licensed_features
(
alert_metric_upload:
true
)
project
.
send
(
"add_
#{
user_role
}
"
,
user
)
end
...
...
@@ -142,7 +145,6 @@ RSpec.describe API::AlertManagementAlerts do
context
'file size too large'
do
before
do
stub_licensed_features
(
alert_metric_upload:
true
)
allow_next_instance_of
(
UploadedFile
)
do
|
upload_file
|
allow
(
upload_file
).
to
receive
(
:size
).
and_return
(
AlertManagement
::
MetricImage
::
MAX_FILE_SIZE
+
1
)
end
...
...
@@ -161,7 +163,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'
,
http_status: :bad_request
)
error
=
instance_double
(
ServiceResponse
,
success?:
false
,
message:
'some error'
,
http_status: :bad_request
)
allow
(
service
).
to
receive
(
:execute
).
and_return
(
error
)
end
end
...
...
@@ -177,7 +179,6 @@ RSpec.describe API::AlertManagementAlerts do
context
'object storage enabled'
do
before
do
# Object storage
stub_licensed_features
(
alert_metric_upload:
true
)
stub_uploads_object_storage
(
MetricImageUploader
)
allow_next_instance_of
(
MetricImageUploader
)
do
|
uploader
|
...
...
@@ -240,7 +241,6 @@ RSpec.describe API::AlertManagementAlerts do
with_them
do
before
do
stub_licensed_features
(
alert_metric_upload:
true
)
project
.
send
(
"add_
#{
user_role
}
"
,
user
)
unless
user_role
==
:not_member
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
unless
public_project
end
...
...
@@ -255,7 +255,10 @@ RSpec.describe API::AlertManagementAlerts do
let!
(
:image
)
{
create
(
:alert_metric_image
,
alert:
alert
)
}
let
(
:params
)
{
{
url:
'http://test.example.com'
,
url_text:
'Example website 123'
}
}
subject
{
put
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/
#{
image
.
id
}
"
,
user
),
params:
params
}
subject
do
put
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/
#{
image
.
id
}
"
,
user
),
params:
params
end
shared_examples
'can_update_metric_image'
do
it
'can update the metric images'
do
...
...
@@ -286,7 +289,6 @@ RSpec.describe API::AlertManagementAlerts do
with_them
do
before
do
stub_licensed_features
(
alert_metric_upload:
true
)
project
.
send
(
"add_
#{
user_role
}
"
,
user
)
unless
user_role
==
:not_member
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
unless
public_project
end
...
...
@@ -299,44 +301,27 @@ RSpec.describe API::AlertManagementAlerts do
project
.
add_developer
(
user
)
end
context
'feature is enabled'
do
before
do
stub_licensed_features
(
alert_metric_upload:
true
)
end
context
'and metric image not found'
do
subject
{
put
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/
#{
non_existing_record_id
}
"
,
user
)
}
it
'returns an error'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Metric image not found'
)
end
context
'and metric image not found'
do
subject
do
put
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/
#{
non_existing_record_id
}
"
,
user
)
# rubocop: disable Layout/LineLength
end
context
'metric image cannot be updated'
do
let
(
:params
)
{
{
url_text:
'something_long'
*
100
}
}
it
'returns an error'
do
subject
it
'returns an error'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:unprocessable_entity
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Metric image could not be updated'
)
end
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Metric image not found'
)
end
end
context
'feature not enabled'
do
before
do
stub_licensed_features
(
alert_metric_upload:
false
)
end
context
'metric image cannot be updated'
do
let
(
:params
)
{
{
url_text:
'something_long'
*
100
}
}
it
'returns an error'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:
forbidden
)
expect
(
json_response
[
'message'
]).
to
eq
(
'
Feature not available
'
)
expect
(
response
).
to
have_gitlab_http_status
(
:
unprocessable_entity
)
expect
(
json_response
[
'message'
]).
to
eq
(
'
Metric image could not be updated
'
)
end
end
end
...
...
@@ -347,7 +332,9 @@ RSpec.describe API::AlertManagementAlerts do
let!
(
:image
)
{
create
(
:alert_metric_image
,
alert:
alert
)
}
subject
{
delete
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/
#{
image
.
id
}
"
,
user
)
}
subject
do
delete
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/
#{
image
.
id
}
"
,
user
)
end
shared_examples
'can delete metric image successfully'
do
it
'can delete the metric images'
do
...
...
@@ -377,7 +364,6 @@ RSpec.describe API::AlertManagementAlerts do
with_them
do
before
do
stub_licensed_features
(
alert_metric_upload:
true
)
project
.
send
(
"add_
#{
user_role
}
"
,
user
)
unless
user_role
==
:not_member
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
unless
public_project
end
...
...
@@ -387,12 +373,13 @@ RSpec.describe API::AlertManagementAlerts do
context
'when user has access'
do
before
do
stub_licensed_features
(
alert_metric_upload:
true
)
project
.
add_developer
(
user
)
end
context
'when metric image not found'
do
subject
{
delete
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/
#{
non_existing_record_id
}
"
,
user
)
}
subject
do
delete
api
(
"/projects/
#{
project
.
id
}
/alert_management_alerts/
#{
alert
.
iid
}
/metric_images/
#{
non_existing_record_id
}
"
,
user
)
# rubocop: disable Layout/LineLength
end
it
'returns an error'
do
subject
...
...
@@ -419,19 +406,6 @@ RSpec.describe API::AlertManagementAlerts do
expect
(
json_response
[
'message'
]).
to
eq
(
'Metric image could not be deleted'
)
end
end
context
'when feature not enabled'
do
before
do
stub_licensed_features
(
alert_metric_upload:
false
)
end
it
'returns an error'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Feature not available'
)
end
end
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