-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #37987 - Filters dont inherit taxonomy on creation #10370
base: develop
Are you sure you want to change the base?
Conversation
baf4134
to
f46f2a5
Compare
319787a
to
e2698dc
Compare
filters = Filter.where(role_id: Role.where(origin: nil).or(Role.where(builtin: 2))).where(override: false).where(taxonomy_search: nil) | ||
|
||
filters.each do |filter| | ||
filter.build_taxonomy_search_from_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter.build_taxonomy_search_from_ids | |
filter.build_taxonomy_search |
test/models/filter_test.rb
Outdated
location_test = FactoryBot.create(:location) | ||
f.role = FactoryBot.create(:role, :organizations => [organization_test], :locations => [location_test]) | ||
f.save | ||
assert_equal f.taxonomy_search(), "(organization_id ^ (#{organization_test.id})) and (location_id ^ (#{location_test.id}))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_equal f.taxonomy_search(), "(organization_id ^ (#{organization_test.id})) and (location_id ^ (#{location_test.id}))" | |
assert_equal f.taxonomy_search, "(organization_id ^ (#{organization_test.id})) and (location_id ^ (#{location_test.id}))" |
@@ -29,7 +29,7 @@ const NewFiltersFormPage = ({ location: { search }, history }) => { | |||
isNew | |||
roleName={roleName || ''} | |||
roleId={urlRoleId} | |||
data={{}} | |||
data={{ locations, organizations }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
data.organizations?.map(o => o.id) || []
mean it would always be []
since taxonomies weren't passed within data
before your patch?..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new page, in the edit page we have data={response}
e2698dc
to
1579997
Compare
thanks @ofedoren, updated |
Draft until I finish "remove taxonimoes override from filter" |
|
||
<FormGroup | ||
label={__('Locations')} | ||
helperText={__('Taxonomies are inherited from the role')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of "Taxonomies are inherited...", how about adding a line like that after Organizations and Locations each? So: "Organizations are inherited..." and "Locations are inherited ...". It's two lines instead of one but I'm concerned about the term taxonomies: will everyone know that it refers to orgs and locs?
Also, looking at the web UI, due to the layout of the page (indentation) and the formatting, it might look like "Taxonomies are inherited..." relates only to Locations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thats a better way, I'll change it
69d381a
to
c054e59
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some comments, you can ignore until the final review (pasting them just so I don't lose them)
:unlimited, | ||
:override, | ||
:permissions => [], :permission_ids => [], :permission_names => [] | ||
add_taxonomix_params_filter(filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_taxonomix_params_filter(filter) |
along with
include Foreman::Controller::Parameters::Taxonomix
@@ -1,7 +1,6 @@ | |||
class Filter < ApplicationRecord | |||
audited :associated_with => :role | |||
|
|||
include Taxonomix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, we don't make filters non-taxonomable, but rather force them to be in line with the role they're assigned to disabling user override possibility.
If so, this should stay since this concern makes filter model taxonomable.
I think by disabling possibility to override taxonomies on filter level, there is no longer need to have taxonomy association, taxonomy_search
can be created on the fly during before_save
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isnt that what before_save :enforce_inherited_taxonomies,
do?
ouiaId="taxonomy-search-alert" | ||
variant="info" | ||
title={__( | ||
"The filter is scoped to the selected organizations and locations, therefore can't be unlimited" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if helpful or just nitpicking, but I actually had trouble parsing what the alert meant. Do you think this would be better?
"The filter is scoped to the selected organizations and locations, therefore can't be unlimited" | |
"You cannot use unlimited filtering because the filter is scoped to the organizations and locations inherited from the role." |
I propose s/selected/inherited because 1. I think you don't really "select" orgs/locs anymore and 2. "inherited" is used in the descriptions on lines 122 and 135, I think consistency would help users connect the dots more quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to move the info alert below the (greyed-out) unlimited checkbox?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @MariaAga, LGTM, just few cents inline (consider previous comments as well). Small rubocop issue as well https://github.com/theforeman/foreman/actions/runs/12709621398/job/35429016546?pr=10370
UPD: Reminder for me to remove related stuff from hammer: https://github.com/theforeman/hammer-cli-foreman/blob/master/lib/hammer_cli_foreman/filter.rb#L13
@@ -0,0 +1,23 @@ | |||
class RemoveTaxonomyAndOverrideFromFilter < ActiveRecord::Migration[7.0] | |||
def up | |||
# remove_column :filters, :taxonomy_search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to remove the column even though we use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not? we want to keep using it right?
def up | ||
# remove_column :filters, :taxonomy_search | ||
# remove_column :filters, :override | ||
# filters = Filter.where(role_id: Role.where(origin: nil).or(Role.where(builtin: 2))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity: if we drop overriding anyway and force all the filters use inherited taxonomies, shouldn't we update all the filters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this selects only the editable filters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this selects only the editable filters
Aren't they all editable?..
Also, since filters were taxonomable and we're removing this, we should probably also clean related leftovers, such as TaxableTaxonomy.where(taxable_type: 'Filter')
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the locked ones
def locked?
return false if modify_locked || self.class.modify_locked
return false unless respond_to? :origin
origin.present? && builtin != BUILTIN_DEFAULT_ROLE
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is for role
, not filter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but filters are a part of one role, and if its locked it cant be edited, not the role and not its filters, so it cant have override: true
Or do we just want to run it on the default roles anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies, you're right. It a role is locked, the filters can't be overriden and we also don't allow to lock roles.
I guess we could then search for overriden filters before we remove the column to update their taxonomy search to be based on the assigned role. And after that we could remove the column and the related taxonomy records.
b310f1e
to
4ea5855
Compare
4ea5855
to
30dd1f9
Compare
To test:
before the pr: no taxonomy_search in the DB, and the filter is marked as unlimited
Added a migration to regenerate the taxonomy_search field of all filters which have override set to false to make them honor the organizations and locations set on the role.
Added a ui block on the unlimited checkbox if there are taxonomies in place.
Fixed "build_taxonomy_search" as it relayed on
locations
, but on creation there are onlylocation_ids
. Before this pr the workaround would be to edit and submit the filter (with no changes) since on editlocations
are already populated