Feature #20047
closedFilter roles by assigned permissions in UI
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.
Updated by Marek Hulán over 7 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?
Updated by Daniel Lobato Garcia over 7 years ago
This could work using ":ext_method => " and use SQL directly to search for the permissions too.
Updated by Kavita Gaikwad about 7 years ago
- Assignee set to Kavita Gaikwad
- Target version changed from 115 to 1.17.0-RC1
Updated by The Foreman Bot about 7 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/4679 added
Updated by Kavita Gaikwad about 7 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 550c40633febe3e9e9f82cc2fa98ee3b40bc8710.
Updated by Marek Hulán about 7 years ago
- Translation missing: en.field_release set to 240