Compare commits

...

34 Commits

Author SHA1 Message Date
nek0 1b8c913c58 version bump 2 months ago
nek0 d67f517e04 make cofnigurable sendmail and from-email 2 months ago
sand20 e7069228a8 Strip ghc from final build 2 months ago
Astro 63191180a5 yammat.cabal: add extensions DataKinds, FlexibleInstances 1 year ago
Astro 29a34b4759 flake.nix: remove ${system} from hydraJobs schema 1 year ago
Astro 38ecd78db1 flake.nix: switch hydraJobs schema 1 year ago
Astro 618f72ad55 flake.lock: update 1 year ago
Astro a11f1f4e2f flake.nix: add hydraJobs against all ghc versions 1 year ago
Astro 75b3d7ca98 s/stdenv.lib/lib/ 1 year ago
Astro d91c4563aa nixos-module.nix: fix syntax 1 year ago
astro dcf2bf0984 Merge branch 'config+' of nek0/yammat into nix 1 year ago
nek0 40badca197 typo 1 year ago
nek0 f989233828 read default config from file 1 year ago
Astro fa86ef2526 flake.nix: remove flake-utils again 1 year ago
Astro 3b82d37bd2 flakify 1 year ago
nek0 f7e29b172a execute service with config 1 year ago
Astro f476e773df sendMail: add new partDisposition 1 year ago
Astro fa81445701 nixos-module: make sendmail available 1 year ago
nek0 4e2ead93ea add configuration option 1 year ago
Astro 5685fffd86 Foundation: fix schema in approotRequest 1 year ago
Astro 68507c174a nixos-module.nix: init 2 years ago
Astro 3bb3e3bb0d yammat.cabal: add newly required language extensions 2 years ago
Astro 0a0e9e424c pkg.nix: copy config+static subdirs, link client_session_key.aes in postInstall 2 years ago
Astro dcddc1eec6 pkg.nix: reduce rebuilds by filtering out *.nix 2 years ago
Astro d5ec922ab7 pkg.nix: rename from default.nix, add sensible default.nix 2 years ago
rys ostrovid 94b5dc497a
Merge pull request #126 from astro/master 2 years ago
Astro faad483f00 default.nix: don't build docs 2 years ago
Astro 90108556ca default.nix: disable tests 2 years ago
Astro d913465154 test: fix pending signatures 2 years ago
Astro cd6676944d TestImport: update withApp type 2 years ago
Astro 98d709752d .cabal: list test modules 2 years ago
Astro 4b91f54e3e more updates 2 years ago
Astro 46d9cfd81e TestImport: fix dup export 2 years ago
Astro 9d7a9f2b2a update for newer ghc+yesod 2 years ago
  1. 3
      Foundation.hs
  2. 2
      Handler/Buy.hs
  3. 16
      Handler/Common.hs
  4. 14
      Handler/NewUser.hs
  5. 4
      Handler/Transfer.hs
  6. 5
      Model.hs
  7. 9
      Settings.hs
  8. 3
      config/settings.yml
  9. 41
      default.nix
  10. 25
      flake.lock
  11. 46
      flake.nix
  12. 72
      nixos-module.nix
  13. 28
      pkg.nix
  14. 4
      shell.nix
  15. 2
      test/Handler/HomeSpec.hs
  16. 7
      test/Handler/SupplierActionsSpec.hs
  17. 7
      test/Handler/SupplierSpec.hs
  18. 8
      test/TestImport.hs
  19. 13
      yammat.cabal

@ -26,6 +26,7 @@ import Yesod.Auth.Hardcoded
import Yesod.Auth.Message
import qualified Data.Text as T
import Network.Wai as Wai
import Network.Wai.Request (appearsSecure)
import Data.List (tail)
import Data.List.Split
import Text.Printf
@ -96,7 +97,7 @@ approotRequest master req =
Nothing -> appRoot $ appSettings master
where
prefix =
if isSecure req
if appearsSecure req
then "https://"
else "http://"

