# グループと信頼レベルの組み合わせによるタイトル自動化のベストプラクティス

**URL:** https://meta.discourse.org/t/best-practice-for-automating-titles-by-group-trust-level-combinations/377324
**Category:** Development
**Created:** [2025 年 8 月 5 日午前 7:16 UTC](https://meta.discourse.org/t/best-practice-for-automating-titles-by-group-trust-level-combinations/377324 "2025-08-05T07:16:33Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![joo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joo/32/334852_2.png) [@joo](https://meta.discourse.org/u/joo)
#### Post date: [2025 年 8 月 7 日午後 5:55 UTC](https://meta.discourse.org/t/best-practice-for-automating-titles-by-group-trust-level-combinations/377324/9 "2025-08-07T17:55:08Z")

</div>

> [@joo](#):
>
> フォーラムに2つの主要なグループがあると仮定します。
> 
> - グループA：デザイナー
> - グループB：開発者
> 
> 各グループについて、異なる信頼レベルを持つユーザーに、完全に異なるタイトルを付けたいと考えています。例えば以下のようになります。
> 
> デザイナーグループの場合：  
> 信頼レベル1 → 「ジュニアデザイナー」  
> 信頼レベル2 → 「デザイナー」  
> 信頼レベル3 → 「シニアデザイナー」  
> 信頼レベル4 → 「チーフデザイナー」
> 
> 開発者グループの場合：  
> 信頼レベル1 → 「ジュニア開発者」  
> 信頼レベル2 → 「開発者」  
> 信頼レベル3 → 「シニア開発者」  
> 信頼レベル4 → 「テックリード」
> 
> したがって、「デザイナー」グループのTL3のユーザーは、「シニアデザイナー」というタイトルになるはずです。  
> 「開発者」グループのTL2のユーザーは、「開発者」というタイトルになるはずです。
> 
> 各グループと信頼レベルについてこれらのルールを設定し、ユーザーのグループや信頼レベルが変更されたときにタイトルが自動的に割り当てられるようにしたいです。

こんにちは！

私のニーズに合わせてプラグインを修正しましたので、行ったこと、現在のワークフロー、およびいくつか質問/アドバイスを共有したいと思います。

* * *

### 1. 私の修正内容

**ファイルパスと内容：**

**ファイル:** `app/jobs/scheduled/update-all-titles.rb`

```ruby
# frozen_string_literal: true

module AddTitleBasedOnTrustLevel
  class UpdateTitles < ::Jobs::Scheduled
    every SiteSetting.update_title_frequency.hours

    def execute(args)
      group_titles = JSON.parse(SiteSetting.group_trust_level_titles || "{}")

      User.find_each do |user|
        # 管理者とモデレーターはスキップし、タイトルを更新しない
        next if user.admin? || user.moderator?

        group_id = user.primary_group_id
        next unless group_id

        group = Group.find_by(id: group_id)
        next unless group

        group_key = group.name.downcase
        tl = user.trust_level

        titles = group_titles[group_key]
        next unless titles.is_a?(Array)
        next unless tl >= 1 && tl <= 4

        new_title = titles[tl]
        next unless new_title.present?

        user.update_column(:title, new_title) if user.title != new_title
      end
    end
  end
end

```

**ファイル:** `config/settings.yml`

```yaml
plugins:
  add_title_based_on_trust_level_enabled:
    default: false
    client: true
  group_trust_level_titles:
    default: '{"designers": ["", "Junior Designer", "Designer", "Senior Designer", "Chief Designer"], "developers": ["", "Junior Developer", "Developer", "Senior Developer", "Tech Lead"]}'
    type: string
    client: true
    multiline: true
  update_title_frequency:
    default: 24
    type: integer

```

* * *

### 2. テスト方法

現在、 **rails console** を介してこのロジックを手動で実行し、機能が動作するかどうかを確認しています。要件に従って、ユーザーのタイトルが一括で更新されます。

* * *

### 3. プラグイン設定エントリの問題

`/admin/plugins` ページにこのプラグインの「設定」ボタンが表示されません。現在、設定を変更するには、直接 `/admin/plugins/add-title-based-on-trust-level/settings` にアクセスする必要があります。  
設定ボタンまたはリンクをプラグインページに表示して、アクセスしやすくする方法はありますか？

 ![chrome_2025-08-08_02-45-13](https://global.discourse-cdn.com/meta/original/4X/7/2/c/72c669d854068ef2edeba62ec168c2ae650e6037.png)

* * *

### 4. 現在の設定

これが私の現在のJSON設定です（スクリーンショットも添付します）：

```json
{
  "designers": ["", "Junior Designer", "Designer", "Senior Designer", "Chief Designer"],
  "developers": ["", "Junior Developer", "Developer", "Senior Developer", "Tech Lead"]
}

```

 ![chrome_2025-08-08_02-42-17](https://global.discourse-cdn.com/meta/original/4X/f/e/9/fe99089b246cc11986d1a4e62651bf05dccf487f.png)

* * *

### 5. 質問 / 可能な改善点

- このアプローチ（すべてのユーザーをループしてタイトルを更新する）は、ユーザーが多い場合にパフォーマンスの問題を引き起こすリスクはありますか？これに対するより良いベストプラクティスはありますか？
- スケジュールジョブまたは管理設定UIの最適化に関するアドバイスはありますか？
- 私の方法に、注意すべき安全でない点や問題点はありますか？

* * *

素晴らしい仕事とこの便利なプラグインに心から感謝いたします！  
提案があれば、または将来的にグループ+信頼レベルのタイトル設定を改善する予定があれば、ぜひご意見をお聞かせください。

---

_[View the full topic](https://meta.discourse.org/t/best-practice-for-automating-titles-by-group-trust-level-combinations/377324)._
