// SetAdmin a "normal" user to an admin user func (*UsersController) SetAdmin(ctx *gin.Context) { var convertJSON convertUserJSON ctx.Bind(&convertJSON) var userToGrant = models.User{} err := userToGrant.FindByUsername(convertJSON.Username) if err != nil { AbortWithReturnError(ctx, http.StatusBadRequest, fmt.Errorf("user with username %s does not exist", convertJSON.Username)) return } if userToGrant.IsAdmin { AbortWithReturnError(ctx, http.StatusBadRequest, fmt.Errorf("user with username %s is already an admin user", convertJSON.Username)) return } err = userToGrant.ConvertToAdmin(utils.GetCtxUsername(ctx)) if err != nil { AbortWithReturnError(ctx, http.StatusBadRequest, fmt.Errorf("Convert %s to admin user failed", convertJSON.Username)) return } ctx.JSON(http.StatusCreated, "") }