From ca973edc28b5fe543c583217896590f4a2e98897 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 24 Aug 2023 22:34:05 +0300 Subject: fix: mod flag for easy check (#49) Former-commit-id: 06ee23ee9659834252d3cb5c3c255797e9f93b62 --- backend/controllers/modController.go | 44 ++++++++++-------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'backend/controllers/modController.go') diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index 7ce5cb4..7acdb5d 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go @@ -49,18 +49,13 @@ type EditMapImageRequest struct { // @Router /maps/{id}/summary [post] func CreateMapSummary(c *gin.Context) { // Check if user exists - user, exists := c.Get("user") + _, exists := c.Get("user") if !exists { c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) return } - var moderator bool - for _, title := range user.(models.User).Titles { - if title == "Moderator" { - moderator = true - } - } - if !moderator { + mod, exists := c.Get("mod") + if !exists || !mod.(bool) { c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) return } @@ -135,18 +130,13 @@ func CreateMapSummary(c *gin.Context) { // @Router /maps/{id}/summary [put] func EditMapSummary(c *gin.Context) { // Check if user exists - user, exists := c.Get("user") + _, exists := c.Get("user") if !exists { c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) return } - var moderator bool - for _, title := range user.(models.User).Titles { - if title == "Moderator" { - moderator = true - } - } - if !moderator { + mod, exists := c.Get("mod") + if !exists || !mod.(bool) { c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) return } @@ -221,18 +211,13 @@ func EditMapSummary(c *gin.Context) { // @Router /maps/{id}/summary [delete] func DeleteMapSummary(c *gin.Context) { // Check if user exists - user, exists := c.Get("user") + _, exists := c.Get("user") if !exists { c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) return } - var moderator bool - for _, title := range user.(models.User).Titles { - if title == "Moderator" { - moderator = true - } - } - if !moderator { + mod, exists := c.Get("mod") + if !exists || !mod.(bool) { c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) return } @@ -311,18 +296,13 @@ func DeleteMapSummary(c *gin.Context) { // @Router /maps/{id}/image [put] func EditMapImage(c *gin.Context) { // Check if user exists - user, exists := c.Get("user") + _, exists := c.Get("user") if !exists { c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) return } - var moderator bool - for _, title := range user.(models.User).Titles { - if title == "Moderator" { - moderator = true - } - } - if !moderator { + mod, exists := c.Get("mod") + if !exists || !mod.(bool) { c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) return } -- cgit v1.2.3