コード例 #1
0
ファイル: user.go プロジェクト: ovh/tat
// AddFavoriteTag Add a favorite tag to user
func AddFavoriteTag(user *tat.User, tag string) error {
	if containsFavoriteTag(user, tag) {
		return fmt.Errorf("AddFavoriteTag not possible, %s is already a favorite tag", tag)
	}
	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$push": bson.M{"favoritesTags": tag}})
}
コード例 #2
0
ファイル: user.go プロジェクト: ovh/tat
// DisableNotificationsTopic add topic to user list offNotificationsTopics
func DisableNotificationsTopic(user *tat.User, topic string) error {
	if containsOffNotificationsTopic(user, topic) {
		return fmt.Errorf("DisableNotificationsTopic not possible, notifications are already off on topic %s", topic)
	}

	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$push": bson.M{"offNotificationsTopics": topic}})
}
コード例 #3
0
ファイル: user.go プロジェクト: ovh/tat
// RemoveContact removes a contact from user
func RemoveContact(user *tat.User, contactUsername string) error {
	l, err := getContact(user, contactUsername)
	if err != nil {
		return fmt.Errorf("Remove Contact is not possible, %s is not a contact of this user", contactUsername)
	}

	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$pull": bson.M{"contacts": l}})
}
コード例 #4
0
ファイル: user.go プロジェクト: ovh/tat
// AddContact add a contact to user
func AddContact(user *tat.User, contactUsername string, contactFullname string) error {
	if containsContact(user, contactUsername) {
		return fmt.Errorf("AddContact not possible, %s is already a contact of this user", contactUsername)
	}
	var newContact = &tat.Contact{Username: contactUsername, Fullname: contactFullname}

	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$push": bson.M{"contacts": newContact}})
}
コード例 #5
0
ファイル: user.go プロジェクト: ovh/tat
// RemoveFavoriteTag remove a favorite tag from user
func RemoveFavoriteTag(user *tat.User, tag string) error {
	t, err := getFavoriteTag(user, tag)
	if err != nil {
		return fmt.Errorf("Remove favorite tag is not possible, %s is not a favorite of this user", tag)
	}

	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$pull": bson.M{"favoritesTags": t}})
}
コード例 #6
0
ファイル: user.go プロジェクト: ovh/tat
// AddFavoriteTopic add a favorite topic to user
func AddFavoriteTopic(user *tat.User, topic string) error {
	if containsFavoriteTopic(user, topic) {
		return fmt.Errorf("AddFavoriteTopic not possible, %s is already a favorite topic", topic)
	}

	err := store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$push": bson.M{"favoritesTopics": topic}})
	if err != nil {
		log.Errorf("Error while add favorite topic to user %s: %s", user.Username, err)
		return err
	}
	cache.CleanUsernames(user.Username)
	return nil
}
コード例 #7
0
ファイル: user.go プロジェクト: 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}})
}
コード例 #8
0
ファイル: user.go プロジェクト: ovh/tat
// DisableNotificationsAllTopics add all topics to user list offNotificationsTopics, except /Private/*
func DisableNotificationsAllTopics(user *tat.User) error {
	criteria := &tat.TopicCriteria{
		Skip:  0,
		Limit: 9000000,
	}
	_, topics, err := topic.ListTopics(criteria, user, false, false, false)
	if err != nil {
		return err
	}

	topicsToSet := []string{}
	for _, topic := range topics {
		if !strings.HasPrefix(topic.Topic, "/Private") {
			topicsToSet = append(topicsToSet, topic.Topic)
		}
	}

	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$set": bson.M{"offNotificationsTopics": topicsToSet}})
}
コード例 #9
0
ファイル: user.go プロジェクト: 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
}
コード例 #10
0
ファイル: user.go プロジェクト: ovh/tat
// Update changes fullname and email of user
func Update(user *tat.User, newFullname, newEmail string) error {

	userCheck := tat.User{}
	found, err := FindByEmail(&userCheck, newEmail)
	if err != nil {
		return err
	}
	if user.Email != newEmail && found {
		return fmt.Errorf("Email %s already exists", newEmail)
	}

	found2, err2 := FindByFullname(&userCheck, newFullname)
	if err2 != nil {
		return err2
	}
	if user.Fullname != newFullname && found2 {
		return fmt.Errorf("Fullname %s already exists", newFullname)
	}

	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$set": bson.M{"fullname": newFullname, "email": newEmail}})
}
コード例 #11
0
ファイル: user.go プロジェクト: ovh/tat
// Rename changes username of one user
func Rename(user *tat.User, newUsername string) error {
	var userCheck = tat.User{}
	found, errCheck := FindByUsername(&userCheck, newUsername)

	if errCheck != nil {
		return fmt.Errorf("Rename> Error with DB Backend:%s", errCheck)
	} else if found {
		return fmt.Errorf("Rename> Username %s already exists", newUsername)
	}

	err := store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$set": bson.M{"username": newUsername}})

	if err != nil {
		return err
	}

	topic.ChangeUsernameOnTopics(user.Username, newUsername)
	group.ChangeUsernameOnGroups(user.Username, newUsername)
	presence.ChangeAuthorUsernameOnPresences(user.Username, newUsername)
	cache.CleanUsernames(user.Username)
	return nil
}
コード例 #12
0
ファイル: user.go プロジェクト: ovh/tat
// EnableNotificationsAllTopics removes all topics from user list offNotificationsTopics
func EnableNotificationsAllTopics(user *tat.User) error {
	cache.CleanUsernames(user.Username)
	return store.Tat().CUsers.Update(
		bson.M{"_id": user.ID},
		bson.M{"$set": bson.M{"offNotificationsTopics": []bson.M{}}})
}