From 41961c840c557e631e630f188df52cf7af515474 Mon Sep 17 00:00:00 2001 From: Leif Battermann Date: Wed, 21 Aug 2024 12:20:33 +0000 Subject: [PATCH 01/10] db tool for data request --- cabal.project | 1 + nix/local-haskell-packages.nix | 1 + nix/wire-server.nix | 1 + tools/db/team-info/.ormolu | 1 + tools/db/team-info/README.md | 44 ++++++++ tools/db/team-info/app/Main.hs | 23 ++++ tools/db/team-info/default.nix | 40 +++++++ tools/db/team-info/src/TeamInfo/Lib.hs | 93 ++++++++++++++++ tools/db/team-info/src/TeamInfo/Types.hs | 134 +++++++++++++++++++++++ tools/db/team-info/team-info.cabal | 92 ++++++++++++++++ 10 files changed, 430 insertions(+) create mode 120000 tools/db/team-info/.ormolu create mode 100644 tools/db/team-info/README.md create mode 100644 tools/db/team-info/app/Main.hs create mode 100644 tools/db/team-info/default.nix create mode 100644 tools/db/team-info/src/TeamInfo/Lib.hs create mode 100644 tools/db/team-info/src/TeamInfo/Types.hs create mode 100644 tools/db/team-info/team-info.cabal diff --git a/cabal.project b/cabal.project index ed3bbc74931..61843de1a3a 100644 --- a/cabal.project +++ b/cabal.project @@ -50,6 +50,7 @@ packages: , tools/db/move-team/ , tools/db/phone-users/ , tools/db/repair-handles/ + , tools/db/team-info/ , tools/db/repair-brig-clients-table/ , tools/db/service-backfill/ , tools/fedcalls/ diff --git a/nix/local-haskell-packages.nix b/nix/local-haskell-packages.nix index 38c381258a4..5a7d488c79a 100644 --- a/nix/local-haskell-packages.nix +++ b/nix/local-haskell-packages.nix @@ -53,6 +53,7 @@ repair-brig-clients-table = hself.callPackage ../tools/db/repair-brig-clients-table/default.nix { inherit gitignoreSource; }; repair-handles = hself.callPackage ../tools/db/repair-handles/default.nix { inherit gitignoreSource; }; service-backfill = hself.callPackage ../tools/db/service-backfill/default.nix { inherit gitignoreSource; }; + team-info = hself.callPackage ../tools/db/team-info/default.nix { inherit gitignoreSource; }; fedcalls = hself.callPackage ../tools/fedcalls/default.nix { inherit gitignoreSource; }; mlsstats = hself.callPackage ../tools/mlsstats/default.nix { inherit gitignoreSource; }; rabbitmq-consumer = hself.callPackage ../tools/rabbitmq-consumer/default.nix { inherit gitignoreSource; }; diff --git a/nix/wire-server.nix b/nix/wire-server.nix index 9f3eed3d4e4..bf1593940f4 100644 --- a/nix/wire-server.nix +++ b/nix/wire-server.nix @@ -86,6 +86,7 @@ let integration = [ "integration" ]; rabbitmq-consumer = [ "rabbitmq-consumer" ]; test-stats = [ "test-stats" ]; + team-info = [ "team-info" ]; }; inherit (lib) attrsets; diff --git a/tools/db/team-info/.ormolu b/tools/db/team-info/.ormolu new file mode 120000 index 00000000000..ffc2ca9745e --- /dev/null +++ b/tools/db/team-info/.ormolu @@ -0,0 +1 @@ +../../../.ormolu \ No newline at end of file diff --git a/tools/db/team-info/README.md b/tools/db/team-info/README.md new file mode 100644 index 00000000000..1124f4b0cdc --- /dev/null +++ b/tools/db/team-info/README.md @@ -0,0 +1,44 @@ +# Phone users + +This program scans brig's users table and determines the number of users that can only login by phone/sms. + +Example usage: + +```shell +team-info --brig-cassandra-keyspace brig --galley-cassandra-keyspace galley -l 100000 +``` + +Display usage: + +```shell +team-info -h +``` + +```text +team-info + +Usage: team-info [--brig-cassandra-host HOST] [--brig-cassandra-port PORT] + [--brig-cassandra-keyspace STRING] + [--galley-cassandra-host HOST] [--galley-cassandra-port PORT] + [--galley-cassandra-keyspace STRING] [-l|--limit INT] + + This program scans brig's users table and determines the number of users that + can only login by phone/sms + +Available options: + -h,--help Show this help text + --brig-cassandra-host HOST + Cassandra Host for brig (default: "localhost") + --brig-cassandra-port PORT + Cassandra Port for brig (default: 9042) + --brig-cassandra-keyspace STRING + Cassandra Keyspace for brig (default: "brig_test") + --galley-cassandra-host HOST + Cassandra Host for galley (default: "localhost") + --galley-cassandra-port PORT + Cassandra Port for galley (default: 9043) + --galley-cassandra-keyspace STRING + Cassandra Keyspace for galley + (default: "galley_test") + -l,--limit INT Limit the number of users to process +``` diff --git a/tools/db/team-info/app/Main.hs b/tools/db/team-info/app/Main.hs new file mode 100644 index 00000000000..46b640ea4b6 --- /dev/null +++ b/tools/db/team-info/app/Main.hs @@ -0,0 +1,23 @@ +-- This file is part of the Wire Server implementation. +-- +-- Copyright (C) 2024 Wire Swiss GmbH +-- +-- This program is free software: you can redistribute it and/or modify it under +-- the terms of the GNU Affero General Public License as published by the Free +-- Software Foundation, either version 3 of the License, or (at your option) any +-- later version. +-- +-- This program is distributed in the hope that it will be useful, but WITHOUT +-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +-- details. +-- +-- You should have received a copy of the GNU Affero General Public License along +-- with this program. If not, see . + +module Main where + +import qualified TeamInfo.Lib as Lib + +main :: IO () +main = Lib.main diff --git a/tools/db/team-info/default.nix b/tools/db/team-info/default.nix new file mode 100644 index 00000000000..d939d1c1fe4 --- /dev/null +++ b/tools/db/team-info/default.nix @@ -0,0 +1,40 @@ +# WARNING: GENERATED FILE, DO NOT EDIT. +# This file is generated by running hack/bin/generate-local-nix-packages.sh and +# must be regenerated whenever local packages are added or removed, or +# dependencies are added or removed. +{ mkDerivation +, base +, cassandra-util +, conduit +, cql +, gitignoreSource +, imports +, lens +, lib +, optparse-applicative +, time +, tinylog +, types-common +}: +mkDerivation { + pname = "team-info"; + version = "1.0.0"; + src = gitignoreSource ./.; + isLibrary = true; + isExecutable = true; + libraryHaskellDepends = [ + cassandra-util + conduit + cql + imports + lens + optparse-applicative + time + tinylog + types-common + ]; + executableHaskellDepends = [ base ]; + description = "get team info from cassandra"; + license = lib.licenses.agpl3Only; + mainProgram = "team-info"; +} diff --git a/tools/db/team-info/src/TeamInfo/Lib.hs b/tools/db/team-info/src/TeamInfo/Lib.hs new file mode 100644 index 00000000000..d60d013a6db --- /dev/null +++ b/tools/db/team-info/src/TeamInfo/Lib.hs @@ -0,0 +1,93 @@ +{-# LANGUAGE OverloadedStrings #-} + +-- This file is part of the Wire Server implementation. +-- +-- Copyright (C) 2024 Wire Swiss GmbH +-- +-- This program is free software: you can redistribute it and/or modify it under +-- the terms of the GNU Affero General Public License as published by the Free +-- Software Foundation, either version 3 of the License, or (at your option) any +-- later version. +-- +-- This program is distributed in the hope that it will be useful, but WITHOUT +-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +-- details. +-- +-- You should have received a copy of the GNU Affero General Public License along +-- with this program. If not, see . + +module TeamInfo.Lib where + +import Cassandra as C +import Cassandra.Settings as C +import Data.Conduit +import qualified Data.Conduit.Combinators as Conduit +import qualified Data.Conduit.List as CL +import Data.Id (TeamId, UserId) +import Data.Time +import qualified Database.CQL.Protocol as CQL +import Imports +import Options.Applicative +import qualified System.Logger as Log +import TeamInfo.Types + +lookupClientsLastActiveTimestamps :: ClientState -> UserId -> IO [Maybe UTCTime] +lookupClientsLastActiveTimestamps client u = do + runClient client $ runIdentity <$$> retry x1 (query selectClients (params One (Identity u))) + where + selectClients :: PrepQuery R (Identity UserId) (Identity (Maybe UTCTime)) + selectClients = "SELECT last_active from clients where user = ?" + +selectTeamMembers :: ClientState -> TeamId -> ConduitM () [TeamMemberRow] IO () +selectTeamMembers client teamId = + transPipe (runClient client) (paginateC cql (paramsP One (Identity teamId) 1000) x5) + .| Conduit.map (fmap CQL.asRecord) + where + cql :: C.PrepQuery C.R (Identity TeamId) (CQL.TupleType TeamMemberRow) + cql = + "SELECT user, legalhold_status FROM team_members WHERE team = ?" + +lookUpActivity :: ClientState -> TeamMemberRow -> IO TeamMember +lookUpActivity brigClient tmr = do + lastActiveTimestamps <- catMaybes <$> lookupClientsLastActiveTimestamps brigClient tmr.id + if null lastActiveTimestamps + then do + pure $ TeamMember tmr.id tmr.legalhold Nothing + else do + let lastActive = maximum lastActiveTimestamps + pure $ TeamMember tmr.id tmr.legalhold (Just lastActive) + +process :: TeamId -> ClientState -> ClientState -> IO [TeamMember] +process teamId brigClient galleyClient = + runConduit + $ selectTeamMembers galleyClient teamId + .| Conduit.concat + .| Conduit.mapM (lookUpActivity brigClient) + .| CL.consume + +main :: IO () +main = do + opts <- execParser (info (helper <*> optsParser) desc) + logger <- initLogger + brigClient <- initCas opts.brigDb logger + galleyClient <- initCas opts.galleyDb logger + teamMembers <- process opts.teamId brigClient galleyClient + for_ teamMembers $ \tm -> Log.info logger $ Log.msg (show tm) + where + initLogger = + Log.new + . Log.setLogLevel Log.Info + . Log.setOutput Log.StdOut + . Log.setFormat Nothing + . Log.setBufSize 0 + $ Log.defSettings + initCas settings l = + C.init + . C.setLogger (C.mkLogger l) + . C.setContacts settings.host [] + . C.setPortNumber (fromIntegral settings.port) + . C.setKeyspace settings.keyspace + . C.setProtocolVersion C.V4 + $ C.defSettings + desc = header "team-info" <> progDesc "get team info" <> fullDesc diff --git a/tools/db/team-info/src/TeamInfo/Types.hs b/tools/db/team-info/src/TeamInfo/Types.hs new file mode 100644 index 00000000000..e9112a7b1bc --- /dev/null +++ b/tools/db/team-info/src/TeamInfo/Types.hs @@ -0,0 +1,134 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE TemplateHaskell #-} + +-- This file is part of the Wire Server implementation. +-- +-- Copyright (C) 2024 Wire Swiss GmbH +-- +-- This program is free software: you can redistribute it and/or modify it under +-- the terms of the GNU Affero General Public License as published by the Free +-- Software Foundation, either version 3 of the License, or (at your option) any +-- later version. +-- +-- This program is distributed in the hope that it will be useful, but WITHOUT +-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +-- details. +-- +-- You should have received a copy of the GNU Affero General Public License along +-- with this program. If not, see . + +module TeamInfo.Types where + +import Cassandra as C +import Control.Lens +import Data.Id +import Data.LegalHold (UserLegalHoldStatus) +import Data.Text.Strict.Lens +import Data.Time +import Database.CQL.Protocol hiding (Result) +import Imports +import Options.Applicative + +data CassandraSettings = CassandraSettings + { host :: String, + port :: Int, + keyspace :: C.Keyspace + } + +data Opts = Opts + { brigDb :: CassandraSettings, + galleyDb :: CassandraSettings, + teamId :: TeamId + } + +optsParser :: Parser Opts +optsParser = + Opts + <$> brigCassandraParser + <*> galleyCassandraParser + <*> ( option + auto + ( long "team-id" + <> short 't' + <> metavar "ID" + <> help "Team ID" + ) + ) + +galleyCassandraParser :: Parser CassandraSettings +galleyCassandraParser = + CassandraSettings + <$> strOption + ( long "galley-cassandra-host" + <> metavar "HOST" + <> help "Cassandra Host for galley" + <> value "localhost" + <> showDefault + ) + <*> option + auto + ( long "galley-cassandra-port" + <> metavar "PORT" + <> help "Cassandra Port for galley" + <> value 9043 + <> showDefault + ) + <*> ( C.Keyspace + . view packed + <$> strOption + ( long "galley-cassandra-keyspace" + <> metavar "STRING" + <> help "Cassandra Keyspace for galley" + <> value "galley_test" + <> showDefault + ) + ) + +brigCassandraParser :: Parser CassandraSettings +brigCassandraParser = + CassandraSettings + <$> strOption + ( long "brig-cassandra-host" + <> metavar "HOST" + <> help "Cassandra Host for brig" + <> value "localhost" + <> showDefault + ) + <*> option + auto + ( long "brig-cassandra-port" + <> metavar "PORT" + <> help "Cassandra Port for brig" + <> value 9042 + <> showDefault + ) + <*> ( C.Keyspace + . view packed + <$> strOption + ( long "brig-cassandra-keyspace" + <> metavar "STRING" + <> help "Cassandra Keyspace for brig" + <> value "brig_test" + <> showDefault + ) + ) + +data TeamMemberRow = TeamMemberRow + { id :: UserId, + legalhold :: Maybe UserLegalHoldStatus + } + deriving (Show, Generic) + +recordInstance ''TeamMemberRow + +data TeamMember = TeamMember + { id :: UserId, + legalhold :: Maybe UserLegalHoldStatus, + lastActive :: Maybe UTCTime + } + deriving (Generic) + +-- output as csv +instance Show TeamMember where + show tm = show tm.id <> "," <> maybe " " show tm.legalhold <> "," <> maybe " " show tm.lastActive diff --git a/tools/db/team-info/team-info.cabal b/tools/db/team-info/team-info.cabal new file mode 100644 index 00000000000..c96cb3485c1 --- /dev/null +++ b/tools/db/team-info/team-info.cabal @@ -0,0 +1,92 @@ +cabal-version: 3.0 +name: team-info +version: 1.0.0 +synopsis: get team info from cassandra +category: Network +author: Wire Swiss GmbH +maintainer: Wire Swiss GmbH +copyright: (c) 2024 Wire Swiss GmbH +license: AGPL-3.0-only +build-type: Simple + +library + hs-source-dirs: src + exposed-modules: + TeamInfo.Lib + TeamInfo.Types + + ghc-options: + -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates + -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path + -funbox-strict-fields -threaded -with-rtsopts=-N + -Wredundant-constraints -Wunused-packages + + build-depends: + , cassandra-util + , conduit + , cql + , imports + , lens + , optparse-applicative + , time + , tinylog + , types-common + + default-extensions: + AllowAmbiguousTypes + BangPatterns + ConstraintKinds + DataKinds + DefaultSignatures + DeriveFunctor + DeriveGeneric + DeriveLift + DeriveTraversable + DerivingStrategies + DerivingVia + DuplicateRecordFields + EmptyCase + FlexibleContexts + FlexibleInstances + FunctionalDependencies + GADTs + GeneralizedNewtypeDeriving + InstanceSigs + KindSignatures + LambdaCase + MultiParamTypeClasses + MultiWayIf + NamedFieldPuns + NoImplicitPrelude + OverloadedLabels + OverloadedRecordDot + OverloadedStrings + PackageImports + PatternSynonyms + PolyKinds + QuasiQuotes + RankNTypes + RecordWildCards + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeFamilies + TypeFamilyDependencies + TypeOperators + UndecidableInstances + ViewPatterns + +executable team-info + main-is: Main.hs + build-depends: + , base + , team-info + + hs-source-dirs: app + default-language: Haskell2010 + ghc-options: + -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates + -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path + -funbox-strict-fields -threaded -with-rtsopts=-N + -Wredundant-constraints -Wunused-packages From 3644ae128d28d48247fd0305b1663fbebdd2c8b2 Mon Sep 17 00:00:00 2001 From: Leif Battermann Date: Wed, 21 Aug 2024 15:01:03 +0000 Subject: [PATCH 02/10] fix --- tools/db/team-info/src/TeamInfo/Lib.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/db/team-info/src/TeamInfo/Lib.hs b/tools/db/team-info/src/TeamInfo/Lib.hs index d60d013a6db..f68fa9fa153 100644 --- a/tools/db/team-info/src/TeamInfo/Lib.hs +++ b/tools/db/team-info/src/TeamInfo/Lib.hs @@ -46,7 +46,7 @@ selectTeamMembers client teamId = where cql :: C.PrepQuery C.R (Identity TeamId) (CQL.TupleType TeamMemberRow) cql = - "SELECT user, legalhold_status FROM team_members WHERE team = ?" + "SELECT user, legalhold_status FROM team_member WHERE team = ?" lookUpActivity :: ClientState -> TeamMemberRow -> IO TeamMember lookUpActivity brigClient tmr = do From 1444d8fd328c3a6f6494dc1dd34db16461a65f9c Mon Sep 17 00:00:00 2001 From: Leif Battermann Date: Thu, 26 Sep 2024 12:57:47 +0000 Subject: [PATCH 03/10] rm readme --- tools/db/team-info/README.md | 44 ------------------------------------ 1 file changed, 44 deletions(-) delete mode 100644 tools/db/team-info/README.md diff --git a/tools/db/team-info/README.md b/tools/db/team-info/README.md deleted file mode 100644 index 1124f4b0cdc..00000000000 --- a/tools/db/team-info/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Phone users - -This program scans brig's users table and determines the number of users that can only login by phone/sms. - -Example usage: - -```shell -team-info --brig-cassandra-keyspace brig --galley-cassandra-keyspace galley -l 100000 -``` - -Display usage: - -```shell -team-info -h -``` - -```text -team-info - -Usage: team-info [--brig-cassandra-host HOST] [--brig-cassandra-port PORT] - [--brig-cassandra-keyspace STRING] - [--galley-cassandra-host HOST] [--galley-cassandra-port PORT] - [--galley-cassandra-keyspace STRING] [-l|--limit INT] - - This program scans brig's users table and determines the number of users that - can only login by phone/sms - -Available options: - -h,--help Show this help text - --brig-cassandra-host HOST - Cassandra Host for brig (default: "localhost") - --brig-cassandra-port PORT - Cassandra Port for brig (default: 9042) - --brig-cassandra-keyspace STRING - Cassandra Keyspace for brig (default: "brig_test") - --galley-cassandra-host HOST - Cassandra Host for galley (default: "localhost") - --galley-cassandra-port PORT - Cassandra Port for galley (default: 9043) - --galley-cassandra-keyspace STRING - Cassandra Keyspace for galley - (default: "galley_test") - -l,--limit INT Limit the number of users to process -``` From f2d9bbbf7b656e43884a2b4f651fecc41d9fcf72 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Thu, 26 Sep 2024 15:04:55 +0200 Subject: [PATCH 04/10] Revert "rm readme" This reverts commit b0e7949a7a565dcdef50d89c239fdf3b3a9dc569. --- tools/db/team-info/README.md | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tools/db/team-info/README.md diff --git a/tools/db/team-info/README.md b/tools/db/team-info/README.md new file mode 100644 index 00000000000..1124f4b0cdc --- /dev/null +++ b/tools/db/team-info/README.md @@ -0,0 +1,44 @@ +# Phone users + +This program scans brig's users table and determines the number of users that can only login by phone/sms. + +Example usage: + +```shell +team-info --brig-cassandra-keyspace brig --galley-cassandra-keyspace galley -l 100000 +``` + +Display usage: + +```shell +team-info -h +``` + +```text +team-info + +Usage: team-info [--brig-cassandra-host HOST] [--brig-cassandra-port PORT] + [--brig-cassandra-keyspace STRING] + [--galley-cassandra-host HOST] [--galley-cassandra-port PORT] + [--galley-cassandra-keyspace STRING] [-l|--limit INT] + + This program scans brig's users table and determines the number of users that + can only login by phone/sms + +Available options: + -h,--help Show this help text + --brig-cassandra-host HOST + Cassandra Host for brig (default: "localhost") + --brig-cassandra-port PORT + Cassandra Port for brig (default: 9042) + --brig-cassandra-keyspace STRING + Cassandra Keyspace for brig (default: "brig_test") + --galley-cassandra-host HOST + Cassandra Host for galley (default: "localhost") + --galley-cassandra-port PORT + Cassandra Port for galley (default: 9043) + --galley-cassandra-keyspace STRING + Cassandra Keyspace for galley + (default: "galley_test") + -l,--limit INT Limit the number of users to process +``` From e874d2f6fe3cd0ab778bcea79f9178e419f26795 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Thu, 26 Sep 2024 15:05:16 +0200 Subject: [PATCH 05/10] stern end-point that does the same [wip] --- tools/stern/src/Stern/API.hs | 4 ++++ tools/stern/src/Stern/API/Routes.hs | 7 +++++++ tools/stern/src/Stern/Types.hs | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/tools/stern/src/Stern/API.hs b/tools/stern/src/Stern/API.hs index 3e915b2a69e..02769593f46 100644 --- a/tools/stern/src/Stern/API.hs +++ b/tools/stern/src/Stern/API.hs @@ -146,6 +146,7 @@ sitemap' = :<|> Named @"delete-user-blacklist" deleteFromBlacklist :<|> Named @"get-team-info-by-member-email" getTeamInfoByMemberEmail :<|> Named @"get-team-info" getTeamInfo + :<|> Named @"get-team-activity-info" getTeamActivityInfo :<|> Named @"get-team-admin-info" getTeamAdminInfo :<|> Named @"get-route-legalhold-config" (mkFeatureGetRoute @LegalholdConfig) :<|> Named @"put-route-legalhold-config" (mkFeaturePutRouteTrivialConfigNoTTL @LegalholdConfig) @@ -303,6 +304,9 @@ getTeamInfoByMemberEmail e = do getTeamInfo :: TeamId -> Handler TeamInfo getTeamInfo = Intra.getTeamInfo +getTeamActivityInfo :: TeamId -> Handler TeamActivityInfo +getTeamActivityInfo = Intra.getTeamActivityInfo + getTeamAdminInfo :: TeamId -> Handler TeamAdminInfo getTeamAdminInfo = fmap toAdminInfo . Intra.getTeamInfo diff --git a/tools/stern/src/Stern/API/Routes.hs b/tools/stern/src/Stern/API/Routes.hs index 777bd118c5d..511b28c59bf 100644 --- a/tools/stern/src/Stern/API/Routes.hs +++ b/tools/stern/src/Stern/API/Routes.hs @@ -240,6 +240,13 @@ type SternAPI = :> Capture "tid" TeamId :> Get '[JSON] TeamInfo ) + :<|> Named + "get-team-activity-info" + ( Summary "Gets information about last activity of members of a team" + :> "teams" + :> Capture "tid" TeamId + :> Get '[JSON] TeamActivityInfo + ) :<|> Named "get-team-admin-info" ( Summary "Gets information about a team's members, owners, and admins" diff --git a/tools/stern/src/Stern/Types.hs b/tools/stern/src/Stern/Types.hs index 24dde504caa..449797c672a 100644 --- a/tools/stern/src/Stern/Types.hs +++ b/tools/stern/src/Stern/Types.hs @@ -67,6 +67,10 @@ instance S.ToSchema TeamInfo where <$> tiData S..= S.field "info" S.schema <*> tiMembers S..= S.field "members" (S.array S.schema) +data TeamActivityInfo = TeamActivityInfo + { tiData :: TeamData, + tiMembers :: [( + data TeamAdminInfo = TeamAdminInfo { taData :: TeamData, taOwners :: [TeamMemberInfo], From 15612373cffcf3046f7a4b5429d1879c5a4bb39e Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Thu, 26 Sep 2024 16:02:03 +0200 Subject: [PATCH 06/10] Revert "stern end-point that does the same [wip]" This reverts commit 08548a66e79b205114d84f9de348493b2d48f55a. --- tools/stern/src/Stern/API.hs | 4 ---- tools/stern/src/Stern/API/Routes.hs | 7 ------- tools/stern/src/Stern/Types.hs | 4 ---- 3 files changed, 15 deletions(-) diff --git a/tools/stern/src/Stern/API.hs b/tools/stern/src/Stern/API.hs index 02769593f46..3e915b2a69e 100644 --- a/tools/stern/src/Stern/API.hs +++ b/tools/stern/src/Stern/API.hs @@ -146,7 +146,6 @@ sitemap' = :<|> Named @"delete-user-blacklist" deleteFromBlacklist :<|> Named @"get-team-info-by-member-email" getTeamInfoByMemberEmail :<|> Named @"get-team-info" getTeamInfo - :<|> Named @"get-team-activity-info" getTeamActivityInfo :<|> Named @"get-team-admin-info" getTeamAdminInfo :<|> Named @"get-route-legalhold-config" (mkFeatureGetRoute @LegalholdConfig) :<|> Named @"put-route-legalhold-config" (mkFeaturePutRouteTrivialConfigNoTTL @LegalholdConfig) @@ -304,9 +303,6 @@ getTeamInfoByMemberEmail e = do getTeamInfo :: TeamId -> Handler TeamInfo getTeamInfo = Intra.getTeamInfo -getTeamActivityInfo :: TeamId -> Handler TeamActivityInfo -getTeamActivityInfo = Intra.getTeamActivityInfo - getTeamAdminInfo :: TeamId -> Handler TeamAdminInfo getTeamAdminInfo = fmap toAdminInfo . Intra.getTeamInfo diff --git a/tools/stern/src/Stern/API/Routes.hs b/tools/stern/src/Stern/API/Routes.hs index 511b28c59bf..777bd118c5d 100644 --- a/tools/stern/src/Stern/API/Routes.hs +++ b/tools/stern/src/Stern/API/Routes.hs @@ -240,13 +240,6 @@ type SternAPI = :> Capture "tid" TeamId :> Get '[JSON] TeamInfo ) - :<|> Named - "get-team-activity-info" - ( Summary "Gets information about last activity of members of a team" - :> "teams" - :> Capture "tid" TeamId - :> Get '[JSON] TeamActivityInfo - ) :<|> Named "get-team-admin-info" ( Summary "Gets information about a team's members, owners, and admins" diff --git a/tools/stern/src/Stern/Types.hs b/tools/stern/src/Stern/Types.hs index 449797c672a..24dde504caa 100644 --- a/tools/stern/src/Stern/Types.hs +++ b/tools/stern/src/Stern/Types.hs @@ -67,10 +67,6 @@ instance S.ToSchema TeamInfo where <$> tiData S..= S.field "info" S.schema <*> tiMembers S..= S.field "members" (S.array S.schema) -data TeamActivityInfo = TeamActivityInfo - { tiData :: TeamData, - tiMembers :: [( - data TeamAdminInfo = TeamAdminInfo { taData :: TeamData, taOwners :: [TeamMemberInfo], From 7d4ac8e5924899379a8a2b5f46fd1f09169034d4 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Thu, 26 Sep 2024 16:10:07 +0200 Subject: [PATCH 07/10] update README --- tools/db/team-info/README.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/db/team-info/README.md b/tools/db/team-info/README.md index 1124f4b0cdc..81961bae4de 100644 --- a/tools/db/team-info/README.md +++ b/tools/db/team-info/README.md @@ -1,11 +1,16 @@ -# Phone users +# Team info -This program scans brig's users table and determines the number of users that can only login by phone/sms. +This program scans brig's and galley's cassandra for members of a team, their clients, and those clients' last access times. + +Useful for finding out which accounts you don't want to pay license fees any more. Example usage: ```shell -team-info --brig-cassandra-keyspace brig --galley-cassandra-keyspace galley -l 100000 +team-info \ + --brig-cassandra-port 9048 --brig-cassandra-keyspace brig \ + --galley-cassandra-port 9049 --galley-cassandra-keyspace galley \ + --team-id=904912aa-7c10-11ef-9c85-8bfd758593f6 ``` Display usage: @@ -18,12 +23,11 @@ team-info -h team-info Usage: team-info [--brig-cassandra-host HOST] [--brig-cassandra-port PORT] - [--brig-cassandra-keyspace STRING] - [--galley-cassandra-host HOST] [--galley-cassandra-port PORT] - [--galley-cassandra-keyspace STRING] [-l|--limit INT] + [--brig-cassandra-keyspace STRING] + [--galley-cassandra-host HOST] [--galley-cassandra-port PORT] + [--galley-cassandra-keyspace STRING] (-t|--team-id ID) - This program scans brig's users table and determines the number of users that - can only login by phone/sms + get team info Available options: -h,--help Show this help text @@ -40,5 +44,5 @@ Available options: --galley-cassandra-keyspace STRING Cassandra Keyspace for galley (default: "galley_test") - -l,--limit INT Limit the number of users to process + -t,--team-id ID Team ID ``` From caf22563f5ffc265b3ab16f5031ebbf3d6c98f9f Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Thu, 26 Sep 2024 16:13:54 +0200 Subject: [PATCH 08/10] Changelog. --- changelog.d/5-internal/WPB-11301-db-tool-team-info | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5-internal/WPB-11301-db-tool-team-info diff --git a/changelog.d/5-internal/WPB-11301-db-tool-team-info b/changelog.d/5-internal/WPB-11301-db-tool-team-info new file mode 100644 index 00000000000..e1cda09aa88 --- /dev/null +++ b/changelog.d/5-internal/WPB-11301-db-tool-team-info @@ -0,0 +1 @@ +tools/db/team-info: collects last login times of all team members \ No newline at end of file From d01237ed6f5c58b9ea1af37fbae02a0a22af2913 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 10:37:06 +0200 Subject: [PATCH 09/10] hi ci From 64e590fb2e0682a87d8c5bdf70a7f597217b4b84 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 11:59:14 +0200 Subject: [PATCH 10/10] hi ci