Splash-Media-Co / server

Backend server for Splash
6 stars 0 forks source link

Sweep: #11

Closed NotFenixio closed 7 months ago

NotFenixio commented 7 months ago

Details

Enhancement: move the client.id in authenticated_clients boilerplaté from main.py to utils.py in a function that accepts the authenticated_clients list and the server object

Checklist - [X] Modify `utils.py` ✓ https://github.com/Splash-Media-Co/server/commit/c9a24192b72bd0e6fd662c363c49268f23fe0003 [Edit](https://github.com/Splash-Media-Co/server/edit/sweep/_a2258/utils.py) - [X] Modify `main.py` ✓ https://github.com/Splash-Media-Co/server/commit/bae3aca181a5288f517e5f5637bfada1ff939abb [Edit](https://github.com/Splash-Media-Co/server/edit/sweep/_a2258/main.py#L89-L90) - [X] Modify `main.py` ! No changes made [Edit](https://github.com/Splash-Media-Co/server/edit/sweep/_a2258/main.py#L127-L131) - [X] Modify `main.py` ✓ https://github.com/Splash-Media-Co/server/commit/b633dabd838f79e674c5762408624c8693d1f3d0 [Edit](https://github.com/Splash-Media-Co/server/edit/sweep/_a2258/main.py#L215-L217) - [X] Modify `main.py` ✓ https://github.com/Splash-Media-Co/server/commit/5b28c548b5c47f93d6c197933e0d046b0a3a84f7 [Edit](https://github.com/Splash-Media-Co/server/edit/sweep/_a2258/main.py#L316-L318)
sweep-ai[bot] commented 7 months ago

🚀 Here's the PR! #12

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 5 GPT-4 tickets left for the month and 3 for the day. (tracking ID: 18cbd276cc)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)

GitHub Actions failed

The sandbox appears to be unavailable or down.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/Splash-Media-Co/server/blob/dbbbe3d7728e29da2ee8a4d19d09717ea3ce0aa8/main.py#L86-L90 https://github.com/Splash-Media-Co/server/blob/dbbbe3d7728e29da2ee8a4d19d09717ea3ce0aa8/main.py#L127-L131 https://github.com/Splash-Media-Co/server/blob/dbbbe3d7728e29da2ee8a4d19d09717ea3ce0aa8/main.py#L215-L217 https://github.com/Splash-Media-Co/server/blob/dbbbe3d7728e29da2ee8a4d19d09717ea3ce0aa8/main.py#L316-L318 https://github.com/Splash-Media-Co/server/blob/dbbbe3d7728e29da2ee8a4d19d09717ea3ce0aa8/utils.py#L1-L30

Step 2: ⌨️ Coding

--- 
+++ 
@@ -29,3 +29,6 @@
             return True
         else:
             return False
+
+async def is_client_authenticated(client_id, authenticated_clients):
+    return client_id in authenticated_clients

--- 
+++ 
@@ -33,7 +33,7 @@
 # Import logging helpers, OceanAudit, and rate-limiter
 from logs import Critical, Debug, Error, Info, Warning  # noqa: F401
 from oceanaudit import OceanAuditLogger
-from utils import WebSocketRateLimiter
+from utils import WebSocketRateLimiter, is_client_authenticated

 # Import DB handler
 from oceandb import OceanDB  # noqa: F401
@@ -87,7 +87,7 @@
 @server.on_disconnect
 async def on_disconnect(client):
     Info(f"Client {str(client.id)} disconnected")
-    if client.id in authenticated_clients:
+    if await is_client_authenticated(client.id, authenticated_clients):
         authenticated_clients.remove(client.id)

@@ -129,7 +129,7 @@
         case "post":
             match str(message["val"]["val"]["type"]):
                 case "send":
