fix perm issue

This commit is contained in:
Dot-Rar 2020-04-15 15:03:55 +01:00
parent fa8fb824da
commit 97d3dacd95
17 changed files with 23 additions and 21 deletions

View File

@ -33,7 +33,7 @@ func BlacklistHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -34,7 +34,7 @@ func BlacklistRemoveHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -42,7 +42,7 @@ func LogsHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -37,7 +37,7 @@ func PanelCreateHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -40,7 +40,7 @@ func PanelDeleteHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -41,7 +41,7 @@ func PanelHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -36,7 +36,7 @@ func SendMessage(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -42,7 +42,7 @@ func SettingsHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -35,7 +35,7 @@ func TicketCloseHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -34,7 +34,7 @@ func TicketListHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -40,7 +40,7 @@ func TicketViewHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -35,7 +35,7 @@ func UpdateSettingsHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -37,7 +37,7 @@ func LogViewHandler(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildId, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
return return

View File

@ -126,7 +126,7 @@ func WebChatWs(ctx *gin.Context) {
// Verify the user has permissions to be here // Verify the user has permissions to be here
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(guild, guildIdParsed, userId, isAdmin) go utils.IsAdmin(guild, userId, isAdmin)
if !<-isAdmin { if !<-isAdmin {
fmt.Println(err.Error()) fmt.Println(err.Error())
conn.Close() conn.Close()

View File

@ -30,12 +30,13 @@ func IndexHandler(ctx *gin.Context) {
} }
fakeGuild := guild.Guild{ fakeGuild := guild.Guild{
Owner: g.Owner, Id: guildId,
OwnerId: g.OwnerId,
Permissions: g.Permissions, Permissions: g.Permissions,
} }
isAdmin := make(chan bool) isAdmin := make(chan bool)
go utils.IsAdmin(fakeGuild, guildId, userId, isAdmin) go utils.IsAdmin(fakeGuild, userId, isAdmin)
if <-isAdmin { if <-isAdmin {
adminGuilds = append(adminGuilds, g) adminGuilds = append(adminGuilds, g)
} }

View File

@ -5,5 +5,6 @@ type Guild struct {
Name string Name string
Icon string Icon string
Owner bool Owner bool
OwnerId uint64 `json:"id,string"`
Permissions int Permissions int
} }

View File

@ -10,16 +10,16 @@ import (
"strconv" "strconv"
) )
func IsAdmin(g guild.Guild, guildId, userId uint64, res chan bool) { func IsAdmin(g guild.Guild, userId uint64, res chan bool) {
if Contains(config.Conf.Admins, strconv.Itoa(int(userId))) { if Contains(config.Conf.Admins, strconv.Itoa(int(userId))) {
res <- true res <- true
} }
if g.Owner { if g.OwnerId == userId {
res <- true res <- true
} }
if table.IsAdmin(guildId, userId) { if table.IsAdmin(g.Id, userId) {
res <- true res <- true
} }
@ -28,10 +28,10 @@ func IsAdmin(g guild.Guild, guildId, userId uint64, res chan bool) {
} }
adminRolesChan := make(chan []uint64) adminRolesChan := make(chan []uint64)
go table.GetAdminRoles(guildId, adminRolesChan) go table.GetAdminRoles(g.Id, adminRolesChan)
adminRoles := <- adminRolesChan adminRoles := <- adminRolesChan
userRoles, found := getRoles(guildId, userId) userRoles, found := getRoles(g.Id, userId)
hasAdminRole := false hasAdminRole := false
if found { if found {