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

Require supervisor+ group to access RS activity #53

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func initializeRoutes(engine *gin.Engine) {
// Ranking Queue
engine.GET("/v2/ranking/config", handlers.CreateHandler(handlers.GetRankingQueueConfig))
engine.GET("/v2/ranking/queue/mode/:mode", handlers.CreateHandler(handlers.GetRankingQueue))
engine.GET("/v2/ranking/queue/supervisors/actions", handlers.CreateHandler(handlers.GetRankingSupervisorActions))
engine.GET("/v2/ranking/queue/supervisors/actions", middleware.RequireAuth, handlers.CreateHandler(handlers.GetRankingSupervisorActions))
engine.POST("/v2/ranking/queue/:id/submit", middleware.RequireAuth, handlers.CreateHandler(handlers.SubmitMapsetToRankingQueue))
engine.POST("/v2/ranking/queue/:id/remove", middleware.RequireAuth, handlers.CreateHandler(handlers.RemoveFromRankingQueue))
engine.GET("/v2/ranking/queue/:id/comments", handlers.CreateHandler(handlers.GetRankingQueueComments))
Expand Down
15 changes: 15 additions & 0 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,18 @@ func canUserAccessAdminRoute(c *gin.Context) bool {
enums.HasUserGroup(user.UserGroups, enums.UserGroupAdmin) ||
enums.HasUserGroup(user.UserGroups, enums.UserGroupBot)
}

// Returns if a user can access private ranking supervisor endpoints
func canUserAccessSupervisorRoute(c *gin.Context) bool {
user := getAuthedUser(c)

if user == nil {
return false
}

return enums.HasUserGroup(user.UserGroups, enums.UserGroupSwan) ||
enums.HasUserGroup(user.UserGroups, enums.UserGroupDeveloper) ||
enums.HasUserGroup(user.UserGroups, enums.UserGroupAdmin) ||
enums.HasUserGroup(user.UserGroups, enums.UserGroupBot) ||
enums.HasUserGroup(user.UserGroups, enums.UserGroupRankingSupervisor)
}
10 changes: 10 additions & 0 deletions handlers/ranking_supervisors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import (
// GetRankingSupervisorActions Retrieves ranking supervisor actions between a given time frame
// Endpoint: GET /ranking/queue/supervisors/actions?start=&end=
func GetRankingSupervisorActions(c *gin.Context) *APIError {
user := getAuthedUser(c)

if user == nil {
return nil
}

if !canUserAccessSupervisorRoute(c) {
return APIErrorForbidden("You do not have permission to access this endpoint.")
}

body := struct {
Start int64 `form:"start" json:"start"`
End int64 `form:"end" json:"end"`
Expand Down
Loading