@@ -80,7 +80,10 @@ import Text.XHtml hiding (base, text, (</>))
80
80
import qualified Data.Aeson as Aeson
81
81
import qualified Data.Aeson.Types as Aeson
82
82
import qualified Data.ByteString.Lazy.Char8 as BS
83
+ import Data.Text (Text )
83
84
import qualified Data.Text as T
85
+ import qualified Data.Text.Lazy as TL
86
+ import qualified Data.Text.Lazy.Encoding as TL
84
87
import qualified Data.Vector as Vec
85
88
86
89
-- A feature to manage notifications to users when package metadata, etc is updated.
@@ -689,8 +692,7 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
689
692
revisionUploadNotifications <- concatMapM (genRevUploadList notifyPrefs trimLastTime now) revisionsAndUploads
690
693
691
694
groupActions <- collectAdminActions trimLastTime now
692
- groupActionNotifications <- foldM (genGroupUploadList notifyPrefs) Map. empty groupActions
693
- let groupActionEmails = mconcat . mapMaybe (describeGroupAction users) <$> groupActionNotifications
695
+ groupActionNotifications <- concatMapM (genGroupUploadList notifyPrefs) groupActions
694
696
695
697
docReports <- collectDocReport trimLastTime now
696
698
docReportNotifications <- foldM (genDocReportList notifyPrefs) Map. empty docReports
@@ -708,14 +710,14 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
708
710
emails <-
709
711
getNotificationEmails serverEnv userDetailsFeature users
710
712
( foldr1 (Map. unionWith (<>) )
711
- [ groupActionEmails
712
- , docReportEmails
713
+ [ docReportEmails
713
714
, tagProposalEmails
714
715
]
715
716
, dependencyEmails
716
717
) $
717
718
concat
718
719
[ revisionUploadNotifications
720
+ , groupActionNotifications
719
721
]
720
722
mapM_ sendNotifyEmailAndDelay emails
721
723
@@ -728,11 +730,6 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
728
730
{ uriPath = " /package/" <> display (packageName pkg) <> " -" <> display (packageVersion pkg)
729
731
}
730
732
731
- formatTimeUser users t u =
732
- EmailContentText . T. pack $
733
- display (Users. userIdToName users u) ++ " [" ++
734
- (formatTime defaultTimeLocale " %c" t) ++ " ]"
735
-
736
733
collectRevisionsAndUploads earlier now = do
737
734
pkgIndex <- queryGetPackageIndex
738
735
let isRecent pkgInfo =
@@ -797,18 +794,36 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
797
794
{ notifyPackageInfo = pkg
798
795
}
799
796
800
- genGroupUploadList notifyPrefs mp ga =
801
- let (actor,gdesc) = case ga of (_,uid,Admin_GroupAddUser _ gd,_) -> (uid, gd)
802
- (_,uid,Admin_GroupDelUser _ gd,_) -> (uid, gd)
803
- addNotification uid m = if not (notifyOptOut npref) && notifyMaintainerGroup npref
804
- then Map. insertWith (++) uid [ga] m
805
- else m
806
- where npref = fromMaybe defaultNotifyPrefs (Map. lookup uid notifyPrefs)
807
- in case gdesc of
808
- (MaintainerGroup pkg) -> do
809
- maintainers <- queryUserGroup $ maintainersGroup (mkPackageName $ BS. unpack pkg)
810
- return $ foldr addNotification mp (toList (delete actor maintainers))
811
- _ -> return mp
797
+ genGroupUploadList notifyPrefs groupAction =
798
+ let notifyAllMaintainers actor pkg notif = do
799
+ maintainers <- queryUserGroup $ maintainersGroup (mkPackageName $ BS. unpack pkg)
800
+ pure . flip mapMaybe (toList maintainers) $ \ uid -> do
801
+ let NotifyPref {.. } = fromMaybe defaultNotifyPrefs (Map. lookup uid notifyPrefs)
802
+ guard $ uid /= actor
803
+ guard $ not notifyOptOut
804
+ Just (uid, notif)
805
+ in case groupAction of
806
+ (time, userActor, Admin_GroupAddUser userSubject (MaintainerGroup pkg), reason) ->
807
+ notifyAllMaintainers userActor pkg $
808
+ NotifyMaintainerUpdate
809
+ { notifyMaintainerUpdateType = MaintainerAdded
810
+ , notifyUserActor = userActor
811
+ , notifyUserSubject = userSubject
812
+ , notifyPackageName = mkPackageName $ BS. unpack pkg
813
+ , notifyReason = TL. toStrict $ TL. decodeUtf8 reason
814
+ , notifyUpdatedAt = time
815
+ }
816
+ (time, userActor, Admin_GroupDelUser userSubject (MaintainerGroup pkg), reason) ->
817
+ notifyAllMaintainers userActor pkg $
818
+ NotifyMaintainerUpdate
819
+ { notifyMaintainerUpdateType = MaintainerRemoved
820
+ , notifyUserActor = userActor
821
+ , notifyUserSubject = userSubject
822
+ , notifyPackageName = mkPackageName $ BS. unpack pkg
823
+ , notifyReason = TL. toStrict $ TL. decodeUtf8 reason
824
+ , notifyUpdatedAt = time
825
+ }
826
+ _ -> pure []
812
827
813
828
genDocReportList notifyPrefs mp pkgDoc = do
814
829
let addNotification uid m =
@@ -832,28 +847,6 @@ userNotifyFeature serverEnv@ServerEnv{serverBaseURI, serverCron}
832
847
Map. mapKeys (, pid) <$>
833
848
getUserNotificationsOnRelease (queryUserGroup . maintainersGroup) idx revIdx queryGetUserNotifyPref pid
834
849
835
- describeGroupAction users (time, uid, act, reason) =
836
- fmap
837
- ( \ message ->
838
- EmailContentParagraph (" Group modified by " <> formatTimeUser users time uid <> " :" )
839
- <> EmailContentList
840
- [ message
841
- , " Reason: " <> emailContentLBS reason
842
- ]
843
- )
844
- $ case act of
845
- (Admin_GroupAddUser tn (MaintainerGroup pkg)) ->
846
- Just $
847
- emailContentDisplay (Users. userIdToName users tn)
848
- <> " added to maintainers for "
849
- <> emailContentLBS pkg
850
- (Admin_GroupDelUser tn (MaintainerGroup pkg)) ->
851
- Just $
852
- emailContentDisplay (Users. userIdToName users tn)
853
- <> " removed from maintainers for "
854
- <> emailContentLBS pkg
855
- _ -> Nothing
856
-
857
850
describeDocReport (pkg, success) =
858
851
EmailContentParagraph $
859
852
" Package doc build for " <> emailContentDisplay (packageName pkg) <> " :" <> EmailContentSoftBreak <>
@@ -917,6 +910,16 @@ data Notification
917
910
{ notifyPackageId :: PackageId
918
911
, notifyRevisions :: [UploadInfo ]
919
912
}
913
+ | NotifyMaintainerUpdate
914
+ { notifyMaintainerUpdateType :: NotifyMaintainerUpdateType
915
+ , notifyUserActor :: UserId
916
+ , notifyUserSubject :: UserId
917
+ , notifyPackageName :: PackageName
918
+ , notifyReason :: Text
919
+ , notifyUpdatedAt :: UTCTime
920
+ }
921
+
922
+ data NotifyMaintainerUpdateType = MaintainerAdded | MaintainerRemoved
920
923
921
924
-- | Notifications in the same group are batched in the same email.
922
925
--
@@ -1024,6 +1027,15 @@ getNotificationEmails
1024
1027
renderNotifyNewRevision
1025
1028
notifyPackageId
1026
1029
notifyRevisions
1030
+ NotifyMaintainerUpdate {.. } ->
1031
+ generalNotification $
1032
+ renderNotifyMaintainerUpdate
1033
+ notifyMaintainerUpdateType
1034
+ notifyUserActor
1035
+ notifyUserSubject
1036
+ notifyPackageName
1037
+ notifyReason
1038
+ notifyUpdatedAt
1027
1039
where
1028
1040
generalNotification emailContent = Just (emailContent, GeneralNotification )
1029
1041
@@ -1036,8 +1048,22 @@ getNotificationEmails
1036
1048
EmailContentParagraph (" Package metadata revision(s), " <> renderPkgLink pkg <> " :" )
1037
1049
<> EmailContentList (map (uncurry $ flip renderUserTime) $ sortOn (Down . fst ) revs)
1038
1050
1051
+ renderNotifyMaintainerUpdate updateType userActor userSubject pkg reason time =
1052
+ EmailContentParagraph (" Group modified by " <> renderUserTime userActor time <> " :" )
1053
+ <> EmailContentList
1054
+ [ case updateType of
1055
+ MaintainerAdded ->
1056
+ renderUser userSubject <> " added to maintainers for " <> renderPackageName pkg
1057
+ MaintainerRemoved ->
1058
+ renderUser userSubject <> " removed from maintainers for " <> renderPackageName pkg
1059
+ , " Reason: " <> EmailContentText reason
1060
+ ]
1061
+
1062
+
1039
1063
{- ---- Rendering helpers -----}
1040
1064
1065
+ renderPackageName = emailContentStr . unPackageName
1066
+
1041
1067
renderPkgLink pkg =
1042
1068
EmailContentLink
1043
1069
(T. pack $ display pkg)
0 commit comments