Skip to content

[5.3] Fix item count does not take access level into account #44950

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

Open
wants to merge 4 commits into
base: 5.3-dev
Choose a base branch
from

Conversation

janschoenherr
Copy link
Contributor

@janschoenherr janschoenherr commented Feb 21, 2025

Currently when getting the item count of a category, the access level is not being taken into account. This PR fixes the issue.

Summary of Changes

Add the access condition to the item subquery.

Testing Instructions

Create a menu item of type List All Categories in an Article Category Tree.

If you navigate to the menu item, it should display a list of categories with an article count.

Bildschirmfoto 2025-02-21 um 14 29 34

Have at least one article in one of the categories restricted by its access level. Make sure you are not logged in.

Actual result BEFORE applying this Pull Request

The access restricted article is being included in the article count.
The Articles > Unauthorized Links option has no effect on the article count.

Expected result AFTER applying this Pull Request

The access restricted article is not being included in the item count.

If however Articles > Unauthorized Links option is set to Yes the access restricted article is included.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@janschoenherr janschoenherr force-pushed the patch-30 branch 2 times, most recently from f9af518 to dd5e3b4 Compare February 21, 2025 09:36
@ghost
Copy link

ghost commented Feb 21, 2025

@janschoenherr I think the test instructions belong to the new Articles-module? If so i didn't find where the "Article Count" to set. If not, can you please be more specific in the test instructions?

@janschoenherr
Copy link
Contributor Author

@janschoenherr I think the test instructions belong to the new Articles-module? If so i didn't find where the "Article Count" to set. If not, can you please be more specific in the test instructions?

I updated the testing instructions.

@ghost
Copy link

ghost commented Feb 21, 2025

I have tested this item ✅ successfully on dd5e3b4


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

1 similar comment
@viocassel
Copy link
Contributor

I have tested this item ✅ successfully on dd5e3b4


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

@brianteeman
Copy link
Contributor

I have tested this item 🔴 unsuccessfully on dd5e3b4


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

@brianteeman
Copy link
Contributor

This doesnt take into account what happens when you have unauthorised links set to yes
image

Before the PR the menu item would display the total number of articles and then when entered the category will display the intro text of the registered articles to guest users

After the PR the menu item only displays the public number of articles which if greater than 0 will still display the intro text of the registered articles to guest users. If the number of public articles in the category is 0 then the category will not be displayed at all.

See video

After PR

chrome_RAEUI9rGdb.mp4

Before PR

chrome_04rbtN0569.mp4

@brianteeman
Copy link
Contributor

There are probably other areas negatively impacted by this change - this was just the first one that came to mind

@janschoenherr
Copy link
Contributor Author

janschoenherr commented Feb 24, 2025

I have added a new option accessOnItems to resolve that.

@janschoenherr
Copy link
Contributor Author

$params = (clone $this->getState('params'))->merge($params);

This actually fixes another bug. Just evaluating the menu params, doesn't take the global component parameters into account. e.g. Use Global (hide) Which might lead to fetching countItems unnecessarily.

@ghost
Copy link

ghost commented Feb 26, 2025

@janschoenherr Can you update the test instructions including the #44950 (comment) by @brianteeman and your comment?

This actually fixes another bug. Just evaluating the menu params, doesn't take the global component parameters into account. e.g. Use Global (hide) Which might lead to fetching countItems unnecessarily.

@janschoenherr
Copy link
Contributor Author

This actually fixes another bug. Just evaluating the menu params, doesn't take the global component parameters into account. e.g. Use Global (hide) Which might lead to fetching countItems unnecessarily.

Regarding my additional comment:

You'll have to enable Debug System.

Then set Empty Categories to Show and # Articles in Category to Hide

Bildschirmfoto 2025-02-26 um 13 34 16 in the Global Configuration.

Without the fix, the numItems are still queried:
Bildschirmfoto 2025-02-26 um 13 32 20

With the fix, they are not:
Bildschirmfoto 2025-02-26 um 13 34 01

@ghost
Copy link

ghost commented Feb 26, 2025

I have tested this item ✅ successfully on 5085b03

Unauthorised Links No

1-no-unauthorised-test44950 2-no-unauthorised-articlespublicorunauthorised

