mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 12:00:27 +08:00
FEATURE: add user_suspended
attribute in post serialize. (#16413)
This PR will include `suspended` attribute in post serializer to check it in post widget and add a CSS class name. Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>
This commit is contained in:
parent
01107e418e
commit
c863244382
@ -84,6 +84,7 @@ export function transformBasicPost(post) {
|
||||
readCount: post.readers_count,
|
||||
canPublishPage: false,
|
||||
trustLevel: post.trust_level,
|
||||
userSuspended: post.user_suspended,
|
||||
};
|
||||
|
||||
_additionalAttributes.forEach((a) => (postAtts[a] = post[a]));
|
||||
|
@ -849,6 +849,9 @@ export default createWidget("post", {
|
||||
} else {
|
||||
classNames.push("regular");
|
||||
}
|
||||
if (attrs.userSuspended) {
|
||||
classNames.push("user-suspended");
|
||||
}
|
||||
if (addPostClassesCallbacks) {
|
||||
for (let i = 0; i < addPostClassesCallbacks.length; i++) {
|
||||
let pluginClasses = addPostClassesCallbacks[i].call(this, attrs);
|
||||
|
@ -246,6 +246,15 @@ acceptance("Topic", function (needs) {
|
||||
assert.ok(exists(".category-moderator"), "it has a class applied");
|
||||
assert.ok(exists(".d-icon-shield-alt"), "it shows an icon");
|
||||
});
|
||||
|
||||
test("Suspended user posts", async function (assert) {
|
||||
await visit("/t/topic-from-suspended-user/54077");
|
||||
|
||||
assert.ok(
|
||||
exists(".topic-post.user-suspended > #post_1"),
|
||||
"it has a class applied"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
acceptance("Topic featured links", function (needs) {
|
||||
|
@ -6251,6 +6251,7 @@ export default {
|
||||
edit_reason: null,
|
||||
can_view_edit_history: true,
|
||||
wiki: false,
|
||||
user_suspended: true,
|
||||
},
|
||||
{
|
||||
id: 419,
|
||||
|
@ -86,7 +86,8 @@ class PostSerializer < BasicPostSerializer
|
||||
:excerpt,
|
||||
:reviewable_id,
|
||||
:reviewable_score_count,
|
||||
:reviewable_score_pending_count
|
||||
:reviewable_score_pending_count,
|
||||
:user_suspended
|
||||
|
||||
def initialize(object, opts)
|
||||
super(object, opts)
|
||||
@ -549,6 +550,14 @@ class PostSerializer < BasicPostSerializer
|
||||
can_review_topic?
|
||||
end
|
||||
|
||||
def user_suspended
|
||||
true
|
||||
end
|
||||
|
||||
def include_user_suspended?
|
||||
object.user&.suspended?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def can_review_topic?
|
||||
|
@ -88,6 +88,26 @@ describe PostSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
context "a post by a suspended user" do
|
||||
def subject
|
||||
PostSerializer.new(post, scope: Guardian.new(Fabricate(:admin)), root: false).as_json
|
||||
end
|
||||
|
||||
it "serializes correctly" do
|
||||
expect(subject[:user_suspended]).to be_nil
|
||||
|
||||
post.user.update!(
|
||||
suspended_till: 1.month.from_now,
|
||||
)
|
||||
|
||||
expect(subject[:user_suspended]).to eq(true)
|
||||
|
||||
freeze_time (2.months.from_now)
|
||||
|
||||
expect(subject[:user_suspended]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "display_username" do
|
||||
let(:user) { post.user }
|
||||
let(:serializer) { PostSerializer.new(post, scope: Guardian.new, root: false) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user