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

Make the Request available to the Formatter\Rendering event #1721

Merged
merged 1 commit into from
Jan 22, 2019

Conversation

tobyzerner
Copy link
Contributor

@tobyzerner tobyzerner commented Jan 3, 2019

Make the Request available to the Formatter\Rendering event.

This is important because extensions may wish to render post content
differently depending on Request factors such as the actor. For example,
an attachments extension might wish to hide attachments from guests.

This solution is a bit of a hack-job for now, but soon when we refactor
the API layer to use tobscure/json-api-server, and also refactor the
Formatter layer, it can be revised.

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run php vendor/bin/phpunit).

This is important because extensions may wish to render post content
differently depending on Request factors such as the actor. For example,
an attachments extension might wish to hide attachments from guests.

This solution is a bit of a hack-job for now, but soon when we refactor
the API layer to use tobscure/json-api-server, and also refactor the
Formatter layer, it can be revised.
@tobyzerner tobyzerner requested a review from franzliedke January 3, 2019 00:46
@franzliedke
Copy link
Contributor

Can you explain the use case in more detail? It does feel very icky to introduce dependencies to HTTP-level classes in our core domain code.

@tobyzerner
Copy link
Contributor Author

tobyzerner commented Jan 3, 2019

Use-cases:

  1. An attachments extension allows embedding of attachments within post content. However the forum admin has decided to only allow logged-in users to download attachments. So if you are viewing the post as a guest, the post should be rendered with "log in to download this attachment" instead of the attachment preview/download link.

  2. (My client's use case) Users on a forum have display names as their full name (eg. Toby Zerner). However for privacy reasons we don't want search engines to be indexing full names. So for guests, the display name shown in @mentions should be altered to only show the initial of the last name (eg. @Toby Z).

Basically, I'm arguing that rendering a post's content is intrinsically a request/actor-dependent process, just like serialising the rest of the post data is. The parsed post content is part of the core domain, but actually rendering it is a presentation-level event.

@franzliedke
Copy link
Contributor

Okay, but both of these examples only need the actor, not the request, right?

@tobyzerner
Copy link
Contributor Author

Well yes, but I think the concept of an actor is still HTTP-level rather than domain. Take example use-case 1 but instead of being logged in you need to enter a password which sets a session flag to true. (I did something like this for another client who wanted certain tags to be password-protected.)

API serializers should definitely be receiving the whole request (the equivalent in tobscure/json-api-server does) and by extension rendering should as well.

Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

Well, then, looking forward to json-api-servers and more extenders. 😀

@franzliedke franzliedke merged commit 0ab9fac into master Jan 22, 2019
@franzliedke franzliedke deleted the tz/formatter-request branch January 22, 2019 22:33
wzdiyb pushed a commit to wzdiyb/core that referenced this pull request Feb 16, 2020
)

This is important because extensions may wish to render post content
differently depending on Request factors such as the actor. For example,
an attachments extension might wish to hide attachments from guests.

This solution is a bit of a hack-job for now, but soon when we refactor
the API layer to use tobscure/json-api-server, and also refactor the
Formatter layer, it can be revised.
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.

2 participants