1
0
Fork 0
forked from External/grumble

Simplify group invert logic.

This commit is contained in:
Mikkel Krautz 2011-04-27 22:04:23 +02:00
parent 18adc1a41d
commit 07bdd1c03b

View file

@ -130,19 +130,18 @@ func (group *Group) Members() map[int]bool {
// the group from an acl in aclchan. // the group from an acl in aclchan.
// //
// The channel aclchan will always be either equal to current, or be an ancestor. // The channel aclchan will always be either equal to current, or be an ancestor.
func GroupMemberCheck(current *Channel, aclchan *Channel, name string, client *Client) bool { func GroupMemberCheck(current *Channel, aclchan *Channel, name string, client *Client) (ok bool) {
invert := false invert := false
token := false token := false
hash := false hash := false
// Returns the 'correct' return value considering the value // Returns the 'correct' return value considering the value
// of the invert flag. // of the invert flag.
retvalify := func(in bool) bool { defer func() {
if invert { if invert {
return !in ok = !ok
} }
return in }()
}
member := false member := false
channel := current channel := current
@ -287,14 +286,14 @@ func GroupMemberCheck(current *Channel, aclchan *Channel, name string, client *C
cofs += minpath cofs += minpath
// Check that the minpath parameter that was given is a valid index for groupChain. // Check that the minpath parameter that was given is a valid index for groupChain.
if cofs >= len(groupChain) { if cofs >= len(groupChain) {
return retvalify(false) return false
} else if cofs < 0 { } else if cofs < 0 {
cofs = 0 cofs = 0
} }
// If our 'base' channel is not in the playerChain, the group does not apply to the client. // If our 'base' channel is not in the playerChain, the group does not apply to the client.
if indexOf(playerChain, groupChain[cofs]) == -1 { if indexOf(playerChain, groupChain[cofs]) == -1 {
return retvalify(false) return false
} }
// Down here, we're certain that the playerChain includes the base channel // Down here, we're certain that the playerChain includes the base channel
@ -338,7 +337,7 @@ func GroupMemberCheck(current *Channel, aclchan *Channel, name string, client *C
} }
} }
return retvalify(member) return member
} }
// Get the list of group names in a particular channel. // Get the list of group names in a particular channel.