func (*GroupsController) preCheckUser(ctx *gin.Context, paramJSON *paramUserJSON) (models.Group, error) { usernameExists := models.IsUsernameExists(paramJSON.Username) group := models.Group{} if !usernameExists { e := errors.New("username " + paramJSON.Username + " does not exist") ctx.AbortWithError(http.StatusInternalServerError, e) return group, e } errfinding := group.FindByName(paramJSON.Groupname) if errfinding != nil { ctx.AbortWithError(http.StatusInternalServerError, errfinding) return group, errfinding } if utils.IsTatAdmin(ctx) { // if Tat admin, ok return group, nil } user, err := PreCheckUser(ctx) if err != nil { return models.Group{}, err } if !group.IsUserAdmin(&user) { e := fmt.Errorf("user %s is not admin on group %s", user.Username, group.Name) ctx.AbortWithError(http.StatusInternalServerError, e) return models.Group{}, e } return group, nil }