Skip to content

Commit

Permalink
Revert "Remove non binding teams (#2514)" (#2607)
Browse files Browse the repository at this point in the history
Co-authored-by: Leif Battermann <[email protected]>
  • Loading branch information
fisx and battermann authored Aug 10, 2022
1 parent b1c39db commit 2400e8b
Show file tree
Hide file tree
Showing 66 changed files with 604 additions and 87 deletions.
2 changes: 1 addition & 1 deletion changelog.d/5-internal/pr-2514
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Deprecated non-binding teams removed
Prepare removing deprecated non-binding teams (no more used in integration tests) (#2514, #2607)
11 changes: 10 additions & 1 deletion libs/wire-api/src/Wire/API/Error/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ data GalleyError
| TeamNotFound
| TeamMemberNotFound
| NotATeamMember
| NonBindingTeam
| BroadcastLimitExceeded
| UserBindingExists
| NoAddToBinding
Expand All @@ -79,7 +80,9 @@ data GalleyError
| MLSCommitMissingReferences
| MLSSelfRemovalNotAllowed
| --
NotAOneMemberTeam
NoBindingTeamMembers
| NoBindingTeam
| NotAOneMemberTeam
| TooManyMembers
| ConvMemberNotFound
| GuestLinksDisabled
Expand Down Expand Up @@ -141,6 +144,8 @@ type instance MapError 'InvalidTargetAccess = 'StaticError 403 "invalid-op" "Inv

type instance MapError 'TeamNotFound = 'StaticError 404 "no-team" "Team not found"

type instance MapError 'NonBindingTeam = 'StaticError 404 "non-binding-team" "Not a member of a binding team"

type instance MapError 'BroadcastLimitExceeded = 'StaticError 400 "too-many-users-to-broadcast" "Too many users to fan out the broadcast event to"

type instance MapError 'TeamMemberNotFound = 'StaticError 404 "no-team-member" "Team member not found"
Expand Down Expand Up @@ -189,6 +194,10 @@ type instance MapError 'MLSCommitMissingReferences = 'StaticError 409 "mls-commi

type instance MapError 'MLSSelfRemovalNotAllowed = 'StaticError 409 "mls-self-removal-not-allowed" "Self removal from group is not allowed"

type instance MapError 'NoBindingTeamMembers = 'StaticError 403 "non-binding-team-members" "Both users must be members of the same binding team"

type instance MapError 'NoBindingTeam = 'StaticError 403 "no-binding-team" "Operation allowed only on binding teams"

type instance MapError 'NotAOneMemberTeam = 'StaticError 403 "not-one-member-team" "Can only delete teams with a single member"

type instance MapError 'TooManyMembers = 'StaticError 403 "too-many-members" "Maximum number of members per conversation reached"
Expand Down
90 changes: 80 additions & 10 deletions libs/wire-api/src/Wire/API/Routes/Public/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ type ConversationAPI =
( Summary "Create a 1:1 conversation"
:> CanThrow 'ConvAccessDenied
:> CanThrow 'InvalidOperation
:> CanThrow 'NoBindingTeamMembers
:> CanThrow 'NonBindingTeam
:> CanThrow 'NotATeamMember
:> CanThrow 'NotConnected
:> CanThrow OperationDenied
Expand Down Expand Up @@ -912,25 +914,45 @@ type TeamConversationAPI =

type TeamAPI =
Named
"update-team"
( Summary "Update team properties"
"create-non-binding-team"
( Summary "Create a new non binding team"
-- FUTUREWORK: deprecated in https://github.com/wireapp/wire-server/pull/2607
:> ZUser
:> ZConn
:> CanThrow 'NotATeamMember
:> CanThrow ('MissingPermission ('Just 'SetTeamData))
:> CanThrow 'NotConnected
:> CanThrow 'UserBindingExists
:> "teams"
:> Capture "tid" TeamId
:> ReqBody '[JSON] TeamUpdateData
:> ReqBody '[Servant.JSON] NonBindingNewTeam
:> MultiVerb
'PUT
'POST
'[JSON]
'[RespondEmpty 200 "Team updated"]
()
'[ WithHeaders
'[DescHeader "Location" "Team ID" TeamId]
TeamId
(RespondEmpty 201 "Team ID as `Location` header value")
]
TeamId
)
:<|> Named
"update-team"
( Summary "Update team properties"
:> ZUser
:> ZConn
:> CanThrow 'NotATeamMember
:> CanThrow ('MissingPermission ('Just 'SetTeamData))
:> "teams"
:> Capture "tid" TeamId
:> ReqBody '[JSON] TeamUpdateData
:> MultiVerb
'PUT
'[JSON]
'[RespondEmpty 200 "Team updated"]
()
)
:<|> Named
"get-teams"
( Summary "Get teams (deprecated); use `GET /teams/:tid`"
:> Until 'V2
-- FUTUREWORK: deprecated in https://github.com/wireapp/wire-server/pull/2607
:> ZUser
:> "teams"
:> Get '[JSON] TeamList
Expand Down Expand Up @@ -989,6 +1011,7 @@ type MessagingAPI =
:> ZConn
:> CanThrow 'TeamNotFound
:> CanThrow 'BroadcastLimitExceeded
:> CanThrow 'NonBindingTeam
:> "broadcast"
:> "otr"
:> "messages"
Expand Down Expand Up @@ -1026,6 +1049,7 @@ type MessagingAPI =
:> ZConn
:> CanThrow 'TeamNotFound
:> CanThrow 'BroadcastLimitExceeded
:> CanThrow 'NonBindingTeam
:> "broadcast"
:> "proteus"
:> "messages"
Expand Down Expand Up @@ -1606,6 +1630,30 @@ type TeamMemberAPI =
:> ReqBody '[JSON] User.UserIdList
:> Post '[JSON] TeamMemberListOptPerms
)
:<|> Named
"add-team-member"
( Summary "Add a new team member"
-- FUTUREWORK: deprecated in https://github.com/wireapp/wire-server/pull/2607
:> CanThrow 'InvalidPermissions
:> CanThrow 'NoAddToBinding
:> CanThrow 'NotATeamMember
:> CanThrow 'NotConnected
:> CanThrow OperationDenied
:> CanThrow 'TeamNotFound
:> CanThrow 'TooManyTeamMembers
:> CanThrow 'UserBindingExists
:> CanThrow 'TooManyTeamMembersOnTeamWithLegalhold
:> ZLocalUser
:> ZConn
:> "teams"
:> Capture "tid" TeamId
:> "members"
:> ReqBody '[JSON] NewTeamMember
:> MultiVerb1
'POST
'[JSON]
(RespondEmpty 200 "")
)
:<|> Named
"delete-team-member"
( Summary "Remove an existing team member"
Expand All @@ -1628,6 +1676,28 @@ type TeamMemberAPI =
TeamMemberDeleteResultResponseType
TeamMemberDeleteResult
)
:<|> Named
"delete-non-binding-team-member"
( Summary "Remove an existing team member"
-- FUTUREWORK: deprecated in https://github.com/wireapp/wire-server/pull/2607
:> CanThrow AuthenticationError
:> CanThrow 'AccessDenied
:> CanThrow 'TeamMemberNotFound
:> CanThrow 'TeamNotFound
:> CanThrow 'NotATeamMember
:> CanThrow OperationDenied
:> ZLocalUser
:> ZConn
:> "teams"
:> Capture "tid" TeamId
:> "members"
:> Capture "uid" UserId
:> MultiVerb
'DELETE
'[JSON]
TeamMemberDeleteResultResponseType
TeamMemberDeleteResult
)
:<|> Named
"update-team-member"
( Summary "Update an existing team member"
Expand Down
40 changes: 38 additions & 2 deletions libs/wire-api/src/Wire/API/Team.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module Wire.API.Team
teamName,
teamIcon,
teamIconKey,
teamBinding,
teamSplashScreen,
TeamBinding (..),
Icon (..),

-- * TeamList
Expand All @@ -40,6 +42,7 @@ module Wire.API.Team
-- * NewTeam
BindingNewTeam (..),
bindingNewTeamObjectSchema,
NonBindingNewTeam (..),
NewTeam (..),
newNewTeam,
newTeamName,
Expand Down Expand Up @@ -88,6 +91,7 @@ import Imports
import Test.QuickCheck.Gen (suchThat)
import Wire.API.Arbitrary (Arbitrary (arbitrary), GenericUniform (..))
import Wire.API.Asset (AssetKey)
import Wire.API.Team.Member (TeamMember)

--------------------------------------------------------------------------------
-- Team
Expand All @@ -98,14 +102,15 @@ data Team = Team
_teamName :: Text,
_teamIcon :: Icon,
_teamIconKey :: Maybe Text,
_teamBinding :: TeamBinding,
_teamSplashScreen :: Icon
}
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform Team)
deriving (ToJSON, FromJSON, S.ToSchema) via (Schema Team)

newTeam :: TeamId -> UserId -> Text -> Icon -> Team
newTeam tid uid nme ico = Team tid uid nme ico Nothing DefaultIcon
newTeam :: TeamId -> UserId -> Text -> Icon -> TeamBinding -> Team
newTeam tid uid nme ico tb = Team tid uid nme ico Nothing tb DefaultIcon

modelTeam :: Doc.Model
modelTeam = Doc.defineModel "Team" $ do
Expand All @@ -121,6 +126,8 @@ modelTeam = Doc.defineModel "Team" $ do
Doc.property "icon_key" Doc.string' $ do
Doc.description "team icon asset key"
Doc.optional
Doc.property "binding" Doc.bool' $
Doc.description "user binding team"
Doc.property "splash_screen" Doc.string' $ do
Doc.description "new splash screen asset key"
Doc.optional
Expand All @@ -134,8 +141,21 @@ instance ToSchema Team where
<*> _teamName .= field "name" schema
<*> _teamIcon .= field "icon" schema
<*> _teamIconKey .= maybe_ (optField "icon_key" schema)
<*> _teamBinding .= (fromMaybe Binding <$> optField "binding" schema)
<*> _teamSplashScreen .= (fromMaybe DefaultIcon <$> optField "splash_screen" schema)

data TeamBinding
= Binding
| NonBinding
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform TeamBinding)
deriving (ToJSON, FromJSON, S.ToSchema) via (Schema TeamBinding)

instance ToSchema TeamBinding where
schema =
enum @Bool "TeamBinding" $
mconcat [element True Binding, element False NonBinding]

--------------------------------------------------------------------------------
-- TeamList

Expand Down Expand Up @@ -188,6 +208,22 @@ instance Arbitrary BindingNewTeam where
where
zeroTeamMembers tms = tms {_newTeamMembers = Nothing}

-- | FUTUREWORK: this is dead code! remove!
newtype NonBindingNewTeam = NonBindingNewTeam (NewTeam (Range 1 127 [TeamMember]))
deriving stock (Eq, Show, Generic)
deriving (FromJSON, ToJSON, S.ToSchema) via (Schema NonBindingNewTeam)

instance ToSchema NonBindingNewTeam where
schema =
object "NonBindingNewTeam" $
NonBindingNewTeam
<$> unwrap .= newTeamObjectSchema sch
where
unwrap (NonBindingNewTeam nt) = nt

sch :: ValueSchema SwaggerDoc (Range 1 127 [TeamMember])
sch = fromRange .= rangedSchema (array schema)

data NewTeam a = NewTeam
{ _newTeamName :: Range 1 256 Text,
_newTeamIcon :: Icon,
Expand Down
Loading

0 comments on commit 2400e8b

Please sign in to comment.