Skip to content

Commit

Permalink
Avoid hardcoding miq_task product feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jvlcek committed Dec 20, 2018
1 parent 3d09297 commit 683e17f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/controllers/api/tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
module Api
class TasksController < BaseController
def find_collection(klass)
return klass.all if current_user.role_allows?(:identifier => "miq_task_all_ui")
return klass.where(:userid => [current_user.userid]) if current_user.report_only_my_user_tasks?

klass.where(:userid => [current_user.userid]) # Role must have product feature miq_task_my_ui
klass.all
end

def find_resource(klass, key_id, id)
if current_user.role_allows?(:identifier => "miq_task_all_ui")
key_id == "id" ? klass.find(id) : klass.find_by(key_id => id)
else
klass.find_by(key_id => id, :userid => [current_user.userid]) # Role must have product feature miq_task_my_ui
end
return klass.find_by(key_id => id, :userid => [current_user.userid]) if current_user.report_only_my_user_tasks?

key_id == "id" ? klass.find(id) : klass.find_by(key_id => id)
end
end
end

0 comments on commit 683e17f

Please sign in to comment.