From 5f73e460b7fea23493feb9c29dac5a963d65ec4f Mon Sep 17 00:00:00 2001 From: Tim Wade Date: Mon, 21 Aug 2017 14:26:52 -0700 Subject: [PATCH] Set the current userid when running a report With nothing specified it defaults to "system". Since we now enforce checking the ownership of report results, the report results' userid must be set to the current user instead. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1479296 --- app/controllers/api/reports_controller.rb | 2 +- spec/requests/reports_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/reports_controller.rb b/app/controllers/api/reports_controller.rb index d359d68a7c..eef156586b 100644 --- a/app/controllers/api/reports_controller.rb +++ b/app/controllers/api/reports_controller.rb @@ -17,7 +17,7 @@ def find_reports(id) def run_resource(type, id, _data) report = resource_search(id, type, MiqReport) - report_result = MiqReportResult.find(report.queue_generate_table) + report_result = MiqReportResult.find(report.queue_generate_table(:userid => User.current_user.userid)) run_report_result(true, "running report #{report.id}", :task_id => report_result.miq_task_id, diff --git a/spec/requests/reports_spec.rb b/spec/requests/reports_spec.rb index b1890e20b1..4c61c896e4 100644 --- a/spec/requests/reports_spec.rb +++ b/spec/requests/reports_spec.rb @@ -215,6 +215,8 @@ :success => true, :message => "running report #{report.id}" ) + actual = MiqReportResult.find(ApplicationRecord.uncompress_id(response.parsed_body["result_id"])) + expect(actual.userid).to eq("api_user_id") end it "can schedule a run" do