Project

General

Profile

Actions

Feature #20047

closed

Filter roles by assigned permissions in UI

Added by Marek Hulán over 6 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Category:
Search
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

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.

Actions #1

Updated by Marek Hulán over 6 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(new_permissions.map(&:name).uniq) if new_permissions.present?
Actions #2

Updated by Daniel Lobato Garcia over 6 years ago

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

Actions #3

Updated by Kavita Gaikwad over 6 years ago

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

Updated by The Foreman Bot over 6 years ago

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

Updated by Kavita Gaikwad over 6 years ago

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

Updated by Marek Hulán over 6 years ago

  • translation missing: en.field_release set to 240
Actions

Also available in: Atom PDF