Skip to content

Commit

Permalink
hard deleting pending post also deletes related activity logs
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Jun 24, 2023
1 parent a455ce5 commit 547d6bc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions community/models/pending_posts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ do
local _class_0
local _parent_0 = Model
local _base_0 = {
delete = function(self)
local ActivityLogs
ActivityLogs = require("community.models").ActivityLogs
if _class_0.__parent.__base.delete(self) then
db.delete(ActivityLogs:table_name(), {
object_type = assert(ActivityLogs.object_types.pending_post),
object_id = self.id
})
return true
end
end,
allowed_to_moderate = function(self, user)
do
local parent = self:get_topic() or self:get_category()
Expand Down
9 changes: 9 additions & 0 deletions community/models/pending_posts.moon
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ class PendingPosts extends Model

super opts

delete: =>
import ActivityLogs from require "community.models"
if super!
db.delete ActivityLogs\table_name!, {
object_type: assert ActivityLogs.object_types.pending_post
object_id: @id
}
true

allowed_to_moderate: (user) =>
if parent = @get_topic! or @get_category!
if parent\allowed_to_moderate user
Expand Down
4 changes: 4 additions & 0 deletions spec/models/pending_posts_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ describe "models.pending_posts", ->
it "creates a pending post", ->
factory.PendingPosts!

it "hard deletes pending post", ->
pp = factory.PendingPosts!
pp\delete!

it "promotes pending post", ->
pending = factory.PendingPosts!
post = pending\promote!
Expand Down

0 comments on commit 547d6bc

Please sign in to comment.