Skip to content

Commit a92f4f0

Browse files
authored
Merge pull request #271 from sdslabs/api_fixes
API fixes
2 parents 7e98882 + 751bd9b commit a92f4f0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

api/info.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func challengeInfoHandler(c *gin.Context) {
7474
var challengeUser []UserSolveResp
7575

7676
for _, user := range users {
77-
if user.Role != "author" {
77+
if user.Role == core.USER_ROLES["contestant"] {
7878
userResp := UserSolveResp{
7979
UserID: user.ID,
8080
Username: user.Username,
@@ -141,7 +141,7 @@ func availableChallengeInfoHandler(c *gin.Context) {
141141
var challengeUser []UserSolveResp
142142

143143
for _, user := range users {
144-
if user.Role != "author" {
144+
if user.Role == core.USER_ROLES["contestant"] {
145145
userResp := UserSolveResp{
146146
UserID: user.ID,
147147
Username: user.Username,
@@ -393,7 +393,8 @@ func userInfoHandler(c *gin.Context) {
393393
for _, challenge := range challenges {
394394
challNameString = append(challNameString, challenge.Name)
395395
}
396-
var userChallenges []ChallengeSolveResp
396+
397+
userChallenges := make([]ChallengeSolveResp, len(challenges))
397398
for _, challenge := range challenges {
398399
challResp := ChallengeSolveResp{
399400
Id: challenge.ID,
@@ -480,7 +481,7 @@ func submissionsHandler(c *gin.Context) {
480481
return
481482
}
482483

483-
if user.Role != "author" {
484+
if user.Role == core.USER_ROLES["contestant"] {
484485
challenge, err := database.QueryChallengeEntries("id", strconv.Itoa(int(submission.ChallengeID)))
485486
if err != nil {
486487
c.JSON(http.StatusInternalServerError, HTTPPlainResp{

api/router.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ func initGinRouter() *gin.Engine {
7777
}
7878

7979
// Notification route group
80-
notificationGroup := apiGroup.Group("/notification", adminAuthorize)
80+
notificationGroup := apiGroup.Group("/notification")
8181
{
82-
notificationGroup.POST("/add", addNotification)
83-
notificationGroup.POST("/delete", removeNotification)
84-
notificationGroup.POST("/update", updateNotifications)
82+
notificationGroup.POST("/add", adminAuthorize, addNotification)
83+
notificationGroup.POST("/delete", adminAuthorize, removeNotification)
84+
notificationGroup.POST("/update", adminAuthorize, updateNotifications)
8585
notificationGroup.POST("/available", availableNotificationHandler)
8686
}
8787

0 commit comments

Comments
 (0)