Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.d/5-internal/pr-2008
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Servantify Galley Teams API. (#2008)
Servantify Galley Teams API. (#2008, #2010)
6 changes: 6 additions & 0 deletions libs/wire-api/src/Wire/API/ErrorDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Servant.API.Status (KnownStatus, statusVal)
import Servant.Client.Core
import Servant.Swagger.Internal
import Wire.API.Routes.MultiVerb
import Wire.API.Team.Permission

-- This can be added to an endpoint to document a possible failure
-- case outside its return type (usually through an exception).
Expand Down Expand Up @@ -234,6 +235,11 @@ noIdentity n = ErrorDescription (Text.pack (symbolVal (Proxy @desc)) <> " (code

type OperationDenied = ErrorDescription 403 "operation-denied" "Insufficient permissions"

-- FUTUREWORK(leif): We need this to document possible (operation denied) errors in the servant routes.
-- Be aware that this is redundant and should be replaced by a more type safe solution in the future.
type family OperationDeniedError (a :: Perm) :: * where
OperationDeniedError 'SetTeamData = ErrorDescription 403 "operation-denied" "Insufficient permissions (missing SetTeamData)"

operationDeniedSpecialized :: String -> OperationDenied
operationDeniedSpecialized p =
ErrorDescription $
Expand Down
18 changes: 17 additions & 1 deletion libs/wire-api/src/Wire/API/Routes/Public/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Wire.API.ServantProto (Proto, RawProto)
import Wire.API.Team
import Wire.API.Team.Conversation
import Wire.API.Team.Feature
import Wire.API.Team.Permission (Perm (..))

instance AsHeaders '[ConvId] Conversation Conversation where
toHeaders c = (I (qUnqualified (cnvQualifiedId c)) :* Nil, c)
Expand Down Expand Up @@ -725,7 +726,22 @@ data Api routes = Api
TeamId
(RespondEmpty 201 "Team ID as `Location` header value")
]
TeamId
TeamId,
updateTeam ::
routes
:- Summary "Update team properties"
:> ZUser
:> ZConn
:> CanThrow NotATeamMember
:> CanThrow (OperationDeniedError 'SetTeamData)
:> "teams"
:> Capture "tid" TeamId
:> ReqBody '[JSON] TeamUpdateData
:> MultiVerb
'PUT
'[JSON]
'[RespondEmpty 200 "Team updated"]
()
}
deriving (Generic)

Expand Down
2 changes: 1 addition & 1 deletion libs/wire-api/src/Wire/API/Team/Member.hs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ invitedSchema' :: ObjectSchema SwaggerDoc (Maybe (UserId, UTCTimeMillis))
invitedSchema' = withParser invitedSchema $ \(invby, invat) ->
case (invby, invat) of
(Just b, Just a) -> pure $ Just (b, a)
(Nothing, Nothing) -> pure $ Nothing
(Nothing, Nothing) -> pure Nothing
_ -> fail "created_by, created_at"

instance ToSchema NewTeamMember where
Expand Down
18 changes: 2 additions & 16 deletions services/galley/src/Galley/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,14 @@ servantSitemap =
GalleyAPI.featureConfigConferenceCallingGet = Features.getFeatureConfig @'Public.WithoutLockStatus @'Public.TeamFeatureConferenceCalling Features.getConferenceCallingInternal,
GalleyAPI.featureConfigSelfDeletingMessagesGet = Features.getFeatureConfig @'Public.WithLockStatus @'Public.TeamFeatureSelfDeletingMessages Features.getSelfDeletingMessagesInternal,
GalleyAPI.featureConfigGuestLinksGet = Features.getFeatureConfig @'Public.WithLockStatus @'Public.TeamFeatureGuestLinks Features.getGuestLinkInternal,
GalleyAPI.createNonBindingTeam = Teams.createNonBindingTeamH
GalleyAPI.createNonBindingTeam = Teams.createNonBindingTeamH,
GalleyAPI.updateTeam = Teams.updateTeamH
}

sitemap :: Routes ApiBuilder (Sem GalleyEffects) ()
sitemap = do
-- Team API -----------------------------------------------------------

put "/teams/:tid" (continue Teams.updateTeamH) $
zauthUserId
.&. zauthConnId
.&. capture "tid"
.&. jsonRequest @Public.TeamUpdateData
.&. accept "application" "json"
document "PUT" "updateTeam" $ do
summary "Update team properties"
parameter Path "tid" bytes' $
description "Team ID"
body (ref Public.modelUpdateData) $
description "JSON body"
errorResponse (Error.errorDescriptionTypeToWai @Error.NotATeamMember)
errorResponse (Error.errorDescriptionToWai (Error.operationDenied Public.SetTeamData))

get "/teams" (continue Teams.getManyTeamsH) $
zauthUserId
.&. opt (query "ids" ||| query "start")
Expand Down
19 changes: 1 addition & 18 deletions services/galley/src/Galley/API/Teams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -326,23 +326,6 @@ updateTeamStatus tid (TeamStatusUpdate newStatus cur) = do
(_, _) -> throw InvalidTeamStatusUpdate

updateTeamH ::
Members
'[ Error ActionError,
Error NotATeamMember,
GundeckAccess,
Input UTCTime,
TeamStore,
WaiRoutes
]
r =>
UserId ::: ConnId ::: TeamId ::: JsonRequest Public.TeamUpdateData ::: JSON ->
Sem r Response
updateTeamH (zusr ::: zcon ::: tid ::: req ::: _) = do
updateData <- fromJsonBody req
updateTeam zusr zcon tid updateData
pure empty

updateTeam ::
Members
'[ Error ActionError,
Error NotATeamMember,
Expand All @@ -356,7 +339,7 @@ updateTeam ::
TeamId ->
Public.TeamUpdateData ->
Sem r ()
updateTeam zusr zcon tid updateData = do
updateTeamH zusr zcon tid updateData = do
zusrMembership <- E.getTeamMember tid zusr
-- let zothers = map (view userId) membs
-- Log.debug $
Expand Down