@ -113,7 +113,7 @@ notifyUser user bev quant price master = do
"VERDAMMT NOCHMAL!!!"
else
return ""
liftIO $ sendMail email "Einkauf beim Matematen"
liftIO $ sendMail master email "Einkauf beim Matematen"
[lt|
Hallo #{userIdent user},

@ -191,7 +191,7 @@ checkAlert bId oldamount = do
master <- getYesod
let tos = appEmail $ appSettings master
mapM_ (\to ->
liftIO $ sendMail to "Niedriger Bestand"
liftIO $ sendMail master to "Niedriger Bestand"
[stext|
Hallo,
@ -204,22 +204,24 @@ Dein Matemat
|]
) tos
sendMail :: MonadIO m => Text -> Text -> TL.Text -> m ()
sendMail to subject body =
liftIO $ renderSendMail
sendMail :: MonadIO m => App -> Text -> Text -> TL.Text -> m ()
sendMail master to subject body = liftIO $ do
let sendmailLocation = appSendmailLocation $ appSettings master
fromMail = appFromMail $ appSettings master
renderSendMailCustom sendmailLocation []
Mail
{ mailFrom = Address Nothing "noreply"
, mailTo = [Address Nothing to]
, mailCc = []
, mailBcc = []
, mailHeaders = [("Subject", subject),
("List-Id", "\"Matemat\" <matemat@matemat.hq.c3d2.de>")]
("List-Id", "\"Matemat\" <"<> (fromString fromMail) <>">")]
, mailParts =[[Part
{ partType = "text/plain; charset=utf-8"
, partEncoding = None
, partFilename = Nothing
, partHeaders = []
, partContent = E.encodeUtf8 body
, partContent = PartContent $ E.encodeUtf8 body
, partDisposition = DefaultDisposition
}]]
}

@ -119,7 +119,8 @@ postModifyUserR uId =
, UserAvatar =. userConfAvatar uc
, UserPin =. userConfPIN uc
]
liftIO $ notify user (userConfEmail uc)
master <- getYesod
liftIO $ notify user (userConfEmail uc) master
handleBarcodes (Left uId) (fromMaybe [] $ userConfBarcode uc)
setMessageI MsgUserEdited
redirect $ SelectR uId
@ -144,12 +145,13 @@ modifyUserForm user bs = UserConf
ents <- runDB $ selectList [] [Asc AvatarIdent]
optionsPairs $ map (\ent -> ((avatarIdent $ entityVal ent), entityKey ent)) ents
notify :: User -> Maybe Text -> IO ()
notify user email
notify :: User -> Maybe Text -> App -> IO ()
notify user email master
| (userEmail user) == email = return ()
| otherwise = case userEmail user of
Just address -> sendMail address "Profiländerung"
[stext|
Just address ->
sendMail master address "Profiländerung"
[stext|
Hallo #{userIdent user},
deine Profileinstellungen wurden geändert.
@ -158,5 +160,5 @@ Nur damit du Bescheid weißt.
Grüße,
der Matemat
|]
|]
Nothing -> return ()

@ -76,7 +76,7 @@ transferForm = areq currencyField (bfs MsgValue) (Just 0)
notify :: User -> User -> Int -> App -> IO ()
notify sender rcpt amount master = do
when (isJust $ userEmail sender) $
liftIO $ sendMail (fromJust $ userEmail sender) "Guthabentransfer beim Matematen"
liftIO $ sendMail master (fromJust $ userEmail sender) "Guthabentransfer beim Matematen"
[stext|
Hallo #{userIdent sender}
@ -87,7 +87,7 @@ Viele Grüße,
Dein Matemat
|]
when (isJust $ userEmail rcpt) $
liftIO $ sendMail (fromJust $ userEmail rcpt) "Guthabentransfer eingetroffen"
liftIO $ sendMail master (fromJust $ userEmail rcpt) "Guthabentransfer eingetroffen"
[stext|
Hallo #{userIdent rcpt}

@ -13,6 +13,11 @@
--
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
module Model where
import ClassyPrelude.Yesod

@ -20,7 +20,7 @@
-- declared in the Foundation.hs file.
module Settings where
import ClassyPrelude.Yesod hiding (throw)
import ClassyPrelude.Yesod
import Control.Exception (throw)
import Data.Aeson (Result (..), fromJSON, withObject, (.!=),
(.:?))
@ -80,6 +80,10 @@ data AppSettings = AppSettings
-- ^ Block user creation
, appAdminCreds :: Maybe Login
-- ^ optional admin credentials
, appSendmailLocation :: FilePath
-- ^ location of system's sendmail command
, appFromMail :: String
-- ^ Email address from which the yammat appears to send emails
}
data Login = Login
@ -125,6 +129,9 @@ instance FromJSON AppSettings where
appAdminCreds <- o .:? "credentials"
appSendmailLocation <- o .: "sendmail-location"
appFromMail <- o .: "from-mail"
return AppSettings {..}
-- | Settings for 'widgetFile', such as which template languages to support and

@ -36,6 +36,9 @@ copyright_link: "https://github.com/nek0/yammat"
block_users: false
sendmail-location: "/usr/sbin/sendmail"
from-mail: "matemat@matemat.hq.c3d2.de"
# optional administrative credentials.
# credentials:
# login: "admin"

@ -1,38 +1,3 @@
{ mkDerivation, aeson, base, base64-bytestring, blaze-builder
, blaze-markup, bytestring, classy-prelude, classy-prelude-conduit
, classy-prelude-yesod, conduit, conduit-extra, containers
, cryptohash, data-default, directory, fast-logger, file-embed
, HDBC, HDBC-postgresql, hjsmin, hspec, http-conduit, JuicyPixels
, JuicyPixels-scale-dct, mime-mail, monad-control, monad-logger
, persistent, persistent-mysql, persistent-postgresql
, persistent-template, resourcet, safe, safe-exceptions
, shakespeare, split, stdenv, template-haskell, text, time
, transformers, unordered-containers, vector, wai, wai-extra
, wai-logger, warp, yaml, yesod, yesod-auth, yesod-core, yesod-form
, yesod-static, yesod-test
}:
mkDerivation {
pname = "yammat";
version = "0.0.8";
src = ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
aeson base base64-bytestring blaze-builder blaze-markup bytestring
classy-prelude classy-prelude-conduit classy-prelude-yesod conduit
conduit-extra containers cryptohash data-default directory
fast-logger file-embed HDBC HDBC-postgresql hjsmin http-conduit
JuicyPixels JuicyPixels-scale-dct mime-mail monad-control
monad-logger persistent persistent-postgresql persistent-template
safe safe-exceptions shakespeare split template-haskell text time
unordered-containers vector wai wai-extra wai-logger warp yaml
yesod yesod-auth yesod-core yesod-form yesod-static
];
executableHaskellDepends = [ base ];
testHaskellDepends = [
base classy-prelude classy-prelude-yesod hspec monad-logger
persistent persistent-mysql resourcet transformers yesod yesod-core
yesod-test
];
license = stdenv.lib.licenses.agpl3;
}
{ pkgs ? import <nixpkgs> {} }:
pkgs.haskellPackages.callPackage ./pkg.nix {}

@ -0,0 +1,25 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1615511049,
"narHash": "sha256-WNaFbCaqUTWnvCSOh2CDGuHu0IKLY0JODNv1I9cWeFo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d2145883676216077b1abddcc5e640d1fba66371",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