-                    if client.id not in authenticated_clients:
+                    if not await is_client_authenticated(client.id, authenticated_clients):
                         try:
                             server.send_packet_unicast(
                                 client,
@@ -215,7 +215,7 @@
                             with concurrent.futures.ProcessPoolExecutor() as executor:
                                 executor.submit(post, url + str(payload[0]))
                 case "delete":
-                    if client.id not in authenticated_clients:
+                    if not await is_client_authenticated(client.id, authenticated_clients):
                         try:
                             server.send_packet_unicast(
                                 client,
@@ -316,7 +316,7 @@
                                 f"User tried to delete a post with UID {str(message["val"]["val"]["uid"])} that didn't exist",
                             )
                 case "edit":
-                    if client.id not in authenticated_clients:
+                    if not await is_client_authenticated(client.id, authenticated_clients):
                         try:
                             server.send_packet_unicast(
                                 client,

--- 
+++ 
@@ -33,7 +33,7 @@
 # Import logging helpers, OceanAudit, and rate-limiter
 from logs import Critical, Debug, Error, Info, Warning  # noqa: F401
 from oceanaudit import OceanAuditLogger
-from utils import WebSocketRateLimiter
+from utils import WebSocketRateLimiter, is_client_authenticated

 # Import DB handler
 from oceandb import OceanDB  # noqa: F401
@@ -87,7 +87,7 @@
 @server.on_disconnect
 async def on_disconnect(client):
     Info(f"Client {str(client.id)} disconnected")
-    if client.id in authenticated_clients:
+    if await is_client_authenticated(client.id, authenticated_clients):
         authenticated_clients.remove(client.id)

@@ -129,7 +129,9 @@
         case "post":
             match str(message["val"]["val"]["type"]):
                 case "send":
-                    if client.id not in authenticated_clients:
+                    if not await is_client_authenticated(
+                        client.id, authenticated_clients
+                    ):
                         try:
                             server.send_packet_unicast(
                                 client,
@@ -215,7 +217,7 @@
                             with concurrent.futures.ProcessPoolExecutor() as executor:
                                 executor.submit(post, url + str(payload[0]))
                 case "delete":
-                    if client.id not in authenticated_clients:
+                    if client.id in authenticated_clients:
                         try:
                             server.send_packet_unicast(
                                 client,
@@ -316,7 +318,9 @@
                                 f"User tried to delete a post with UID {str(message["val"]["val"]["uid"])} that didn't exist",
                             )
                 case "edit":
-                    if client.id not in authenticated_clients:
+                    if not await is_client_authenticated(
+                        client.id, authenticated_clients
+                    ):
                         try:
                             server.send_packet_unicast(
                                 client,

--- 
+++ 
@@ -33,7 +33,7 @@
 # Import logging helpers, OceanAudit, and rate-limiter
 from logs import Critical, Debug, Error, Info, Warning  # noqa: F401
 from oceanaudit import OceanAuditLogger
-from utils import WebSocketRateLimiter
+from utils import WebSocketRateLimiter, is_client_authenticated

 # Import DB handler
 from oceandb import OceanDB  # noqa: F401
@@ -87,7 +87,7 @@
 @server.on_disconnect
 async def on_disconnect(client):
     Info(f"Client {str(client.id)} disconnected")
-    if client.id in authenticated_clients:
+    if await is_client_authenticated(client.id, authenticated_clients):
         authenticated_clients.remove(client.id)

@@ -129,7 +129,9 @@
         case "post":
             match str(message["val"]["val"]["type"]):
                 case "send":
-                    if client.id not in authenticated_clients:
+                    if not await is_client_authenticated(
+                        client.id, authenticated_clients
+                    ):
                         try:
                             server.send_packet_unicast(
                                 client,
@@ -215,7 +217,7 @@
                             with concurrent.futures.ProcessPoolExecutor() as executor:
                                 executor.submit(post, url + str(payload[0]))
                 case "delete":
-                    if client.id not in authenticated_clients:
+                    if client.id in authenticated_clients:
                         try:
                             server.send_packet_unicast(
                                 client,
@@ -316,7 +318,7 @@
                                 f"User tried to delete a post with UID {str(message["val"]["val"]["uid"])} that didn't exist",
                             )
                 case "edit":
-                    if client.id not in authenticated_clients:
+                    if not await is_client_authenticated(client.id, authenticated_clients):
                         try:
                             server.send_packet_unicast(
                                 client,


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/_a2258.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.

This is an automated message generated by Sweep AI.