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

Fixed condition to use correct feature id #5362

Merged
merged 1 commit into from
Mar 22, 2019
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
2 changes: 1 addition & 1 deletion app/controllers/application_controller/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ApplicationController::Tags

# Edit user, group or tenant tags
def tagging_edit(db = nil, assert = true)
assert_privileges("#{@display ? @display.singularize : controller_for_common_methods}_tag") if assert
assert_privileges("#{@display && @display != "main" ? @display.singularize : controller_for_common_methods}_tag") if assert
@explorer = true if request.xml_http_request? # Ajax request means in explorer

@tagging = session[:tag_db] = params[:db] ? params[:db] : db if params[:db] || db
Expand Down
25 changes: 21 additions & 4 deletions spec/controllers/application_controller/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,32 @@ def convert_to_region_id(id)

describe EmsInfraController do
before do
login_as FactoryBot.create(:user, :features => %w(storage_tag))
login_as FactoryBot.create(:user, :features => %w(storage_tag ems_infra_tag))
controller.instance_variable_set(:@_params, params)
controller.instance_variable_set(:@display, "storages")
end

context 'check for correct feature id when tagging selected storage thru Provider relationship' do
context 'check for correct feature id when tagging selected storage thru Provider relationship and directly from summary screen' do
let(:params) { {:db => "Storage", :id => "1"} }
it 'sets @tagging properly' do
let(:controller_name) { Storage }
it 'sets @tagging properly and passes in correct feature to assert_privileges' do
controller.instance_variable_set(:@display, "storages")
allow(controller).to receive(:tagging_edit_tags_reset)
expect(controller).to receive(:assert_privileges).with("storage_tag")
controller.send(:tagging_edit, "storage", true)
expect(controller.instance_variable_get(:@tagging)).not_to be_nil
end

it 'checks proper feature id when trying to go to tagging directly from a summary screen' do
controller.instance_variable_set(:@display, "main")
allow(controller).to receive(:tagging_edit_tags_reset)
expect(controller).to receive(:assert_privileges).with("ems_infra_tag")
controller.send(:tagging_edit)
expect(controller.instance_variable_get(:@tagging)).not_to be_nil
end

it 'checks proper feature id when trying to go to tagging from list view and @dsiplay is not set' do
allow(controller).to receive(:tagging_edit_tags_reset)
expect(controller).to receive(:assert_privileges).with("ems_infra_tag")
controller.send(:tagging_edit)
expect(controller.instance_variable_get(:@tagging)).not_to be_nil
end
Expand Down