@ -0,0 +1,46 @@
{
description = "Matemat";
outputs = { self, nixpkgs }:
let
systems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
forSystems = nixpkgs.lib.genAttrs systems;
in rec {
packages = forSystems (system: {
yammat = nixpkgs.legacyPackages.${system}.haskellPackages.callPackage ./pkg.nix {};
});
defaultPackage = forSystems (system:
self.packages.${system}.yammat
);
checks = packages;
hydraJobs =
let
system = builtins.head systems;
pkgs = nixpkgs.legacyPackages.${system};
ghcVersions =
builtins.filter (p:
builtins.match "ghc.+" p != null
) (builtins.attrNames pkgs.haskell.packages);
in
builtins.foldl' (checks: ghcVersion:
let
haskellPackages = pkgs.haskell.packages.${ghcVersion};
inherit (pkgs.haskell.lib.compose) justStaticExecutables;
in
checks // {
"${ghcVersion}".yammat = justStaticExecutables(haskellPackages.callPackage ./pkg.nix {});
}
) {} ghcVersions;
devShell = forSystems (system:
import ./shell.nix {
nixpkgs = nixpkgs.legacyPackages.${system};
}
);
nixosModule = import ./nixos-module.nix;
};
}

@ -0,0 +1,72 @@
{ config, lib, pkgs, ... }:
let
yammat = import ./. { inherit pkgs; };
cfg = config.services.yammat;
in
{
options.services.yammat = with lib; {
enable = mkEnableOption "Yammat";
user = mkOption {
type = types.str;
default = "yammat";
description = "System user to run Yammat";
};
group = mkOption {
type = types.str;
default = "yammat";
description = "System group to run Yammat";
};
config = mkOption {
type = types.lines;
default = builtins.readFile ./config/settings.yml;
description = "Configuration for Yammat";
};
};
config = lib.mkIf cfg.enable {
users.users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
};
users.groups.${cfg.group} = {};
services.postgresql = {
enable = true;
ensureDatabases = [ "yammat" ];
ensureUsers = [ {
name = cfg.user;
ensurePermissions = {
"DATABASE yammat" = "ALL PRIVILEGES";
};
} ];
};
systemd.services.yammat = {
description = "Yammat Matemat";
after = [ "postgresql.service" ];
requires = [ "postgresql.service" ];
wantedBy = [ "multi-user.target" ];
environment = {
APPROOT = yammat;
STATIC_DIR = "${yammat}/static";
PGHOST = "";
};
# make sendmail available
path = [ "/run/wrappers" ];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
WorkingDirectory = yammat;
ExecStart = "${yammat}/bin/yammat /etc/yammat.yml";
};
};
environment.etc."yammat.yml" = {
enable = true;
text = cfg.config;
};
};
}

@ -1,4 +1,4 @@
{ mkDerivation, dontHaddock, aeson, base, base64-bytestring, blaze-builder
{ mkDerivation, aeson, base, base64-bytestring, blaze-builder
, blaze-markup, bytestring, classy-prelude, classy-prelude-conduit
, classy-prelude-yesod, conduit, conduit-extra, containers
, cryptohash, data-default, directory, fast-logger, file-embed
@ -6,27 +6,22 @@
, JuicyPixels-scale-dct, mime-mail, monad-control, monad-logger
, persistent, persistent-mysql, persistent-postgresql
, persistent-template, resourcet, safe, safe-exceptions
, shakespeare, split, stdenv, template-haskell, text, time
, shakespeare, split, lib, template-haskell, text, time
, transformers, unordered-containers, vector, wai, wai-extra
, wai-logger, warp, yaml, yesod, yesod-auth, yesod-core, yesod-form
, yesod-static, yesod-test
}:
let
fixed-classy-prelude = dontHaddock classy-prelude;
fixed-classy-prelude-yesod = dontHaddock classy-prelude-yesod;
in
mkDerivation {
pname = "yammat";
version = "0.0.8";
src = ./.;
src = builtins.filterSource (
path: type: builtins.match ".*\.nix" path == null
) ./.;
isLibrary = true;
isExecutable = true;
doHaddock = false;
libraryHaskellDepends = [
aeson base base64-bytestring blaze-builder blaze-markup bytestring
fixed-classy-prelude classy-prelude-conduit fixed-classy-prelude-yesod conduit
classy-prelude classy-prelude-conduit classy-prelude-yesod conduit
conduit-extra containers cryptohash data-default directory
fast-logger file-embed HDBC HDBC-postgresql hjsmin http-conduit
JuicyPixels JuicyPixels-scale-dct mime-mail monad-control
@ -36,11 +31,16 @@ mkDerivation {
yesod yesod-auth yesod-core yesod-form yesod-static
];
executableHaskellDepends = [ base ];
doCheck = false;
testHaskellDepends = [
base fixed-classy-prelude fixed-classy-prelude-yesod hspec monad-logger
base classy-prelude classy-prelude-yesod hspec monad-logger
persistent persistent-mysql resourcet transformers yesod yesod-core
yesod-test
];
license = stdenv.lib.licenses.agpl3;
doCheck = false;
doHaddock = false;
license = lib.licenses.agpl3;
postInstall = ''
cp -ar config static $out/
ln -s /tmp/yammat_session_key.aes $out/config/client_session_key.aes
'';
}

@ -12,7 +12,7 @@ let
, JuicyPixels-scale-dct, mime-mail, monad-control, monad-logger
, persistent, persistent-mysql, persistent-postgresql
, persistent-template, resourcet, safe, safe-exceptions
, shakespeare, split, stdenv, template-haskell, text, time
, shakespeare, split, lib, template-haskell, text, time
, transformers, unordered-containers, vector, wai, wai-extra
, wai-logger, warp, yaml, yesod, yesod-auth, yesod-core, yesod-form
, yesod-static, yesod-test
@ -40,7 +40,7 @@ let
persistent persistent-mysql resourcet transformers yesod yesod-core
yesod-test
];
license = stdenv.lib.licenses.agpl3;
license = lib.licenses.agpl3;
};
haskellPackages = if compiler == "default"

