Skip to content

Commit 37b43d8

Browse files
Copilotmaebeale
andcommitted
Add visitor_featured functionality to dashboard and forms
Co-authored-by: maebeale <[email protected]>
1 parent cb81ae8 commit 37b43d8

20 files changed

+41
-11
lines changed

app/controllers/application_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ class ApplicationController < ActionController::Base
22
# Prevent CSRF attacks by raising an exception.
33
# For APIs, you may want to use :null_session instead.
44
protect_from_forgery with: :exception
5-
before_action :authenticate_user! # ensures only logged-in users can access pages
5+
before_action :authenticate_user!, unless: :public_page?
66

77
private
88

9+
def public_page?
10+
# Allow unauthenticated access to the dashboard index
11+
controller_name == "dashboard" && action_name == "index"
12+
end
13+
914
def after_sign_in_path_for(resource)
1015
user_signed_in? ? authenticated_root_path : unauthenticated_root_path
1116
end

app/controllers/community_news_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def set_community_news
8383
# Strong parameters
8484
def community_news_params
8585
params.require(:community_news).permit(
86-
:title, :body, :published, :featured,
86+
:title, :body, :published, :featured, :visitor_featured,
8787
:reference_url, :youtube_url,
8888
:project_id, :windows_type_id,
8989
:author_id, :created_by_id, :updated_by_id,

app/controllers/dashboard_controller.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,33 @@ class DashboardController < ApplicationController
22
include AdminDashboardCardsHelper
33

44
def index
5+
# Use visitor_featured scope for non-authenticated users, featured for authenticated users
6+
featured_scope = user_signed_in? ? :featured : :visitor_featured
7+
58
workshops = Workshop.includes(:sectors, :categories, :windows_type, :primary_asset, :gallery_assets)
6-
.featured
9+
.send(featured_scope)
710
.published
811
.decorate
912
@workshops = workshops.sort { |x, y| Date.parse(y.date) <=> Date.parse(x.date) }
1013

1114
@resources = Resource.includes(:windows_type, :primary_asset, :gallery_assets)
12-
.featured
15+
.send(featured_scope)
1316
.published
1417
.by_most_viewed(6)
1518
.order(position: :asc, created_at: :desc)
1619
.decorate
1720
@stories = Story.includes(:windows_type, :primary_asset, :gallery_assets)
18-
.featured
21+
.send(featured_scope)
1922
.published
2023
.order(:title)
2124
.decorate
2225
@community_news = CommunityNews.includes(:windows_type, :primary_asset, :gallery_assets)
23-
.featured
26+
.send(featured_scope)
2427
.published
2528
.order(updated_at: :desc)
2629
.decorate
2730
@events = Event.includes(:event_registrations, :primary_asset, :gallery_assets)
28-
.featured
31+
.send(featured_scope)
2932
.published
3033
.order(:start_date)
3134
.decorate

app/controllers/events_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def event_params
8181
:title,
8282
:description,
8383
:featured,
84+
:visitor_featured,
8485
:start_date, :end_date,
8586
:registration_close_date,
8687
:publicly_visible,

app/controllers/resources_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def resource_id_param
135135

136136
def resource_params
137137
params.require(:resource).permit(
138-
:text, :rhino_text, :kind, :male, :female, :title, :featured, :inactive, :url,
138+
:text, :rhino_text, :kind, :male, :female, :title, :featured, :visitor_featured, :inactive, :url,
139139
:agency, :author, :filemaker_code, :windows_type_id, :position,
140140
primary_asset_attributes: [ :id, :file, :_destroy ],
141141
gallery_assets_attributes: [ :id, :file, :_destroy ],

app/controllers/stories_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def set_story
102102
# Strong parameters
103103
def story_params
104104
params.require(:story).permit(
105-
:title, :body, :featured, :published, :youtube_url, :website_url,
105+
:title, :body, :featured, :visitor_featured, :published, :youtube_url, :website_url,
106106
:windows_type_id, :project_id, :workshop_id, :external_workshop_title,
107107
:created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id,
108108
primary_asset_attributes: [ :id, :file, :_destroy ],

app/controllers/workshops_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def view_all_workshops?
202202

203203
def workshop_params
204204
params.require(:workshop).permit(
205-
:title, :featured, :inactive,
205+
:title, :featured, :visitor_featured, :inactive,
206206
:full_name, :user_id, :windows_type_id, :workshop_idea_id,
207207
:month, :year,
208208

app/models/community_news.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CommunityNews < ApplicationRecord
3636

3737
scope :by_most_viewed, ->(limit = 10) { order(view_count: :desc).limit(limit) }
3838
scope :featured, -> { where(featured: true) }
39+
scope :visitor_featured, -> { where(visitor_featured: true) }
3940
scope :category_names, ->(names) { tag_names(:categories, names) }
4041
scope :sector_names, ->(names) { tag_names(:sectors, names) }
4142
scope :community_news_name, ->(community_news_name) {

app/models/event.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Event < ApplicationRecord
3535

3636
scope :by_most_viewed, ->(limit = 10) { order(view_count: :desc).limit(limit) }
3737
scope :featured, -> { where(featured: true) }
38+
scope :visitor_featured, -> { where(visitor_featured: true) }
3839
scope :published, ->(published = nil) { publicly_visible(published) }
3940
scope :publicly_visible, ->(publicly_visible = nil) { publicly_visible ? where(publicly_visible: publicly_visible): where(publicly_visible: true) }
4041
scope :category_names, ->(names) { tag_names(:categories, names) }

app/models/resource.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Resource < ApplicationRecord
7373
scope :category_names, ->(names) { tag_names(:categories, names) }
7474
scope :sector_names, ->(names) { tag_names(:sectors, names) }
7575
scope :featured, ->(featured = nil) { featured.present? ? where(featured: featured) : where(featured: true) }
76+
scope :visitor_featured, -> { where(visitor_featured: true) }
7677
scope :kinds, ->(kinds) {
7778
kinds = Array(kinds).flatten.map(&:to_s)
7879
where(kind: kinds)

0 commit comments

Comments
 (0)