コード例 #1
0
ファイル: messages.go プロジェクト: ovh/tatcli
func (ui *tatui) removeLabel(msg tat.Message, label string) error {
	var err error
	if label == "doing" && msg.ContainsLabel("doing") {
		internal.Client().MessageUntask(msg.Topic, msg.ID)
	} else {
		internal.Client().MessageUnlabel(msg.Topic, msg.ID, label)
		if label == "done" {
			for _, l := range msg.Labels {
				if strings.HasPrefix(l.Text, "done:") {
					internal.Client().MessageUnlabel(msg.Topic, msg.ID, l.Text)
				}
			}
		}
	}
	return err
}
コード例 #2
0
ファイル: messages.go プロジェクト: ovh/tat
// checkBeforeDelete checks
// - if user is RW on topic
// - if topic is Private OR is CanDeleteMsg or CanDeleteAllMsg
func (m *MessagesController) checkBeforeDelete(ctx *gin.Context, message tat.Message, user tat.User, force bool, topic tat.Topic) error {

	isRW, isTopicAdmin := topicDB.GetUserRights(&topic, &user)
	if !isRW {
		e := fmt.Sprintf("No RW Access to topic %s", message.Topic)
		ctx.JSON(http.StatusForbidden, gin.H{"error": e})
		return fmt.Errorf(e)
	}

	if topic.AdminCanDeleteAllMsg && isTopicAdmin {
		return nil
	}

	if !strings.HasPrefix(message.Topic, "/Private/"+user.Username) && !topic.CanDeleteMsg && !topic.CanDeleteAllMsg {
		if !topic.CanDeleteMsg && !topic.CanDeleteAllMsg {
			e := fmt.Sprintf("You can't delete a message from topic %s", topic.Topic)
			ctx.JSON(http.StatusForbidden, gin.H{"error": e})
			return fmt.Errorf(e)
		}
		e := fmt.Sprintf("Could not delete a message in topic %s", message.Topic)
		ctx.JSON(http.StatusBadRequest, gin.H{"error": e})
		return fmt.Errorf(e)
	}

	if !topic.CanDeleteAllMsg && message.Author.Username != user.Username && !strings.HasPrefix(message.Topic, "/Private/"+user.Username) {
		// if it's a reply and force true, allow delete it.
		if !force || (force && message.InReplyOfIDRoot == "") {
			e := fmt.Sprintf("Could not delete a message from another user %s than you %s", message.Author.Username, user.Username)
			ctx.JSON(http.StatusBadRequest, gin.H{"error": e})
			return fmt.Errorf(e)
		}
	}

	// if label done on msg, can delete it
	if !force && message.IsDoing() {
		e := fmt.Sprintf("Could not delete a message with a doing label")
		ctx.JSON(http.StatusBadRequest, gin.H{"error": e})
		return fmt.Errorf(e)
	}
	return nil
}
コード例 #3
0
ファイル: hook.go プロジェクト: ovh/tat
func matchCriteria(m tat.Message, c tat.FilterCriteria) bool {
	/*
		bson:"label" json:"label,omitempty
		bson:"notLabel" json:"notLabel,omitempty
		bson:"andLabel" json:"andLabel,omitempty
		bson:"tag" json:"tag,omitempty
		bson:"notTag" json:"notTag,omitempty
		bson:"andTag" json:"andTag,omitempty
		bson:"username" json:"username,omitempty
		bson:"onlyMsgRoot" json:"onlyMsgRoot,omitempty
	*/

	if c.OnlyMsgRoot && m.InReplyOfID != "" {
		return false
	}

	if c.Label != "" {
		labels := strings.Split(c.Label, ",")
		ok := false
		for _, l := range labels {
			if m.ContainsLabel(l) {
				ok = true
				break
			}
		}
		if !ok {
			return false
		}
	}

	if c.NotLabel != "" {
		notLabels := strings.Split(c.NotLabel, ",")
		for _, l := range notLabels {
			if m.ContainsLabel(l) {
				return false
			}
		}
	}

	if c.AndLabel != "" {
		andLabels := strings.Split(c.AndLabel, ",")
		ok := 0
		for _, l := range andLabels {
			if m.ContainsLabel(l) {
				ok++
			}
		}
		if ok != len(andLabels) {
			return false
		}
	}

	if c.Tag != "" {
		tags := strings.Split(c.Tag, ",")
		ok := false
		for _, l := range tags {
			if m.ContainsTag(l) {
				ok = true
				break
			}
		}
		if !ok {
			return false
		}
	}

	if c.NotTag != "" {
		notTags := strings.Split(c.NotTag, ",")
		for _, l := range notTags {
			if m.ContainsTag(l) {
				return false
			}
		}
	}

	if c.AndTag != "" {
		andTags := strings.Split(c.AndTag, ",")
		ok := 0
		for _, l := range andTags {
			if m.ContainsTag(l) {
				ok++
			}
		}
		if ok != len(andTags) {
			return false
		}
	}

	if c.Username != "" && c.Username != m.Author.Username {
		return false
	}

	return true
}