diff --git a/app/http/endpoints/manage/blacklist.go b/app/http/endpoints/manage/blacklist.go index cbcdf2e..ff09af9 100644 --- a/app/http/endpoints/manage/blacklist.go +++ b/app/http/endpoints/manage/blacklist.go @@ -33,7 +33,7 @@ func BlacklistHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/blacklistremove.go b/app/http/endpoints/manage/blacklistremove.go index 7a2e4df..81fafc0 100644 --- a/app/http/endpoints/manage/blacklistremove.go +++ b/app/http/endpoints/manage/blacklistremove.go @@ -34,7 +34,7 @@ func BlacklistRemoveHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/logs.go b/app/http/endpoints/manage/logs.go index 5d97230..81721fe 100644 --- a/app/http/endpoints/manage/logs.go +++ b/app/http/endpoints/manage/logs.go @@ -42,7 +42,7 @@ func LogsHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/panelcreate.go b/app/http/endpoints/manage/panelcreate.go index 3d5b39e..0ba188f 100644 --- a/app/http/endpoints/manage/panelcreate.go +++ b/app/http/endpoints/manage/panelcreate.go @@ -37,7 +37,7 @@ func PanelCreateHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/paneldelete.go b/app/http/endpoints/manage/paneldelete.go index 134ba65..a237a4e 100644 --- a/app/http/endpoints/manage/paneldelete.go +++ b/app/http/endpoints/manage/paneldelete.go @@ -40,7 +40,7 @@ func PanelDeleteHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/panels.go b/app/http/endpoints/manage/panels.go index 5c4694b..ff61658 100644 --- a/app/http/endpoints/manage/panels.go +++ b/app/http/endpoints/manage/panels.go @@ -41,7 +41,7 @@ func PanelHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/sendmessage.go b/app/http/endpoints/manage/sendmessage.go index 7ec2d60..d71b732 100644 --- a/app/http/endpoints/manage/sendmessage.go +++ b/app/http/endpoints/manage/sendmessage.go @@ -36,7 +36,7 @@ func SendMessage(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/settings.go b/app/http/endpoints/manage/settings.go index 04c4980..bdab4c0 100644 --- a/app/http/endpoints/manage/settings.go +++ b/app/http/endpoints/manage/settings.go @@ -42,7 +42,7 @@ func SettingsHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/ticketclose.go b/app/http/endpoints/manage/ticketclose.go index c773df9..3e2e75f 100644 --- a/app/http/endpoints/manage/ticketclose.go +++ b/app/http/endpoints/manage/ticketclose.go @@ -35,7 +35,7 @@ func TicketCloseHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/ticketlist.go b/app/http/endpoints/manage/ticketlist.go index 951fcb6..7d7221c 100644 --- a/app/http/endpoints/manage/ticketlist.go +++ b/app/http/endpoints/manage/ticketlist.go @@ -34,7 +34,7 @@ func TicketListHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/ticketview.go b/app/http/endpoints/manage/ticketview.go index 89658a4..f119a1e 100644 --- a/app/http/endpoints/manage/ticketview.go +++ b/app/http/endpoints/manage/ticketview.go @@ -40,7 +40,7 @@ func TicketViewHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/updatesettings.go b/app/http/endpoints/manage/updatesettings.go index 99a5037..9087f22 100644 --- a/app/http/endpoints/manage/updatesettings.go +++ b/app/http/endpoints/manage/updatesettings.go @@ -35,7 +35,7 @@ func UpdateSettingsHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/viewlog.go b/app/http/endpoints/manage/viewlog.go index e58986e..1ac27cb 100644 --- a/app/http/endpoints/manage/viewlog.go +++ b/app/http/endpoints/manage/viewlog.go @@ -37,7 +37,7 @@ func LogViewHandler(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page return diff --git a/app/http/endpoints/manage/webchatws.go b/app/http/endpoints/manage/webchatws.go index cfec2b0..b5c80da 100644 --- a/app/http/endpoints/manage/webchatws.go +++ b/app/http/endpoints/manage/webchatws.go @@ -126,7 +126,7 @@ func WebChatWs(ctx *gin.Context) { // Verify the user has permissions to be here isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildIdParsed, userId, isAdmin) + go utils.IsAdmin(guild, userId, isAdmin) if !<-isAdmin { fmt.Println(err.Error()) conn.Close() diff --git a/app/http/endpoints/root/index.go b/app/http/endpoints/root/index.go index 89e7d15..ea8ce27 100644 --- a/app/http/endpoints/root/index.go +++ b/app/http/endpoints/root/index.go @@ -30,12 +30,13 @@ func IndexHandler(ctx *gin.Context) { } fakeGuild := guild.Guild{ - Owner: g.Owner, + Id: guildId, + OwnerId: g.OwnerId, Permissions: g.Permissions, } isAdmin := make(chan bool) - go utils.IsAdmin(fakeGuild, guildId, userId, isAdmin) + go utils.IsAdmin(fakeGuild, userId, isAdmin) if <-isAdmin { adminGuilds = append(adminGuilds, g) } diff --git a/utils/discord/objects/guild.go b/utils/discord/objects/guild.go index 8d6b7cc..ae33125 100644 --- a/utils/discord/objects/guild.go +++ b/utils/discord/objects/guild.go @@ -5,5 +5,6 @@ type Guild struct { Name string Icon string Owner bool + OwnerId uint64 `json:"id,string"` Permissions int } diff --git a/utils/permissionutils.go b/utils/permissionutils.go index befd612..7e0729f 100644 --- a/utils/permissionutils.go +++ b/utils/permissionutils.go @@ -10,16 +10,16 @@ import ( "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))) { res <- true } - if g.Owner { + if g.OwnerId == userId { res <- true } - if table.IsAdmin(guildId, userId) { + if table.IsAdmin(g.Id, userId) { res <- true } @@ -28,10 +28,10 @@ func IsAdmin(g guild.Guild, guildId, userId uint64, res chan bool) { } adminRolesChan := make(chan []uint64) - go table.GetAdminRoles(guildId, adminRolesChan) + go table.GetAdminRoles(g.Id, adminRolesChan) adminRoles := <- adminRolesChan - userRoles, found := getRoles(guildId, userId) + userRoles, found := getRoles(g.Id, userId) hasAdminRole := false if found {