fix(avs): match mobile number better between LDAP and AVS

This commit is contained in:
Steffen Jost 2024-06-25 17:36:33 +02:00
parent e4fa1ddd68
commit f108c6cfec
3 changed files with 49 additions and 17 deletions

View File

@ -357,12 +357,12 @@ updateAvsUserByADC newAvsDataContact@(AvsDataContact apid newAvsPersonInfo newAv
(mkCheckUpdate CU_API_UserLdapPrimaryKey)
[mkCheckUpdate CU_API_UserCompanyPersonalNumber]
let per_ups = mapMaybe (mkUpdate' usr newAvsPersonInfo oldAvsPersonInfo . mkCheckUpdate)
[ CU_API_UserFirstName
, CU_API_UserSurname
, CU_API_UserDisplayName
, CU_API_UserBirthday
, CU_API_UserMobile
, CU_API_UserMatrikelnummer
[ CU_API_UserFirstName
, CU_API_UserSurname
, CU_API_UserDisplayName
, CU_API_UserBirthday
, CU_API_UserMobile
, CU_API_UserMatrikelnummer
-- , CU_API_UserCompanyPersonalNumber -- needs special treatment, see ldap_ups above
]
eml_up = mkUpdate usr newAvsDataContact oldAvsDataContact $ mkCheckUpdate CU_ADC_UserDisplayEmail -- Email updates erfolgen nur, wenn identisch. Für Firmen-Email leer lassen.

View File

@ -31,7 +31,7 @@ import Data.Aeson
import Data.Aeson.Types as Aeson
import Utils.Postal (validPostAddressText)
import Utils.Mail (pickValidEmail)
import Utils.Mail (pickValidEmail, canonicalPhone)
{-
@ -557,14 +557,14 @@ _avsInfoDisplayName = lens g s
instance FromJSON AvsPersonInfo where
parseJSON = withObject "AvsPersonInfo" $ \o -> AvsPersonInfo
<$> o .: "PersonsNo" -- NOTE: PersonsNo, not PersonNo as elsewhere
<*> o .: "FirstName"
<*> o .: "LastName"
<*> o .: "RampLicence"
<*> o .:? "DateOfBirth"
<*> o .:?! "PersonEMail"
<*> o .:?! "PersonMobilePhoneNo"
<*> o .:?! "InternalPersonalNo"
<$> o .: "PersonsNo" -- NOTE: PersonsNo, not PersonNo as elsewhere
<*> o .: "FirstName"
<*> o .: "LastName"
<*> o .: "RampLicence"
<*> o .:? "DateOfBirth"
<*> o .:?! "PersonEMail"
<*> (o .:?! "PersonMobilePhoneNo" <&> fmap canonicalPhone)
<*> o .:?! "InternalPersonalNo"
instance ToJSON AvsPersonInfo where

View File

@ -58,7 +58,39 @@ pickValidUserEmail x y
-- | returns first valid email address or none if none are valid
pickValidUserEmail' :: CI Text -> CI Text -> Maybe (CI Text)
pickValidUserEmail' x y
pickValidUserEmail' x y
| validEmail' x = Just x
| validEmail' y = Just y
| otherwise = Nothing
| otherwise = Nothing
--------------------
-- Telephone Utils
-- | normalize phone numbers
canonicalPhone :: Text -> Text
canonicalPhone pn
| Just pn01 <- Text.stripPrefix "01" pn
= german_mobile pn01
| Just pn01 <- Text.stripPrefix "+491" pn
= german_mobile pn01
| Just pn00 <- Text.stripPrefix "00" pn
= Text.cons '+' $ Text.map repl_nondigit pn00
| Just ('0', pn0) <- Text.uncons pn
, Just (snr, _ ) <- Text.uncons pn0
, snr /= '0'
, Char.isDigit snr
= "+49 " <> Text.map repl_nondigit pn0
| otherwise
= Text.map repl_nondigit pn
where
german_mobile :: Text -> Text
german_mobile wpx =
let (area,endnr) = Text.splitAt 2 $ Text.filter Char.isDigit wpx
in "+49 1" <> area <> Text.cons ' ' endnr
repl_nondigit :: Char -> Char
repl_nondigit c
| Char.isDigit c = c
| c == '+' = '+'
| otherwise = ' '