Ejemplo n.º 1
0
// IsUserAdmin return true if user is Tat admin or is admin on this topic
// Check personal access to topic, and group access
func (topic *Topic) IsUserAdmin(user *User) bool {

	if user.IsAdmin {
		return true
	}

	if utils.ArrayContains(topic.AdminUsers, user.Username) {
		return true
	}

	userGroups, err := user.GetGroups()
	if err != nil {
		log.Errorf("Error while fetching user groups")
		return false
	}

	var groups []string
	for _, g := range userGroups {
		groups = append(groups, g.Name)
	}

	if utils.ItemInBothArrays(topic.AdminGroups, groups) {
		return true
	}

	// user is "Admin" on his /Private/usrname topics
	if strings.HasPrefix(topic.Topic, "/Private/"+user.Username) {
		return true
	}

	return false
}
Ejemplo n.º 2
0
// IsUserReadAccess  return true if user has read access to topic
func (topic *Topic) IsUserReadAccess(user User) bool {
	currentTopic := topic

	if topic.IsROPublic {
		return true
	}

	// if user not admin, reload topic with admin rights
	if !user.IsAdmin {
		currentTopic = &Topic{}
		e := currentTopic.FindByID(topic.ID, true)
		if e != nil {
			return false
		}
	}

	if utils.ArrayContains(currentTopic.ROUsers, user.Username) ||
		utils.ArrayContains(currentTopic.RWUsers, user.Username) ||
		utils.ArrayContains(currentTopic.AdminUsers, user.Username) {
		return true
	}
	userGroups, err := user.GetGroups()
	if err != nil {
		log.Errorf("Error while fetching user groups for user %s", user.Username)
		return false
	}

	var groups []string
	for _, g := range userGroups {
		groups = append(groups, g.Name)
	}

	if utils.ItemInBothArrays(currentTopic.RWGroups, groups) ||
		utils.ItemInBothArrays(currentTopic.ROGroups, groups) ||
		utils.ItemInBothArrays(currentTopic.AdminGroups, groups) {
		return true
	}

	return false
}
Ejemplo n.º 3
0
// IsUserRW return true if user can write on a this topic
// Check personal access to topic, and group access
func (topic *Topic) IsUserRW(user *User) bool {
	if utils.ArrayContains(topic.RWUsers, user.Username) ||
		utils.ArrayContains(topic.AdminUsers, user.Username) {
		return true
	}
	userGroups, err := user.GetGroups()
	if err != nil {
		log.Errorf("Error while fetching user groups")
		return false
	}

	var groups []string
	for _, g := range userGroups {
		groups = append(groups, g.Name)
	}

	if utils.ItemInBothArrays(topic.RWGroups, groups) {
		return true
	}

	return false
}