0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/plugins/discourse-rewind/app/services/discourse_rewind/toggle_share.rb
Martin Brennan c4d4ed890f
FEATURE: Share Rewind reports publicly by default and allow for making them private (#36587)
This commit introduces a toggle which is enabled by default
to share the Discourse Rewind report publicly.

**IMPORTANT NOTES**:

*  Users with "Hide my public profile" enabled
**will not** have their Rewind shared publicly by default,
and will not be able to unless they disable "Hide my public
profile" first.
* This commit also excludes personal messages from best
   posts and best topics reports so sensitive message data
   will never be shown, but other report data like reaction
   counts may still be based off of PM data

Other users who cannot see the rewind will see an error.

We always show a message saying which  user you are looking
at when viewing another user's Rewind.

Users can also unshare their rewind from Rewind preferences.
2025-12-16 09:29:35 +10:00

38 lines
1 KiB
Ruby
Vendored

# frozen_string_literal: true
module DiscourseRewind
# Service responsible for toggling the user's public sharing preference for Rewind.
#
# @example
# ::DiscourseRewind::ToggleShare.call(guardian: guardian)
#
class ToggleShare
include Service::Base
# @!method self.call(guardian:)
# @param [Guardian] guardian
# @return [Service::Base::Context]
policy :user_not_hiding_profile
step :toggle_share_preference
private
def user_not_hiding_profile(guardian:)
if guardian.user.user_option.hide_profile &&
!guardian.user.user_option.discourse_rewind_share_publicly
false
else
# Even if hiding profile, it's fine to turn off rewind public sharing.
true
end
end
def toggle_share_preference(guardian:)
guardian.user.user_option.update!(
discourse_rewind_share_publicly: !guardian.user.user_option.discourse_rewind_share_publicly,
)
context[:shared] = guardian.user.user_option.discourse_rewind_share_publicly
end
end
end