aboutsummaryrefslogtreecommitdiff
path: root/backend/controllers/modController.go
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-08-24 22:34:05 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-08-24 22:34:05 +0300
commitca973edc28b5fe543c583217896590f4a2e98897 (patch)
tree7f37713ac587ef80fb3a17d869d01520a1d94dca /backend/controllers/modController.go
parentMerge branch 'main' of https://github.com/pektezol/LeastPortalsHub (diff)
downloadlphub-ca973edc28b5fe543c583217896590f4a2e98897.tar.gz
lphub-ca973edc28b5fe543c583217896590f4a2e98897.tar.bz2
lphub-ca973edc28b5fe543c583217896590f4a2e98897.zip
fix: mod flag for easy check (#49)
Former-commit-id: 06ee23ee9659834252d3cb5c3c255797e9f93b62
Diffstat (limited to 'backend/controllers/modController.go')
-rw-r--r--backend/controllers/modController.go44
1 files changed, 12 insertions, 32 deletions
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 {
49// @Router /maps/{id}/summary [post] 49// @Router /maps/{id}/summary [post]
50func CreateMapSummary(c *gin.Context) { 50func CreateMapSummary(c *gin.Context) {
51 // Check if user exists 51 // Check if user exists
52 user, exists := c.Get("user") 52 _, exists := c.Get("user")
53 if !exists { 53 if !exists {
54 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) 54 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in."))
55 return 55 return
56 } 56 }
57 var moderator bool 57 mod, exists := c.Get("mod")
58 for _, title := range user.(models.User).Titles { 58 if !exists || !mod.(bool) {
59 if title == "Moderator" {
60 moderator = true
61 }
62 }
63 if !moderator {
64 c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) 59 c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions."))
65 return 60 return
66 } 61 }
@@ -135,18 +130,13 @@ func CreateMapSummary(c *gin.Context) {
135// @Router /maps/{id}/summary [put] 130// @Router /maps/{id}/summary [put]
136func EditMapSummary(c *gin.Context) { 131func EditMapSummary(c *gin.Context) {
137 // Check if user exists 132 // Check if user exists
138 user, exists := c.Get("user") 133 _, exists := c.Get("user")
139 if !exists { 134 if !exists {
140 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) 135 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in."))
141 return 136 return
142 } 137 }
143 var moderator bool 138 mod, exists := c.Get("mod")
144 for _, title := range user.(models.User).Titles { 139 if !exists || !mod.(bool) {
145 if title == "Moderator" {
146 moderator = true
147 }
148 }
149 if !moderator {
150 c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) 140 c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions."))
151 return 141 return
152 } 142 }
@@ -221,18 +211,13 @@ func EditMapSummary(c *gin.Context) {
221// @Router /maps/{id}/summary [delete] 211// @Router /maps/{id}/summary [delete]
222func DeleteMapSummary(c *gin.Context) { 212func DeleteMapSummary(c *gin.Context) {
223 // Check if user exists 213 // Check if user exists
224 user, exists := c.Get("user") 214 _, exists := c.Get("user")
225 if !exists { 215 if !exists {
226 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) 216 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in."))
227 return 217 return
228 } 218 }
229 var moderator bool 219 mod, exists := c.Get("mod")
230 for _, title := range user.(models.User).Titles { 220 if !exists || !mod.(bool) {
231 if title == "Moderator" {
232 moderator = true
233 }
234 }
235 if !moderator {
236 c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) 221 c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions."))
237 return 222 return
238 } 223 }
@@ -311,18 +296,13 @@ func DeleteMapSummary(c *gin.Context) {
311// @Router /maps/{id}/image [put] 296// @Router /maps/{id}/image [put]
312func EditMapImage(c *gin.Context) { 297func EditMapImage(c *gin.Context) {
313 // Check if user exists 298 // Check if user exists
314 user, exists := c.Get("user") 299 _, exists := c.Get("user")
315 if !exists { 300 if !exists {
316 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) 301 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in."))
317 return 302 return
318 } 303 }
319 var moderator bool 304 mod, exists := c.Get("mod")
320 for _, title := range user.(models.User).Titles { 305 if !exists || !mod.(bool) {
321 if title == "Moderator" {
322 moderator = true
323 }
324 }
325 if !moderator {
326 c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) 306 c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions."))
327 return 307 return
328 } 308 }