diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d7ba8a61b..1e3747a16 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,10 +2,15 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - before_action :authenticate_user! # ensures only logged-in users can access pages + before_action :authenticate_user!, unless: :public_page? private + def public_page? + # Allow unauthenticated access to the dashboard index + controller_name == "dashboard" && action_name == "index" + end + def after_sign_in_path_for(resource) user_signed_in? ? authenticated_root_path : unauthenticated_root_path end diff --git a/app/controllers/community_news_controller.rb b/app/controllers/community_news_controller.rb index 87ce45b3f..cfaabe3f8 100644 --- a/app/controllers/community_news_controller.rb +++ b/app/controllers/community_news_controller.rb @@ -83,7 +83,7 @@ def set_community_news # Strong parameters def community_news_params params.require(:community_news).permit( - :title, :body, :published, :featured, + :title, :body, :published, :featured, :visitor_featured, :reference_url, :youtube_url, :project_id, :windows_type_id, :author_id, :created_by_id, :updated_by_id, diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index c077cc633..a178ed310 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -2,30 +2,33 @@ class DashboardController < ApplicationController include AdminDashboardCardsHelper def index + # Use visitor_featured scope for non-authenticated users, featured for authenticated users + featured_scope = user_signed_in? ? :featured : :visitor_featured + workshops = Workshop.includes(:sectors, :categories, :windows_type, :primary_asset, :gallery_assets) - .featured + .send(featured_scope) .published .decorate @workshops = workshops.sort { |x, y| Date.parse(y.date) <=> Date.parse(x.date) } @resources = Resource.includes(:windows_type, :primary_asset, :gallery_assets) - .featured + .send(featured_scope) .published .by_most_viewed(6) .order(position: :asc, created_at: :desc) .decorate @stories = Story.includes(:windows_type, :primary_asset, :gallery_assets) - .featured + .send(featured_scope) .published .order(:title) .decorate @community_news = CommunityNews.includes(:windows_type, :primary_asset, :gallery_assets) - .featured + .send(featured_scope) .published .order(updated_at: :desc) .decorate @events = Event.includes(:event_registrations, :primary_asset, :gallery_assets) - .featured + .send(featured_scope) .published .order(:start_date) .decorate diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index f6e5b3a1e..7b97e47a9 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -81,6 +81,7 @@ def event_params :title, :description, :featured, + :visitor_featured, :start_date, :end_date, :registration_close_date, :publicly_visible, diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index bddbd9c21..21adfdaed 100644 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -135,7 +135,7 @@ def resource_id_param def resource_params params.require(:resource).permit( - :text, :rhino_text, :kind, :male, :female, :title, :featured, :inactive, :url, + :text, :rhino_text, :kind, :male, :female, :title, :featured, :visitor_featured, :inactive, :url, :agency, :author, :filemaker_code, :windows_type_id, :position, primary_asset_attributes: [ :id, :file, :_destroy ], gallery_assets_attributes: [ :id, :file, :_destroy ], diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 0e6b8007e..2138d1f19 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -102,7 +102,7 @@ def set_story # Strong parameters def story_params params.require(:story).permit( - :title, :body, :featured, :published, :youtube_url, :website_url, + :title, :body, :featured, :visitor_featured, :published, :youtube_url, :website_url, :windows_type_id, :project_id, :workshop_id, :external_workshop_title, :created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id, primary_asset_attributes: [ :id, :file, :_destroy ], diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb index 137d833e3..fe8ad6965 100644 --- a/app/controllers/workshops_controller.rb +++ b/app/controllers/workshops_controller.rb @@ -202,7 +202,7 @@ def view_all_workshops? def workshop_params params.require(:workshop).permit( - :title, :featured, :inactive, + :title, :featured, :visitor_featured, :inactive, :full_name, :user_id, :windows_type_id, :workshop_idea_id, :month, :year, diff --git a/app/models/community_news.rb b/app/models/community_news.rb index d64f35c83..e3fceaeac 100644 --- a/app/models/community_news.rb +++ b/app/models/community_news.rb @@ -36,6 +36,7 @@ class CommunityNews < ApplicationRecord scope :by_most_viewed, ->(limit = 10) { order(view_count: :desc).limit(limit) } scope :featured, -> { where(featured: true) } + scope :visitor_featured, -> { where(visitor_featured: true) } scope :category_names, ->(names) { tag_names(:categories, names) } scope :sector_names, ->(names) { tag_names(:sectors, names) } scope :community_news_name, ->(community_news_name) { diff --git a/app/models/event.rb b/app/models/event.rb index bd5fc1500..230051e4f 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -35,6 +35,7 @@ class Event < ApplicationRecord scope :by_most_viewed, ->(limit = 10) { order(view_count: :desc).limit(limit) } scope :featured, -> { where(featured: true) } + scope :visitor_featured, -> { where(visitor_featured: true) } scope :published, ->(published = nil) { publicly_visible(published) } scope :publicly_visible, ->(publicly_visible = nil) { publicly_visible ? where(publicly_visible: publicly_visible): where(publicly_visible: true) } scope :category_names, ->(names) { tag_names(:categories, names) } diff --git a/app/models/resource.rb b/app/models/resource.rb index 30329883a..83c0ba562 100644 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -73,6 +73,7 @@ class Resource < ApplicationRecord scope :category_names, ->(names) { tag_names(:categories, names) } scope :sector_names, ->(names) { tag_names(:sectors, names) } scope :featured, ->(featured = nil) { featured.present? ? where(featured: featured) : where(featured: true) } + scope :visitor_featured, -> { where(visitor_featured: true) } scope :kinds, ->(kinds) { kinds = Array(kinds).flatten.map(&:to_s) where(kind: kinds) diff --git a/app/models/story.rb b/app/models/story.rb index c7078f1ca..7617d868f 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -42,6 +42,7 @@ class Story < ApplicationRecord # Scopes scope :by_most_viewed, ->(limit = 10) { order(view_count: :desc).limit(limit) } scope :featured, -> { where(featured: true) } + scope :visitor_featured, -> { where(visitor_featured: true) } scope :category_names, ->(names) { tag_names(:categories, names) } scope :sector_names, ->(names) { tag_names(:sectors, names) } scope :story_name, ->(story_name) { diff --git a/app/models/workshop.rb b/app/models/workshop.rb index c8dc49fd6..9cfb03443 100644 --- a/app/models/workshop.rb +++ b/app/models/workshop.rb @@ -119,6 +119,7 @@ class Workshop < ApplicationRecord scope :sector_names, ->(names) { tag_names(:sectors, names) } scope :created_by_id, ->(created_by_id) { where(user_id: created_by_id) } scope :featured, -> { where(featured: true) } + scope :visitor_featured, -> { where(visitor_featured: true) } scope :legacy, -> { where(legacy: true) } scope :published, ->(published = nil) { published.to_s.present? ? where(inactive: !published) : where(inactive: false) } diff --git a/app/views/community_news/_form.html.erb b/app/views/community_news/_form.html.erb index 5ee0121f3..d7e2fcdd9 100644 --- a/app/views/community_news/_form.html.erb +++ b/app/views/community_news/_form.html.erb @@ -10,6 +10,7 @@