boonebgorges / buddypress-docs

GNU General Public License v3.0
106 stars 44 forks source link

Docs list page won't show a sub folder #748

Closed bwk1224 closed 4 months ago

bwk1224 commented 4 months ago

The system is currently using BuddyPress Docs version 2.2.1 plug-in.

A user of a private group submitted a ticket that the following stopped working few months ago.

When trying to view a sub folder of a folder within the private group documents page, the program generates 0 results, causing the list table to be empty.

For example:

Folder 1
    Sub-folder 1 to Folder 1
    Sub-folder 2 to Folder 1
    Sub-folder 3 to Folder 1
    Sub-folder 4 to Folder 1
    Sub-folder 5 to Folder 1
Folder 2
    Document 1
    Document 2
Folder 3
Etc.

The "Folder 1" shows an empty list when expanded on the documents list page. However, when there's only documents under a folder(Ex. folder 2), the list is generated properly.

The user claims that the folder 1 used to show its sub folders before.

Is this a program design change or a bug? If it's a program design change, how can I make this work as before?

Thanks.

boonebgorges commented 4 months ago

Thanks for the report. This sounds very similar to https://wordpress.org/support/topic/problems-with-the-sub-folders/, which was also just reported.

buddypress-docs 2.2.1 had a small bug that caused some inconsistencies in access control for folders in private groups. I've just pushed version 2.2.2 to wordpress.org, which includes a fix. I'm not very confident that it will address your issue, but please update to 2.2.2 just to be sure.

If you're still experiencing the issue, please outline some specific setup steps I can take to replicate. Specifically, I suspect that the current issue may be due to the relationship between the "ownership" of groups/docs/folders. So, if you have a private group G with folders F1 and F2, please lay out carefully which users created each of these items, and which users are (or are not) able to see the expected contents of the Docs directory.

bwk1224 commented 4 months ago

Hello, the version 2.2.2 didn't solve the issue.

Here's the sample setup that you could try.

The site has multiple private groups. Let's focus on group A.

User A is the group administrator of the group A.

The group A's "Documents" settings have the following options set.

All folders and documents were uploaded by the user A.

Folder permissions

There are 90 total main and sub folders under this private group. Each folder has random number of documents.

The issue of showing sub-folder contents occurs on the following page: https://abcd.com/groups/A/docs/ Spinner shows when a folder 1 is clicked to expand the view, but no sub folders show. An empty table list is returned.

Going to the folder 1 page directly shows all sub-folders correctly for all private group members. Ex. https://abcd.com/groups/A/docs/?folder=xxxx(ID of folder 1).

No wordpress account (even the system administrator) can view the list correctly now on the docs list table page.

Please let me know if you need additional information.

boonebgorges commented 4 months ago

Thanks so much for the extremely helpful details. I'll try to reproduce this soon.

In the meantime, your note about the "spinner" stood out to me. It suggests that there's a failed AJAX request taking place. Can you monitor your Network tab to see whether that's the case? Or is there anything in your PHP error log indicating, say, a fatal error associated with these AJAX requests?

bwk1224 commented 4 months ago

When requesting a folder 1 list, the network got 200 for this request url. https://abcd.com/wp-admin/admin-ajax.php?lang=en&bpml_filter=true&folder=xxxxx&group_id=x&user_id=0&action=bp_docs_get_folder_content

But when a table is inspected, the table with ".doctable" class generated a tr row with "no-docs-row" class.

I didn't see any error msgs related to docs. I did see an error log for the buddypress/menu-notifications.php, but I don't think this is related.

dcavins commented 4 months ago

Boone, it looks to me like, with BP 12, the $_GET['folder'] attribute isn't making it into bp_docs_get_folders(). The AJAX request contains the same parameters, but the $_GET array is empty by the time the function runs. I'll look at what changed in BP that might be consuming those params.

This was a red herring anyway. That function is called at page load, not in response to the AJAX call. I confused myself with my logging.

boonebgorges commented 4 months ago

@dcavins I think it's deeper than that. bp_is_group() isn't returning true inside of the AJAX request, which I think might be due to BP 12 load-order problems. I'm trying to figure out a workaround.

boonebgorges commented 4 months ago

@bwk1224 Thanks for your detailed feedback. I was able to reproduce this with the right configuration and versions of BP.

@dcavins As noted above, I think the problem is that in BP 12, bp_is_group() and friends doesn't work right in AJAX callbacks. This seems like a pretty big bug in BP not to have been caught previously, so I wouldn't be surprised if it's something specific to the way buddypress-docs works. Anyway, I built a "get current group ID" wrapper function in e0b3c54 that works in AJAX by deriving the group ID from the passed URL. The technique used is pretty wacky, but I couldn't find a tool in either BP or WP for matching and parsing rewrite rules. (WP-CLI does something not dissimilar so I'm guessing this is as good as it gets https://github.com/wp-cli/rewrite-command/blob/293f9de9905b9d0199d72ff0d17e837228e47a10/src/Rewrite_Command.php#L237) Could you have a look?

dcavins commented 4 months ago

Yes, I'll look at your patch and also keep thinking about this generally. If BP is failing at this generally, we need to fix it there.

boonebgorges commented 4 months ago

After feedback on how this is supposed to work in BP 12+, I've updated my branch. See https://github.com/boonebgorges/buddypress-docs/pull/750/files. @dcavins Can you please review before I push this out?

dcavins commented 4 months ago

@boonebgorges I've tested this on my local site that I was able to recreate the problem on, and it does resolve the problem. It should resolve a lot of problems (that we didn't know we had?)! Thanks @imath!

Code looks good, too. Thanks for the quick resolution!

boonebgorges commented 4 months ago

Thanks, all. This issue should be fixed by the 2.2.3 release, which I've just pushed to wordpress.org.