示例#1
0
文件: group.go 项目: ovh/tat
func actionOnSet(group *tat.Group, operand, set, groupname, admin, history string) error {
	err := store.Tat().CGroups.Update(
		bson.M{"_id": group.ID},
		bson.M{operand: bson.M{set: groupname}},
	)
	if err != nil {
		return err
	}
	cache.CleanAllGroups()
	return addToHistory(group, admin, history+" "+groupname)
}
示例#2
0
文件: group.go 项目: ovh/tat
// Delete deletes a group
func Delete(group *tat.Group, user *tat.User) error {
	cache.CleanAllGroups()

	if len(group.Users) > 0 {
		return fmt.Errorf("Could not delete this group, this group have Users")
	}
	if len(group.AdminUsers) > 0 {
		return fmt.Errorf("Could not delete this group, this group have Admin Users")
	}

	return store.Tat().CGroups.Remove(bson.M{"_id": group.ID})
}
示例#3
0
文件: group.go 项目: ovh/tat
// Insert insert new group
func Insert(group *tat.Group) error {

	cache.CleanAllGroups()
	group.ID = bson.NewObjectId().Hex()

	group.DateCreation = time.Now().Unix()
	err := store.Tat().CGroups.Insert(group)
	if err != nil {
		log.Errorf("Error while inserting new group %s", err)
	}
	return err
}
示例#4
0
文件: group.go 项目: ovh/tat
// Update updates a group : name and description
func Update(group *tat.Group, newGroupname, description string, user *tat.User) error {

	cache.CleanAllGroups()

	// Check if name already exists -> checked in controller
	err := store.Tat().CGroups.Update(
		bson.M{"_id": group.ID},
		bson.M{"$set": bson.M{"name": newGroupname, "description": description}})

	if err != nil {
		log.Errorf("Error while update group %s to %s:%s", group.Name, newGroupname, err.Error())
		return fmt.Errorf("Error while update group")
	}
	group.Name = newGroupname
	group.Description = description

	return err
}
示例#5
0
文件: group.go 项目: ovh/tat
// ChangeUsernameOnGroups changes a username on groups
func ChangeUsernameOnGroups(oldUsername, newUsername string) {
	cache.CleanAllGroups()

	// Users
	_, err := store.Tat().CGroups.UpdateAll(
		bson.M{"users": oldUsername},
		bson.M{"$set": bson.M{"users.$": newUsername}})

	if err != nil {
		log.Errorf("Error while changes username from %s to %s on Groups (Users) %s", oldUsername, newUsername, err)
	}

	// AdminUsers
	_, err = store.Tat().CGroups.UpdateAll(
		bson.M{"adminUsers": oldUsername},
		bson.M{"$set": bson.M{"adminUsers.$": newUsername}})

	if err != nil {
		log.Errorf("Error while changes username from %s to %s on Groups (Admins) %s", oldUsername, newUsername, err)
	}
}