Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/community_news_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def event_params
:title,
:description,
:featured,
:visitor_featured,
:start_date, :end_date,
:registration_close_date,
:publicly_visible,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ],
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ],
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/workshops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions app/models/community_news.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
1 change: 1 addition & 0 deletions app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app/models/workshop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
1 change: 1 addition & 0 deletions app/views/community_news/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<%= 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" } %>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<div class="admin-only bg-blue-100 flex items-center mt-6 md:mt-0">
<%= 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" } %>
</div>
<% end %>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/views/resources/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<div class="flex items-center gap-6">
<div><%= f.input :featured, as: :boolean, wrapper: false, label_html: { class: "inline" } %></div>
<div><%= f.input :visitor_featured, as: :boolean, wrapper: false, label: "Visitor Featured?", label_html: { class: "inline" } %></div>

<div>
<%= f.input :inactive, as: :boolean,
Expand Down
2 changes: 2 additions & 0 deletions app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<!-- Profile dropdown -->
<% 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 %>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/views/stories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div class="flex gap-4">
<%= 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" } %>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions app/views/workshops/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

<div class="flex gap-x-6 items-center">
<%= 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 %>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions db/migrate/20260120005922_add_visitor_featured_to_models.rb
Original file line number Diff line number Diff line change
@@ -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