Cleanup legacy code
This commit is contained in:
parent
458d9551c1
commit
d8a77ec380
@ -1,8 +1,6 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/TicketsBot/GoPanel/config"
|
|
||||||
"github.com/TicketsBot/GoPanel/rpc/cache"
|
"github.com/TicketsBot/GoPanel/rpc/cache"
|
||||||
"github.com/TicketsBot/GoPanel/utils"
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
"github.com/TicketsBot/common/permission"
|
"github.com/TicketsBot/common/permission"
|
||||||
@ -11,20 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// requires AuthenticateCookie middleware to be run before
|
// requires AuthenticateCookie middleware to be run before
|
||||||
func AuthenticateGuild(isApiMethod bool, requiredPermissionLevel permission.PermissionLevel) gin.HandlerFunc {
|
func AuthenticateGuild(requiredPermissionLevel permission.PermissionLevel) gin.HandlerFunc {
|
||||||
return func(ctx *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
if guildId, ok := ctx.Params.Get("id"); ok {
|
if guildId, ok := ctx.Params.Get("id"); ok {
|
||||||
parsed, err := strconv.ParseUint(guildId, 10, 64)
|
parsed, err := strconv.ParseUint(guildId, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if isApiMethod {
|
ctx.JSON(400, utils.ErrorStr("Invalid guild ID"))
|
||||||
ctx.JSON(400, gin.H{
|
|
||||||
"success": false,
|
|
||||||
"error": "Invalid guild ID",
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
utils.ErrorPage(ctx, 400, "Invalid server ID")
|
|
||||||
ctx.Abort()
|
|
||||||
}
|
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -34,11 +24,7 @@ func AuthenticateGuild(isApiMethod bool, requiredPermissionLevel permission.Perm
|
|||||||
// TODO: Do we need this? Only really serves as a check whether the bot is in the server
|
// TODO: Do we need this? Only really serves as a check whether the bot is in the server
|
||||||
guild, found := cache.Instance.GetGuild(parsed, false)
|
guild, found := cache.Instance.GetGuild(parsed, false)
|
||||||
if !found {
|
if !found {
|
||||||
if isApiMethod {
|
ctx.JSON(404, utils.ErrorStr("Guild not found"))
|
||||||
ctx.Redirect(302, fmt.Sprintf("https://invite.ticketsbot.net/?guild_id=%d&disable_guild_select=true&response_type=code&scope=bot%%20identify&redirect_uri=%s", parsed, config.Conf.Server.BaseUrl))
|
|
||||||
} else {
|
|
||||||
utils.ErrorPage(ctx, 404, "Couldn't find server with the provided ID")
|
|
||||||
}
|
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -48,30 +34,17 @@ func AuthenticateGuild(isApiMethod bool, requiredPermissionLevel permission.Perm
|
|||||||
|
|
||||||
permLevel, err := utils.GetPermissionLevel(guild.Id, userId)
|
permLevel, err := utils.GetPermissionLevel(guild.Id, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
ctx.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if permLevel < requiredPermissionLevel {
|
if permLevel < requiredPermissionLevel {
|
||||||
if isApiMethod {
|
ctx.JSON(403, utils.ErrorStr("Unauthorized"))
|
||||||
ctx.AbortWithStatusJSON(403, gin.H{
|
|
||||||
"success": false,
|
|
||||||
"error": "Unauthorized",
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
utils.ErrorPage(ctx, 403, "You don't have permission to be here - make sure the server owner has added you as an admin with t!addadmin")
|
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if isApiMethod {
|
ctx.JSON(400, utils.ErrorStr("Invalid guild ID"))
|
||||||
ctx.JSON(400, gin.H{
|
|
||||||
"success": false,
|
|
||||||
"error": "Invalid guild ID",
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
utils.ErrorPage(ctx, 400, "Invalid server ID")
|
|
||||||
}
|
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import "github.com/gin-gonic/gin"
|
|
||||||
|
|
||||||
func ErrorPage(ctx *gin.Context, statusCode int, error string) {
|
|
||||||
ctx.HTML(statusCode, "error", gin.H{
|
|
||||||
"status": statusCode,
|
|
||||||
"error": error,
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user