Skip to content

A platform for community discussion. Free, open, simple.

FIX: Recover user deleted post (#30145)

Sérgio Saquetimb8325f2190a8
diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.js
index d6264dac0ba..d07a4d00ea4 100644
--- a/app/assets/javascripts/discourse/app/models/post.js
+++ b/app/assets/javascripts/discourse/app/models/post.js
@@ -171,14 +171,13 @@ export default class Post extends RestModel {
@alias("can_edit") canEdit; // for compatibility with existing code
@equal("trust_level", 0) new_user;
@equal("post_number", 1) firstPost;
- @or("deleted_at", "deletedViaTopic") deleted;
+ @and("firstPost", "topic.deleted_at") deletedViaTopic; // mark fist post as deleted if topic was deleted
+ @or("deleted_at", "deletedViaTopic") deleted; // post is either highlighted as deleted or hidden/removed from the post stream
@not("deleted") notDeleted;
+ @or("deleted_at", "user_deleted") recoverable; // post or content still can be recovered
@propertyEqual("topic.details.created_by.id", "user_id") topicOwner;
@alias("topic.details.created_by.id") topicCreatedById;
- // Posts can show up as deleted if the topic is deleted
- @and("firstPost", "topic.deleted_at") deletedViaTopic;
-
constructor() {
super(...arguments);
@@ -314,14 +313,6 @@ export default class Post extends RestModel {
return this.firstPost && !!this.topic.details.can_publish_page;
}
- get canRecover() {
- return this.deleted && this.can_recover;
- }
-
- get isRecovering() {
- return !this.deleted && this.can_recover;
- }
-
get canRecoverTopic() {
return this.firstPost && this.deleted && this.topic.details.can_recover;
}
@@ -330,6 +321,14 @@ export default class Post extends RestModel {
return this.firstPost && !this.deleted && this.topic.details.can_recover;
}
+ get canRecover() {
+ return !this.canRecoverTopic && this.recoverable && this.can_recover;
+ }
+
+ get isRecovering() {
+ return !this.isRecoveringTopic && !this.recoverable && this.can_recover;
+ }
+
get canToggleLike() {
return !!this.likeAction?.get("canToggle");
}
diff --git a/spec/system/post_menu_spec.rb b/spec/system/post_menu_spec.rb
index 4e49c252c6e..879a6a70d6b 100644
--- a/spec/system/post_menu_spec.rb
+++ b/spec/system/post_menu_spec.rb
@@ -213,16 +213,30 @@ describe "Post menu", type: :system do
expect(topic_page).to have_no_post_action_button(post, :recover)
expect(topic_page).to have_no_post_action_button(post2, :recover)
- # do not display the recover button because when `user` deletes teh post. it's just marked for deletion
- # `user` cannot recover it.
+ # display the recover button when the POST was user deleted
+ # `post2` is marked for deletion and displays text (post deleted by author) but `user` as the author can
+ # recover it.
sign_in(user)
topic_page.visit_topic(post.topic)
+ expect(topic_page).to have_no_post_action_button(post, :recover)
+ expect(topic_page).to have_post_action_button(post2, :recover)
+
+ # do not display the recover button for other users when the post was USER deleted
+ sign_in(Fabricate(:user))
+ topic_page.visit_topic(post.topic)
+ expect(topic_page).to have_no_post_action_button(post, :recover)
+ expect(topic_page).to have_no_post_action_button(post2, :recover)
+
+ # do not display the recover button even for admins when the post was USER deleted, because the action
+ # displayed for the admin is deleting the post to remove it from the post stream
+ sign_in(admin)
+ topic_page.visit_topic(post.topic)
expect(topic_page).to have_no_post_action_button(post, :recover)
expect(topic_page).to have_no_post_action_button(post2, :recover)
- # display the recover button for the deleted post because an admin is logged
+ # display the recover button for an admin when the post was deleted
PostDestroyer.new(admin, post).destroy
sign_in(admin)