Inkonsistenter Code / Anforderungen für PM-Tagging

Der Code zur Handhabung des Tagging von persönlichen Nachrichten ist inkonsistent.

In einigen Teilen der Codebasis reicht es aus, in pm_tags_allowed_for_groups zu sein, um eine persönliche Nachricht taggen zu können.

In anderen Teilen der Codebasis muss man sowohl in pm_tags_allowed_for_groups als auch in tag_topic_allowed_groups sein.

Dies ist besonders restriktiv, wenn Benutzer ihre eigenen persönlichen Nachrichten taggen können sollen, während sie keine öffentlichen Themen taggen sollen (z. B. dies Private template permissions to override allowed PM tagging groups ), d. h. wenn pm_tags_allowed_for_groups keine echte Teilmenge von tag_topic_allowed_groups ist.

Analyse

In TagGuardian sind dies unterschiedliche Einstellungen. Sie müssen nur in pm_tags_allowed_for_groups sein, um eine PM taggen zu können.

  def can_tag_topics?
    SiteSetting.tagging_enabled && @user.in_any_groups?(SiteSetting.tag_topic_allowed_groups_map)
  end

  def can_tag_pms?
    return false if !SiteSetting.tagging_enabled
    return false if @user.blank?
    return true if @user == Discourse.system_user

    group_ids = SiteSetting.pm_tags_allowed_for_groups_map
    group_ids.include?(Group::AUTO_GROUPS[:everyone]) ||
      @user.group_users.exists?(group_id: group_ids)
  end

Das Gleiche gilt für Guardian.can_tag? Die Einstellungen sind unterschiedlich.

  def can_tag?(topic)
    return false if topic.blank?

    topic.private_message? ? can_tag_pms? : can_tag_topics?
  end

ListController ist ebenfalls mit nur can_tag_pms? zufrieden.

    when :private_messages_tag
      raise Discourse::NotFound if target_user.id != current_user.id
      raise Discourse::NotFound if !guardian.can_tag_pms?

Allerdings verlangt TopicGuardian, dass ein Benutzer sowohl in tag_topic_allowed_groups als auch in pm_tags_allowed_for_groups ist, wenn er eine PM taggen möchte.

  def can_edit_tags?(topic)
    return false unless can_tag_topics?
    return false if topic.private_message? && !can_tag_pms?
    return true if can_edit_topic?(topic)

    if topic&.first_post&.wiki &&
         @user.in_any_groups?(SiteSetting.edit_wiki_post_allowed_groups_map)
      return can_create_post?(topic)
    end

    false
  end

Auf der Client-Seite befindet sich die gleiche Einschränkung in Composer

  @discourseComputed("model.canEditTitle", "model.creatingPrivateMessage")
  canEditTags(canEditTitle, creatingPrivateMessage) {
    const isPrivateMessage =
      creatingPrivateMessage || this.get("model.topic.isPrivateMessage");
    return (
      canEditTitle &&
      this.site.can_tag_topics &&
      (!isPrivateMessage || this.site.can_tag_pms)
    );
  }

und TopicController

  @discourseComputed("model.isPrivateMessage")
  canEditTags(isPrivateMessage) {
    return (
      this.site.get("can_tag_topics") &&
      (!isPrivateMessage || this.site.get("can_tag_pms"))
    );
  }

Aber das Modal Move to Topic hat diese Einschränkung nicht:

  get canTagMessages() {
    return this.site.can_tag_pms;
  }

und auch nicht ChatToTopicSelector

@alias("site.can_tag_pms") canTagMessages;

und auch nicht UserPrivateMessagesController

@readOnly("site.can_tag_pms") pmTaggingEnabled;

    if (this.pmTaggingEnabled) {
      content.push({
        id: this.router.urlFor("userPrivateMessages.tags", usernameLower),
        name: i18n("user.messages.tags"),
        icon: "tags",
      });
    }

Zusammenfassung

Klasse S/C Verhalten
TagGuardian Server nur pm_tags_allowed_for_groups
Guardian Server nur pm_tags_allowed_for_groups
ListController Server nur pm_tags_allowed_for_groups
TopicGuardian Server sowohl pm_tags_allowed_for_groups als auch tag_topic_allowed_groups
Composer Client sowohl pm_tags_allowed_for_groups als auch tag_topic_allowed_groups
TopicController Client sowohl pm_tags_allowed_for_groups als auch tag_topic_allowed_groups
Move to Topic modal Client nur pm_tags_allowed_for_groups
ChatToTopicSelector Client nur pm_tags_allowed_for_groups

Zusätzliche Probleme

Ich habe zwei weitere zusätzliche Hindernisse gefunden:

PostRevisor verwendet tc.guardian.can_tag_topics? anstelle von tc.guardian.can_tag?(tc.topic)

und in DiscourseTagging

tag_topic_by_names macht das Richtige

  def self.tag_topic_by_names(topic, guardian, tag_names_arg, append: false)
    if guardian.can_tag?(topic)    

aber dann macht tags_for_saving das nicht


   def self.tags_for_saving(tags_arg, guardian, opts = {})
    return [] unless guardian.can_tag_topics? && tags_arg.present?

Letzteres ist besonders tückisch, da die Funktion nicht weiß, ob sie an einer PM arbeitet.

6 „Gefällt mir“