FEATURE: Introduce personal_message_enabled_groups setting (#18042)

This will replace `enable_personal_messages` and
`min_trust_to_send_messages`, this commit introduces
the setting `personal_message_enabled_groups`
and uses it in all places that `enable_personal_messages`
and `min_trust_to_send_messages` currently apply.

A migration is included to set `personal_message_enabled_groups`
based on the following rules:

* If `enable_personal_messages` was false, then set
  `personal_message_enabled_groups` to `3`, which is
  the staff auto group
* If `min_trust_to_send_messages` is not default (1)
  and the above condition is false, then set the
  `personal_message_enabled_groups` setting to
  the appropriate auto group based on the trust level
* Otherwise just set `personal_message_enabled_groups` to
  11 which is the TL1 auto group

After follow-up PRs to plugins using these old settings, we will be
able to drop the old settings from core, in the meantime I've added
 DEPRECATED notices to their descriptions and added them
to the deprecated site settings list.

This commit also introduces a `_map` shortcut method definition
for all `group_list` site settings, e.g. `SiteSetting.personal_message_enabled_groups`
also has `SiteSetting.personal_message_enabled_groups_map` available,
which automatically splits the setting by `|` and converts it into
an array of integers.
This commit is contained in:
Martin Brennan
2022-09-26 13:58:40 +10:00
committed by GitHub
parent 7ca89827a0
commit e62e93f83a
55 changed files with 375 additions and 120 deletions

View File

@ -1091,12 +1091,18 @@ RSpec.describe TopicQuery do
TopicUser.update_last_read(user, topic, post_number, post_number, 10000)
end
it 'returns the correct suggestions' do
before do
user.change_trust_level!(4)
sender.change_trust_level!(4)
end
it 'returns the correct suggestions' do
pm_to_group = create_pm(sender, target_group_names: [group_with_user.name])
pm_to_user = create_pm(sender, target_usernames: [user.username])
old_unrelated_pm = create_pm(target_usernames: [user.username])
other_user = Fabricate(:user)
other_user.change_trust_level!(1)
old_unrelated_pm = create_pm(other_user, target_usernames: [user.username])
read(user, old_unrelated_pm, 1)
related_by_user_pm = create_pm(sender, target_usernames: [user.username])
@ -1113,7 +1119,7 @@ RSpec.describe TopicQuery do
eq([related_by_user_pm.id])
)
SiteSetting.enable_personal_messages = false
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:staff]
expect(TopicQuery.new(user).list_related_for(pm_to_group)).to be_blank
expect(TopicQuery.new(user).list_related_for(pm_to_user)).to be_blank
end
@ -1236,6 +1242,8 @@ RSpec.describe TopicQuery do
before do
group.add(group_user)
another_group.add(user)
Group.user_trust_level_change!(user.id, user.trust_level)
Group.user_trust_level_change!(group_user.id, group_user.trust_level)
end
context 'as user not part of group' do