From 3e617a4f9cfb07347d18b38671131097f2e919f4 Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Mon, 11 Dec 2023 07:45:50 +0000 Subject: [PATCH] authors groups - update indexer and janitor --- src/Monocle/Backend/Documents.hs | 2 +- src/Monocle/Backend/Janitor.hs | 8 ++++---- src/Monocle/Backend/Test.hs | 13 ++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Monocle/Backend/Documents.hs b/src/Monocle/Backend/Documents.hs index b9424ba4f..4b36563df 100644 --- a/src/Monocle/Backend/Documents.hs +++ b/src/Monocle/Backend/Documents.hs @@ -48,7 +48,7 @@ instance From ChangePB.Ident Author where Author { authorMuid = identMuid , authorUid = identUid - , authorGroups = mempty + , authorGroups = toList identGroups } fromMaybeIdent :: Maybe ChangePB.Ident -> Author diff --git a/src/Monocle/Backend/Janitor.hs b/src/Monocle/Backend/Janitor.hs index c2829c0ea..4cd4c3257 100644 --- a/src/Monocle/Backend/Janitor.hs +++ b/src/Monocle/Backend/Janitor.hs @@ -28,13 +28,13 @@ import Streaming.Prelude qualified as Streaming updateAuthor :: Config.Index -> D.Author -> D.Author updateAuthor index author@D.Author {..} = case getIdent of - Just ident -> D.Author ident authorUid mempty + Just (identMuid, identGroups) -> D.Author (from identMuid) authorUid (from <$> identGroups) Nothing - | newMuid /= from authorMuid -> D.Author (from newMuid) authorUid mempty + | newMuid /= from authorMuid -> D.Author (from newMuid) authorUid authorGroups | otherwise -> author where - getIdent :: Maybe LText - getIdent = from . fst <$> Config.getIdentByAlias index (from authorUid) + getIdent :: Maybe (Text, [Text]) + getIdent = Config.getIdentByAlias index (from authorUid) -- Remove the host prefix newMuid = T.drop 1 $ T.dropWhile (/= '/') (from authorUid) diff --git a/src/Monocle/Backend/Test.hs b/src/Monocle/Backend/Test.hs index fa74da53a..647c437b3 100644 --- a/src/Monocle/Backend/Test.hs +++ b/src/Monocle/Backend/Test.hs @@ -185,6 +185,10 @@ testIndexChanges = withTenant doTest (I.getChangeDocId fakeChange1) echangeTitle (echangeTitle fakeChange1) + checkEChangeField + (I.getChangeDocId fakeChange1) + echangeAuthor + (echangeAuthor fakeChange1) checkDocExists' $ I.getChangeDocId fakeChange2 checkEChangeField (I.getChangeDocId fakeChange2) @@ -230,6 +234,7 @@ testIndexChanges = withTenant doTest , echangeTitle = title , echangeRepositoryFullname = "fakerepo" , echangeUrl = "https://fakehost/change/" <> show number + , echangeAuthor = Author "John" "John" ["dev", "core"] } testIndexEvents :: Assertion @@ -598,12 +603,10 @@ testJanitorUpdateIdents = do , crawlers = [] , crawlers_api_key = Nothing , projects = Nothing - , idents = Just [mkIdent ["github.com/john"] "John Doe"] + , idents = Just [Config.Ident ["github.com/john"] (Just ["dev", "core"]) "John Doe"] , search_aliases = Nothing } - mkIdent :: [Text] -> Text -> Config.Ident - mkIdent uid = Config.Ident uid Nothing - expectedAuthor = Author "John Doe" "github.com/john" mempty + expectedAuthor = Author "John Doe" "github.com/john" ["dev", "core"] doUpdateIndentOnEventsTest :: Eff [MonoQuery, ElasticEffect, LoggerEffect, IOE] () doUpdateIndentOnEventsTest = E.runFailIO do @@ -617,7 +620,7 @@ testJanitorUpdateIdents = do evt2' <- I.getChangeEventById $ I.getEventDocId evt2 assertEqual' "Ensure event not changed" evt2' $ Just evt2 where - evt1 = mkEventWithAuthor "e1" (Author "john" "github.com/john" mempty) + evt1 = mkEventWithAuthor "e1" (Author "john" "github.com/john" ["not-core"]) evt2 = mkEventWithAuthor "e2" (Author "paul" "github.com/paul" mempty) mkEventWithAuthor :: -- eventId