Skip to content

DEV: Improve user handling and access in post components #34013

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

Merged
merged 16 commits into from
Aug 6, 2025

Conversation

megothss
Copy link
Contributor

@megothss megothss commented Jul 31, 2025

This pull request improves how user properties are managed and accessed in post-related components and models. Notable improvements include:

  • The Post model now provides a cached user property, ensuring a consistent and up-to-date user object using relevant post fields, instead of relying on user being set directly or via the PostStream.
  • Components such as PostAvatar and PostMetaDataPosterName now consistently reference the user property, improving reliability and reducing the risk of missing or inconsistent user data.
  • User context is more accurately passed to value transformers and plugin outlets, ensuring that avatar and name rendering logic always receives the correct user information.
  • The GroupPostSerializer now includes the user_id attribute, improving API consistency.
  • Test cases have been updated to work with the new user property approach, removing direct creation of user objects on posts and instead relying on post fields.
  • The discourse-reactions plugin was updated to align with the new user property logic, ensuring reaction-related user data is accessed consistently.

Overall, these changes improve data integrity, reduce the risk of rendering errors due to user data inconsistencies, and streamline how user information is passed through Discourse post-related features.

megothss added 5 commits July 31, 2025 22:57
Reorganized the `post-avatar` component by introducing `let` bindings to share `avatarOutletArgs` in all plugin outlets
…ents

Moved user creation logic to a `user` getter in the `post` model. Updated `post-stream` and `post-avatar` components to leverage this centralized logic, enhancing maintainability and consistency.
Removed the redundant `test` class from the `post-notice-message` div to clean up the template and avoid unused styles.
Updated the `avatarTemplate` property check to `avatar_template` for consistency with user object properties.
Introduced `#transformerContext` to simplify repeated code and centralize context creation for `applyValueTransformer` calls, improving readability and maintainability.
@megothss megothss force-pushed the dev/post-user-missing-attributes branch from 9bce04a to 1398914 Compare August 1, 2025 02:31
@megothss megothss marked this pull request as ready for review August 1, 2025 02:31
@megothss megothss marked this pull request as draft August 1, 2025 03:05
Updated the `poster-name` component to rely on the `user` model from the `post` object, replacing direct property access. Simplified logic in templates and improved maintainability by aligning with recent user model centralization efforts.
Removed the `store` service from the `post` model as it was unused.

Restored `dismissed_banner_key` as a tracked property in the `user` model
Replaced inline condition in template with a `shouldShowUserStatus` getter. Improves readability and centralizes logic for checking user status visibility.
Centralized `user` logic in reactions by aligning `post_user` with `post.user`. Updated `group_post_serializer` to expose `user_id` for consistency. Simplifies user object management across reactions and serialization.
Aligned `poster-name` component with centralized `user` handling in `post` model. Consolidated name sanitization logic and ensured consistency by using `user` object throughout templates and tests. Improves readability and maintainability.
Added a check to return `null` for cases where the `user` is missing. Updated `userWasDeleted` logic to use the `user` object instead of `user_id`. Simplifies error handling and ensures consistency with centralized `user` handling.
@megothss megothss marked this pull request as ready for review August 6, 2025 05:38
@megothss megothss changed the title DEV: Improve handling of user properties in the post avatar DEV: Improve handling of user properties in posts Aug 6, 2025
@megothss megothss changed the title DEV: Improve handling of user properties in posts # DEV: Improve user handling and access in post components Aug 6, 2025
@megothss megothss changed the title # DEV: Improve user handling and access in post components DEV: Improve user handling and access in post components Aug 6, 2025
@megothss megothss merged commit 4013d1f into main Aug 6, 2025
22 checks passed
@megothss megothss deleted the dev/post-user-missing-attributes branch August 6, 2025 20:00
@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/trust-level-avatar-flair/82656/122

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

Successfully merging this pull request may close these issues.

3 participants