FEATURE - SiteSetting to disable user option to hide their profiles and presences (#10885)

* FEATURE - SiteSetting to disable user option to hide their profiles and presences
This commit is contained in:
jbrw
2020-10-09 17:18:44 -04:00
committed by GitHub
parent 195119b77c
commit ac31fe8321
13 changed files with 139 additions and 34 deletions

View File

@ -102,7 +102,18 @@ const Presence = EmberObject.extend({
},
publish(state, whisper, postId, staffOnly) {
if (this.get("currentUser.hide_profile_and_presence")) {
// NOTE: `user_option` is the correct place to get this value from, but
// it may not have been set yet. It will always have been set directly
// on the currentUser, via the preloaded_json payload.
// TODO: Remove this when preloaded_json is refactored.
let hiddenProfile = this.get(
"currentUser.user_option.hide_profile_and_presence"
);
if (hiddenProfile === undefined) {
hiddenProfile = this.get("currentUser.hide_profile_and_presence");
}
if (hiddenProfile && this.get("siteSettings.allow_users_to_hide_profile")) {
return;
}

View File

@ -155,7 +155,8 @@ after_initialize do
def ensure_presence_enabled
if !SiteSetting.presence_enabled ||
current_user.user_option.hide_profile_and_presence?
(SiteSetting.allow_users_to_hide_profile &&
current_user.user_option.hide_profile_and_presence?)
raise Discourse::NotFound
end

View File

@ -45,6 +45,15 @@ describe ::Presence::PresencesController do
expect(response.status).to eq(404)
end
it 'returns the right response when user disables the presence feature and allow_users_to_hide_profile is disabled' do
user.user_option.update_column(:hide_profile_and_presence, true)
SiteSetting.allow_users_to_hide_profile = false
post '/presence/publish.json', params: { topic_id: public_topic.id, state: 'replying' }
expect(response.status).to eq(200)
end
it 'returns the right response when the presence site settings is disabled' do
SiteSetting.presence_enabled = false