Feature #20047

Filter roles by assigned permissions in UI

Added by Marek Hulán 10 months ago. Updated 9 months ago.

Status:Closed
Priority:Normal
Assigned To:Kavita Gaikwad
Category:Search
Target version:Team Anurag Iteration 18
Difficulty: Bugzilla link:1455132
Found in release: Pull request:https://github.com/theforeman/foreman/pull/4679
Story points-
Velocity based estimate-
Release1.16.0Release relationshipAuto

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1455132

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
Added by Kavita Gaikwad 9 months ago

Fixes #20047 - Filter roles by permission

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

History

#1 Updated by Marek Hulán 10 months 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 Team Marek backlog

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(new_permissions.map(&:name).uniq) if new_permissions.present?

#2 Updated by Daniel Lobato Garcia 10 months ago

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

#3 Updated by Kavita Gaikwad 10 months ago

  • Assigned To set to Kavita Gaikwad
  • Target version changed from Team Marek backlog to Team Anurag Iteration 18

#4 Updated by The Foreman Bot 9 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4679 added

#5 Updated by Kavita Gaikwad 9 months ago

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

#6 Updated by Marek Hulán 9 months ago

  • Release set to 1.16.0

Also available in: Atom PDF