-
Notifications
You must be signed in to change notification settings - Fork 118
Fix: removed duplicate toggleCamera function and cleaned TeamDebateRo… #124
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "arguehub/db" | ||
| "arguehub/models" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| "github.com/gorilla/websocket" | ||
| "go.mongodb.org/mongo-driver/bson" | ||
| "go.mongodb.org/mongo-driver/bson/primitive" | ||
|
|
@@ -243,3 +244,33 @@ func (c *TeamDebateClient) writePump() { | |
| } | ||
| } | ||
| } | ||
| func TeamDebateWebsocketHandler(c *gin.Context) { | ||
| debateIDHex := c.Param("debateID") | ||
| teamIDHex := c.Query("teamId") | ||
| userIDHex := c.Query("userId") | ||
| isTeam1 := c.Query("isTeam1") == "true" | ||
|
|
||
| debateID, _ := primitive.ObjectIDFromHex(debateIDHex) | ||
| teamID, _ := primitive.ObjectIDFromHex(teamIDHex) | ||
| userID, _ := primitive.ObjectIDFromHex(userIDHex) | ||
|
|
||
| conn, err := upgrader.Upgrade(c.Writer, c.Request, nil) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| client := &TeamDebateClient{ | ||
| conn: conn, | ||
| send: make(chan []byte, 256), | ||
| debateID: debateID, | ||
| teamID: teamID, | ||
| userID: userID, | ||
| isTeam1: isTeam1, | ||
| } | ||
|
|
||
| teamDebateHub.register <- client | ||
|
|
||
| go client.writePump() | ||
| go client.readPump() | ||
| } | ||
|
Comment on lines
+247
to
+275
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add authentication and authorization checks. The handler doesn't verify that the requesting user has permission to join the debate or that they belong to the specified team. This could allow:
Consider implementing one of these approaches:
Example authorization check: func TeamDebateWebsocketHandler(c *gin.Context) {
// ... existing parameter extraction and validation ...
// Verify user belongs to the team
teamCollection := db.GetCollection("teams")
var team models.Team
err := teamCollection.FindOne(nil, bson.M{
"_id": teamID,
"members": bson.M{"$elemMatch": bson.M{"user_id": userID}},
}).Decode(&team)
if err != nil {
c.JSON(403, gin.H{"error": "User is not a member of the specified team"})
return
}
// Verify team is part of the debate
debateCollection := db.GetCollection("team_debates")
var debate models.TeamDebate
err = debateCollection.FindOne(nil, bson.M{
"_id": debateID,
"$or": []bson.M{
{"team1_id": teamID},
{"team2_id": teamID},
},
}).Decode(&debate)
if err != nil {
c.JSON(403, gin.H{"error": "Team is not participating in this debate"})
return
}
// ... rest of handler ...
}🤖 Prompt for AI Agents |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add input validation and error handling for required parameters.
The handler extracts query parameters and converts them to ObjectIDs without validation or error handling. This creates several risks:
teamId,userId) will result in empty strings being parsed, creating zero-value ObjectIDsApply this diff to add proper validation and error handling:
func TeamDebateWebsocketHandler(c *gin.Context) { debateIDHex := c.Param("debateID") teamIDHex := c.Query("teamId") userIDHex := c.Query("userId") isTeam1 := c.Query("isTeam1") == "true" + + // Validate required parameters + if debateIDHex == "" || teamIDHex == "" || userIDHex == "" { + c.JSON(400, gin.H{"error": "Missing required parameters: debateID, teamId, and userId"}) + return + } - debateID, _ := primitive.ObjectIDFromHex(debateIDHex) - teamID, _ := primitive.ObjectIDFromHex(teamIDHex) - userID, _ := primitive.ObjectIDFromHex(userIDHex) + debateID, err := primitive.ObjectIDFromHex(debateIDHex) + if err != nil { + c.JSON(400, gin.H{"error": "Invalid debateID format"}) + return + } + + teamID, err := primitive.ObjectIDFromHex(teamIDHex) + if err != nil { + c.JSON(400, gin.H{"error": "Invalid teamId format"}) + return + } + + userID, err := primitive.ObjectIDFromHex(userIDHex) + if err != nil { + c.JSON(400, gin.H{"error": "Invalid userId format"}) + return + }📝 Committable suggestion
🤖 Prompt for AI Agents