Browse Source

removed workaround in permissions

master
David Haukeness 5 years ago
parent
commit
ada77628c8
  1. 29
      permissions.go

29
permissions.go

@ -9,40 +9,12 @@ import (
// checkPermissionAndExecute will check the minimum required role for the permission and execute the handler function if allowed // checkPermissionAndExecute will check the minimum required role for the permission and execute the handler function if allowed
func (b *bot) checkPermissionAndExecute(requiredRole string, m chat1.MsgSummary, f func(chat1.MsgSummary)) { func (b *bot) checkPermissionAndExecute(requiredRole string, m chat1.MsgSummary, f func(chat1.MsgSummary)) {
// get the members of the conversation // get the members of the conversation
b.debug("Executing permissions check")
// currently this doesn't work due to a keybase bug unless you're in the role of resticted bot
// the workaround is to check the general channel the old way
// so first check the new way
members, err := b.k.ListMembersOfConversation(m.ConvID) members, err := b.k.ListMembersOfConversation(m.ConvID)
if err != nil { if err != nil {
eid := b.logError(err) eid := b.logError(err)
b.k.ReactByConvID(m.ConvID, m.Id, "Error ID %s", eid) b.k.ReactByConvID(m.ConvID, m.Id, "Error ID %s", eid)
return return
} }
// **** <workaround>
// check if the length of the lists are zero
// it'll look like this:
// {"owners":[],"admins":[],"writers":[],"readers":[],"bots":[],"restrictedBots":[]}
if len(members.Owners) == 0 &&
len(members.Admins) == 0 &&
len(members.Writers) == 0 &&
len(members.Readers) == 0 &&
len(members.Bots) == 0 &&
len(members.RestrictedBots) == 0 {
channel := chat1.ChatChannel{
Name: m.Channel.Name,
MembersType: m.Channel.MembersType,
TopicName: "general",
}
// re-map the members using the workaround, in case you're not in the restricted bot role
members, err = b.k.ListMembersOfChannel(channel)
if err != nil {
eid := b.logError(err)
b.k.ReactByConvID(m.ConvID, m.Id, "Error ID %s", eid)
return
}
}
/// **** </workaround>
// create a map of valid roles, according to @dxb struc // create a map of valid roles, according to @dxb struc
memberTypes := make(map[string]struct{}) memberTypes := make(map[string]struct{})
@ -64,7 +36,6 @@ func (b *bot) checkPermissionAndExecute(requiredRole string, m chat1.MsgSummary,
f(m) f(m)
return return
} }
b.debug("no")
} }
// if the required role was owner, return and don't evaluate the rest // if the required role was owner, return and don't evaluate the rest
if strings.ToLower(requiredRole) == "owner" { if strings.ToLower(requiredRole) == "owner" {

Loading…
Cancel
Save