Example #1
0
File: topic.go Project: ovh/tat
// CheckAndFixName Add a / to topic name is it is not present
// return an error if length of name is < 4 or > 100
func CheckAndFixName(topic *tat.Topic) error {
	name, err := tat.CheckAndFixNameTopic(topic.Topic)
	if err != nil {
		return err
	}
	topic.Topic = name
	return nil
}
Example #2
0
File: user.go Project: ovh/tat
// EnableNotificationsTopic remove topic from user list offNotificationsTopics
func EnableNotificationsTopic(user *tat.User, topic string) error {
	topicName, err := tat.CheckAndFixNameTopic(topic)
	if err != nil {
		return err
	}

	t, err := getOffNotificationsTopic(user, topicName)
	if err != nil {
		return fmt.Errorf("Enable notifications on topic %s is not possible, notifications are already enabled", topicName)
	}

	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$pull": bson.M{"offNotificationsTopics": t}})
}
Example #3
0
File: user.go Project: ovh/tat
// RemoveFavoriteTopic removes a favorite topic from user
func RemoveFavoriteTopic(user *tat.User, topic string) error {
	topicName, err := tat.CheckAndFixNameTopic(topic)
	if err != nil {
		return err
	}

	t, err := getFavoriteTopic(user, topicName)
	if err != nil {
		return fmt.Errorf("Remove favorite topic is not possible, %s is not a favorite of this user", topicName)
	}

	err = store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$pull": bson.M{"favoritesTopics": t}})

	if err != nil {
		log.Errorf("Error while remove favorite topic from user %s: %s", user.Username, err)
		return err
	}
	cache.CleanUsernames(user.Username)
	return nil
}