Ejemplo n.º 1
0
// ChannelAllowed checks if the requested channel is allowed by the user for sending
// out the notification
func ChannelAllowed(user, org, app_name, ident, channelName string) bool {

	var available = []string{"email", "web", "push"}
	var preference map[string]availableTopics.ChotaTopic

	appTopics, err := availableTopics.GetAppTopics(app_name, org)
	channels := []string{}
	for _, idnt := range available {
		channels = append(channels, idnt)
	}
	preference, err = availableTopics.GetUserPreferences(user, org, appTopics, &channels)

	if err != nil {
		log.Println(err)
		return false
	}

	if _, ok := preference[ident]; !ok {
		return false
	}

	if _, ok := preference[ident][channelName]; !ok {
		return false
	}

	return preference[ident][channelName].Value
}
Ejemplo n.º 2
0
func (self *Topics) Get(request *gottp.Request) {
	var args struct {
		AppName      string `json:"app_name" required:"true"`
		Organization string `json:"org"`
		User         string `json:"user"`
	}
	var iter map[string]available_topics.ChotaTopic
	var err error

	request.ConvertArguments(&args)

	if !utils.ValidateAndRaiseError(request, args) {
		log.Println("Validation Failed")
		return
	}

	appTopics, err := available_topics.GetAppTopics(args.AppName, args.Organization)

	if args.Organization == "" {
		request.Write(appTopics)
		return
	}

	channels := []string{}
	for ident, _ := range core.ChannelMap {
		channels = append(channels, ident)
	}

	if args.User == "" {
		iter, err = available_topics.GetOrgPreferences(args.Organization, appTopics, &channels)
	} else {
		iter, err = available_topics.GetUserPreferences(args.User, args.Organization, appTopics, &channels)
	}

	if err != nil {
		if err != mgo.ErrNotFound {
			log.Println(err)
			request.Raise(gottp.HttpError{
				http.StatusInternalServerError,
				"Unable to fetch data, Please try again later.",
			})

		} else {
			request.Raise(gottp.HttpError{
				http.StatusNotFound,
				"Not Found.",
			})
		}

		return
	}

	request.Write(iter)
	return
}