Skip to content

Add Newsfeed#507

Open
frcroth wants to merge 25 commits intofsr-de:mainfrom
frcroth:feed
Open

Add Newsfeed#507
frcroth wants to merge 25 commits intofsr-de:mainfrom
frcroth:feed

Conversation

@frcroth
Copy link
Copy Markdown
Contributor

@frcroth frcroth commented Feb 13, 2024

Close #479

image

TODO

  • When logged in as student and going to the "/" page, redirect to the feed
  • Automatically write to feed on release. See https://github.com/frcroth/myHPI/actions/runs/7907525385/job/21584753770 for this. Obviously I couldn't test this properly (also the first time this will fail because the feed will only be deployed after the release is published).
  • Create tests
  • Add feed to setup test data
  • Pagination
  • Render html properly in snippet
  • Properly break snippet so that no html tag is unclosed
  • Translations
  • Ensure everything looks fine for mobile
  • Position pagination buttons better

Optional todos (can also be followups)

  • Rss feed
  • Icons for post accounts (Fsr logo for fsr posts)
  • Non-optional but not really part of this PR: The thing that posts the FSR mails
  • Reactions on posts?

Questions

  • how exactly should the redirect behavior work. Always redirect when clicking on "myhpi"? Redirect only when logging in and no next is set?

@jeriox we can do the election release first and merge this afterward if there were no problems

@frcroth frcroth marked this pull request as ready for review February 14, 2024 21:22
@frcroth frcroth changed the title Add feed Add Newsfeed Feb 14, 2024
@frcroth frcroth requested a review from jeriox February 14, 2024 21:22
@frcroth frcroth force-pushed the feed branch 2 times, most recently from 8efdf01 to 8e0080a Compare February 15, 2024 09:06
from myhpi.feed.models import NewsFeed


class FeedRedirectMiddleware:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you could also implement this inside the serve() of RootPage, that would only do the check when it is actually necessary and not with every request

Copy link
Copy Markdown
Contributor Author

@frcroth frcroth Feb 20, 2024

Choose a reason for hiding this comment

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

But that would increase coupling. Currently disabling/removing the app is very easy, it is never mentioned / used in core. Your thoughts on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In my opinion, it would be okay to introduce some change to core, as myHPI (this application) is developed specifically for our myHPI website and not meant as a generic CMS. Hence, we don't need to be able to deactivate/remove the newsfeed app per installation and that small amount of coupling would be acceptable.

However, I'm not that familiar with Django patterns, so I can't really argue on whether there is even a need to replace this middleware or not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lukasrad02 Felix and I had a conversation about the conflict of cool new features vs. size of codebase/maintainability. I made the argument that as long as fancy features are loosely coupled, future maintainer could easily remove them without the need to understand/update/fix them and therefore delay or block the maintenance of the core app.

The middleware is probably fine, as it doesn't do much. I just thought about it because we always struggle with pageload times and this is code that is not necessary on all pages but the root page.

Another way that we could pursue this is by adding some kind of "plugin" mechanism. Again citing ephios: we are sending out custom django signals to "plugins" (other django apps within the same repo or installed separately) and let them inject stuff at various places. e.g. there is a signal that says "hey plugin, give me some html to append to the homepage if you want to". This way, the additional code is only run when it is necessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm fine with you two deciding on the best approach to do this. Especially when it comes to performance or plugins in Django, I would not be able to give any qualified arguments.

post_key = models.CharField(max_length=255)
name = models.CharField(max_length=255)

icon = models.ImageField(upload_to=upload_avatar_to, null=True, blank=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this the correct reference to also use all of the wagtail stuff for images?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the same code that is used for uploading user avatars in Wagtail. Does not have to deal with collections etc., which makes sense because the post accounts should only be edited by admins anyway.

@dasGoogle
Copy link
Copy Markdown
Contributor

As an idea on how to handle this on the main page: Provide the first 3-4 news items (I think we could go for a two-column layout there and maybe even make the design a bit more compact) and add a link to "Further News" or similar.

@lukasrad02
Copy link
Copy Markdown
Contributor

Regarding the Automatically write to feed on release feature: Do you think it would make sense to integrate this into the myHPI source code instead of the GitHub pipeline? I would think about some logic that checks the current version on startup, compares it with the version from the last startup and fetches the release description from GitHub if the version has changed.

I would prefer this over creating the post from the pipeline, as there are usually a couple of hours or days between the release on GitHub and deploying it in production. Having some large post advertising new features on the homepage although these features are not even available might confuse users.

@frcroth
Copy link
Copy Markdown
Contributor Author

frcroth commented Feb 21, 2024

Your reasoning makes sense to me. I wonder how that could be implemented. Especially, it is not guaranteed that there are not two releases between restarting myHPI.

So basically, on start:

  1. Check github for releases
  2. Diff that list with some stored version (I think this may be tricky)
  3. Create posts for all new releases (Since this does not need to use the POST route, we can also set the releases date as the post date)

I'm not sure how to do the diffing. We could of course just do this by title or something like that, seems a little flaky as both github releases and news feed posts are not guaranteed to keep their title. Otherwise another structure would need to be created to store the mapping of release to post for diffing purposes.

@lukasrad02
Copy link
Copy Markdown
Contributor

You've got a good point. I was thinking about comparing the version numbers, but this would of course require us to store them in addition to the posts, like the separate structure you've mentioned.

I don't have a strong opinion on whether to introduce such a structure or not, but am slightly in favor of doing this. Otherwise, we would even have to differentiate between release posts and other posts during diffing, so there will be a lot of edge cases to consider.

@dasGoogle
Copy link
Copy Markdown
Contributor

As another Idea: Why don't we pull the releases from GitHub in the action and place it in a file in the docker container?
We could then simply parse that file on startup and mix it into the existing newsfeed without persisting anything in the DB.

@jeriox
Copy link
Copy Markdown
Contributor

jeriox commented Feb 21, 2024

I think all of your variants are quite complex. I would prefer just using the tag of the current version (which we have easy acccess to from the python code) and creating a post for that by pulling the corresponding release notes if it does not exist yet.

@lukasrad02
Copy link
Copy Markdown
Contributor

From my perspective, both the suggestions from Aaron and Julian would be fine

@frcroth
Copy link
Copy Markdown
Contributor Author

frcroth commented Feb 25, 2024

Now implemented @jeriox 's version. the only problem I see here is that some releases may not be published. I.e.

  • New version 2.0 is published with many cool features.
  • A bug is found immediately after publishing (or while deploying)
  • Version 2.0.1 is published with one fix.
  • It deploys successfully, and only the 2.0.1 post is published.

To fix this, an admin needs to manually publish the post with python manage.py publish_release_post v2.0.0

Coming back to how the user is presented the feed. What I like about the current version is that no changes are done to core. I am not sure if that would be possible when including the posts on the root page. If that is not relevant, I think it should be possible.

@frcroth frcroth requested a review from jeriox February 25, 2024 18:23
@lukasrad02
Copy link
Copy Markdown
Contributor

To fix this, an admin needs to manually publish the post with python manage.py publish_release_post v2.0.0

Nice solution!

Coming back to how the user is presented the feed. What I like about the current version is that no changes are done to core. I am not sure if that would be possible when including the posts on the root page. If that is not relevant, I think it should be possible.

Added some comment on this to the discussion above.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Newsfeed

4 participants