diff --git a/app/controllers/public/api/v1/portals/articles_controller.rb b/app/controllers/public/api/v1/portals/articles_controller.rb index a8e22d878..2bbfafcc7 100644 --- a/app/controllers/public/api/v1/portals/articles_controller.rb +++ b/app/controllers/public/api/v1/portals/articles_controller.rb @@ -62,7 +62,7 @@ class Public::Api::V1::Portals::ArticlesController < Public::Api::V1::Portals::B def set_article @article = @portal.articles.find_by(slug: permitted_params[:article_slug]) - @parsed_content = render_article_content(@article.content) + @parsed_content = render_article_content(@article.content.to_s) end def set_category diff --git a/app/javascript/dashboard/components/widgets/WootWriter/FullEditor.vue b/app/javascript/dashboard/components/widgets/WootWriter/FullEditor.vue index 817f6e2b9..976ed3270 100644 --- a/app/javascript/dashboard/components/widgets/WootWriter/FullEditor.vue +++ b/app/javascript/dashboard/components/widgets/WootWriter/FullEditor.vue @@ -79,7 +79,7 @@ export default { created() { state = createState( - this.modelValue, + this.modelValue || '', this.placeholder, this.plugins, { onImageUpload: this.openFileBrowser }, @@ -170,7 +170,7 @@ export default { }, reloadState() { state = createState( - this.modelValue, + this.modelValue || '', this.placeholder, this.plugins, { onImageUpload: this.openFileBrowser }, diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/PortalsArticlesNewPage.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/PortalsArticlesNewPage.vue index 3833573ad..0c541fd19 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/PortalsArticlesNewPage.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/PortalsArticlesNewPage.vue @@ -39,7 +39,7 @@ const createNewArticle = async ({ title, content }) => { if (title) article.value.title = title; if (content) article.value.content = content; - if (!article.value.title || !article.value.content) return; + if (!article.value.title) return; isUpdating.value = true; try { diff --git a/app/models/article.rb b/app/models/article.rb index cb6215157..2a56b006d 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -58,7 +58,7 @@ class Article < ApplicationRecord validates :account_id, presence: true validates :author_id, presence: true validates :title, presence: true - validates :content, presence: true + validates :content, presence: true, if: :published? # ensuring that the position is always set correctly before_create :add_position_to_article diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 161f3541d..5741b95f0 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -10,7 +10,16 @@ RSpec.describe Article do it { is_expected.to validate_presence_of(:account_id) } it { is_expected.to validate_presence_of(:author_id) } it { is_expected.to validate_presence_of(:title) } - it { is_expected.to validate_presence_of(:content) } + + it 'validates content presence only for published articles' do + article = build(:article, portal_id: portal_1.id, author_id: user.id, category_id: category_1.id, + title: 'test', content: nil, status: :draft) + expect(article).to be_valid + + article.status = :published + expect(article).not_to be_valid + expect(article.errors[:content]).to include("can't be blank") + end end describe 'associations' do