Skip to content
Snippets Groups Projects
Commit 817e08fa authored by pabois's avatar pabois
Browse files

Merge branch 'master' of github.com:noesya/osuny

parents 77ca6723 126a16a9
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ class Communication::Website::GithubFile < ApplicationRecord
after_destroy :remove_from_github
def publish
return unless github.valid?
return unless valid? && github.valid?
add_to_batch(github)
if github.commit_batch(github_commit_message)
update_column :github_path, manifest_data[:generated_path]
......@@ -36,6 +36,7 @@ class Communication::Website::GithubFile < ApplicationRecord
handle_asynchronously :publish, queue: 'default'
def add_to_batch(github)
return unless valid?
github.add_to_batch github_params
add_media_to_batch(github)
end
......@@ -120,4 +121,9 @@ class Communication::Website::GithubFile < ApplicationRecord
item[:identifier] == manifest_identifier
}
end
def valid?
return about.published? if about_type == 'Communication::Website::Post'
true
end
end
......@@ -55,6 +55,8 @@ class Communication::Website::Post < ApplicationRecord
validates :title, presence: true
validates :slug, uniqueness: { scope: :communication_website_id }
before_validation :set_published_at, if: :published_changed?
scope :ordered, -> { order(published_at: :desc, created_at: :desc) }
scope :recent, -> { order(published_at: :desc).limit(5) }
......@@ -72,4 +74,8 @@ class Communication::Website::Post < ApplicationRecord
def slug_unavailable?(slug)
self.class.unscoped.where(communication_website_id: self.communication_website_id, slug: slug).where.not(id: self.id).exists?
end
def set_published_at
self.published_at = published? ? Time.zone.now : nil
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment