feat(ldap): manually trigger ldap sync
This commit is contained in:
parent
d56e12d207
commit
83afb6f15f
@ -41,7 +41,7 @@ health-check-delay-notify: "_env:HEALTHCHECK_DELAY_NOTIFY:true"
|
|||||||
health-check-http: "_env:HEALTHCHECK_HTTP:true" # Can we assume, that we can reach ourselves under APPROOT via HTTP (reverse proxies or firewalls might prevent this)?
|
health-check-http: "_env:HEALTHCHECK_HTTP:true" # Can we assume, that we can reach ourselves under APPROOT via HTTP (reverse proxies or firewalls might prevent this)?
|
||||||
health-check-active-job-executors-timeout: "_env:HEALTHCHECK_ACTIVE_JOB_EXECUTORS_TIMEOUT:5"
|
health-check-active-job-executors-timeout: "_env:HEALTHCHECK_ACTIVE_JOB_EXECUTORS_TIMEOUT:5"
|
||||||
|
|
||||||
synchronise-ldap-users-within: "_env:SYNCHRONISE_LDAP_WITHIN:604800"
|
synchronise-ldap-users-within: "_env:SYNCHRONISE_LDAP_WITHIN:1209600"
|
||||||
synchronise-ldap-users-interval: "_env:SYNCHRONISE_LDAP_INTERVAL:3600"
|
synchronise-ldap-users-interval: "_env:SYNCHRONISE_LDAP_INTERVAL:3600"
|
||||||
|
|
||||||
log-settings:
|
log-settings:
|
||||||
|
|||||||
@ -1590,3 +1590,7 @@ SchoolEvaluation: Kursumfragenverwaltung
|
|||||||
SchoolExamOffice: Prüfungsamt
|
SchoolExamOffice: Prüfungsamt
|
||||||
|
|
||||||
ApplicationEditTip: Während des Bewerbungszeitraums können eigene Bewerbungen beliebig angepasst und auch wieder zurückgezogen werden.
|
ApplicationEditTip: Während des Bewerbungszeitraums können eigene Bewerbungen beliebig angepasst und auch wieder zurückgezogen werden.
|
||||||
|
|
||||||
|
BtnAdminSynchroniseLdap: Alle Ldap-Daten synchronisieren
|
||||||
|
LdapSynchronisationQueued: LDAP-Synchronisation angestoßen
|
||||||
|
OldestLdapSynchronisation: Älteste LDAP-Synchronisation
|
||||||
@ -29,15 +29,43 @@ import qualified Handler.Utils.TermCandidates as Candidates
|
|||||||
|
|
||||||
-- import qualified Data.UUID.Cryptographic as UUID
|
-- import qualified Data.UUID.Cryptographic as UUID
|
||||||
|
|
||||||
|
data AdminButton = BtnAdminSynchroniseLdap
|
||||||
|
deriving (Enum, Eq, Ord, Bounded, Read, Show, Generic, Typeable)
|
||||||
|
instance Universe AdminButton
|
||||||
|
instance Finite AdminButton
|
||||||
|
|
||||||
|
nullaryPathPiece ''AdminButton $ camelToPathPiece' 2
|
||||||
|
|
||||||
|
embedRenderMessage ''UniWorX ''AdminButton id
|
||||||
|
|
||||||
|
instance Button UniWorX AdminButton where
|
||||||
|
btnClasses _ = [BCIsButton, BCPrimary]
|
||||||
|
|
||||||
|
|
||||||
getAdminR :: Handler Html
|
getAdminR :: Handler Html
|
||||||
getAdminR = -- do
|
getAdminR = do
|
||||||
siteLayoutMsg MsgAdminHeading $ do
|
((ldapSyncRes, ldapSyncView), ldapSyncEnctype) <- runFormPost $ buttonForm' [BtnAdminSynchroniseLdap]
|
||||||
setTitleI MsgAdminHeading
|
|
||||||
[whamlet|
|
formResult ldapSyncRes $ \case
|
||||||
This shall become the Administrators' overview page.
|
BtnAdminSynchroniseLdap -> do
|
||||||
Its current purpose is to provide links to some important admin functions
|
queueJob' $ JobSynchroniseLdap 1 0 0
|
||||||
|]
|
addMessageI Success MsgLdapSynchronisationQueued
|
||||||
|
redirect AdminR
|
||||||
|
|
||||||
|
oldestLdapSync <- fmap (join . preview (_head . _Value)) . runDB . E.select . E.from $ \user -> do
|
||||||
|
E.orderBy [E.desc . E.isNothing $ user E.^. UserLastLdapSynchronisation, E.asc $ user E.^. UserLastLdapSynchronisation]
|
||||||
|
E.limit 1
|
||||||
|
return $ user E.^. UserLastLdapSynchronisation
|
||||||
|
oldestLdapSync' <- for oldestLdapSync $ formatTime SelFormatDateTime
|
||||||
|
|
||||||
|
|
||||||
|
siteLayoutMsg MsgAdminHeading $ do
|
||||||
|
setTitleI MsgAdminHeading
|
||||||
|
wrapForm $(widgetFile "admin/ldapSync") def
|
||||||
|
{ formAction = Just $ SomeRoute AdminR
|
||||||
|
, formSubmit = FormNoSubmit
|
||||||
|
, formEncoding = ldapSyncEnctype
|
||||||
|
}
|
||||||
|
|
||||||
-- BEGIN - Buttons needed only here
|
-- BEGIN - Buttons needed only here
|
||||||
data ButtonCreate = CreateMath | CreateInf -- Dummy for Example
|
data ButtonCreate = CreateMath | CreateInf -- Dummy for Example
|
||||||
|
|||||||
@ -105,11 +105,12 @@ determineCrontab = execWriterT $ do
|
|||||||
-> do
|
-> do
|
||||||
now <- liftIO getPOSIXTime
|
now <- liftIO getPOSIXTime
|
||||||
let
|
let
|
||||||
|
epochInterval = syncWithin / 2
|
||||||
interval = appSynchroniseLdapUsersInterval
|
interval = appSynchroniseLdapUsersInterval
|
||||||
|
|
||||||
(ldapEpoch, epochNow) = now `divMod'` syncWithin
|
(ldapEpoch, epochNow) = now `divMod'` epochInterval
|
||||||
ldapInterval = epochNow `div'` interval
|
ldapInterval = epochNow `div'` interval
|
||||||
numIntervals = floor $ syncWithin / interval
|
numIntervals = floor $ epochInterval / interval
|
||||||
|
|
||||||
nextIntervals = do
|
nextIntervals = do
|
||||||
let
|
let
|
||||||
@ -118,7 +119,7 @@ determineCrontab = execWriterT $ do
|
|||||||
let
|
let
|
||||||
((+ ldapEpoch) -> nextEpoch, nextInterval) = (ldapInterval + i) `divMod` numIntervals
|
((+ ldapEpoch) -> nextEpoch, nextInterval) = (ldapInterval + i) `divMod` numIntervals
|
||||||
nextIntervalTime
|
nextIntervalTime
|
||||||
= posixSecondsToUTCTime $ fromInteger nextEpoch * syncWithin + fromInteger nextInterval * interval
|
= posixSecondsToUTCTime $ fromInteger nextEpoch * epochInterval + fromInteger nextInterval * interval
|
||||||
return (nextEpoch, nextInterval, nextIntervalTime)
|
return (nextEpoch, nextInterval, nextIntervalTime)
|
||||||
|
|
||||||
forM_ nextIntervals $ \(nextEpoch, nextInterval, nextIntervalTime) -> do
|
forM_ nextIntervals $ \(nextEpoch, nextInterval, nextIntervalTime) -> do
|
||||||
|
|||||||
10
templates/admin/ldapSync.hamlet
Normal file
10
templates/admin/ldapSync.hamlet
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<dl>
|
||||||
|
<dt>
|
||||||
|
_{MsgOldestLdapSynchronisation}
|
||||||
|
<dd>
|
||||||
|
$maybe time <- oldestLdapSync'
|
||||||
|
#{time}
|
||||||
|
$nothing
|
||||||
|
_{MsgNever}
|
||||||
|
|
||||||
|
^{ldapSyncView}
|
||||||
Reference in New Issue
Block a user