Skip to content

Commit

Permalink
Merge pull request #248 from bcgov/ob-perm
Browse files Browse the repository at this point in the history
Return full object permissions in object search
  • Loading branch information
TimCsaky authored Feb 13, 2024
2 parents 7fa81c6 + caed857 commit 427d162
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
54 changes: 53 additions & 1 deletion app/src/docs/v1.api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ paths:
schema:
type: array
items:
$ref: "#/components/schemas/DB-Object"
$ref: "#/components/schemas/DB-Object+Permissions"
headers:
X-Total-Rows:
schema:
Expand Down Expand Up @@ -2107,6 +2107,58 @@ components:
permCode:
$ref: "#/components/schemas/PermCode"
- $ref: "#/components/schemas/DB-TimestampUserData"
DB-Object+Permissions:
title: DB Object and Permissions
type: object
allOf:
- type: object
required:
- id
- path
- public
- active
properties:
id:
type: string
description: The primary identifier for this object
format: uuid
example: ac246e31-c807-496c-bc93-cd8bc2f1b2b4
path:
type: string
description: The canonical S3 path string of the object
example: coms/env/foobar.txt
public:
type: boolean
description: Determines whether this object is publicly accessible
default: false
example: false
active:
type: boolean
description: Determines whether this object is considered active
default: true
example: true
bucketId:
type: string
description: The primary identifier for the bucket
format: uuid
example: c05c7650-5f48-4e51-bf17-762e8fc121a1
name:
type: string
description: The filename of the original file uploaded
example: foobar.txt
lastSyncedDate:
type: string
format: date-time
description: >-
Time when the object was last synced with the S3 bucket
example: "2022-03-11T23:19:16.343Z"
default: null
permissions:
type: array
description: An array of object permissions for the current user. Empty if authenticated via Basic auth. Attribute only returned if `permissions=true` on request.
items:
$ref: "#/components/schemas/DB-ObjectPermission"
- $ref: "#/components/schemas/DB-TimestampUserData"
DB-TagKeyValue:
title: DB Tag Key Value
type: object
Expand Down
15 changes: 9 additions & 6 deletions app/src/services/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,17 @@ const service = {
results.map(row => {
// eslint-disable-next-line no-unused-vars
const { objectPermission, bucketPermission, version, ...object } = row;
if (params.permissions) {
object.permissions = [];
if (objectPermission && params.userId && params.userId !== SYSTEM_USER) {
object.permissions = objectPermission.map(o => o.permCode);

if (row.id) {
if (params.permissions) {
object.permissions = [];
if (objectPermission && params.userId) {
object.permissions = objectPermission.filter(p => p.userId === params.userId);
}
}
return object;
}
return object;
})
}).filter(x => x)
);
});

Expand Down
3 changes: 2 additions & 1 deletion app/tests/unit/services/object.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('searchObjects', () => {
// TODO: Add in other untested multiplicity cases
it('Search and filter for specific object records with permissions and without pagination', async () => {
const params = {
id: '123',
bucketId: BUCKET_ID,
active: 'true',
key: 'key',
Expand All @@ -127,7 +128,7 @@ describe('searchObjects', () => {
expect(result).toHaveProperty('data');
expect(Array.isArray(result.data)).toBeTruthy();
expect(result.data[0]).toHaveProperty('permissions');
expect(result.data[0].permissions).toEqual(expect.arrayContaining(['READ']));
expect(result.data[0].permissions).toEqual([]);

expect(ObjectModel.startTransaction).toHaveBeenCalledTimes(1);
expect(ObjectModel.query).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 427d162

Please sign in to comment.