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

[Gaprindashvili] converge UI and API privs for request/report admins #4489

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ def populate_reports_menu(hide_custom = false)

def reports_group_title
tenant_name = current_tenant.name
if current_user.admin_user?
if current_user.report_admin_user?
_("%{tenant_name} (All Groups)") % {:tenant_name => tenant_name}
else
_("%{tenant_name} (Group): %{group_description}") %
Expand All @@ -967,7 +967,7 @@ def get_reports_menu(hide_custom = false, group = current_group)
# TODO: move this into a named scope
@sb[:grp_title] = reports_group_title
custom = MiqReport.for_user(current_user).where(:template_type => "report", :rpt_type => 'Custom').order(:name).pluck(:name, :miq_group_id)
custom.select! { |item| item.second.to_i == current_group.try(:id) } unless current_user.admin_user?
custom.select! { |item| item.second.to_i == current_group.try(:id) } unless current_user.report_admin_user?
reports.push([@sb[:grp_title], [[_("Custom"), custom.map(&:first)]]])
end
reports
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller/current_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ApplicationController::CurrentUser
included do
helper_method :current_user, :current_userid
helper_method :current_group, :current_group_id
helper_method :admin_user?, :super_admin_user?
helper_method :report_admin_user?, :super_admin_user?
private :clear_current_user
end

Expand All @@ -20,8 +20,8 @@ def current_user=(db_user)
session[:group] = db_user.current_group_id
end

def admin_user?
current_user.try(:admin_user?)
def report_admin_user?
current_user&.report_admin_user?
end

