tag which conflicts with inline entity tags/mentions. + #Remove it and ensure a trailing space. + #Yuck + sanitized + .strip + .delete_prefix("
") + .delete_suffix("
") + .concat(" ") + end end end diff --git a/server/app/models/activities/delete_comment.rb b/server/app/models/activities/delete_comment.rb new file mode 100644 index 000000000..141da0d13 --- /dev/null +++ b/server/app/models/activities/delete_comment.rb @@ -0,0 +1,39 @@ +module Activities + class DeleteComment < Base + attr_reader :comment + + def initialize(comment:, originating_user:, organization_id:) + super(organization_id: organization_id, user: originating_user) + @comment = comment + end + + private + def create_activity + @activity = DeleteCommentActivity.create!( + subject: comment, + user: user, + organization: organization, + ) + end + + def call_actions + cmd = Actions::DeleteComment.new( + comment: comment, + originating_user: user, + organization_id: organization&.id + ) + + cmd.perform + + if !cmd.succeeded? + raise StandardError.new(cmd.errors.join(', ')) + end + + events << cmd.events + end + + def linked_entities + comment + end + end +end diff --git a/server/app/models/comment.rb b/server/app/models/comment.rb index 24d11e8a4..81db5d732 100644 --- a/server/app/models/comment.rb +++ b/server/app/models/comment.rb @@ -27,6 +27,10 @@ def link end end + def deleted? + deleted_at.present? + end + private def mark_events_unlinkable if self.commentable.respond_to?(:events) diff --git a/server/app/models/delete_comment_activity.rb b/server/app/models/delete_comment_activity.rb new file mode 100644 index 000000000..00077518c --- /dev/null +++ b/server/app/models/delete_comment_activity.rb @@ -0,0 +1,7 @@ +class DeleteCommentActivity < Activity + has_one_linked :comment + + def generate_verbiage + 'deleted' + end +end diff --git a/server/db/migrate/20240823181636_add_deleted_at_to_comments.rb b/server/db/migrate/20240823181636_add_deleted_at_to_comments.rb new file mode 100644 index 000000000..0a4d008b2 --- /dev/null +++ b/server/db/migrate/20240823181636_add_deleted_at_to_comments.rb @@ -0,0 +1,5 @@ +class AddDeletedAtToComments < ActiveRecord::Migration[7.1] + def change + add_column :comments, :deleted_at, :datetime, null: true + end +end diff --git a/server/db/schema.rb b/server/db/schema.rb index 7deaa0a4a..5a648770f 100644 --- a/server/db/schema.rb +++ b/server/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_08_22_155113) do +ActiveRecord::Schema[7.1].define(version: 2024_08_23_181636) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -303,6 +303,7 @@ t.string "role", default: "comments" t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil + t.datetime "deleted_at" t.index ["commentable_id"], name: "index_comments_on_commentable_id" t.index ["commentable_type"], name: "index_comments_on_commentable_type" t.index ["user_id"], name: "index_comments_on_user_id"