Skip to content
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

Access show cost by in chargeback report for restricted user #3494

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions app/controllers/report_controller/reports/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def build_edit_screen

get_time_profiles # Get time profiles list (global and user specific)
cb_entities_by_provider if Chargeback.db_is_chargeback?(@edit[:new][:model]) && [ChargebackContainerImage, ChargebackContainerProject, MeteringContainerImage, MeteringContainerProject].include?(@edit[:new][:model].safe_constantize)
refresh_chargeback_filter_tab if Chargeback.db_is_chargeback?(@edit[:new][:model])
case @sb[:miq_tab].split("_")[1]
when "1" # Select columns
@edit[:models] ||= reportable_models
Expand Down Expand Up @@ -1331,16 +1332,6 @@ def set_form_vars
cb_entities_by_provider if [ChargebackContainerImage, ChargebackContainerProject, MeteringContainerImage, MeteringContainerProject].include?(@rpt.db.safe_constantize)
end

# Only show chargeback users choice if an admin
if admin_user?
@edit[:cb_users] = User.all.each_with_object({}) { |u, h| h[u.userid] = u.name }
@edit[:cb_tenant] = Tenant.all.each_with_object({}) { |t, h| h[t.id] = t.name }
else
@edit[:new][:cb_show_typ] = "owner"
@edit[:new][:cb_owner_id] = session[:userid]
@edit[:cb_owner_name] = current_user.name
end

# Build trend limit cols array
if model_report_type(@rpt.db) == :trend
@edit[:limit_cols] = VimPerformanceTrend.trend_limit_cols(@edit[:new][:perf_trend_db], @edit[:new][:perf_trend_col], @edit[:new][:perf_interval])
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/report_helper/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ def cb_entities_by_provider_id(provider_id, entity_type)
def cb_image_labels
CustomAttribute.where(:section => "docker_labels").distinct('name').pluck(:name).each_with_object({}) { |l, h| h[l] = l }
end

def refresh_chargeback_filter_tab
@edit[:cb_users] = Rbac::Filterer.filtered(User.in_my_region).each_with_object({}) { |u, h| h[u.userid] = u.name }
@edit[:cb_tenant] = Rbac::Filterer.filtered(Tenant).each_with_object({}) { |t, h| h[t.id] = t.name }
end
end
20 changes: 18 additions & 2 deletions spec/controllers/miq_report_controller/reports/editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,24 @@ def empty_category(attrs = {})
chargeback_tabs = [:formatting, :filter, :preview]

describe '#build_edit_screen' do
let(:user) { FactoryGirl.create(:user) }
let(:default_tenant) { Tenant.seed }
let(:user) { FactoryGirl.create(:user_with_group, :tenant => default_tenant) }
let(:user_group) do
group = user.miq_groups.first
group.tenant = default_tenant
group.save
group
end

let(:chargeback_report) do
FactoryGirl.create(:miq_report, :db => 'ChargebackVm', :db_options => {:options => {:owner => user.userid}},
:col_order => ['name'], :headers => ['Name'])
end

before { login_as user }
before do
EvmSpecHelper.create_guid_miq_server_zone
login_as user
end

tabs.slice(*chargeback_tabs).each do |tab_number|
it 'flash messages should be nil' do
Expand All @@ -285,6 +296,11 @@ def empty_category(attrs = {})
controller.instance_variable_set(:@sb, :miq_tab => "edit_#{tab_number.second}")
controller.send(:build_edit_screen)

if tab_number == [:filter, 3]
expect(controller.instance_variable_get(:@edit)[:cb_users]).to eq(user.userid => user.name)
expect(controller.instance_variable_get(:@edit)[:cb_tenant]).to eq(default_tenant.id => default_tenant.name)
end

expect(assigns(:flash_array)).to be_nil
end
end
Expand Down