Project

General

Profile

How to get query result without any visibility restriction

Added by salman mp 7 days ago

I'm developing a new plugin that needs to query issues based on custom field values (regardless of the custom field's visibility to the user executing the query). Is it safe to temporarily change User.current to an admin user and then, after the query block, revert it to the original user?

begin
   old_current = User.current
   User.current = User.active.admin.first
   ic = query.issue_count
rescue
ensure
   User.current = old_current
end