From 4530c9589531691cc4290c61088b96c5e9134151 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 23 Jan 2023 16:56:46 -0600 Subject: [PATCH 1/8] Implement function to find expiring owners --- LICENSE | 2 +- package.yaml | 1 - src/Owner.hs | 6 ++++++ stack.yaml | 2 +- stack.yaml.lock | 8 ++++---- zgo-backend.cabal | 25 ++++++++++++++++++++++--- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/LICENSE b/LICENSE index 3c7592f..4eb1836 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2022 Vergara Technologies LLC +Copyright (c) 2023 Vergara Technologies LLC ======================================================= Bootstrap Open Source Licence ("BOSL") v. 1.0 diff --git a/package.yaml b/package.yaml index 8c5b0b3..1e68947 100644 --- a/package.yaml +++ b/package.yaml @@ -112,7 +112,6 @@ executables: - warp-tls - warp - tests: zgo-backend-test: main: Spec.hs diff --git a/src/Owner.hs b/src/Owner.hs index fbbeaa6..c9dba61 100644 --- a/src/Owner.hs +++ b/src/Owner.hs @@ -292,3 +292,9 @@ findOwner zaddy = findOne (select ["address" =: zaddy] "owners") findOwnerById :: T.Text -> Action IO (Maybe Document) findOwnerById i = findOne (select ["_id" =: (read (T.unpack i) :: ObjectId)] "owners") + +-- | Function to find Owners about to expire +findExpiringOwners :: UTCTime -> Action IO [Document] +findExpiringOwners now = + rest =<< + find (select ["expiration" =: ["$lte" =: addUTCTime 1728000 now]] "owners") diff --git a/stack.yaml b/stack.yaml index 27fad16..1b263b1 100644 --- a/stack.yaml +++ b/stack.yaml @@ -17,7 +17,7 @@ # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: lts-19.33 +resolver: lts-20.8 #url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/4.yaml # User packages to be built. diff --git a/stack.yaml.lock b/stack.yaml.lock index ad88f96..7ed2b05 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -24,7 +24,7 @@ packages: hackage: blake3-0.2@sha256:d1146b9a51ccfbb0532780778b6d016a614e3d44c05d8c1923dde9a8be869045,2448 snapshots: - completed: - sha256: 6d1532d40621957a25bad5195bfca7938e8a06d923c91bc52aa0f3c41181f2d4 - size: 619204 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/33.yaml - original: lts-19.33 + sha256: bfafe5735ccb74527d754b1f9999ded72d7c3a6c3a88529449661431ccfbd6cc + size: 649327 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/8.yaml + original: lts-20.8 diff --git a/zgo-backend.cabal b/zgo-backend.cabal index 34fee47..009552c 100644 --- a/zgo-backend.cabal +++ b/zgo-backend.cabal @@ -5,9 +5,9 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: zgo-backend -version: 1.1.1 +version: 1.2.0 synopsis: Haskell Back-end for the ZGo point-of-sale application -description: Please see the README on GitLab at +description: Please see the README at category: Web author: Rene Vergara maintainer: rene@vergara.network @@ -22,7 +22,7 @@ extra-source-files: source-repository head type: git - location: https://gitlab.com/pitmutt/zgo-backend + location: https://git.vergara.tech/Vergara_Tech/zgo-backend library exposed-modules: @@ -78,6 +78,7 @@ library executable zgo-backend-exe main-is: Server.hs other-modules: + Notify TokenRefresh Paths_zgo_backend hs-source-dirs: @@ -101,9 +102,27 @@ executable zgo-backend-exe , zgo-backend default-language: Haskell2010 +executable zgo-notifier + main-is: Notify.hs + other-modules: + Server + TokenRefresh + Paths_zgo_backend + hs-source-dirs: + app + ghc-options: -main-is Notify -threaded -rtsopts -with-rtsopts=-N -Wall + build-depends: + base >=4.7 && <5 + , mongoDB + , time + , warp + , zgo-backend + default-language: Haskell2010 + executable zgo-token-refresh main-is: TokenRefresh.hs other-modules: + Notify Server Paths_zgo_backend hs-source-dirs: From 927b213dff3d20968f19bb95f3a714cb52ec5034 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 23 Jan 2023 17:09:54 -0600 Subject: [PATCH 2/8] Prepare library --- zgo-backend.cabal | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/zgo-backend.cabal b/zgo-backend.cabal index 009552c..f7e0ae2 100644 --- a/zgo-backend.cabal +++ b/zgo-backend.cabal @@ -78,7 +78,6 @@ library executable zgo-backend-exe main-is: Server.hs other-modules: - Notify TokenRefresh Paths_zgo_backend hs-source-dirs: @@ -102,27 +101,9 @@ executable zgo-backend-exe , zgo-backend default-language: Haskell2010 -executable zgo-notifier - main-is: Notify.hs - other-modules: - Server - TokenRefresh - Paths_zgo_backend - hs-source-dirs: - app - ghc-options: -main-is Notify -threaded -rtsopts -with-rtsopts=-N -Wall - build-depends: - base >=4.7 && <5 - , mongoDB - , time - , warp - , zgo-backend - default-language: Haskell2010 - executable zgo-token-refresh main-is: TokenRefresh.hs other-modules: - Notify Server Paths_zgo_backend hs-source-dirs: From 789211b06f674051795a3945dcc609b75ea3d938 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 24 Jan 2023 10:18:16 -0600 Subject: [PATCH 3/8] Correct Xero expiration query --- src/Xero.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Xero.hs b/src/Xero.hs index e98921d..14091ce 100644 --- a/src/Xero.hs +++ b/src/Xero.hs @@ -283,8 +283,7 @@ findToken a = findOne (select ["address" =: a] "xerotokens") findExpiringTokens :: UTCTime -> Action IO [Document] findExpiringTokens now = rest =<< - find - (select ["refExpires" =: ["$lte" =: addUTCTime 1728000 now]] "xerotokens") + find (select ["refExpires" =: ["$lte" =: addUTCTime 172800 now]] "xerotokens") -- | Function to request accesstoken requestXeroToken :: Pipe -> T.Text -> Xero -> T.Text -> T.Text -> IO Bool From 1a100fd8ca44f399cfe5ecc35bcdb63f189fe611 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 24 Jan 2023 10:20:00 -0600 Subject: [PATCH 4/8] Correct owner expiration query --- src/Owner.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Owner.hs b/src/Owner.hs index c9dba61..4deb848 100644 --- a/src/Owner.hs +++ b/src/Owner.hs @@ -297,4 +297,4 @@ findOwnerById i = findExpiringOwners :: UTCTime -> Action IO [Document] findExpiringOwners now = rest =<< - find (select ["expiration" =: ["$lte" =: addUTCTime 1728000 now]] "owners") + find (select ["expiration" =: ["$lte" =: addUTCTime 172800 now]] "owners") From a8e1c1b4d8365c6c9f1959bf597558f50bb1a1cc Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 24 Jan 2023 10:21:17 -0600 Subject: [PATCH 5/8] Update Changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1d7ebe..a245aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Owner expiration query +- Xero token expiration query + ## [1.2.0] - 2023-01-09 ### Added From 1e2784f7db56750bb661f9b8ed1f4f3563287692 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 24 Jan 2023 13:27:32 -0600 Subject: [PATCH 6/8] Implement SMTP configuration --- CHANGELOG.md | 4 ++++ src/Config.hs | 12 ++++++++++++ zgo.cfg | 4 ++++ zgotest.cfg | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a245aa0..e89c3d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New configuration fields for SMTP + ### Fixed - Owner expiration query diff --git a/src/Config.hs b/src/Config.hs index 1abfcef..41cda45 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -21,6 +21,10 @@ data Config = , c_useTls :: Bool , c_certificate :: String , c_key :: String + , c_smtpHost :: String + , c_smtpPort :: Int + , c_smtpUser :: String + , c_smtpPwd :: String } deriving (Eq, Show) @@ -39,6 +43,10 @@ loadZGoConfig path = do useTls <- require config "tls" cert <- require config "certificate" key <- require config "key" + mailHost <- require config "smtpHost" + mailPort <- require config "smtpPort" + mailUser <- require config "smtpUser" + mailPwd <- require config "smtpPwd" return $ Config dbHost @@ -53,3 +61,7 @@ loadZGoConfig path = do useTls cert key + mailHost + mailPort + mailUser + mailPwd diff --git a/zgo.cfg b/zgo.cfg index eec2397..aa2bbf8 100644 --- a/zgo.cfg +++ b/zgo.cfg @@ -10,3 +10,7 @@ port = 3000 tls = false certificate = "/path/to/cert.pem" key = "/path/to/key.pem" +mailHost = "127.0.0.1" +mailPort = 1025 +mailUser = "contact@zgo.cash" +mailPwd = "uib3K8BkCPexl_wr5bYfrg" diff --git a/zgotest.cfg b/zgotest.cfg index ca65231..673b5ca 100644 --- a/zgotest.cfg +++ b/zgotest.cfg @@ -10,3 +10,7 @@ port = 3000 tls = false certificate = "/path/to/cert.pem" key = "/path/to/key.pem" +mailHost = "127.0.0.1" +mailPort = 1025 +mailUser = "contact@zgo.cash" +mailPwd = "uib3K8BkCPexl_wr5bYfrg" From f2c04ec8d5723b54d16f2657dcb7b8476bb0d1ec Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 24 Jan 2023 13:54:21 -0600 Subject: [PATCH 7/8] Correct types --- package.yaml | 1 + src/Config.hs | 3 ++- zgo-backend.cabal | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package.yaml b/package.yaml index 1e68947..087c04e 100644 --- a/package.yaml +++ b/package.yaml @@ -58,6 +58,7 @@ library: - blake3 - memory - ghc-prim + - network executables: zgo-backend-exe: diff --git a/src/Config.hs b/src/Config.hs index 41cda45..9455cca 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -6,6 +6,7 @@ import qualified Data.ByteString as BS import Data.Configurator import Data.SecureMem import qualified Data.Text as T +import Network.Socket (PortNumber) data Config = Config @@ -22,7 +23,7 @@ data Config = , c_certificate :: String , c_key :: String , c_smtpHost :: String - , c_smtpPort :: Int + , c_smtpPort :: Integer , c_smtpUser :: String , c_smtpPwd :: String } diff --git a/zgo-backend.cabal b/zgo-backend.cabal index f7e0ae2..9e1060e 100644 --- a/zgo-backend.cabal +++ b/zgo-backend.cabal @@ -58,6 +58,7 @@ library , jwt , memory , mongoDB + , network , quickcheck-instances , random , regex-base From 814d4c9ee542a0449145f94ce2bd32cb00a4cad2 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 24 Jan 2023 14:11:34 -0600 Subject: [PATCH 8/8] Version bump --- CHANGELOG.md | 2 +- package.yaml | 2 +- zgo-backend.cabal | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e89c3d7..2285413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [1.2.1] - 2023-01-24 ### Added diff --git a/package.yaml b/package.yaml index 087c04e..2e21f5b 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: zgo-backend -version: 1.2.0 +version: 1.2.1 git: "https://git.vergara.tech/Vergara_Tech/zgo-backend" license: BOSL author: "Rene Vergara" diff --git a/zgo-backend.cabal b/zgo-backend.cabal index 9e1060e..5f872b2 100644 --- a/zgo-backend.cabal +++ b/zgo-backend.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: zgo-backend -version: 1.2.0 +version: 1.2.1 synopsis: Haskell Back-end for the ZGo point-of-sale application description: Please see the README at category: Web