FEATURE: Show user cards for inactive users (#21387)
It used to return 404 which made the user card render and then quickly disappear.
This commit is contained in:
parent
e25468b2ca
commit
78022e7a5f
|
@ -28,7 +28,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="card-row first-row">
|
<div class="card-row first-row">
|
||||||
<div class="user-card-avatar">
|
<div class="user-card-avatar">
|
||||||
{{#if this.user.profile_hidden}}
|
{{#if this.contentHidden}}
|
||||||
<span class="card-huge-avatar">{{bound-avatar
|
<span class="card-huge-avatar">{{bound-avatar
|
||||||
this.user
|
this.user
|
||||||
"huge"
|
"huge"
|
||||||
|
@ -57,7 +57,7 @@
|
||||||
{{this.newUser}}
|
{{this.newUser}}
|
||||||
{{if this.nameFirst 'full-name' 'username'}}"
|
{{if this.nameFirst 'full-name' 'username'}}"
|
||||||
>
|
>
|
||||||
{{#if this.user.profile_hidden}}
|
{{#if this.contentHidden}}
|
||||||
<span
|
<span
|
||||||
id="discourse-user-card-title"
|
id="discourse-user-card-title"
|
||||||
class="name-username-wrapper"
|
class="name-username-wrapper"
|
||||||
|
@ -193,6 +193,12 @@
|
||||||
<span>{{i18n "user.profile_hidden"}}</span>
|
<span>{{i18n "user.profile_hidden"}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{else if this.user.inactive}}
|
||||||
|
<div class="card-row second-row">
|
||||||
|
<div class="inactive-user">
|
||||||
|
<span>{{i18n "user.inactive_user"}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if this.isSuspendedOrHasBio}}
|
{{#if this.isSuspendedOrHasBio}}
|
||||||
|
@ -292,7 +298,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="card-row metadata-row">
|
<div class="card-row metadata-row">
|
||||||
{{#unless this.user.profile_hidden}}
|
{{#unless this.contentHidden}}
|
||||||
<div class="metadata">
|
<div class="metadata">
|
||||||
{{#if this.user.last_posted_at}}
|
{{#if this.user.last_posted_at}}
|
||||||
<h3><span class="desc">{{i18n "last_post"}}</span>
|
<h3><span class="desc">{{i18n "last_post"}}</span>
|
||||||
|
|
|
@ -178,6 +178,11 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, {
|
||||||
return `group-${primaryGroup}`;
|
return `group-${primaryGroup}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@discourseComputed("user.profile_hidden", "user.inactive")
|
||||||
|
contentHidden(profileHidden, inactive) {
|
||||||
|
return profileHidden || inactive;
|
||||||
|
},
|
||||||
|
|
||||||
_showCallback(username, $target) {
|
_showCallback(username, $target) {
|
||||||
this._positionCard($target);
|
this._positionCard($target);
|
||||||
this.setProperties({ visible: true, loading: true });
|
this.setProperties({ visible: true, loading: true });
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import I18n from "I18n";
|
||||||
import {
|
import {
|
||||||
acceptance,
|
acceptance,
|
||||||
exists,
|
exists,
|
||||||
|
@ -98,3 +99,68 @@ acceptance("User Card - User Status", function (needs) {
|
||||||
assert.notOk(exists(".user-card h3.user-status"));
|
assert.notOk(exists(".user-card h3.user-status"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
acceptance("User Card - Hidden Profile", function (needs) {
|
||||||
|
needs.user();
|
||||||
|
needs.pretender((server, helper) => {
|
||||||
|
server.get("/u/eviltrout/card.json", () =>
|
||||||
|
helper.response({
|
||||||
|
user: {
|
||||||
|
id: 6,
|
||||||
|
username: "eviltrout",
|
||||||
|
name: null,
|
||||||
|
avatar_template: "/letter_avatar_proxy/v4/letter/f/8edcca/{size}.png",
|
||||||
|
profile_hidden: true,
|
||||||
|
title: null,
|
||||||
|
primary_group_name: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("it shows less information", async function (assert) {
|
||||||
|
await visit("/t/this-is-a-test-topic/9");
|
||||||
|
await click('a[data-user-card="eviltrout"]');
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
query(".user-card .name-username-wrapper").innerText,
|
||||||
|
"eviltrout"
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
query(".user-card .profile-hidden").innerText,
|
||||||
|
I18n.t("user.profile_hidden")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
acceptance("User Card - Inactive user", function (needs) {
|
||||||
|
needs.user();
|
||||||
|
needs.pretender((server, helper) => {
|
||||||
|
server.get("/u/eviltrout/card.json", () =>
|
||||||
|
helper.response({
|
||||||
|
user: {
|
||||||
|
id: 6,
|
||||||
|
username: "eviltrout",
|
||||||
|
name: null,
|
||||||
|
avatar_template: "/letter_avatar_proxy/v4/letter/f/8edcca/{size}.png",
|
||||||
|
inactive: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("it shows less information", async function (assert) {
|
||||||
|
await visit("/t/this-is-a-test-topic/9");
|
||||||
|
await click('a[data-user-card="eviltrout"]');
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
query(".user-card .name-username-wrapper").innerText,
|
||||||
|
"eviltrout"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
query(".user-card .inactive-user").innerText,
|
||||||
|
I18n.t("user.inactive_user")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -171,7 +171,8 @@ $avatar_margin: -50px; // negative margin makes avatars extend above cards
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.profile-hidden {
|
.profile-hidden,
|
||||||
|
.inactive-user {
|
||||||
font-size: var(--font-up-1);
|
font-size: var(--font-up-1);
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,12 +110,15 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
@user =
|
@user =
|
||||||
fetch_user_from_params(
|
fetch_user_from_params(
|
||||||
include_inactive:
|
include_inactive: current_user&.staff? || for_card || SiteSetting.show_inactive_accounts,
|
||||||
current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
user_serializer = nil
|
user_serializer = nil
|
||||||
if guardian.can_see_profile?(@user)
|
if !current_user&.staff? && !@user.active?
|
||||||
|
user_serializer = InactiveUserSerializer.new(@user, scope: guardian, root: "user")
|
||||||
|
elsif !guardian.can_see_profile?(@user)
|
||||||
|
user_serializer = HiddenProfileSerializer.new(@user, scope: guardian, root: "user")
|
||||||
|
else
|
||||||
serializer_class = for_card ? UserCardSerializer : UserSerializer
|
serializer_class = for_card ? UserCardSerializer : UserSerializer
|
||||||
user_serializer = serializer_class.new(@user, scope: guardian, root: "user")
|
user_serializer = serializer_class.new(@user, scope: guardian, root: "user")
|
||||||
|
|
||||||
|
@ -125,8 +128,6 @@ class UsersController < ApplicationController
|
||||||
topic_id => Post.secured(guardian).where(topic_id: topic_id, user_id: @user.id).count,
|
topic_id => Post.secured(guardian).where(topic_id: topic_id, user_id: @user.id).count,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
else
|
|
||||||
user_serializer = HiddenProfileSerializer.new(@user, scope: guardian, root: "user")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
track_visit_to_user_profile if !params[:skip_track_visit] && (@user != current_user)
|
track_visit_to_user_profile if !params[:skip_track_visit] && (@user != current_user)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class InactiveUserSerializer < BasicUserSerializer
|
||||||
|
attributes :inactive
|
||||||
|
|
||||||
|
def inactive
|
||||||
|
!object.active?
|
||||||
|
end
|
||||||
|
end
|
|
@ -1124,6 +1124,7 @@ en:
|
||||||
warning: "Are you sure you want to clear your featured topic?"
|
warning: "Are you sure you want to clear your featured topic?"
|
||||||
use_current_timezone: "Use Current Timezone"
|
use_current_timezone: "Use Current Timezone"
|
||||||
profile_hidden: "This user's public profile is hidden."
|
profile_hidden: "This user's public profile is hidden."
|
||||||
|
inactive_user: "This user is no longer active."
|
||||||
expand_profile: "Expand"
|
expand_profile: "Expand"
|
||||||
sr_expand_profile: "Expand profile details"
|
sr_expand_profile: "Expand profile details"
|
||||||
collapse_profile: "Collapse"
|
collapse_profile: "Collapse"
|
||||||
|
|
|
@ -4592,13 +4592,13 @@ RSpec.describe UsersController do
|
||||||
before { sign_in(user1) }
|
before { sign_in(user1) }
|
||||||
|
|
||||||
it "works correctly" do
|
it "works correctly" do
|
||||||
get "/u/#{user1.username}/card.json"
|
get "/u/#{user.username}/card.json"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
json = response.parsed_body
|
json = response.parsed_body
|
||||||
|
|
||||||
expect(json["user"]["associated_accounts"]).to eq(nil) # Not serialized in card
|
expect(json["user"]["associated_accounts"]).to eq(nil) # Not serialized in card
|
||||||
expect(json["user"]["username"]).to eq(user1.username)
|
expect(json["user"]["username"]).to eq(user.username)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns not found when the username doesn't exist" do
|
it "returns not found when the username doesn't exist" do
|
||||||
|
@ -4606,9 +4606,23 @@ RSpec.describe UsersController do
|
||||||
expect(response).not_to be_successful
|
expect(response).not_to be_successful
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns partial response when inactive user" do
|
||||||
|
user.update!(active: false)
|
||||||
|
get "/u/#{user.username}/card.json"
|
||||||
|
expect(response).to be_successful
|
||||||
|
expect(response.parsed_body["user"]["inactive"]).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns partial response when hidden users" do
|
||||||
|
user.user_option.update!(hide_profile_and_presence: true)
|
||||||
|
get "/u/#{user.username}/card.json"
|
||||||
|
expect(response).to be_successful
|
||||||
|
expect(response.parsed_body["user"]["profile_hidden"]).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
it "raises an error on invalid access" do
|
it "raises an error on invalid access" do
|
||||||
Guardian.any_instance.expects(:can_see?).with(user1).returns(false)
|
Guardian.any_instance.expects(:can_see?).with(user).returns(false)
|
||||||
get "/u/#{user1.username}/card.json"
|
get "/u/#{user.username}/card.json"
|
||||||
expect(response).to be_forbidden
|
expect(response).to be_forbidden
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue