작은 액션 게시물에 관리자 도구/렌치 적용

Would it be possible to include admin tools on the small action posts (the closed/pinned etc. messages?) Such as allowing for permanent deletion, changing of ownership and the like.

I’m the only admin user on my site, and while these posts are hidden away as soft deletions, they’re still kind of ugly - even as an staff user. Sometimes I jot things down in soft-deleted messages too before making rough drafts into proper posts, so it becomes a bit difficult to distinguish these from the small action messages whenever I click in to show hidden replies.

I also don’t really want to use CSS in a component - because there are a few instances where I want the small action message to be displayed such as letting users know I’ve archived or closed specific topics. I just don’t want the streams of pinned/unpinned/pinned/unpinned etc - we’ve all seen this before so I think you get the gist of what I mean.

For context, I run a small site with about 10 users which I basically use as a digital library for various notes and media (I do events promotion as a hobby so the page publishing is super useful for permanent linking of information).

My guess is that the wrench wasn’t implemented on small action posts on purpose because most sites would rather have staff be able to audit trail who has done what to a post, which makes sense. But I do think it could be useful in specific circumstances, maybe as an additional plugin.

It’s also my first time posting on this site :hugs:. I think this is the right place for this request but apologies if not!

3개의 좋아요

Great first post. It’s extremely helpful to have the specific context behind requests like this, so thank you for including that.

For your use case, is “permanent delete” the main thing you’re looking for that you can’t do currently?

Or do you have a need for any of the other actions? (If so, which ones and why?)

2개의 좋아요

Thanks for your kind words, I appreciate it!

Permanent deletion is definitely the main one. I can’t personally think of a specific use case for changing the ownership of a small action, or the other admin options that are usually available on posts.

I can delete these messages through rails, but of course that involves finding the specific post ID and accessing the console so it would be a lot more convenient within the UI.

I’m somewhat familiar with component creation (not too familiar with plugin design yet but I do want to learn soon!). If I can get this working in a component - if that’s even possible - then I’ll definitely provide a GitHub link for the community!

2개의 좋아요

조금 전에 이 게시물을 떠올랐습니다. 혹시 다른 분들도 이 문제를 해결하는 데 도움이 될 수 있을 것 같아, 제가 결국 이 문제에 대해 적용한 해결책을 공유합니다!


원치 않는 작은 작업(small action) 게시물 삭제하기

이 작업을 수행하려면 아래 rails 스크립트가 필요합니다. 저는 이를 smalldelete.rb라고 이름 붙여 컨테이너 내부의 /var/www/discourse/script 경로에 배치했습니다.

또한, 삭제하려는 모든 작은 작업 게시물에 실제 게시물 본문 부분에 delete라는 단어를 넣어두어야 합니다. 이는 유지하고 싶은 게시물과 구별하기 위한 것입니다. 자동 올림(Auto Bump) 게시물에 제가 말씀드린 내용이 어떻게 적용되는지 예시를 보여드리겠습니다:

필요하다면 p.raw.strip.downcase == "delete" 라인을 다른 키워드로 수정하여 이 키워드를 변경할 수 있습니다.

smalldelete.rb 스크립트


class TopicCleaner
  def self.delete_small_actions(topic_id, dry_run: false)
    topic = Topic.find_by(id: topic_id)
    unless topic
      puts "Topic #{topic_id} not found"
      return
    end

    posts = topic.posts.where(post_type: Post.types[:small_action])
    to_delete = posts.select { |p| p.raw.strip.downcase == "delete" }

    if to_delete.empty?
      puts "No small action posts with 'delete' found in topic #{topic_id}"
      return
    end

    puts "Found #{to_delete.size} matching posts in topic ##{topic_id}"

    to_delete.each do |post|
      if dry_run
        puts "Would PERMANENTLY delete post ##{post.id} (created #{post.created_at}, by #{post.user.username})"
      else
        post.destroy()
        puts "🗑️ Permanently deleted post ##{post.id}"
      end
    end

    puts dry_run ? "Dry run complete — no posts deleted." : "Finished permanent cleanup of topic #{topic_id}"
  end
end

이 스크립트는 ID로 주제를 찾은 후, 해당 주제 내의 모든 게시물이 정의된 키워드만 포함하고 있는지 확인합니다. 조건이 충족되면 해당 특정 게시물을 삭제 대상으로 지정합니다.


스크립트가 설정되면 rails 콘솔로 이동하여 이를 로드할 수 있습니다:

load Rails.root.join("script/smalldelete.rb")

그리고 마지막으로 다음을 실행할 수 있습니다.

TopicCleaner.delete_small_actions(topic_id, dry_run: false)

dry_run 플래그도 포함되어 있으며, 원할 경우 영구적으로 삭제될 항목이 정확히 무엇인지 목록으로 확인할 수 있습니다.


물론 이러한 변경 사항은 완전히 외관상의 문제일 뿐이며, 소프트 삭제된 게시물은 본래 스태프가 아닌 멤버들에게 표시되지 않으므로 콘텐츠 측면에서는 차이가 없습니다.

하지만 저는 모든 것을 깔끔하고 정갈하게 유지하는 것을 특히 좋아하기 때문에, 일부 포럼 운영자가 이를 활용하고 싶어 할 수 있는 경우를 충분히 이해할 수 있습니다!

1개의 좋아요