Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always carry a Role in the Invitation type. #577

Merged
merged 15 commits into from
Jan 23, 2019
Merged

Conversation

fisx
Copy link
Contributor

@fisx fisx commented Jan 21, 2019

Without this, the default role would have to be picked twice: once in the backend, and once in team settings. This is both extra work and poses the risk of running out of sync.

With these changes, the backend stores all future Invitations in the DB with a default role that is defined near the type. For migration, we allow for database entries with missing Role, and fill in the default there again. This is marked in the code as FUTUREWORK: remove.

without this, the default role would have to be fixed twice
(once in the backend, and once in team settings), and we
would risk running out of sync.
@fisx fisx changed the title Always carry a Role in the Invitation type. Always carry a Role in the Invitation type. Jan 21, 2019
@@ -49,7 +49,7 @@ instance ToJSON InvitationRequest where
instance FromJSON Invitation where
parseJSON = withObject "invitation" $ \o ->
Invitation <$> o .: "team"
<*> o .:? "role"
<*> o .: "role"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old clients won't have this field, this change is backwards-incompatible.

jschaul and others added 2 commits January 22, 2019 13:42
Co-Authored-By: fisx <mf@zerobuzz.net>
invitation :: Model
invitation = defineModel "Invitation" $ do
description "An invitation to join Wire"
property "inviter" bytes' $
description "User ID of the inviter"
property "role" role $ do
description "User ID of the inviter"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy paste error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry.

... third try? (or is it 4th?)

libs/brig-types/src/Brig/Types/Team/Invitation.hs Outdated Show resolved Hide resolved
@@ -166,7 +166,8 @@ createInvitation (_ ::: uid ::: tid ::: req) = do
body :: InvitationRequest <- parseJsonBody req
idt <- maybe (throwStd noIdentity) return =<< lift (fetchUserIdentity uid)
from <- maybe (throwStd noEmail) return (emailIdentity idt)
let inviteePerms = Team.rolePermissions . fromMaybe Team.RoleMember . irRole $ body
let inviteePerms = Team.rolePermissions inviteeRole
inviteeRole = fromMaybe Team.RoleMember . irRole $ body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Team.defaultRole?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix!

@@ -162,5 +163,8 @@ countInvitations t = fromMaybe 0 . fmap runIdentity <$>
cqlSelect :: PrepQuery R (Identity TeamId) (Identity Int64)
cqlSelect = "SELECT count(*) FROM team_invitation WHERE team = ?"

-- | FUTUREWORK: two weeks after https://github.com/wearezeta/backend-issues/issues/775 has been
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an accident, or is the rule going to be "backend-issues can be referred-to in code but not in issue comments"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accident. :-) will fix, too!

Co-Authored-By: fisx <mf@zerobuzz.net>
@@ -162,5 +163,8 @@ countInvitations t = fromMaybe 0 . fmap runIdentity <$>
cqlSelect :: PrepQuery R (Identity TeamId) (Identity Int64)
cqlSelect = "SELECT count(*) FROM team_invitation WHERE team = ?"

-- | FUTUREWORK: two weeks after https://github.com/wearezeta/backend-issues/issues/775 has been
-- deployed, we won't find any `Nothing` role values any more; then it will be safe to change the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then it will be safe

Actually, I would remove the FUTUREWORK comment entirely; since our code is open-sourced, and this condition of "two weeks" only holds on our infrastructure, and not for anyone running wire-server at an earlier version and deciding to upgrade at some point (possibly after the default is removed and a role inserted in the database being assumed, but then creating exceptions). So Maybe Role / defaultRole should stay here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Maybe Role / defaultRole should stay here.

I like this principle.

I don't like this principle applied inconsistently, however. Sometimes we leave stuff in, sometimes we deprecate things (like managed convs) but make it fairly easy for people to reenable them, sometimes we just don't communicate anything to anybody at all (like when a DB migration tool has to be run manually and we just write a tool but don't write anywhere that it has to be used).

If we decide to apply this principle consistently then I'd like everyone to explicitly agree on that because otherwise I have no idea what I'm allowed / not allowed to do and what I should / shouldn't look for when reviewing other people's PRs.

@julialongtin
Copy link
Contributor

julialongtin commented Jan 23, 2019 via email

@fisx fisx merged commit 40eb0b4 into develop Jan 23, 2019
@fisx fisx deleted the fisx-tweak-invitation-type branch January 23, 2019 14:03
@fisx fisx mentioned this pull request Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants