From 71d1e9bc342753256e27a9977420df89f576281a Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:30:19 +0200 Subject: [PATCH 01/24] fix small mistake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 8cc4ad4..bed5a5e 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ nixpkgs, }: let tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release2.tar.gz"; + url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; sha256 = "1h72drqsk690d5i53czpzgs4761wydk49cvz6fq0hgc3q3z214ha"; }; in { From 90ef6829e9fa52de303f8447d981b59fe1f67467 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:31:28 +0200 Subject: [PATCH 02/24] fix small mistake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index bed5a5e..4c0079b 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }: let tarball = fetchTarball { url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; - sha256 = "1h72drqsk690d5i53czpzgs4761wydk49cvz6fq0hgc3q3z214ha"; + sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv7v"; }; in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; From 62bf6f5933159a6bf1beb50f153bb80444a598e2 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:37:07 +0200 Subject: [PATCH 03/24] update flake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 4c0079b..d63bdf0 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }: let tarball = fetchTarball { url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; - sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv7v"; + sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv7f"; }; in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; From 8b618bfdbb14fedf035fac26de71a3be7e32909d Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:39:36 +0200 Subject: [PATCH 04/24] . --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d63bdf0..4c0079b 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }: let tarball = fetchTarball { url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; - sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv7f"; + sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv7v"; }; in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; From 3ed15bae8787e6c9e9749c27e46bf22edd99cfc9 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:41:02 +0200 Subject: [PATCH 05/24] . --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 4c0079b..5c21143 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }: let tarball = fetchTarball { url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; - sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv7v"; + sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv4v"; }; in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; From 255103af130917050fcf95585067030aff75926d Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:42:13 +0200 Subject: [PATCH 06/24] . --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5c21143..313b6d2 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ nixpkgs, }: let tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; + url = "https://git.stuce.ch/stuce/sTodo/releases/download/r33/release3.tar.gz"; sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv4v"; }; in { From 4984a836b4c26c6430771546a36a51813447583b Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:42:50 +0200 Subject: [PATCH 07/24] . --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 313b6d2..5c21143 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ nixpkgs, }: let tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/r33/release3.tar.gz"; + url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv4v"; }; in { From ddda1e7566d5a83ee66bb6ff60e371643467a3cc Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:48:14 +0200 Subject: [PATCH 08/24] . --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5c21143..e2f9eca 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }: let tarball = fetchTarball { url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; - sha256 = "1fr0sr7l6f19g215gh0kgyhnncf4607ydq0cg49psw1yyvx1iv4v"; + sha256 = "1fr0sr7l6f19g215gh0kgyhndcf4607ydq0cg49psw1yyvx1iv4v"; }; in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; From 842b6c89368dc7b77d78bfb2553767be99816948 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:49:15 +0200 Subject: [PATCH 09/24] . --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index e2f9eca..93b11d1 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ nixpkgs, }: let tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/release3.tar.gz"; + url = "https://git.stuce.ch/stuce/sTodo/releases/download/re3/release3.tar.gz"; sha256 = "1fr0sr7l6f19g215gh0kgyhndcf4607ydq0cg49psw1yyvx1iv4v"; }; in { From f058168db9dd26054de9132887a1e62a150e39c6 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 12:50:33 +0200 Subject: [PATCH 10/24] . --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 93b11d1..a0db889 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ nixpkgs, }: let tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/re3/release3.tar.gz"; + url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/r3.tar.gz"; sha256 = "1fr0sr7l6f19g215gh0kgyhndcf4607ydq0cg49psw1yyvx1iv4v"; }; in { From 2bd43b0df57a62bbb72e427c7c51319bb323b19e Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 13:00:28 +0200 Subject: [PATCH 11/24] . --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index a0db889..1953a62 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }: let tarball = fetchTarball { url = "https://git.stuce.ch/stuce/sTodo/releases/download/r3/r3.tar.gz"; - sha256 = "1fr0sr7l6f19g215gh0kgyhndcf4607ydq0cg49psw1yyvx1iv4v"; + sha256 = "1imgbbgbgx2r8qr90mpxlwfy9hcfpdz0sa4nir05jhqx8q1rl0y1"; }; in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; From 1c395150e05c4aacb0afda899324a8d08bbfc42c Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 13:07:29 +0200 Subject: [PATCH 12/24] fixed permissions --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 1953a62..5ca0add 100644 --- a/flake.nix +++ b/flake.nix @@ -24,6 +24,7 @@ installPhase = '' mkdir -p $out/bin cp $src/sTodo $out/bin + chmod go+x $out/bin/sTodo ''; mainProgram = "sTodo"; }; From 1b591f05d8e3393513cf53a7f3a769f5d97eac51 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Thu, 26 Jun 2025 13:11:57 +0200 Subject: [PATCH 13/24] fixed permissions --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5ca0add..d5dd9c9 100644 --- a/flake.nix +++ b/flake.nix @@ -24,7 +24,7 @@ installPhase = '' mkdir -p $out/bin cp $src/sTodo $out/bin - chmod go+x $out/bin/sTodo + chmod ugo+x $out/bin/sTodo ''; mainProgram = "sTodo"; }; From 3511f257e617795a852e00f3e95bc37e8351646d Mon Sep 17 00:00:00 2001 From: stuce Date: Fri, 27 Jun 2025 13:43:56 +0200 Subject: [PATCH 14/24] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 7579f1c..540f08f 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ The goal is to provide a minimalistic and fast todo list that is self hostable. ## Next goals - Make multi user support - [x] Get user by trusted header - - [ ] Add option to enable single user (usefull for vpn single user easy setup) - - [ ] Add menu to add other users to the group + - [x] Add menu to add other users to the group - [ ] make the code more readable by renaming/moving the handlers better - [ ] write a minimal step by step guide to install with nix, - [ ] add some css to make it look nicer From 2353d2fdc9cf4162b7a740cd2b0b2dd6552509a9 Mon Sep 17 00:00:00 2001 From: Stuce Date: Wed, 2 Jul 2025 16:54:52 +0100 Subject: [PATCH 15/24] refactor to make it easier to navigate --- config/routes.yesodroutes | 2 +- src/Application.hs | 4 +- src/Foundation.hs | 22 +++ src/Handler/Group.hs | 88 +++++++++++ src/Handler/TodoEntry.hs | 301 ------------------------------------ src/Handler/Todolist.hs | 89 +++++++++++ src/Handler/TodolistItem.hs | 127 +++++++++++++++ 7 files changed, 330 insertions(+), 303 deletions(-) create mode 100644 src/Handler/Group.hs delete mode 100644 src/Handler/TodoEntry.hs create mode 100644 src/Handler/Todolist.hs create mode 100644 src/Handler/TodolistItem.hs diff --git a/config/routes.yesodroutes b/config/routes.yesodroutes index 86f2549..9d7e398 100644 --- a/config/routes.yesodroutes +++ b/config/routes.yesodroutes @@ -6,7 +6,7 @@ /favicon.ico FaviconR GET /robots.txt RobotsR GET -/ HomeR GET +/ GroupR GET /group/#GroupId TodolistR GET /add AddGroupR POST diff --git a/src/Application.hs b/src/Application.hs index 667b72d..fd6e107 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -44,7 +44,9 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, -- Import all relevant handler modules here. -- Don't forget to add new modules to your cabal file! import Handler.Common -import Handler.TodoEntry +import Handler.Group +import Handler.Todolist +import Handler.TodolistItem -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/src/Foundation.hs b/src/Foundation.hs index 2c365fe..ffb4191 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -191,3 +191,25 @@ unsafeHandler = Unsafe.fakeHandlerGetLogger appLogger -- https://github.com/yesodweb/yesod/wiki/Sending-email -- https://github.com/yesodweb/yesod/wiki/Serve-static-files-from-a-separate-domain -- https://github.com/yesodweb/yesod/wiki/i18n-messages-in-the-scaffolding + + +-- TODO: complete implementation should short circuit if multi user is on but no user exist +getUserId :: HandlerFor App (Key User) +getUserId = do + mName <- lookupHeader "Remote-User" + mUser <- case mName of + -- TODO: make remote user an argument to make it usable not only with authelia, and maybe do a check for good mesure when nothing is found ? + Just name -> runDB $ insertBy $ User (decodeUtf8 name) + Nothing -> runDB $ insertBy $ User "single-user" + case mUser of + Left (Entity userId _) -> return userId + Right userId -> return userId + +dbIfAuth :: GroupId -> ReaderT SqlBackend (HandlerFor App) b -> HandlerFor App b +dbIfAuth groupId action = do + -- TODO: decide if we prefer fast (rawSql) or safe (type safe persist query) after in production latency tests + -- TODO: optimize the persist implementation anyway + user <- getUserId + result <- runDB $ selectFirst [GroupUserUser ==. user, GroupUserGroupId ==. groupId] [] + if isNothing result then permissionDenied "you are not logged in or you dont have access to this group" + else runDB action \ No newline at end of file diff --git a/src/Handler/Group.hs b/src/Handler/Group.hs new file mode 100644 index 0000000..c2f4bb5 --- /dev/null +++ b/src/Handler/Group.hs @@ -0,0 +1,88 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE FlexibleContexts #-} +{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} +{-# HLINT ignore "Replace case with fromMaybe" #-} +module Handler.Group where + +import Import +import Text.Read +import Database.Persist.Sql (fromSqlKey, toSqlKey, rawSql) +getGroupR :: Handler Html +getGroupR = do + userId <- getUserId + groups <- getGroups userId + mToken <- fmap reqToken getRequest + defaultLayout $ do + setTitle "Groups" + [whamlet| + Home +