Skip to content

Commit

Permalink
wip: Work on getting PolicyController up and running
Browse files Browse the repository at this point in the history
  • Loading branch information
KallynGowdy committed Dec 20, 2024
1 parent 9eaaefd commit b6820a2
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 234 deletions.
21 changes: 7 additions & 14 deletions src/aux-records/MemoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,23 +1186,16 @@ export class MemoryStore
}

async listGrantedEntitlementsByFeatureAndUserId(
recordName: string | null,
inst: string,
packageIds: string[],
feature: Entitlement['feature'],
userId: string
): Promise<GrantedPackageEntitlement[]> {
// const loadedPackages = await this.listLoadedPackages(recordName, inst);
// const grantedEntitlements = loadedPackages.flatMap((p) =>
// this._grantedPackageEntitlements.filter(
// (e) =>
// e.userId === userId &&
// e.feature === feature &&
// e.packageRecordName === p.packageRecordName &&
// e.packageAddress === p.packageAddress
// )
// );
// return grantedEntitlements;
return [];
return this._grantedPackageEntitlements.filter(
(e) =>
e.userId === userId &&
e.feature === feature &&
packageIds.includes(e.packageId)
);
}

async countRecords(filter: CountRecordsFilter): Promise<number> {
Expand Down
39 changes: 26 additions & 13 deletions src/aux-records/PolicyController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5198,6 +5198,7 @@ describe('PolicyController', () => {
});

await services.packagesStore.createItem(packageRecordName, {
id: 'packageId',
address: packageAddress,
markers: [PRIVATE_MARKER],
});
Expand All @@ -5207,9 +5208,8 @@ describe('PolicyController', () => {
userId: userId,
recordName: instRecordName,
inst,
packageRecordName,
packageAddress,
packageVersionKey: packageKey,
packageId: 'packageId',
packageVersionId: 'packageVersionId',
});
});

Expand All @@ -5224,6 +5224,7 @@ describe('PolicyController', () => {
await services.packageVersionStore.createItem(
packageRecordName,
{
id: 'packageVersionId',
address: packageAddress,
key: packageKey,
auxFileName: 'auxFileName',
Expand Down Expand Up @@ -5262,9 +5263,7 @@ describe('PolicyController', () => {

userId: userId,

packageRecordName,
packageAddress,

packageId: 'packageId',
feature: feature,
scope: 'personal',
designatedRecords: [],
Expand All @@ -5288,11 +5287,11 @@ describe('PolicyController', () => {

expect(result).toEqual({
success: true,
recordName: recordName,
recordName: userId,
permission: {
id: null,
recordName,
userId: null,
recordName: userId,
userId: userId,

// The role that record owners recieve
subjectType: 'inst',
Expand All @@ -5301,6 +5300,7 @@ describe('PolicyController', () => {
// resourceKind and action are null because this permission
// applies to all resources and actions.
resourceKind: resourceKind,
resourceId: 'resourceId',
action: 'read',

options: {},
Expand All @@ -5309,14 +5309,27 @@ describe('PolicyController', () => {
entitlementGrant: {
id: 'entitlementId',
userId: userId,
packageRecordName,
packageAddress,
instRecordName: instRecordName,
inst,
packageId: 'packageId',
// packageRecordName,
// packageAddress,
// instRecordName: instRecordName,
// inst,
feature: feature,
scope: 'personal',
expireTimeMs: 999,
createdAtMs: 123,

designatedRecords: [],

loadedPackage: {
id: 'loadedPackageId',
recordName: instRecordName,
inst,
packageId: 'packageId',
packageVersionId:
'packageVersionId',
userId: 'userId',
},
},
explanation: 'Inst has entitlement.',
});
Expand Down
Loading

0 comments on commit b6820a2

Please sign in to comment.