-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
filter out private posts before limiting the number of results #1334
filter out private posts before limiting the number of results #1334
Conversation
What if the user has permission to see the private posts? |
@tpokorra I see the issue, but @datitisev is right, this solution is flawed as now private posts will never be returned even if the user has permission to see them. It's hard, because the only way to properly filter post visibility is to get the discussions for all of the matched posts, which will not be performant before they are limited. 🤔 |
I agree with you. I was not sure if support for private messages was implemented yet at all because I could not find references in the code where is_private is set or used other than in PostPolicy.php. But my solution is not clean, I agree. Another thought: perhaps in the call /api/posts?filter%5Buser%5D=12345&filter%5Btype%5D=comment&page%5Blimit%5D=20&sort=-time we could add another parameter is_private=false, which would be used in getPostIds in ListPostsController. For users with privileges to see private posts we would need to leave out is_private in the api call. Should I try to prepare a pull request for that? |
I like your idea. Maybe use private=1 to say that you do want private posts to appear in the results, as an opt-in instead of an opt-out. |
Do I misunderstand something or would that mean anybody could see private posts by sending Honestly, the beginning of all this trouble seems to be implementing PMs as a subtype of discussions - I am becoming convinced that this causes too much pain / hacks - the current being |
@franzliedke Sorry if that was confusing, it was an idea to not always show private posts in the results (if any available). The user/application could add private=1 as an argument to get the private posts as well, of course only the ones they have permission to see. |
Byobu is an implementation of is_private. Only the extension knows which users and groups are recipients (authorized) of a private discussion. The frontend doesn't necessarily know who is authorized to see specifically what post, especially not on the user profile page. |
Can I just try and clarify what
So, for example, byobu (private discussions). When you create a private discussion, byobu sets If you disable byobu, no one will be able to see any private discussions, because they've been flagged as Ideally we probably should add this same logic to the Tags extension, so that if you restrict a tag's visibility and then accidentally disable the Tags extension, all of the discussions in private tags won't be revealed to the public. That's @luceos Note that byobu should not actually be marking posts as private, that's not the way it's intended to be used. In byobu, the posts themselves are not private - rather, the posts are public in the context of a private discussion. When Flarum is querying posts it makes sure the user is allowed to view all the discussions that the posts are in, so you don't have to worry about controlling the visibility of each individual post. It currently does this by:
It's not feasible to do that for all of the posts in the resultset, flag or no flag. That
Perhaps we need to try and move that logic from PHP into SQL though, so we can do complex queries like this... |
One can be a bit smarter about it: Lets say we want to display 20 posts. You really only need to load all posts until you have 20 public posts (of public discussions). This number is reasonable low when the ratio of private posts to all posts is small. This ensures exactly 20 entries with just minor changes to the current architecture and keeps the processing involved low (statistically, of course). As a safeguard for many private posts that push the number of loaded posts high, its probably good to also add a hard limit of e.g. 100. If we hit this limit, we have to accept displaying too few posts, but this should rarely be the case. |
@ShatteredMotion
Can't really guarantee this. What if 99% of a forum is private (via restricted tags) and there's only a small public area? Doing a No, we really do need to be able to get the posts, with all relevant permission logic, in a single query. I'm currently working on improving search performance (#1042) and I've run into basically the same issue. I'm going to look into how we can change our API so that the |
You can filter for that case directly: Just get all tags that are accessible to the user and then filter for those discussions.
That's not exactly what I meant. It's still only one query, but instead of a simple But you are right, this approach does not play well with pagination. A simple solution could be to replace the page number with something like However, thinking more about it, this probably is harder to implement for search. The assumption that the ratio of private posts is low cannot easily be made here, depending on the search query. |
@ShatteredMotion great thoughts! But let me point out assumptions like these kill the flexibility Flarum tries to guarantee. I'm going to push back to one of the examples I've been using for Byobu (private discussions), which is a role playing forum. Each and every discussion might be private, restricted to a random set of users. As such (depending on the number of posts, but with role playing that might escalate pretty fast) over 99% of all posts might be private.
Assuming all forums use the tags extension isn't very wise either while implementing a generic query mechanism. I wouldn't be surprised to see a classical category based hierarchy extension before (or soon after) a stable release. |
I've made some serious headway on solving this. Will hopefully push in the next few days. |
Closing in favour of #1342 |
fixes #1333