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

Feat: add fields to invites #393

Merged
merged 18 commits into from
Dec 13, 2023
Merged

Feat: add fields to invites #393

merged 18 commits into from
Dec 13, 2023

Conversation

tomasciccola
Copy link
Contributor

should close #275

Tomás Ciccola added 3 commits November 29, 2023 12:03
1. Add roleName and roleDescription to Invite protobuf (rpc.proto)
2. add fields to memberApi.invite
3. send those fields as part of 'invite-received' on  invite-api
   callback
@tomasciccola
Copy link
Contributor Author

the e2e tests that are failing are all related to calling manager.addProject which expects an Invite. I don't know from the context what the roleName (the missing field) should be in any case, or if maybe the signature for that function should Omit the roleName from Invite.
For now I'll go through every failing test and see if I can sort of guess the context?

* Omit roleName from mapeoManager.addProject (solves a bunch of tests,
  but may need to regress this)
* capitalize roleName in member-api
* fix local-peers tests
@tomasciccola
Copy link
Contributor Author

tomasciccola commented Nov 29, 2023

test-e2e/members.js are failing with a timeout. It seems there's a bunch of promises not being resolved (see test-e2e/utils.js:93)
The reason seems to be the error check added here.
One solution would be to add a project name on the e2e test itself (haven't found a method to do that besides passing the name to localPeers.invite() which is different from memberApi.invite() ...)
Another question is, in ProjectSettings schema, name is optional. Should we keep it like that?

@achou11
Copy link
Member

achou11 commented Nov 29, 2023

test-e2e/members.js are failing with a timeout. It seems there's a bunch of promises not being resolved (see test-e2e/utils.js:93) The reason seems to be the error check added here. One solution would be to add a project name on the e2e test itself (haven't found a method to do that besides passing the name to localPeers.invite() which is different from memberApi.invite() ...)

The fix for the test would be to update this line in the test so that the project that's created has a name e.g. await invitor.createProject({ name: 'mapeo' }):

https://github.com/digidem/mapeo-core-next/blob/d1d398d09ed861c6ed2e2ad08eb00ff5d5cc6c36/test-e2e/members.js#L129

Probably also makes sense to have a test that makes sure that invites don't work if the project doesn't have a name, if that doesn't exist already.

Another question is, in ProjectSettings schema, name is optional. Should we keep it like that?

i think it should be kept that way. i believe we explicitly decided to let the consumer decide the fallback name for projects that don't have a name

@tomasciccola
Copy link
Contributor Author

The fix for the test would be to update this line in the test so that the project that's created has a name e.g. await invitor.createProject({ name: 'mapeo' }):

heh, I missed that method signature 😄

Copy link
Member

@achou11 achou11 left a comment

Choose a reason for hiding this comment

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

raised a couple of concerns but seems like the foundational pieces are there! there's a related issue around translations that isn't entirely clear to me just yet, which would be good to get a resolution on

src/member-api.js Outdated Show resolved Hide resolved
src/utils.js Outdated Show resolved Hide resolved
src/local-peers.js Outdated Show resolved Hide resolved
src/generated/rpc.js Outdated Show resolved Hide resolved
Comment on lines 58 to 59
* @param {import('./generated/rpc.js').Invite_RoleName} opts.roleName
* @param {string} [opts.roleDescription]
Copy link
Member

Choose a reason for hiding this comment

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

Not sure the params should change here. To me, the roleId should still be used here, and the name and description sent with the invite are derived based on the capabilities associated with the roleId.

The other (tangential) uncertainty i have is how this all works with translations. if the name and description are built into the capability definition, how does internationalization work when you want to surface those things are part of the UI? (easier for name than description in that case)

thoughts @gmaclennan ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think what you say makes sense, but syncing this morning with gregor we arrived at that change maybe there's some reason I'm forgetting??

Copy link
Member

@achou11 achou11 Nov 29, 2023

Choose a reason for hiding this comment

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

