Пример #1
0
// If a channel list contains a wildcard ("*"), replace it with all the user's accessible channels.
// Do this before calling any of the CanSee or Authorize methods below, as they interpret a
// channel named "*" as, literally, the wildcard channel that contains all documents.
func (user *User) ExpandWildCardChannel(channels []string) []string {
	if ch.ContainsChannel(channels, "*") {
		channels = user.Channels
		if channels == nil {
			channels = []string{}
		}
	}
	return channels
}
Пример #2
0
// Returns true if the User is allowed to access any of the given channels.
// A nil User means access control is disabled, so the function will return true.
func (user *User) CanSeeAnyChannels(channels []string) bool {
	if channels != nil {
		for _, channel := range channels {
			if user.CanSeeChannel(channel) {
				return true
			}
		}
	}
	// If user has wildcard access, allow it anyway
	return ch.ContainsChannel(user.Channels, "*")
}
Пример #3
0
// Returns true if the User is allowed to access the channel.
// A nil User means access control is disabled, so the function will return true.
func (user *User) CanSeeChannel(channel string) bool {
	return user == nil || channel == "*" || ch.ContainsChannel(user.Channels, channel) ||
		ch.ContainsChannel(user.Channels, "*")
}