PMタグ付けの不一致なコード/要件

個人メッセージのタグ付けを処理するコードに一貫性がありません。

コードベースの一部の箇所では、pm_tags_allowed_for_groups に属しているだけで、個人メッセージにタグ付けできることが十分です。

コードベースの他の箇所では、pm_tags_allowed_for_groupstag_topic_allowed_groups の両方に属している必要があります。

これは、パブリックトピックにタグ付けすることを望まない場合に、ユーザーが自分の個人メッセージにタグ付けできるようにする必要がある場合に特に制限的です(例:Private template permissions to override allowed PM tagging groups )。つまり、pm_tags_allowed_for_groupstag_topic_allowed_groups の適切なサブセットではない場合です。

分析

TagGuardian では、これらは個別の設定です。PM にタグ付けするには、pm_tags_allowed_for_groups に属しているだけで十分です。

  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

Guardian.can_tag? でも同様です。設定は個別に管理されています。

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

    topic.private_message? ? can_tag_pms? : can_tag_topics?
  end

ListControllercan_tag_pms? だけで問題ありません。

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

しかし、TopicGuardian では、PM にタグ付けするには、ユーザーが tag_topic_allowed_groupspm_tags_allowed_for_groups の両方に属している必要があります。

  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

クライアント側でも、同じ制限が 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)
    );
  }

および TopicController にあります。

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

しかし、Move to Topic モーダルにはこの制限がありません。

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

ChatToTopicSelector も同様です。

@alias("site.can_tag_pms") canTagMessages;

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",
      });
    }

まとめ

クラス C/S 動作
TagGuardian サーバー pm_tags_allowed_for_groups のみ
Guardian サーバー pm_tags_allowed_for_groups のみ
ListController サーバー pm_tags_allowed_for_groups のみ
TopicGuardian サーバー pm_tags_allowed_for_groups と tag_topic_allowed_groups の両方
Composer クライアント pm_tags_allowed_for_groups と tag_topic_allowed_groups の両方
TopicController クライアント pm_tags_allowed_for_groups と tag_topic_allowed_groups の両方
Move to Topic modal クライアント pm_tags_allowed_for_groups のみ
ChatToTopicSelector クライアント pm_tags_allowed_for_groups のみ

追加の問題

さらに 2 つの追加の障害が見つかりました。

PostRevisor は、tc.guardian.can_tag?(tc.topic) の代わりに tc.guardian.can_tag_topics? を使用しています。

そして DiscourseTagging では

tag_topic_by_names は正しく動作しています。

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

しかし、tags_for_saving はそうではありません。


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

この最後のものは特に厄介です。なぜなら、この関数はそれが PM で動作しているかどうかを認識していないからです。

「いいね!」 6