@ -12,7 +12,7 @@ spec = withApp $ do
request $ do
setMethod "POST"
setUrl HomeR
addNonce
addToken
fileByLabel "Choose a file" "test/Spec.hs" "text/plain" -- talk about self-reference
byLabel "What's on the file?" "Some Content"

@ -3,8 +3,7 @@ module Handler.SupplierActionsSpec (spec) where
import TestImport
spec :: Spec
spec = withApp $ do
spec =
describe "getSupplierActionsR" $ do
error "Spec not implemented: getSupplierActionsR"
xit "Spec not implemented: getSupplierActionsR" $ do
pending

@ -3,8 +3,7 @@ module Handler.SupplierSpec (spec) where
import TestImport
spec :: Spec
spec = withApp $ do
spec =
describe "getSupplierR" $ do
error "Spec not implemented: getSupplierR"
xit "Spec not implemented: getSupplierR" $ do
pending

@ -4,8 +4,8 @@ module TestImport
) where
import Application (makeFoundation)
import ClassyPrelude as X
import Database.Persist as X hiding (get)
import ClassyPrelude as X hiding (Handler)
import Database.Persist as X hiding (get, delete, deleteBy)
import Database.Persist.Sql (SqlPersistM, runSqlPersistMPool)
import Foundation as X
import Model as X
@ -18,10 +18,10 @@ runDB query = do
pool <- fmap appConnPool getTestYesod
liftIO $ runSqlPersistMPool query pool
withApp :: SpecWith App -> Spec
withApp :: SpecWith (App, a -> a) -> Spec
withApp = before $ do
settings <- loadAppSettings
["config/test-settings.yml", "config/settings.yml"]
[]
ignoreEnv
makeFoundation settings
(, id) <$> makeFoundation settings

@ -1,5 +1,5 @@
name: yammat
version: 0.0.8
version: 0.0.9
cabal-version: >= 1.8
build-type: Simple
license: AGPL-3
@ -65,6 +65,11 @@ library
ViewPatterns
TupleSections
RecordWildCards
DerivingStrategies
StandaloneDeriving
UndecidableInstances
DataKinds
FlexibleInstances
build-depends: base >= 4 && < 5
, yesod >= 1.6
@ -164,6 +169,12 @@ test-suite test
ViewPatterns
TupleSections
other-modules: Handler.CommonSpec
Handler.HomeSpec
Handler.SupplierActionsSpec
Handler.SupplierSpec
TestImport
build-depends: base
, yammat
, yesod-test >= 1.4.2

Loading…
Cancel
Save