mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -603,10 +603,23 @@ RSpec.describe ListController do
|
||||
expect(json["topic_list"]["topics"].size).to eq(2)
|
||||
end
|
||||
|
||||
it "returns 404 if `hide_profile_and_presence` user option is checked" do
|
||||
user.user_option.update_columns(hide_profile_and_presence: true)
|
||||
get "/topics/created-by/#{user.username}.json"
|
||||
expect(response.status).to eq(404)
|
||||
context 'when `hide_profile_and_presence` is true' do
|
||||
before do
|
||||
user.user_option.update_columns(hide_profile_and_presence: true)
|
||||
end
|
||||
|
||||
it "returns 404" do
|
||||
get "/topics/created-by/#{user.username}.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "should respond with a list when `allow_users_to_hide_profile` is false" do
|
||||
SiteSetting.allow_users_to_hide_profile = false
|
||||
get "/topics/created-by/#{user.username}.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = response.parsed_body
|
||||
expect(json["topic_list"]["topics"].size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1752,6 +1752,17 @@ describe PostsController do
|
||||
get "/u/#{user.username}/activity.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "succeeds when `allow_users_to_hide_profile` is false" do
|
||||
user.user_option.update_columns(hide_profile_and_presence: true)
|
||||
SiteSetting.allow_users_to_hide_profile = false
|
||||
|
||||
get "/u/#{user.username}/activity.rss"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
get "/u/#{user.username}/activity.json"
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#latest' do
|
||||
|
||||
@@ -10,15 +10,6 @@ describe UserActionsController do
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
|
||||
it "returns a 404 for a user with a hidden profile" do
|
||||
UserActionManager.enable
|
||||
post = Fabricate(:post)
|
||||
post.user.user_option.update_column(:hide_profile_and_presence, true)
|
||||
|
||||
get "/user_actions.json", params: { username: post.user.username }
|
||||
expect(response.code).to eq("404")
|
||||
end
|
||||
|
||||
it 'renders list correctly' do
|
||||
UserActionManager.enable
|
||||
post = create_post
|
||||
@@ -88,5 +79,25 @@ describe UserActionsController do
|
||||
expect(parsed["no_results_help"]).to eq(I18n.t("user_activity.no_bookmarks.others"))
|
||||
end
|
||||
|
||||
context 'hidden profiles' do
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
|
||||
before do
|
||||
UserActionManager.enable
|
||||
post.user.user_option.update_column(:hide_profile_and_presence, true)
|
||||
end
|
||||
|
||||
it "returns a 404" do
|
||||
get "/user_actions.json", params: { username: post.user.username }
|
||||
expect(response.code).to eq("404")
|
||||
end
|
||||
|
||||
it "succeeds when `allow_users_to_hide_profile` is false" do
|
||||
SiteSetting.allow_users_to_hide_profile = false
|
||||
get "/user_actions.json", params: { username: post.user.username }
|
||||
expect(response.code).to eq("200")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,13 +44,6 @@ describe UserBadgesController do
|
||||
expect(parsed["user_badges"].length).to eq(1)
|
||||
end
|
||||
|
||||
it "returns 404 if `hide_profile_and_presence` user option is checked" do
|
||||
user.user_option.update_columns(hide_profile_and_presence: true)
|
||||
|
||||
get "/user-badges/#{user.username}.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it 'returns user_badges for a user with period in username' do
|
||||
user.update!(username: "myname.test")
|
||||
get "/user-badges/#{user.username}", xhr: true
|
||||
@@ -77,6 +70,24 @@ describe UserBadgesController do
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["user_badges"].first.has_key?('count')).to eq(true)
|
||||
end
|
||||
|
||||
context 'hidden profiles' do
|
||||
before do
|
||||
user.user_option.update_columns(hide_profile_and_presence: true)
|
||||
end
|
||||
|
||||
it "returns 404 if `hide_profile_and_presence` user option is checked" do
|
||||
get "/user-badges/#{user.username}.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "returns user_badges if `allow_users_to_hide_profile` is false" do
|
||||
SiteSetting.allow_users_to_hide_profile = false
|
||||
|
||||
get "/user-badges/#{user.username}.json"
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'create' do
|
||||
|
||||
@@ -2868,12 +2868,24 @@ describe UsersController do
|
||||
expect(json["user_summary"]["post_count"]).to eq(0)
|
||||
end
|
||||
|
||||
it "returns 404 for a hidden profile" do
|
||||
user = Fabricate(:user)
|
||||
user.user_option.update_column(:hide_profile_and_presence, true)
|
||||
context '`hide_profile_and_presence` user option is checked' do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
get "/u/#{user.username_lower}/summary.json"
|
||||
expect(response.status).to eq(404)
|
||||
before do
|
||||
user.user_option.update_columns(hide_profile_and_presence: true)
|
||||
end
|
||||
|
||||
it "returns 404" do
|
||||
get "/u/#{user.username_lower}/summary.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "returns summary info if `allow_users_to_hide_profile` is false" do
|
||||
SiteSetting.allow_users_to_hide_profile = false
|
||||
|
||||
get "/u/#{user.username_lower}/summary.json"
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3353,13 +3365,28 @@ describe UsersController do
|
||||
expect(response).to redirect_to '/login'
|
||||
end
|
||||
|
||||
it "does not include hidden profiles" do
|
||||
user2.user_option.update(hide_profile_and_presence: true)
|
||||
get "/user-cards.json?user_ids=#{user.id},#{user2.id}"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body["users"]
|
||||
context '`hide_profile_and_presence` user option is checked' do
|
||||
before do
|
||||
user2.user_option.update_columns(hide_profile_and_presence: true)
|
||||
end
|
||||
|
||||
expect(parsed.map { |u| u["username"] }).to contain_exactly(user.username)
|
||||
it "does not include hidden profiles" do
|
||||
get "/user-cards.json?user_ids=#{user.id},#{user2.id}"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body["users"]
|
||||
|
||||
expect(parsed.map { |u| u["username"] }).to contain_exactly(user.username)
|
||||
end
|
||||
|
||||
it "does include hidden profiles when `allow_users_to_hide_profile` is false" do
|
||||
SiteSetting.allow_users_to_hide_profile = false
|
||||
|
||||
get "/user-cards.json?user_ids=#{user.id},#{user2.id}"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body["users"]
|
||||
|
||||
expect(parsed.map { |u| u["username"] }).to contain_exactly(user.username, user2.username)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user