Example #1
0
File: groups.go Project: ovh/tat
// AddUser add a user to a group
func (g *GroupsController) AddUser(ctx *gin.Context) {
	var paramJSON tat.ParamGroupUserJSON
	ctx.Bind(&paramJSON)
	group, e := g.preCheckUser(ctx, &paramJSON)
	if e != nil {
		return
	}

	if err := groupDB.AddUser(&group, getCtxUsername(ctx), paramJSON.Username); err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Error while add user to group: %s", err)})
		return
	}
	ctx.JSON(http.StatusCreated, "")
}
Example #2
0
File: user.go Project: ovh/tat
// AddDefaultGroup add default group to user
func AddDefaultGroup(user *tat.User) error {
	groupname := viper.GetString("default_group")

	// no default group
	if groupname == "" {
		return nil
	}

	tatGroup, errfinding := group.FindByName(groupname)
	if errfinding != nil {
		e := fmt.Errorf("Error while fetching default group : %s", errfinding.Error())
		return e
	}
	err := group.AddUser(tatGroup, "Tat", user.Username)
	if err != nil {
		e := fmt.Errorf("Error while adding user to default group : %s", err.Error())
		return e
	}
	return nil
}