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

GetTagsForEntityType should only return tags from not trashed entites and published content #15554

Closed
wants to merge 3 commits into from

Conversation

rammi987
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #15524

Description

When using GetAllContentTags or GetAllMediaTags it gets all tags even is entity is trashed or the content is unpublished.
We expect it to only return tags for content witch are published and aviable.

So as #15524 (comment) suggest is have add in the where clause to ensure only take tags from content when is it pulished and if entities is not trashed.

I have added 2 more unit test to ensure it works properly

So now then creating 2 content node and give both node a Tag, and render it with the GetAllContentTags it gives 2 tags items back. But do i unpulished or trash a node and ask the GetAllContentTags again it only return a single tag.

Copy link

github-actions bot commented Jan 10, 2024

Hi there @rammi987, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

Copy link
Member

@nul800sebastiaan nul800sebastiaan left a comment

Choose a reason for hiding this comment

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

Thanks @rammi987 - just a note on performance and I have a few questions about the test that was updated.

Comment on lines +398 to +399
.InnerJoin<ContentVersionDto>().On<ContentVersionDto, NodeDto>((node, cv) => node.NodeId == cv.NodeId)
.InnerJoin<DocumentVersionDto>().On<DocumentVersionDto, ContentVersionDto>((dv, cv) => cv.Id == dv.Id && dv.Published);
Copy link
Member

Choose a reason for hiding this comment

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

Adding joins is not very performant, I know that in other areas of the CMS we look at the content path to see if the highest ancestor is the Id of the recycle bin (Id: -20, and for media -21 I believe, there's constants for these Ids). I would recommend trying that for this PR first.

I don't know if it would also make sense to do this for media items by the way, I assume they have the same problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The is a few issuese here. We have entity for media, content and member.

The first thing is all can be trashed or not, so to exclude the the nodes witch are trashed i add to this line
https://github.com/umbraco/Umbraco-CMS/pull/15554/files/18823f3d8f7aca32a0a50883f558e64ef027e078#diff-6bfd8066a466dcb406442d00e5991f3f8a798dfa9976124fc128476f681fe88aR408 where i test if it trashed or not.
Therefor i dont need to look into the path or parentid.

The secound thing is the content can also be pulished and unpublished, and we only want the tags from content witch are pulished. The is no way to tell is a NodeDto is un-/ published without the inner joins.

Therefor i added in the condition if (objectType == TaggableObjectTypes.Content) to only make the inner joins if it is an entity for content. I know innerJoins is costly but the is no other way to get the PublishedState

Copy link
Contributor

Choose a reason for hiding this comment

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

I see the reasoning for this, but actually when testing - at least as of now, on v13/dev - I don't see tags from unpublished pages included in my result. So I suspect we don't need to filter them out here, rather the act of unpublishing will remove records from the cmsTagRelationship table. This is done within the DocumentRepository.

So it doesn't look like we do need to include these additional joins, but for different reasons.

Comment on lines +792 to +793
content1.PublishCulture(CultureImpact.Invariant);
content1.PublishedState = PublishedState.Publishing;
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure why this needs to be added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if content1.PublishedState = PublishedState.Publishing; is not present the test content is acculty marked as an unpulished node, therefor the test will fail do to the Assert.AreEqual(3, result1.Length); result1.Length will be 0 becouse we dont get tag from unpublished content.

@@ -711,6 +848,7 @@ public void Can_Get_Tags_For_Entity_Type_For_Group()
ContentTypeRepository.Save(contentType);

var content1 = ContentBuilder.CreateSimpleContent(contentType);
content1.PublishedState = PublishedState.Publishing;
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure why this needs to be added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if content1.PublishedState = PublishedState.Publishing; is not present the test content is acculty marked as an unpulished node, therefor the test will fail do to the Assert.AreEqual(3, result1.Length); result1.Length will be 0 becouse we dont get tag from unpublished content.

@AndyButland
Copy link
Contributor

Thanks for this PR @rammi987. I know it's sat for a while, but I came across the issue and saw you had fixed it, so would like to merge in so we get a fix for 13+. I think there have been some changes since you did this that means part isn't required, but I'll take the liberty of updating so we can merge in if that's OK.

@AndyButland
Copy link
Contributor

It'll actually be easier to close this one I'm afraid. I've pulled the parts we needed into #18164, as it made sense to fix this in 13, and thus we'll get it in higher versions when we merge up. Given this one was targeted at a higher version via the contrib branch, I couldn't find a way to retarget it down to v13/dev without bringing in many more unwanted commits.

Hope that's OK @rammi987 and thanks again for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TagQuery.GetAllContentTags includes trashed content
4 participants