-
Notifications
You must be signed in to change notification settings - Fork 898
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
Delete tag assignments when deleting a tag that is referenced in an assignment #16039
Conversation
b2c2a3b
to
a42c7f9
Compare
651deac
to
706ddb8
Compare
spec/models/classification_spec.rb
Outdated
|
||
ent.destroy | ||
|
||
expect(Tag.where(:name => assignment_tag).take).to be_nil |
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 need a test case showing that a similar tag in a different category isn't removed?
For example, "/chargeback_rate/assigned_to/vm/tag/managed/test_category2/test_entry"
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.
The test I added to the AssignmentMixin
tests that. Let me know if you think it still needs more. See https://github.com/ManageIQ/manageiq/pull/16039/files#diff-c96ad7d76c6072d9695e81a29f51e8b0R31
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.
Ah, I guess I was more concerned with destroy not deleting things that are "close" but not exactly the same tag.
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.
Ok, I'll add that test. Thanks!
# with a given tag. | ||
def self.all_assignments(tag = nil) | ||
scope = Tag.where(["name LIKE ?", "%/#{AssignmentMixin::NAMESPACE_SUFFIX}/%"]) | ||
scope = scope.where(["name LIKE ?", "%#{tag}"]) if tag.present? |
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 feel like if there's a bug, it would be in the string matching. As long as we have good tests, it looks ok.
|
||
# This module method was not intended to be mixed into a class. It is used outside | ||
# of any class that may mix this in, (Classification) to find the assignments associated | ||
# with a given tag. |
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.
Wait wat? I don't understand; Why is this not just then a scope on Tag
, as that's exactly what it does?
Actually, just to match the current convention that I'm seeing, why isn't it at last just included in the ClassMethods
belong to be included on the class? Then it'd match the current .assignments
method.
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.
Chris, per your second point, I wanted to do it that way. But, the code in Classification
that needs to delete these tags has no way of knowing which classes have included the mixin and would not know which classes on which to call the method.
I didn't consider making it a scope on Tag
. I think that would work fine. But, then knowledge of how assignments are using tags would be added to the Tag
class and I think it should stay in the mixin.
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.
Ahh I see, I thought that Classification
included this mixin.
In that case, you can make your intentions clear and without your comment by doing the following:
def all_assignments(tag = nil)
# ...
end
module_function :all_assignments
This will signal that this method is intended to be called with the mixin itself as the receiver. It will be mixed in to instances of the class, but will be automatically marked as private. (https://ruby-doc.org/core-2.4.2/Module.html#method-i-module_function)
706ddb8
to
2e51024
Compare
@jrafanie I added that additional test. Please take a look when you can. Thanks. |
Tag.create!(:name => assignment_tag) | ||
|
||
cat.destroy | ||
|
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.
We probably want this just to show that it deletes the correct tag but not the others (on the next two lines)
expect(Tag.exists?(:name => assignment_tag)).to be false
…ssignment Eg. - Tag to be deleted - /managed/environment/any1 - Referenced in assignment by the tag /chargeback_rate/assigned_to/vm/tag/managed/environment/any1. Which means that a chargeback rate (tagged with the latter) is assigned to any Vm tagged with environment/any1. Should also be deleted https://bugzilla.redhat.com/show_bug.cgi?id=1483365
2e51024
to
dba7bf9
Compare
Checked commit gtanzillo@dba7bf9 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 spec/models/classification_spec.rb
|
@jrafanie @chrisarcand I've made all the suggested changes and I think this one is ready to go. |
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.
LGTM
Delete tag assignments when deleting a tag that is referenced in an assignment (cherry picked from commit fc67deb) https://bugzilla.redhat.com/show_bug.cgi?id=1497746
Fine backport details:
|
Delete tag assignments when deleting a tag that is referenced in an assignment (cherry picked from commit fc67deb) https://bugzilla.redhat.com/show_bug.cgi?id=1497748
Euwe backport details:
|
Delete tag assignments when deleting a tag that is referenced in an assignment (cherry picked from commit fc67deb) https://bugzilla.redhat.com/show_bug.cgi?id=1497746
Eg.
/managed/environment/any1
/chargeback_rate/assigned_to/vm/tag/managed/environment/any1
.Which means that a chargeback rate (tagged with the latter) is assigned to any Vm
tagged with
environment/any1
. Should also be deletedhttps://bugzilla.redhat.com/show_bug.cgi?id=1483365
/cc @yrudman, @imtayadeway