Repository navigation
Expose request_logs as a read-only subcollection of all request types #1331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jrafanie
wants to merge
1
commit into
ManageIQ:master
Choose a base branch
from
jrafanie:add-request-log-subcollection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| module Api | ||
| module Subcollections | ||
| module RequestLogs | ||
| def request_logs_query_resource(object) | ||
| # object is the parent MiqRequest (or subclass), already RBAC-filtered by | ||
| # parent_resource_obj before this method is called, so no additional check is needed. | ||
| klass = collection_class(:request_logs) | ||
| object ? klass.where(:resource_id => object.id) : {} | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| RSpec.describe "Request Logs Subcollection API" do | ||
| # request_logs is authorized via miq_request_show_logs, the same feature the classic UI checks | ||
| # before displaying request logs. subcollection_action_identifier resolves this correctly. | ||
| shared_examples "request_logs subcollection" do |parent_collection, parent_factory, logs_url_helper, log_url_helper| | ||
| let(:request) { FactoryBot.create(parent_factory, :requester => @user) } | ||
| let(:log) { FactoryBot.create(:request_log, :resource => request) } | ||
|
|
||
| context "listing logs" do | ||
| it "is forbidden without appropriate role" do | ||
| api_basic_authorize | ||
|
|
||
| get send(logs_url_helper, nil, request) | ||
|
|
||
| expect(response).to have_http_status(:forbidden) | ||
| end | ||
|
|
||
| it "is forbidden with only miq_request_show" do | ||
| api_basic_authorize "miq_request_show" | ||
|
|
||
| get send(logs_url_helper, nil, request) | ||
|
|
||
| expect(response).to have_http_status(:forbidden) | ||
| end | ||
|
|
||
| it "returns only logs belonging to the parent request" do | ||
| other_request = FactoryBot.create(parent_factory, :requester => @user) | ||
| log | ||
| other_log = FactoryBot.create(:request_log, :resource => other_request) | ||
| api_basic_authorize subcollection_action_identifier(parent_collection, :request_logs, :read, :get) | ||
|
|
||
| get send(logs_url_helper, nil, request), :params => {:expand => :resources} | ||
|
|
||
| expect(response).to have_http_status(:ok) | ||
| returned_ids = response.parsed_body["resources"].pluck("id") | ||
| expect(returned_ids).to include(log.id.to_s) | ||
| expect(returned_ids).not_to include(other_log.id.to_s) | ||
| end | ||
|
|
||
| it "returns all logs for the request" do | ||
| log1 = FactoryBot.create(:request_log, :resource => request, :message => "first") | ||
| log2 = FactoryBot.create(:request_log, :resource => request, :message => "second") | ||
| api_basic_authorize subcollection_action_identifier(parent_collection, :request_logs, :read, :get) | ||
|
|
||
| get send(logs_url_helper, nil, request), :params => {:expand => :resources} | ||
|
|
||
| expect(response).to have_http_status(:ok) | ||
| returned_ids = response.parsed_body["resources"].pluck("id") | ||
| expect(returned_ids).to match_array([log1.id.to_s, log2.id.to_s]) | ||
| end | ||
| end | ||
|
|
||
| context "showing a single log" do | ||
| it "is forbidden without appropriate role" do | ||
| api_basic_authorize | ||
|
|
||
| get send(log_url_helper, nil, request, log) | ||
|
|
||
| expect(response).to have_http_status(:forbidden) | ||
| end | ||
|
|
||
| it "returns the log" do | ||
| api_basic_authorize subcollection_action_identifier(parent_collection, :request_logs, :read, :get) | ||
|
|
||
| get send(log_url_helper, nil, request, log) | ||
|
|
||
| expect(response).to have_http_status(:ok) | ||
| expect(response.parsed_body).to include( | ||
| "id" => log.id.to_s, | ||
| "message" => log.message, | ||
| "severity" => log.severity | ||
| ) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context "under /automation_requests" do | ||
| include_examples "request_logs subcollection", | ||
| :automation_requests, | ||
| :automation_request, | ||
| :api_automation_request_request_logs_url, | ||
| :api_automation_request_request_log_url | ||
| end | ||
|
|
||
| context "under /provision_requests" do | ||
| include_examples "request_logs subcollection", | ||
| :provision_requests, | ||
| :miq_provision_request, | ||
| :api_provision_request_request_logs_url, | ||
| :api_provision_request_request_log_url | ||
| end | ||
|
|
||
| context "under /requests" do | ||
| include_examples "request_logs subcollection", | ||
| :requests, | ||
| :service_template_provision_request, | ||
| :api_request_request_logs_url, | ||
| :api_request_request_log_url | ||
| end | ||
|
|
||
| context "under /service_requests" do | ||
| include_examples "request_logs subcollection", | ||
| :service_requests, | ||
| :service_template_provision_request, | ||
| :api_service_request_request_logs_url, | ||
| :api_service_request_request_log_url | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetical.
🏃💨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OH, we added @Fryguy as a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh, I fixed the one but not the other, one second...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, done