Feature #20047

Filter roles by assigned permissions in UI

Added by Marek Hulán over 3 years ago. Updated over 2 years ago.

Target version:
Bugzilla link:
Fixed in Releases:
Found in Releases:


Cloned from

It would be useful to have a possibility to filter out roles that have a specific permission. This would help users to explore what predefined roles have to offer as well as to keep track of their own custom roles.

Associated revisions

Revision 550c4063 (diff)
Added by Kavita Gaikwad about 3 years ago

Fixes #20047 - Filter roles by permission

With this commit, it will allow user to filter roles by
permissions using operators =, !=, , !, , !


#1 Updated by Marek Hulán over 3 years ago

  • Subject changed from : Filter roles by assigned permissions in UI to Filter roles by assigned permissions in UI
  • Category set to Search
  • Target version set to 115

During looking into this I found that scoped search can't search through two has_many :through relations if they are not in the same model. I redefined role has_many :permissions, :through filterings which seems to work. Then it turned out, for some reason scoped search return wrong results when I use "permission = something" while other operators such as ~ or ^ works just fine. I can't continue with this right now, the patch I put together so far follows

diff --git a/app/models/role.rb b/app/models/role.rb
index 082a82f..b821a9c 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -50,7 +50,9 @@ class Role < ApplicationRecord

   has_many :filters, :autosave => true, :dependent => :destroy

-  has_many :permissions, :through => :filters
+  # has_many :permissions, :through => :filters
+  has_many :filterings, :through => :filters
+  has_many :permissions, :through => :filterings

   has_many :cloned_roles, :class_name => 'Role', :foreign_key => 'cloned_from_id', :dependent => :nullify
   belongs_to :cloned_from, :class_name => 'Role'
@@ -70,6 +72,7 @@ class Role < ApplicationRecord
   scoped_search :on => :name, :complete_value => true
   scoped_search :on => :builtin, :complete_value => { :true => true, :false => false }
   scoped_search :on => :description, :complete_value => false
+  scoped_search :on => :name, :relation => :permissions, :complete_value => true, :rename => 'has_permission', :only_explicit => true

   def permissions=(new_permissions)
     add_permissions( if new_permissions.present?

#2 Updated by Daniel Lobato Garcia over 3 years ago

This could work using ":ext_method => " and use SQL directly to search for the permissions too.

#3 Updated by Kavita Gaikwad over 3 years ago

  • Assignee set to Kavita Gaikwad
  • Target version changed from 115 to 1.17.0-RC1

#4 Updated by The Foreman Bot over 3 years ago

  • Status changed from New to Ready For Testing
  • Pull request added

#5 Updated by Kavita Gaikwad about 3 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#6 Updated by Marek Hulán about 3 years ago

  • Legacy Backlogs Release (now unused) set to 240

Also available in: Atom PDF