diff --git a/app/controllers/page_collections_controller.rb b/app/controllers/page_collections_controller.rb index 450dd16f..a1bd881f 100644 --- a/app/controllers/page_collections_controller.rb +++ b/app/controllers/page_collections_controller.rb @@ -36,10 +36,18 @@ class PageCollectionsController < ApplicationController # Build page types from params checkbox list @page_collection.page_types = page_collection_page_types_param - # TODO publish new collection to followers if public - if @page_collection.save - redirect_to @page_collection, notice: 'Page collection was successfully created.' + # Add a stream event for every user following this user if the collection is public + ContentPageShare.create( + user_id: current_user.id, + content_page_type: PageCollection.name, + content_page_id: @page_collection.reload.id, + shared_at: @page_collection.created_at, + privacy: 'public', + message: "I created a new Collection!" + ) + + redirect_to @page_collection, notice: 'Your collection was successfully created.' else render :new end diff --git a/app/models/page_collection.rb b/app/models/page_collection.rb index c083209d..d70b53d8 100644 --- a/app/models/page_collection.rb +++ b/app/models/page_collection.rb @@ -9,7 +9,7 @@ class PageCollection < ApplicationRecord has_many :page_collection_reports has_one_attached :header_image, dependent: :destroy - validates :header_image, attached: false, + validates :header_image, attached: false, presence: true, content_type: { in: ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'], message: 'must be a PNG, JPG, JPEG, or GIF' @@ -23,6 +23,8 @@ class PageCollection < ApplicationRecord less_than: 500.kilobytes, message: "can't be larger than 500KB" } + + validates :title, presence: true def pending_submissions page_collection_submissions.where(accepted_at: nil).order('submitted_at ASC') @@ -36,9 +38,8 @@ class PageCollection < ApplicationRecord User.where(id: accepted_submissions.pluck(:user_id) - [user.id]) end - # Some quick aliases so we can treat this like a content page in streams: def random_public_image - cover_image + cover_image || header_image end def name title diff --git a/app/views/content/components/_collection_header.html.erb b/app/views/content/components/_collection_header.html.erb index 151e316c..8a77273e 100644 --- a/app/views/content/components/_collection_header.html.erb +++ b/app/views/content/components/_collection_header.html.erb @@ -1,7 +1,7 @@