Merge pull request #5407 from techAPJ/show-inactive-accounts

FEATURE: new site setting show_inactive_accounts
This commit is contained in:
Arpit Jalan 2017-12-07 20:52:37 +05:30 committed by GitHub
commit c168c5895f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 7 deletions

View File

@ -124,7 +124,7 @@ class ListController < ApplicationController
def topics_by
list_opts = build_topic_list_options
target_user = fetch_user_from_params({ include_inactive: current_user.try(:staff?) }, [:user_stat, :user_option])
target_user = fetch_user_from_params({ include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts) }, [:user_stat, :user_option])
list = generate_list_for("topics_by", target_user, list_opts)
list.more_topics_url = url_for(construct_url_with(:next, list_opts))
list.prev_topics_url = url_for(construct_url_with(:prev, list_opts))

View File

@ -6,7 +6,7 @@ class UserActionsController < ApplicationController
per_chunk = 30
user = fetch_user_from_params(include_inactive: current_user.try(:staff?))
user = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts))
opts = { user_id: user.id,
user: user,

View File

@ -30,7 +30,7 @@ class UserBadgesController < ApplicationController
def username
params.permit [:grouped]
user = fetch_user_from_params
user = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts))
user_badges = user.user_badges
if params[:grouped]

View File

@ -39,7 +39,7 @@ class UsersController < ApplicationController
return redirect_to path('/login') if SiteSetting.hide_user_profiles_from_public && !current_user
@user = fetch_user_from_params(
{ include_inactive: current_user.try(:staff?) },
{ include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts) },
[{ user_profile: :card_image_badge }]
)
@ -203,14 +203,14 @@ class UsersController < ApplicationController
end
def summary
user = fetch_user_from_params
user = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts))
summary = UserSummary.new(user, guardian)
serializer = UserSummarySerializer.new(summary, scope: guardian)
render_json_dump(serializer)
end
def invited
inviter = fetch_user_from_params
inviter = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts))
offset = params[:offset].to_i || 0
filter_by = params[:filter]
@ -226,7 +226,7 @@ class UsersController < ApplicationController
end
def invited_count
inviter = fetch_user_from_params
inviter = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts))
pending_count = Invite.find_pending_invites_count(inviter)
redeemed_count = Invite.find_redeemed_invites_count(inviter)

View File

@ -1449,6 +1449,8 @@ en:
hide_user_profiles_from_public: "Disable user cards, user profiles and user directory for anonymous users."
show_inactive_accounts: "Allow logged in users to browse profiles of inactive accounts."
hide_suspension_reasons: "Don't display suspension reasons publically on user profiles."
user_website_domains_whitelist: "User website will be verified against these domains. Pipe-delimited list."

View File

@ -415,6 +415,8 @@ users:
hide_user_profiles_from_public:
default: false
client: true
show_inactive_accounts:
default: false
user_website_domains_whitelist:
default: ''
type: list

View File

@ -44,6 +44,14 @@ describe UsersController do
expect(response).not_to be_success
end
it 'returns success when show_inactive_accounts is true and user is logged in' do
SiteSetting.show_inactive_accounts = true
log_in_user(user)
inactive = Fabricate(:user, active: false)
get :show, params: { username: inactive.username }, format: :json
expect(response).to be_success
end
it "raises an error on invalid access" do
Guardian.any_instance.expects(:can_see?).with(user).returns(false)
get :show, params: { username: user.username }, format: :json