hm i see. if this was discussed already then feel free to disregard my initial comment! i admit the advantage of providing the description is that there's more freedom from the consumer to describe the role/capability, as opposed to us hardcoding it in the capability definition. still unsure about the role name as a param but hard to tell without diving deeper myself

Copy link
Member

Choose a reason for hiding this comment

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

Yes good points @achou11, it was late last night when discussing and I hadn't fully wrapped my head around this - I was wondering where the frontend would get the roleId from, but having a fixed role name doesn't allow the frontend to internationalize what is sent in the invite.

  1. We need to export the DEFAULT_CAPABILITIES from @mapeo/core so the front end can read those - ideally they are accessible from the mapeo client without needing to do an async call to the backend - maybe an opportunity to use package.exports @achou11 :)
  2. We keep roleId as the required param here, and both role name and role description optional. Role name can default to the name on the capability record. The frontend can pass a translated role name (the invitor would decide on the translation, rather than the invitee - because in the future capabilities and capability names might not be available on a device before it joins a project)
  3. Need to add a check for a valid role ID and throw if invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we keep roleId, shouldn't we remove roleName from params since it can be grabbed from the roleId. I dunno about roleDescription since DEFAULT_CAPABILITIES doesn't have a roleDescription (maybe the idea is to add it to that record?)

Copy link
Member

@achou11 achou11 Nov 30, 2023

Choose a reason for hiding this comment

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

If we keep roleId, shouldn't we remove roleName from params since it can be grabbed from the roleId.

it's still useful for roleName to be an optional param (not a required param) because otherwise we wouldn't be able to easily provide a translated role name for the invited device to see when they receive the invite. Gregor's suggestion is to have the optional name param and if that isn't provided use the name associated with the roleId. For example, an application should be able to do members.invite({ roleName: "Miembro", ... }) if they want the invited device to see the translated name of the role. Otherwise the default is the english name we're using in the role id definition

Copy link
Member

@achou11 achou11 Nov 30, 2023

Choose a reason for hiding this comment

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

We keep roleId as the required param here, and both role name and role description optional.

The only risk with this is inviting someone with misleading information, which isn't a huge issue for us I guess. For example, one could do this:

members.invite({ 
  roleId: MEMBER_ROLE_ID,
  roleName: "Coordinator",
  roleDescription: "Definitely a coordinator ;)" 
})

This avoid the tests hanging since now we need a project name in order
to send an invite
@achou11
Copy link
Member

achou11 commented Nov 29, 2023

is adding the invitor name and id also going to be part of this PR? doesn't seem like it's doing so at the moment, but I think those were a later addition to that issue's checklist.

if not, let's make sure to update the PR title and description to be precise about which fields are being added by these changes

* regenerate rpc.js due
to formatting issues
@tomasciccola
Copy link
Contributor Author

is adding the invitor name and id also going to be part of this PR? doesn't seem like it's doing so at the moment, but I think those were a later addition to that issue's checklist.

if not, let's make sure to update the PR title and description to be precise about which fields are being added by these changes

I must double check with @gmaclennan but I think what we talked about was that sending the invitorId (peerId) is redundant since its already sended with the invite?
Regarding invitorName, I still need to add it. I think we resolved to being the deviceName by calling mapeoProject.getOwnDeviceName.
If I'm correct I'll update the issue and remove Invitor Name from the checklist, does that sound right??

@achou11
Copy link
Member

achou11 commented Nov 29, 2023

is adding the invitor name and id also going to be part of this PR? doesn't seem like it's doing so at the moment, but I think those were a later addition to that issue's checklist.
if not, let's make sure to update the PR title and description to be precise about which fields are being added by these changes

I must double check with @gmaclennan but I think what we talked about was that sending the invitorId (peerId) is redundant since its already sended with the invite? Regarding invitorName, I still need to add it. I think we resolved to being the deviceName by calling mapeoProject.getOwnDeviceName. If I'm correct I'll update the issue and remove Invitor Name from the checklist, does that sound right??

yeah i think that makes sense 👍

Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

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

a couple of cleanup suggestions, but some requested changes around role names and passing the role ID

