From cbe73af9bf6248bcc0e733cd0e863ca4a6b94159 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 20 Feb 2026 10:30:12 +0100 Subject: [PATCH] handle public dashboards --- app/controllers/home_controller.rb | 14 ++++++++++++++ app/controllers/moods_controller.rb | 4 ++-- app/models/user.rb | 4 ++++ app/views/home/index.html.haml | 1 + config/environments/development.rb | 4 +++- config/routes.rb | 4 +++- 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 app/controllers/home_controller.rb create mode 100644 app/views/home/index.html.haml diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..3bdb9a4 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,14 @@ +class HomeController < ApplicationController + allow_unauthenticated_access + + def index + user = User.find_by(username: request.subdomain) + if user&.public? + @mode = user.current_mood + @history = user.history + render template: "moods/index" + else + redirect_to dashboard_path + end + end +end diff --git a/app/controllers/moods_controller.rb b/app/controllers/moods_controller.rb index e4611ad..8773247 100644 --- a/app/controllers/moods_controller.rb +++ b/app/controllers/moods_controller.rb @@ -1,6 +1,6 @@ class MoodsController < ApplicationController def index - @mode = current_user.moods.last&.mode || "croisiere" - @history = current_user.history + @mode = Current.user.current_mood + @history = Current.user.history end end diff --git a/app/models/user.rb b/app/models/user.rb index 26e0653..38d463b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -33,4 +33,8 @@ class User < ApplicationRecord def history MoodCalendarService.generate_calendar(moods) end + + def current_mood + self.moods.last&.mode || "croisiere" + end end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml new file mode 100644 index 0000000..eec7b9d --- /dev/null +++ b/app/views/home/index.html.haml @@ -0,0 +1 @@ +%h1 Comment ça KLUK ? diff --git a/config/environments/development.rb b/config/environments/development.rb index d9ab0ef..95c0a1c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -73,5 +73,7 @@ Rails.application.configure do # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. # config.generators.apply_rubocop_autocorrect_after_generate! # - config.hosts << "bipodokrat:3000" + config.hosts << "localhost.localdomain:3000" + config.hosts << "robi.localhost.localdomain:3000" + config.hosts << "marie.localhost.localdomain:3000" end diff --git a/config/routes.rb b/config/routes.rb index 8af9e72..85fba14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,8 +15,10 @@ Rails.application.routes.draw do mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? # Defines the root path route ("/") - root "moods#index" + root "home#index" get "/invite/:token", to: "invitations#edit", as: :edit_invitation patch "/invite/:token", to: "invitations#update", as: :invitation + + get "/moods", to: "moods#index", as: :dashboard end