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 @@
<%= f.input :published, as: :boolean, wrapper_html: { class: "flex items-center" } %> <%= f.input :featured, as: :boolean, wrapper_html: { class: "flex items-center" } %> + <%= f.input :visitor_featured, as: :boolean, label: "Visitor Featured?", wrapper_html: { class: "flex items-center" } %>
diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index c4faa636c..3632ac370 100644 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -21,6 +21,7 @@
<%= f.input :publicly_visible, as: :boolean, label: "Publicly visible?", wrapper_html: { class: "ml-2" } %> <%= f.input :featured, as: :boolean, label: "Featured?", wrapper_html: { class: "ml-2" } %> + <%= f.input :visitor_featured, as: :boolean, label: "Visitor Featured?", wrapper_html: { class: "ml-2" } %>
<% end %> diff --git a/app/views/resources/_form.html.erb b/app/views/resources/_form.html.erb index 87c5f8f03..5086cacb1 100644 --- a/app/views/resources/_form.html.erb +++ b/app/views/resources/_form.html.erb @@ -16,6 +16,7 @@
<%= f.input :featured, as: :boolean, wrapper: false, label_html: { class: "inline" } %>
+
<%= f.input :visitor_featured, as: :boolean, wrapper: false, label: "Visitor Featured?", label_html: { class: "inline" } %>
<%= f.input :inactive, as: :boolean, diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index e43ce3687..1ca8b99e8 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -65,6 +65,8 @@ <% if current_user %> <%= render "shared/navbar_user" %> + <% else %> + <%= link_to "Log in", new_user_session_path, class: "text-white bg-primary hover:bg-white/10 px-4 py-2 rounded-md text-sm font-medium transition-colors" %> <% end %>
diff --git a/app/views/stories/_form.html.erb b/app/views/stories/_form.html.erb index 55825eb3a..bd3029b3e 100644 --- a/app/views/stories/_form.html.erb +++ b/app/views/stories/_form.html.erb @@ -13,6 +13,7 @@
<%= f.input :published, as: :boolean, wrapper_html: { class: "flex items-center" } %> <%= f.input :featured, as: :boolean, wrapper_html: { class: "flex items-center" } %> + <%= f.input :visitor_featured, as: :boolean, label: "Visitor Featured?", wrapper_html: { class: "flex items-center" } %>
diff --git a/app/views/workshops/_form.html.erb b/app/views/workshops/_form.html.erb index 6923c5194..0e8ef3860 100644 --- a/app/views/workshops/_form.html.erb +++ b/app/views/workshops/_form.html.erb @@ -77,6 +77,7 @@
<%= f.input :featured, as: :boolean, wrapper: false %> + <%= f.input :visitor_featured, as: :boolean, label: "Visitor Featured?", wrapper: false %> <%= f.input :inactive, as: :boolean, label: "Hidden?", wrapper: false %>
diff --git a/config/routes.rb b/config/routes.rb index a888cd316..b3d90a47a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -125,7 +125,7 @@ # Wrap Devise routes in a scope for unauthenticated users devise_scope :user do unauthenticated do - root to: "devise/sessions#new", as: :unauthenticated_root + root to: "dashboard#index", as: :unauthenticated_root end end end diff --git a/db/migrate/20260120005922_add_visitor_featured_to_models.rb b/db/migrate/20260120005922_add_visitor_featured_to_models.rb new file mode 100644 index 000000000..7e1146cc9 --- /dev/null +++ b/db/migrate/20260120005922_add_visitor_featured_to_models.rb @@ -0,0 +1,9 @@ +class AddVisitorFeaturedToModels < ActiveRecord::Migration[8.1] + def change + add_column :workshops, :visitor_featured, :boolean, default: false, null: false + add_column :resources, :visitor_featured, :boolean, default: false, null: false + add_column :stories, :visitor_featured, :boolean, default: false, null: false + add_column :community_news, :visitor_featured, :boolean, default: false, null: false + add_column :events, :visitor_featured, :boolean, default: false, null: false + end +end