proto/rpc.proto Outdated Show resolved Hide resolved
src/mapeo-manager.js Outdated Show resolved Hide resolved
src/member-api.js Outdated Show resolved Hide resolved
Comment on lines 58 to 59
* @param {import('./generated/rpc.js').Invite_RoleName} opts.roleName
* @param {string} [opts.roleDescription]
Copy link
Member

Choose a reason for hiding this comment

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

Yes good points @achou11, it was late last night when discussing and I hadn't fully wrapped my head around this - I was wondering where the frontend would get the roleId from, but having a fixed role name doesn't allow the frontend to internationalize what is sent in the invite.

  1. We need to export the DEFAULT_CAPABILITIES from @mapeo/core so the front end can read those - ideally they are accessible from the mapeo client without needing to do an async call to the backend - maybe an opportunity to use package.exports @achou11 :)
  2. We keep roleId as the required param here, and both role name and role description optional. Role name can default to the name on the capability record. The frontend can pass a translated role name (the invitor would decide on the translation, rather than the invitee - because in the future capabilities and capability names might not be available on a device before it joins a project)
  3. Need to add a check for a valid role ID and throw if invalid.

@gmaclennan
Copy link
Member

If I'm correct I'll update the issue and remove Invitor Name from the checklist, does that sound right??

Invitor ID can be removed from the checklist, but invitor name is still needed, as you say, from mapeoProject.getOwnDeviceName

Tomás Ciccola added 2 commits November 30, 2023 14:46
* revert Invite.roleName to be a string instead of an enum
* add `roleId` again as a param to memberApi.invite. derive roleName
  as `DEFAULT_CAPABILITIES[roleId]`
* on MapeoManager, instead of `Omit` `roleName`, `Pick` desired fields
  from `Invite`
* fix tests do to api changes in memberApi.invite
src/invite-api.js Outdated Show resolved Hide resolved
@tomasciccola
Copy link
Contributor Author

test-e2e/sync.js is failing with code: 'SQLITE_READONLY_DBMOVED'. It happens only on linux and I can repro locally

@achou11
Copy link
Member

achou11 commented Nov 30, 2023

test-e2e/sync.js is failing with code: 'SQLITE_READONLY_DBMOVED'. It happens only on linux and I can repro locally

seems to happen on windows too, based on another run on the main branch: https://github.com/digidem/mapeo-core-next/actions/runs/7019047664/job/19095674265#step:6:2657

@achou11
Copy link
Member

achou11 commented Nov 30, 2023

@tomasciccola mind trying this from #396 to fix the tests?

https://github.com/digidem/mapeo-core-next/pull/396/files#diff-05ee223fd47283dc5d5dcee7b4b6de4bc57af24b09892a83627080bf64d7603c

EDIT: Doesn't look like it fully fixes the issue but basically seems like a known issue

@gmaclennan
Copy link
Member

The failing test here is because the tear down function is deleting the temporary storage files, but SQLite is still trying to write to the database. I’m ok with ignoring for now until we merge the close() PR.

Copy link
Member

@achou11 achou11 left a comment

Choose a reason for hiding this comment

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

Overall changes are looking good! still noted a couple of items that should be addressed in this PR and ideally have tests added for them.

src/member-api.js Outdated Show resolved Hide resolved
src/member-api.js Outdated Show resolved Hide resolved
test-e2e/utils.js Outdated Show resolved Hide resolved
src/member-api.js Outdated Show resolved Hide resolved
src/capabilities.js Outdated Show resolved Hide resolved
… not

  passed
* check MEMBER and COORDINATOR ROLE_ID as only valid roleIds
* delete `roleIdFromName` from `src/capabilities.js`
@tomasciccola tomasciccola requested a review from achou11 December 11, 2023 20:16
@tomasciccola tomasciccola merged commit 6eac910 into main Dec 13, 2023
7 checks passed
@tomasciccola tomasciccola deleted the feat/addFieldsToInvites branch December 13, 2023 16:41
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.

Add fields to invites
3 participants