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 assignRole() method to MemberApi #423

Merged
merged 8 commits into from
Jan 5, 2024
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
26 changes: 21 additions & 5 deletions src/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,27 @@ export class Capabilities {
if (!ownCapabilities.roleAssignment.includes(roleId)) {
throw new Error('No capability to assign role ' + roleId)
}
await this.#dataType[kCreateWithDocId](deviceId, {
schemaName: 'role',
roleId,
fromIndex,
})

const existingRoleDoc = await this.#dataType
.getByDocId(deviceId)
.catch(() => null)

if (existingRoleDoc) {
await this.#dataType.update(
[existingRoleDoc.versionId, ...existingRoleDoc.forks],
{
schemaName: 'role',
roleId,
fromIndex,
}
)
} else {
await this.#dataType[kCreateWithDocId](deviceId, {
schemaName: 'role',
roleId,
fromIndex,
})
}
}

async #isProjectCreator() {
Expand Down
8 changes: 4 additions & 4 deletions src/mapeo-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ const CORESTORE_STORAGE_FOLDER_NAME = 'corestore'
const INDEXER_STORAGE_FOLDER_NAME = 'indexer'
export const kCoreManager = Symbol('coreManager')
export const kCoreOwnership = Symbol('coreOwnership')
export const kCapabilities = Symbol('capabilities')
export const kSetOwnDeviceInfo = Symbol('kSetOwnDeviceInfo')
export const kBlobStore = Symbol('blobStore')
export const kProjectReplicate = Symbol('replicate project')
export const kDataTypes = Symbol('dataTypes')
const EMPTY_PROJECT_SETTINGS = Object.freeze({})

/**
Expand Down Expand Up @@ -349,10 +349,10 @@ export class MapeoProject extends TypedEmitter {
}

/**
* Capabilities instance, used for tests
* DataTypes object mappings, used for tests
*/
get [kCapabilities]() {
return this.#capabilities
get [kDataTypes]() {
return this.#dataTypes
}

get [kBlobStore]() {
Expand Down
9 changes: 9 additions & 0 deletions src/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,13 @@ export class MemberApi extends TypedEmitter {
})
)
}

/**
* @param {string} deviceId
* @param {import('./capabilities.js').RoleId} roleId
* @returns {Promise<void>}
*/
async assignRole(deviceId, roleId) {
return this.#capabilities.assignRole(deviceId, roleId)
}
}
159 changes: 0 additions & 159 deletions test-e2e/capabilities.js

This file was deleted.

Loading
Loading