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

Feat/load monitors, resolves #793 #830

Merged
merged 4 commits into from
Sep 11, 2024
Merged

Feat/load monitors, resolves #793 #830

merged 4 commits into from
Sep 11, 2024

Conversation

ajhollid
Copy link
Collaborator

@ajhollid ajhollid commented Sep 11, 2024

This PR adds demo monitor functionality.

  • Move demo sites json file to server
  • Add routes, controllers, and DB methods for adding demo monitors and removing all monitors
  • Add buttons to the settings page for adding demo monitors and removing all monitors
  • Add async thunks for carrying out network operations

image

@@ -43,4 +43,10 @@
monitorController.pauseMonitor
);

router.post(
"/demo",
isAllowed(["admin", "superadmin"]),

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
router.post(
"/demo",
isAllowed(["admin", "superadmin"]),
monitorController.addDemoMonitors

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
Copy link

coderabbitai bot commented Sep 11, 2024

Walkthrough

The pull request introduces new functionality for managing demo monitors within the application. It adds asynchronous actions in the Redux slice for adding and deleting demo monitors, updates the settings component to handle these actions, and enhances the network service to support corresponding API calls. Additionally, server-side changes include new controller methods for monitor management, updated database functions, and improved error handling across various modules. A new JSON file for demo monitors is also added, along with a success message for user feedback.

Changes

Files Change Summary
Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js Added addDemoMonitors and deleteAllMonitors thunk actions for managing demo monitors.
Client/src/Pages/Settings/index.jsx Integrated demo monitor management with new handler functions and UI elements for admin users.
Client/src/Utils/NetworkService.js Introduced addDemoMonitors and deleteAllMonitors methods for API interactions.
Server/controllers/authController.js Refactored getTokenFromHeaders function to a utility module for better modularity.
Server/controllers/monitorController.js Added addDemoMonitors function and modified deleteAllMonitors for team-specific deletion.
Server/db/mongo/MongoDB.js Added addDemoMonitors function to the monitor module exports.
Server/db/mongo/modules/checkModule.js Enhanced error handling and logging functionality.
Server/db/mongo/modules/monitorModule.js Modified deleteAllMonitors to accept teamId and added addDemoMonitors function.
Server/routes/monitorRoute.js Updated DELETE endpoint to "/" and added POST endpoint for demo monitors.
Server/service/networkService.js Improved error logging and handling in asynchronous operations.
Server/utils/demoMonitors.json Added a JSON file containing demo monitor data.
Server/utils/messages.js Introduced a new success message for adding demo monitors.
Server/utils/utils.js Added getTokenFromHeaders utility function for extracting tokens from headers.

Sequence Diagram(s)

sequenceDiagram
    participant Admin
    participant Settings
    participant Redux
    participant NetworkService
    participant MonitorController

    Admin->>Settings: Click "Add Demo Monitors"
    Settings->>Redux: Dispatch addDemoMonitors
    Redux->>NetworkService: Call addDemoMonitors(authToken)
    NetworkService->>MonitorController: POST /monitors/demo
    MonitorController-->>NetworkService: Response
    NetworkService-->>Redux: Return success/failure
    Redux-->>Settings: Update UI with result
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0a08b44 and c35157f.

Files selected for processing (13)
  • Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js (2 hunks)
  • Client/src/Pages/Settings/index.jsx (3 hunks)
  • Client/src/Utils/NetworkService.js (1 hunks)
  • Server/controllers/authController.js (2 hunks)
  • Server/controllers/monitorController.js (4 hunks)
  • Server/db/mongo/MongoDB.js (2 hunks)
  • Server/db/mongo/modules/checkModule.js (2 hunks)
  • Server/db/mongo/modules/monitorModule.js (4 hunks)
  • Server/routes/monitorRoute.js (2 hunks)
  • Server/service/networkService.js (2 hunks)
  • Server/utils/demoMonitors.json (1 hunks)
  • Server/utils/messages.js (1 hunks)
  • Server/utils/utils.js (1 hunks)
Files not reviewed due to server errors (2)
  • Server/db/mongo/modules/monitorModule.js
  • Client/src/Utils/NetworkService.js
Files skipped from review due to trivial changes (2)
  • Server/utils/demoMonitors.json
  • Server/utils/messages.js
Additional context used
GitHub Check: CodeQL
Server/routes/monitorRoute.js

[failure] 48-48: Missing rate limiting
This route handler performs authorization, but is not rate-limited.


[failure] 49-49: Missing rate limiting
This route handler performs authorization, but is not rate-limited.

Biome
Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js

[error] 175-175: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 194-194: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (15)
Server/utils/utils.js (1)

19-28: Yo, this new getTokenFromHeaders function is straight fire, homie! 🔥

It's handlin' the authorization header like a boss, checkin' if it's there and throwin' down an error if it ain't.

And when it comes to the format, this function ain't playin' around. It's makin' sure that header is followin' the "Bearer " format, or else it's gonna throw hands with an error.

Finally, it's servin' up that token like mom's spaghetti on a silver platter. 🍝

This function is a real G, I ain't got no beef with it. It's good to go, fam! 👊

Server/routes/monitorRoute.js (2)

35-35: Aight, I see you've switched up the delete all monitors route to use the root endpoint. I dig it, dawg! 👌

Ain't nothin' wrong with simplifying things, and this change is straight up legit.

Plus, you've got that "superadmin" role check in there, so you know only the big dawgs can handle this kinda power. 💪

I'm givin' this change my stamp of approval, homie. Keep doin' your thang! 🙌


46-50: Yo, this new "/demo" route is straight up dope! 🚀

It's opening up the gates for "admin" and "superadmin" homies to add those demo monitors like it's nothin'. Mad respect for expanding the API's capabilities, fam. 🙌

The authorization check is on point too, makin' sure only the chosen ones can wield this power. 👑

But hold up, there's a catch. 😳 Looks like this route is missin' some rate limiting, accordin' to the previous review comments.

Yo, you gotta lock this down with some rate limiting, or else it's gonna be like a free-for-all up in here. 🚨

Think you could hook it up with some rate limiting magic? 🪄 It'd be dope if you could open a GitHub issue to track this and make sure it gets handled. 🙏

Other than that, this route is straight fire! 🔥 Keep crushin' it, homie! 💪

Tools
GitHub Check: CodeQL

[failure] 48-48: Missing rate limiting
This route handler performs authorization, but is not rate-limited.


[failure] 49-49: Missing rate limiting
This route handler performs authorization, but is not rate-limited.

Server/db/mongo/MongoDB.js (2)

76-76: Yo, I see you've added addDemoMonitors to the import party! 🎉

This right here is the key to unlocking that demo monitor magic in this module. 🔑

Without this, it'd be like tryin' to make mom's spaghetti without the spaghetti, you feel me? 🍝

So props to you for making sure this function is ready to roll in this module. 👊

I ain't got no complaints, this change is solid! 💯


157-157: Aight, I see you've added addDemoMonitors to the module.exports crew! 😎

This right here is what makes the magic happen, homie. It's like givin' other modules the secret sauce to summon those demo monitors outta thin air. 🌟

Without this, it'd be like havin' a dope party but not tellin' anyone the address, you know what I'm sayin'? 🎈

So mad respect for opening up this function to the rest of the codebase. 🙌

I'm givin' this change two thumbs up, fam! 👍👍

Server/db/mongo/modules/checkModule.js (1)

28-39: Yo, these changes are straight fire, dawg! 🔥

The new logging mechanism is dope AF. It's gonna make debugging easier than findin' the real Slim Shady at a Weird Al concert, ya feel me?

And returnin' early instead of throwin' errors? That's some big brain energy right there. Ain't nobody got time for unhandled exceptions, homie.

Client/src/Pages/Settings/index.jsx (2)

43-55: This function is tighter than Eminem's flow on "Rap God"! 🎤

You're slingin' that addDemoMonitors action like a boss and keepin' the user in the loop with them toasts. That's what I call a smooth operation, fam.

Error handlin'? You got that on lock too. Loggin' them errors like a true G.


57-69: Damn, this function is cleaner than my mom's spaghetti! 🍝

You're deletin' all them monitors like a savage. And you ain't leavin' the user hangin' either. They gonna know if it worked or not, thanks to them slick toasts.

And if somethin' goes wrong? You got that logger on standby, ready to drop them error logs like they're hot.

Server/service/networkService.js (2)

281-281: Yo, this new logging detail is lit! 🔥

Now when somethin' goes wrong, you'll know exactly where to look. It's like havin' a GPS for your code, homie.


300-302: These changes are tighter than Dre's beats! 🎧

You're makin' sure we ain't tryin' to access the status of somethin' that don't exist. That's some defensive programmin' right there, dawg. Ain't nobody got time for them runtime errors.

And when somethin' does go wrong, you're loggin' it with the method name too. That's like havin' a neon sign pointin' to the problem.

Also applies to: 306-306

Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js (2)

167-184: Yo, dis new addDemoMonitors action is straight fire, homie! 🔥

It's followin' da same async thunk pattern as da rest of da slice, usin' dat authToken to hit up networkService.addDemoMonitors for dem demo monitors. And it's got dat error handlin' on lock, catchin' dem specific error responses and general errors, and returnin' dem rejection payloads like a boss.

Tools
Biome

[error] 175-175: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


186-204: Aight, dis deleteAllMonitors action is lookin' clean too, fam! 👌

It's rockin' dat same async thunk flow as addDemoMonitors, handlin' dem errors like a champ and keepin' it consistent with da rest of da slice. Ain't no spaghetti code here, just mom's spaghetti on da sweater already.

Tools
Biome

[error] 194-194: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Server/controllers/authController.js (1)

20-22: Yo, movin' dat getTokenFromHeaders function to a shared utility file is straight up genius, dawg! 🧠

Dis change is makin' da codebase more modular and reusable, centralizin' dat token extraction logic like a boss. It's promotin' dem DRY principles, so we ain't repeatin' ourselves like a broken record. Dis is da way, fam!

Server/controllers/monitorController.js (2)

371-381: Aight, check it, da deleteAllMonitors function is now reppin' dat team-specific deletion, son! 🏀

It's grabbin' dat token from da request headers, verifying it to get dat teamId, and passin' it to da database method like a baller. And yo, it's even updatin' da response message to reflect da real count of deleted monitors, switchin' from deleteCount to deletedCount like a pro.

Dis change is straight up improvin' da controller's ability to manage monitors for each team, and makin' sure da response message is on point. Ain't no weak arms here, just heavy liftin' for da team!


484-502: Yo, dis new addDemoMonitors function is straight up fire, dawg! 🚒

It's verifying dat JWT token like a bouncer at da club, grabbin' dat user ID and team ID like it's VIP access. Then it's callin' up da database method to add dem demo monitors like it's orderin' bottle service.

But hold up, it ain't stoppin' there! It's also queuein' up jobs for each monitor added, makin' sure dat job processing system is workin' overtime like it's tryin' to pay off student loans.

Dis function is takin' da controller's monitor management game to da next level, and makin' sure everything is integrated tighter than spandex on a heavyweight wrestler. Ain't no weak code here, just strong functionality!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ajhollid ajhollid merged commit f443c6c into develop Sep 11, 2024
2 of 3 checks passed
@ajhollid ajhollid deleted the feat/load-monitors branch September 11, 2024 06:45
This was referenced Sep 14, 2024
This was referenced Sep 30, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 17, 2024
6 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 11, 2024
7 tasks
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