def super_admin_user?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/chargeback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def cb_rpts_fetch_saved_report(id)
return
end
@right_cell_text ||= _("Saved Chargeback Report [%{name}]") % {:name => rr.name}
if !current_user.miq_group_ids.include?(rr.miq_group_id) && !admin_user?
if !current_user.miq_group_ids.include?(rr.miq_group_id) && !report_admin_user?
add_flash(_("Report is not authorized for the logged in user"), :error)
@saved_reports = cb_rpts_get_all_reps(id.split('-')[1])
return
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/configuration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def update
# Show the users list
def show_timeprofiles
build_tabs if params[:action] == "change_tab" || ["cancel", "add", "save"].include?(params[:button])
if admin_user?
if report_admin_user?
@timeprofiles = TimeProfile.in_my_region.ordered_by_desc
else
@timeprofiles = TimeProfile.in_my_region.for_user(session[:userid]).ordered_by_desc
Expand Down Expand Up @@ -254,8 +254,8 @@ def timeprofile_edit
@timeprofile = TimeProfile.find(params[:id])
set_form_vars
@tp_restricted = true if @timeprofile.profile_type == "global" && !admin_user?
title = (@timeprofile.profile_type == "global" && !admin_user?) ? _("Time Profile") : _("Edit")
add_flash(_("Global Time Profile cannot be edited")) if @timeprofile.profile_type == "global" && !admin_user?
title = (@timeprofile.profile_type == "global" && !report_admin_user?) ? _("Time Profile") : _("Edit")
add_flash(_("Global Time Profile cannot be edited")) if @timeprofile.profile_type == "global" && !report_admin_user?
session[:changed] = false
@in_a_form = true
drop_breadcrumb(:name => _("%{title} '%{description}'") % {:title => title,
Expand All @@ -277,7 +277,7 @@ def timeprofile_delete
if tp.description == "UTC"
timeprofiles.delete(tp.id.to_s)
add_flash(_("Default Time Profile \"%{name}\" cannot be deleted") % {:name => tp.description}, :error)
elsif tp.profile_type == "global" && !admin_user?
elsif tp.profile_type == "global" && !report_admin_user?
timeprofiles.delete(tp.id.to_s)
add_flash(_("\"%{name}\": Global Time Profiles cannot be deleted") % {:name => tp.description}, :error)
elsif !tp.miq_reports.empty?
Expand All @@ -302,7 +302,7 @@ def timeprofile_field_changed
page.replace('timeprofile_days_hours_div',
:partial => "timeprofile_days_hours",
:locals => {:disabled => false}) if @redraw
if params.key?(:profile_tz) && admin_user?
if params.key?(:profile_tz) && report_admin_user?
if params[:profile_tz].blank?
page << javascript_hide("rollup_daily_tr")
else
Expand Down Expand Up @@ -424,7 +424,7 @@ def time_profile_form_fields

render :json => {:description => @timeprofile.description,
:admin_user => admin_user?,
:restricted_time_profile => @timeprofile.profile_type == "global" && !admin_user?,
:restricted_time_profile => @timeprofile.profile_type == "global" && !report_admin_user?,
:profile_type => @timeprofile.profile_type || "user",
:profile_tz => @timeprofile.tz.nil? ? "" : @timeprofile.tz,
:rollup_daily => !@timeprofile.rollup_daily_metrics.nil?,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/report_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def get_export_reports
@export_reports = {}
user = current_user
MiqReport.all.each do |rep|
if rep.rpt_type == "Custom" && (user.admin_user? || (rep.miq_group && rep.miq_group.id == user.current_group.id))
if rep.rpt_type == "Custom" && (user.report_admin_user? || (rep.miq_group && rep.miq_group.id == user.current_group.id))
@export_reports[rep.name] = rep.id
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/report_controller/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ def move_menu_cols_right
if params[:selected_reports].include?(nf) # See if this col was selected to move
field = nf.split('* ')
r = MiqReport.find_by_name(field.length == 1 ? field[0].strip : field[1].strip)
if !user.admin_user? && r.miq_group_id.to_i != user.current_group.id.to_i && flg == 0
if !user.report_admin_user? && r.miq_group_id.to_i != user.current_group.id.to_i && flg == 0
flg = 1
# only show this flash message once for all reports
add_flash(_("One or more selected reports are not owned by your group, they cannot be moved"), :warning)
end
if user.admin_user? || r.miq_group_id.to_i == user.current_group.id.to_i
if user.report_admin_user? || r.miq_group_id.to_i == user.current_group.id.to_i
@edit[:available_reports].push(nf) if @edit[:user_typ] || r.miq_group_id.to_i == user.current_group.id.to_i # Add to the available fields list
@edit[:selected_reports].delete(nf)
end
Expand Down Expand Up @@ -526,7 +526,7 @@ def menu_set_form_vars
@edit[:current] = []
@edit[:new] = @rpt_menu unless @rpt_menu.nil?
user = current_user
@edit[:user_typ] = user.admin_user?
@edit[:user_typ] = user.report_admin_user?
@edit[:user_group] = user.current_group.id
@edit[:group_reports] = []
menu_set_reports_for_group
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/report_controller/saved_reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def fetch_saved_report(id)
@right_cell_text ||= _("Saved Report \"%{name}\"") %
{:name => "#{rr.name} - #{format_timezone(rr.created_on, Time.zone, "gt")}"}

unless admin_user? || current_user.miq_group_ids.include?(rr.miq_group_id)
unless report_admin_user? || current_user.miq_group_ids.include?(rr.miq_group_id)
add_flash(_("Report is not authorized for the logged in user"), :error)
get_all_reps(@sb[:miq_report_id].to_s)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ApplicationHelper::Button::MiqRequestDelete < ApplicationHelper::Button::B

def disabled?
requester = current_user
return false if requester.admin_user?
return false if requester.miq_user_role.request_admin_user?
@error_message = _("Users are only allowed to delete their own requests") if requester.name != @record.requester_name
if %w(approved denied).include?(@record.approval_state)
@error_message = _("%{approval_states} requests cannot be deleted") %
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/tree_builder_report_saved_reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def root_options
# Get root nodes count/array for explorer tree
def x_get_tree_roots(_count_only, _options)
u = User.current_user
user_groups = u.admin_user? ? nil : u.miq_groups
user_groups = u.report_admin_user? ? nil : u.miq_groups
having_report_results(user_groups).pluck(:name, :id).sort.map do |name, id|
{:id => to_cid(id.to_i), :text => name, :icon => 'fa fa-file-text-o', :tip => name}
end
Expand All @@ -37,7 +37,7 @@ def x_get_tree_custom_kids(object, count_only, _options)
# Scope on reports that have report results.
def having_report_results(miq_groups)
miq_group_relation = MiqReport.joins(:miq_report_results).distinct
if miq_groups.nil? # u.admin_user?
if miq_groups.nil? # u.report_admin_user?
miq_group_relation.where.not(:miq_report_results => {:miq_group_id => nil})
else
miq_group_relation.where(:miq_report_results => {:miq_group_id => miq_groups})
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_adv_search_body.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
:class => "form-control",
"data-miq_focus" => true,
"data-miq_observe" => {:interval => ".5", :url => url2}.to_json)
- if admin_user?
- if report_admin_user?
.form-group
%label.control-label.col-md-5
= _("Global search:")
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_adv_search_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:title => t,
:onclick => "miqAjaxButton('#{url_for_only_path(:action => 'adv_search_button', :button => "apply")}');")
- if @edit[@expkey][:selected] && @edit[@expkey][:selected][:typ] != "default" && @edit[@expkey][:selected][:id] != 0
- if admin_user? || @edit[@expkey][:selected][:typ] == "user"
- if report_admin_user? || @edit[@expkey][:selected][:typ] == "user"
- actual_filter = @edit[@expkey][:selected][:description]
- confirm_msg = _("Delete the %{model} filter named %{filter}?") % {:model => ui_lookup(:model => @edit[@expkey][:exp_model]),
:filter => actual_filter}
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/report_controller/widget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
before do
user = FactoryGirl.create(:user_with_group)
allow(user).to receive(:get_timezone).and_return(Time.zone)
allow(user).to receive(:admin_user?).and_return(true)
allow(user).to receive(:report_admin_user?).and_return(true)
login_as user
allow(controller).to receive(:current_user).and_return(user)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
allow(record).to receive(:resource_type).and_return(resource_type)
end

let(:current_user) { FactoryGirl.create(:user_admin) }
let(:current_user) { FactoryGirl.create(:user, :features => "everything") }
let(:approval_state) { 'sorryjako' }
let(:requester_name) { {:requester_name => current_user.name} }
let(:resource_type) { 'knedlik' }
Expand Down