Skip to content

Commit

Permalink
authors groups - update indexer and janitor
Browse files Browse the repository at this point in the history
  • Loading branch information
morucci committed Dec 11, 2023
1 parent 1df6d3f commit 540d117
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Monocle/Backend/Documents.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Monocle/Backend/Janitor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 8 additions & 5 deletions src/Monocle/Backend/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 540d117

Please sign in to comment.