discourse/plugins/discourse-presence/plugin.rb
Kris 2d111e2a9a
UX: show all preinstalled plugins and label them as such (#33681)
Instead of listing the redundant commit hash, this now shows
"preinstalled" for the relevant components and links to
https://meta.discourse.org/t/bundling-more-popular-plugins-with-discourse-core/373574.
This is accomplished by checking the URL of the plugin for
`"/discourse/discourse/tree/main/plugins/"` which indicates it's part of
the core Discourse repo.

I've also removed the `hide_plugin` flag from existing preinstalled
plugins. Now Discourse admins will have more clarity into what's
included.

I also made some minor layout adjustments: 
* Larger click area for "how to install a plugin" banner
* Moved "Learn more" into a separate line for consistent positioning

Before:
<img width="2182" height="1192" alt="image"
src="https://github.com/user-attachments/assets/b2943a7f-5212-4abd-8b80-d0d071378f06"
/>


After:
<img width="2226" height="1184" alt="image"
src="https://github.com/user-attachments/assets/0846a2c9-fc1b-435c-b51f-b966af5ade09"
/>
2025-07-17 15:11:52 -04:00

76 lines
2.8 KiB
Ruby
Vendored

# frozen_string_literal: true
# name: discourse-presence
# about: Show which users are replying to a topic, or editing a post
# version: 2.0
# authors: André Pereira, David Taylor, tgxworld
# url: https://github.com/discourse/discourse/tree/main/plugins/discourse-presence
enabled_site_setting :presence_enabled
register_asset "stylesheets/presence.scss"
after_initialize do
register_presence_channel_prefix("discourse-presence") do |channel_name|
if topic_id = channel_name[%r{/discourse-presence/reply/(\d+)}, 1]
topic = Topic.find(topic_id)
config = PresenceChannel::Config.new
if topic.private_message?
config.allowed_user_ids = topic.allowed_users.pluck(:id)
config.allowed_group_ids =
topic.allowed_groups.pluck(:group_id) + [::Group::AUTO_GROUPS[:staff]]
elsif secure_group_ids = topic.secure_group_ids
config.allowed_group_ids = secure_group_ids + [::Group::AUTO_GROUPS[:admins]]
else
# config.public=true would make data available to anon, so use the tl0 group instead
config.allowed_group_ids = [::Group::AUTO_GROUPS[:trust_level_0]]
end
config
elsif topic_id = channel_name[%r{/discourse-presence/whisper/(\d+)}, 1]
Topic.find(topic_id) # Just ensure it exists
PresenceChannel::Config.new(allowed_group_ids: SiteSetting.whispers_allowed_groups_map)
elsif post_id = channel_name[%r{/discourse-presence/edit/(\d+)}, 1]
post = Post.find(post_id)
topic = Topic.find(post.topic_id)
config = PresenceChannel::Config.new
config.allowed_group_ids = [::Group::AUTO_GROUPS[:staff]]
# Locked posts are staff only
next config if post.locked?
# Whispers posts are for allowed whisper groups
if post.whisper?
config.allowed_group_ids += SiteSetting.whispers_allowed_groups_map
next config
end
config.allowed_user_ids = [post.user_id]
if topic.private_message? && post.wiki
# Ignore trust level and just publish to all allowed groups since
# trying to figure out which users in the allowed groups have
# the necessary trust levels can lead to a large array of user ids
# if the groups are big.
config.allowed_user_ids += topic.allowed_users.pluck(:id)
config.allowed_group_ids += topic.allowed_groups.pluck(:id)
elsif post.wiki
config.allowed_group_ids += SiteSetting.edit_wiki_post_allowed_groups_map
end
if !topic.private_message? && SiteSetting.edit_all_post_groups_map.present?
config.allowed_group_ids += SiteSetting.edit_all_post_groups_map
end
if SiteSetting.enable_category_group_moderation? && topic.category
config.allowed_group_ids.push(*topic.category.moderating_groups.pluck(:id))
end
config
end
rescue ActiveRecord::RecordNotFound
nil
end
end