discourse/plugins/chat/app/models/chat_channel_archive.rb
Martin Brennan 5d9306a6fc FIX: Improve error reporting and failure modes for channel archiving (#19791)
There was an issue with channel archiving, where at times the topic
creation could fail which left the archive in a bad state, as read-only
instead of archived. This commit does several things:

* Changes the ChatChannelArchiveService to validate the topic being
  created first and if it is not valid report the topic creation errors
  in the PM we send to the user
* Changes the UI message in the channel with the archive status to reflect
  that topic creation failed
* Validate the new topic when starting the archive process from the UI,
  and show the validation errors to the user straight away instead of
  creating the archive record and starting the process

This also fixes another issue in the discourse_dev config which was
failing because YAML parsing does not enable all classes by default now,
which was making the seeding rake task for chat fail.
2023-01-25 13:48:49 +02:00

43 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class ChatChannelArchive < ActiveRecord::Base
belongs_to :chat_channel
belongs_to :archived_by, class_name: "User"
belongs_to :destination_topic, class_name: "Topic"
def complete?
self.archived_messages >= self.total_messages && self.chat_channel.chat_messages.count.zero?
end
def failed?
!complete? && self.archive_error.present?
end
def new_topic?
self.destination_topic_title.present?
end
end
# == Schema Information
#
# Table name: chat_channel_archives
#
# id :bigint not null, primary key
# chat_channel_id :bigint not null
# archived_by_id :integer not null
# destination_topic_id :integer
# destination_topic_title :string
# destination_category_id :integer
# destination_tags :string is an Array
# total_messages :integer not null
# archived_messages :integer default(0), not null
# archive_error :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_chat_channel_archives_on_chat_channel_id (chat_channel_id)
#