Skip to content
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

Control tags are not appearing in account information section #376 #377

Conversation

grana-equinix
Copy link
Contributor

Issue no #376

Before this fix, only users' tags were showing

Screenshot 2023-09-14 at 1 07 34 PM

After this fix, both control and users' tags are showing

Screenshot 2023-09-14 at 10 55 48 PM
Recording.4.mp4

@@ -25,7 +25,7 @@ class TagDefinition < KillBillClient::Model::TagDefinition

ALL_OBJECT_TYPES.each do |object_type|
define_singleton_method "all_for_#{object_type.downcase}" do |options_for_klient|
(all('NONE', options_for_klient).delete_if { |tag_definition| !tag_definition.applicable_object_types.include?(object_type) || tag_definition.is_control_tag }).sort
(all('NONE', options_for_klient).delete_if { |tag_definition| !tag_definition.applicable_object_types.include?(object_type || tag_definition.is_control_tag) }).sort

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand here we are reverting back to before of Rubucop update to get all tags as before.

but object_type never will be falsey and tag_definition.is_control_tag is never taken into consideration or will it?
object_type || tag_definition.is_control_tag
what is the significance of is_control_tag here? or can we remove it from OR condition?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • even if tag_definition.is_control_tag is considered (assume object_type is nil or false)
  • is_control_tag is a boolean value
  • tag_definition.applicable_object_types.include?(tag_definition.is_control_tag) will be always false
  • as per documention, See ObjectType for a list of the possible values.

so is tag_definition.is_control_tag condition required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, you have a good point.

Actually, before, it was (see https://github.com/killbill/killbill-admin-ui/pull/135/files):

!tag_definition.applicable_object_types.include? object_type || tag_definition.is_control_tag

which I'm guessing is/was equivalent to:

(!tag_definition.applicable_object_types.include?(object_type)) || (tag_definition.is_control_tag)

which makes more sense: return all tag definitions for object_type by fetching all tag definitions, excluding (delete_if) both the ones which don't apply to that object_type and the control tags.

But it sounds like we want: return all tag definitions for object_type by fetching all tag definitions, excluding (delete_if) the ones which don't apply to that object_type UNLESS it's a control tag?

Could we add a few unit tests to make it clearer? Has precedence of operators in Ruby somehow changed in 3.0? 🤔 (we bumped Ruby compatibility version in master - have you tried on various Ruby versions?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, here is the test case added to check if this !tag_definition.applicable_object_types.include?(object_type || tag_definition.is_control_tag) should alway return all the tags uesrs' or control tags as expected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But to @NarothamSai's point, object_type || tag_definition.is_control_tag doesn't make sense?

Copy link
Contributor Author

@grana-equinix grana-equinix Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But to @NarothamSai's point, object_type || tag_definition.is_control_tag doesn't make sense?

Do you have any other suggestion to replace this logic with what? As per what i understood reverted the code as it was earlier because it was not intentional but due to rubocope update?

We have also added a test case to make sure that whatever logic is written here should not break tag_definition functionality and should keep returning tag's list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have removed the check of tag_definition.is_control_tag form above logic and added some test case to make sure it should work as expected.

test 'invoice related tags list should have WRITTEN_OFF tag' do
options_for_klient = build_options_for_klient
invoice_tags = Kaui::TagDefinition.all_for_invoice(options_for_klient)
invoice_tags.each do |invoice_tag|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this list only contain a single element (WRITTEN_OFF)? If so, let's write the test to check this (and check the name of that single tag definition), instead of doing a for loop (a bit confusing as tag definition names should be unique);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@pierre pierre merged commit 75babdd into killbill:master Sep 25, 2023
5 checks passed
@grana-equinix grana-equinix deleted the Control-tags-are-not-appearing-in-account-information-section-#376 branch November 21, 2023 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants