func (t *TopicsController) preCheckUserAdminOnTopic(ctx *gin.Context, topicName string) (models.Topic, error) { topic := models.Topic{} errfinding := topic.FindByTopic(topicName, true) if errfinding != nil { e := errors.New(errfinding.Error()) ctx.AbortWithError(http.StatusInternalServerError, e) return topic, e } if utils.IsTatAdmin(ctx) { // if Tat admin, ok return topic, nil } user, err := PreCheckUser(ctx) if err != nil { return models.Topic{}, err } if !topic.IsUserAdmin(&user) { e := fmt.Errorf("user %s is not admin on topic %s", user.Username, topic.Topic) ctx.AbortWithError(http.StatusForbidden, e) return models.Topic{}, e } return topic, nil }