Hi!
I’ve modified the plugin to fit my needs, and I’d like to share what I did, my current workflow, and a few questions/requests for advice.
1. My Modifications
File path and content:
File: app/jobs/scheduled/update-all-titles.rb
# 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|
# Skip admins and moderators, do not update their titles
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
File: config/settings.yml
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. How I Tested
I am currently manually running this logic via rails console to check if the function works. It does update user titles in bulk according to my requirements.
3. Plugin Settings Entry Issue
There is no “Settings” button for this plugin on the /admin/plugins
page. Right now, to change the config, I have to visit /admin/plugins/add-title-based-on-trust-level/settings
directly.
Is there a way to have the settings button or link appear on the Plugins page for easier access?
4. My Current Settings
This is my current JSON configuration (I will attach a screenshot as well):
{
"designers": ["", "Junior Designer", "Designer", "Senior Designer", "Chief Designer"],
"developers": ["", "Junior Developer", "Developer", "Senior Developer", "Tech Lead"]
}
5. Questions / Possible Improvements
- Does this approach (looping through every user and updating their title) risk performance issues if there are a lot of users? Is there a better best-practice for this?
- Any advice on optimization, either for the scheduled job or for the admin settings UI?
- Is there anything unsafe or problematic with my method that I should be careful about?
Thank you very much for your great work and this useful plugin!
If you have any suggestions, or if you plan to improve group+trust level title config in the future, I would love to hear your thoughts.