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

initial implementation of invite method for MemberApi #232

Merged
merged 8 commits into from
Sep 5, 2023

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Aug 28, 2023

Towards #225

  • Introduces the MemberApi class
  • Implements the invite method

TODO:

  • What is role here and how does it work with MapeoRPC? Our original documentation suggests that it's some human-readable string, but given the recent work on capabilities, wondering if that changes to a role id or something like that. EDIT: answered in initial implementation of invite method for MemberApi #232 (comment)
  • Does this class need to keep track of pending invites? I know MapeoRPC does that internally but how about at this level?
  • What happens when you send multiple invites to the same device id?
  • integrate capabilities to write the capability when invite accepted feat: add capabilities #231

@achou11 achou11 requested a review from gmaclennan August 28, 2023 21:06
@achou11 achou11 force-pushed the 225/member-invite branch from 0843ad2 to ef392b2 Compare August 28, 2023 21:09
import { MemberApi } from '../src/member-api.js'
import { replicate } from './helpers/rpc.js'

test('Invite sends expected project-related details', async (t) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

this test kind of overlaps with some of the rpc unit tests. okay for now since I just want something here until i figure out what else to test

* @param {string} deviceId
*
* @param {Object} opts
* @param {string} opts.role
Copy link
Member Author

Choose a reason for hiding this comment

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

what is this and how should it be used with MapeoRPC?

Copy link
Member

Choose a reason for hiding this comment

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

This should be roleId. After the device responds to the invite we should write that role assignment e.g:

const response = await this.#rpc.invite()
if (response === 'ACCEPT') {
  capabilities.assignRole(deviceId, roleId)
}

(not sure if I have the correct return type of invite())

Copy link
Member Author

Choose a reason for hiding this comment

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

how does the device being invited know what role they will be assigned prior to responding? Shouldn't the call to rpc.invite() also accept some param about the role to send to the target peer?

My understanding is that from a UX perspective, someone with an invite should see something like "Bob has invited you to be ROLE in PROJECT NAME"

Copy link
Member Author

@achou11 achou11 Aug 30, 2023

Choose a reason for hiding this comment

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

param name addressed via 562f73d

Copy link
Member Author

Choose a reason for hiding this comment

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

role assignment addressed via e26ff99

@achou11 achou11 changed the title initial implementation of MemberApi.invite initial implementation of invite method for MemberApi Aug 28, 2023
@achou11 achou11 force-pushed the 225/member-invite branch 3 times, most recently from 9e9b3d7 to c1d0acd Compare August 30, 2023 15:31
* @param {string} deviceId
*
* @param {Object} opts
* @param {string} opts.role
Copy link
Member

Choose a reason for hiding this comment

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

This should be roleId. After the device responds to the invite we should write that role assignment e.g:

const response = await this.#rpc.invite()
if (response === 'ACCEPT') {
  capabilities.assignRole(deviceId, roleId)
}

(not sure if I have the correct return type of invite())

tests/member-api.js Show resolved Hide resolved
@achou11 achou11 force-pushed the 225/member-invite branch from c1d0acd to 88a3ef4 Compare August 30, 2023 16:14
@achou11 achou11 requested a review from gmaclennan August 30, 2023 21:11
@achou11 achou11 force-pushed the 225/member-invite branch from 88a3ef4 to 562f73d Compare August 31, 2023 14:26
@achou11 achou11 marked this pull request as draft August 31, 2023 16:53
Copy link
Member Author

@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.

added the role assignment bit. wanted to have some tests to cover that part but they may be diving into implementation details too much. perhaps better to write an e2e for this?

replicate(r1, r2)
})

test('invite() does not assign role to invited device if invite is not accepted', async (t) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe testing implementation details too much?

replicate(r1, r2)
})

test('invite() assigns role to invited device after invite accepted', async (t) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe testing implementation details too much?

@achou11 achou11 marked this pull request as ready for review September 5, 2023 14:41
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.

Looks good to me, good work on this. I think tests are ok - we can eventually replace with e2e tests but at this stage these tests are helpful for making sure the internals of this are working as expected as we build upon it.

@achou11 achou11 merged commit ec1b381 into main Sep 5, 2023
@achou11 achou11 deleted the 225/member-invite branch September 5, 2023 15:01
gmaclennan added a commit that referenced this pull request Sep 6, 2023
* main: (25 commits)
  add initial implementation of MemberApi (#232)
  feat: $blobs.getUrl and $blobs.create methods (#184)
  chore: update manager e2e tests (#237)
  feat: add capabilities (#231)
  feat: coreOwnership integration [3/3] (#230)
  feat: CoreOwnership class w getOwner & getCoreKey [2/3] (#229)
  feat: handle `coreOwnership` records in `IndexWriter` [1/3] (#214)
  fix: adjust storage options for MapeoManager and MapeoProject (#235)
  implement addProject method for MapeoManager class (#215)
  implement listProjects method for MapeoManager class (#208)
  feat: expose blobStore.writerDriveId (#219)
  implement wrapper client containing createProject and getProject methods (#199)
  add project settings functionality to MapeoProject (#187)
  feat: Add encode/decode for project keys [3/3] (#203)
  feat: update protobuf for RPC [2/3] (#202)
  chore: move protobuf messages into src/generated [1/3] (#201)
  feat: Add internal `dataType.createWithDocId()` (#192)
  chore: explicitly set "mode" opt for encryptionKeys column creation (#186)
  chore: fix linting and type checking (#183)
  chore: consolidate encryption key columns in projectKeys table (#181)
  ...
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.

2 participants