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

Post news feed to user menu #1807

Merged
merged 6 commits into from
Jan 15, 2025
Merged

Post news feed to user menu #1807

merged 6 commits into from
Jan 15, 2025

Conversation

jmthomas
Copy link
Member

@jmthomas jmthomas commented Jan 3, 2025

Pulls news from https://github.com/OpenC3/openc3-news into the backend using the PeriodicMicroservice which updates once per day. This pulls news from the backend every hour since we don't know when the backend news will be updated.

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

Attention: Patch coverage is 61.29032% with 12 lines in your changes missing coverage. Please review.

Project coverage is 79.57%. Comparing base (a792ac2) to head (f5ca53b).
Report is 39 commits behind head on main.

Files with missing lines Patch % Lines
openc3/lib/openc3/api/settings_api.rb 42.85% 8 Missing ⚠️
openc3/lib/openc3/models/news_model.rb 72.72% 3 Missing ⚠️
...mos-cmd-tlm-api/app/controllers/news_controller.rb 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1807   +/-   ##
=======================================
  Coverage   79.56%   79.57%           
=======================================
  Files         517      519    +2     
  Lines       40737    40770   +33     
=======================================
+ Hits        32414    32441   +27     
- Misses       8323     8329    +6     
Flag Coverage Δ
python 84.30% <ø> (+0.04%) ⬆️
ruby-api 48.68% <80.00%> (+0.03%) ⬆️
ruby-backend 82.58% <57.69%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmthomas
Copy link
Member Author

jmthomas commented Jan 3, 2025

Base:
Screenshot 2025-01-09 at 8 45 29 AM

Enterprise enabled:
Screenshot 2025-01-09 at 9 21 49 AM

Enterprise disabled:
Screenshot 2025-01-09 at 9 22 06 AM

Setting:
Screenshot 2025-01-09 at 8 45 59 AM

Copy link
Member

@ryanmelt ryanmelt left a comment

Choose a reason for hiding this comment

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

Please look over comments before merging.


class NewsController < ApplicationController
def index
render json: OpenC3::NewsModel.all()
Copy link
Member

Choose a reason for hiding this comment

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

Would we want to have an HTML version of this page too, and return either json or html based on extension?

Copy link
Member Author

Choose a reason for hiding this comment

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

We already have a news site (https://www.openc3.com/news) so I can't imagine having another one for the little blurb news that goes in this json feed.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine either way. It wouldn't really be used, just a pretty response when people poke around at the domain

this.news.forEach((news) => {
news.read = true
})
localStorage.newsRead = this.news.length
Copy link
Member

Choose a reason for hiding this comment

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

This will break when we start deleting old news. Maybe use a id / timestamp from the last news item?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I could grab the newest timestamp and then look to see if there is anything newer.


module OpenC3
class LocalApi
include Api
end
Copy link
Member

Choose a reason for hiding this comment

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

Why not just include Api in the microservice class?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to pollute the entire class just to call the one method but I guess it doesn't matter

class NewsFeed < Migration
def self.run
setting = SettingModel.get(name: 'news_feed')
SettingModel.set({ name: 'news_feed', data: true }, scope: 'DEFAULT') unless setting
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this migration has issues because I'm storing true/false in there. So this will basically always turn it on. Not sure how to check for existence vs true/false.

Copy link
Member

Choose a reason for hiding this comment

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

We have other true/false settings right?

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see the always will become true thing. You don't really need to unless part, as this should only run on migration and in that scenario the setting really shouldn't have ever existed before.

@jmthomas jmthomas merged commit 0f71247 into main Jan 15, 2025
27 of 28 checks passed
@jmthomas jmthomas deleted the news branch January 15, 2025 19:54
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