// AddUser add a user to a group func (g *GroupsController) AddUser(ctx *gin.Context) { var paramJSON tat.ParamGroupUserJSON ctx.Bind(¶mJSON) group, e := g.preCheckUser(ctx, ¶mJSON) 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, "") }
// 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 }