Unauthorised Links Yes

1-unauthorised-test44950 2-unauthorised-articlespublicorunauthorised
  • The categories All articles are public show 7 articles and No articles show no articles. No difference what value Unauthorised Links is set.
  • Category No articles isn't shown in menu item type List All Categories in an Article Category Tree.
  • Register to read more … works as expected.

This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

@exlemor
Copy link

exlemor commented Mar 17, 2025

I have tested this item ✅ successfully on 24db2a0

I have tested this successfully. :)


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

@ghost
Copy link

ghost commented Mar 17, 2025

I have tested this item ✅ successfully on 24db2a0


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

$options['access'] = $options['access'] ?? 'true';
$options['published'] = $options['published'] ?? 1;
$options['countItems'] = $options['countItems'] ?? 0;
$options['accessOnItems'] = $options['accessOnItems'] ?? true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't checked the details but there are potential issues here. You enable accessOnItems by default, so it will:

  • Change the previous behavior
  • If the items table does not have access field, it will cause SQL error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I enabled it by default, because 'access' is enabled by default too and otherwise we'd have to change all places, where this is called (That's possible too, of course). I believe all relevant Joomla tables have an access field. But yes, if you have a 3rd party extension without the access field on the item table, it might break.

Copy link
Contributor

Choose a reason for hiding this comment

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

Better be safe. We could not know what people do with their own code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I updated the PR to default enable it for core extensions only.

@exlemor
Copy link

exlemor commented Mar 17, 2025

@janschoenherr - now when I try to test, we have a regression possibly, the results are the same with and without the PR - unlike in my previous test where things were different and matching the aim of the PR (filtering out the item count).... FYI.

@exlemor
Copy link

exlemor commented Mar 18, 2025

@janschoenherr yes, I am using a menu item of type List All Categories in an Article Category Tree... I just retested it, 1 minute ago and still same reaction - the numbers do not move, if need be, I can make a video...

@janschoenherr
Copy link
Contributor Author

janschoenherr commented Mar 18, 2025

@exlemor Thanks for testing. Did you set the 'Unauthorised Links' option in Articles to No?

@exlemor
Copy link

exlemor commented Mar 18, 2025

@exlemor Thanks for testing. Did you set the 'Unauthorised Links' option in Articles to No?

With Unauthorized Links set to No or Yes, same results with none of the numbers changing ;(
(I cleared cache after each change just in case).

@janschoenherr
Copy link
Contributor Author

And you are not logged-in in the frontend, right?

@exlemor
Copy link

exlemor commented Mar 18, 2025

And you are not logged-in in the frontend, right?

Definitely only logged into the backend. Not the front-end.

@exlemor
Copy link

exlemor commented Mar 18, 2025

@janschoenherr - Could the issue be that I set those articles to Special and Super Users vs Registered or Publisher etc?

Just changed one of the articles from Special to Registered and it didn't work either ;( - sorry.

@krishnaGandhi11
Copy link

krishnaGandhi11 commented Mar 18, 2025

I have tested this item ✅ successfully on 0ed6a90


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

@krishnaGandhi11
Copy link

I have tested this item ✅ successfully on 0ed6a90

This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

Here's a before-and-after look at the results of this PR!

PR.-.44950.2.1.mp4

@janschoenherr janschoenherr changed the base branch from 5.2-dev to 5.3-dev April 7, 2025 08:02
@janschoenherr janschoenherr changed the title [5.2] Fix item count does not take access level into account [5.3] Fix item count does not take access level into account Apr 7, 2025
@janschoenherr
Copy link
Contributor Author

@exlemor I rebased the PR to 5.3 now. Thanks for looking into it!

@QuyTon
Copy link
Contributor

QuyTon commented Apr 7, 2025

Please fix phpcs: https://ci.joomla.org/joomla/joomla-cms/83956/1/7

@exlemor
Copy link

exlemor commented Apr 7, 2025

I have tested this item ✅ successfully on cc910c8

I have tested this successfully this time :D.

@janschoenherr (sorry it took me so long to re-test this).


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

@janschoenherr
Copy link
Contributor Author

Thanks for testing again!

@Linkedla
Copy link

I have tested this item ✅ successfully on 5aabb98


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44950.

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.