Skip to content

Commit

Permalink
Add permissions to the invite link
Browse files Browse the repository at this point in the history
  • Loading branch information
jatindersingh93 committed Apr 15, 2024
1 parent 6fe31a7 commit 6f416aa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/src/controllers/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ const controller = {
resource: resource,
type: type,
expiresAt: req.body.expiresAt ? new Date(req.body.expiresAt * 1000).toISOString() : undefined,
userId: userId
userId: userId,
permissionsCode: req.body.permissionsCode
});
res.status(201).json(response.token);
} catch (e) {
Expand Down Expand Up @@ -182,7 +183,7 @@ const controller = {

// Grant invitation permission and cleanup
await objectPermissionService.addPermissions(invite.resource, [
{ userId: userId, permCode: Permissions.READ }
{ userId: userId, permCode: 'CREATE' }
], invite.createdBy);
} else if (invite.type === ResourceType.BUCKET) {
// Check for object existence
Expand Down
15 changes: 15 additions & 0 deletions app/src/db/migrations/20240305000000_014-invitePermissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exports.up = function (knex) {
return Promise.resolve()
// Add permissionsCode to the table
.then(() => knex.schema.alterTable('invite', table => {
table.specificType('permissionsCode', 'TEXT[]');
}));
};

exports.down = function (knex) {
return Promise.resolve()
// permissionsCode column from Invite table
.then(() => knex.schema.alterTable('invite', table => {
table.dropColumn('permissionsCode');
}));
};
2 changes: 2 additions & 0 deletions app/src/db/models/tables/invite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Model } = require('objection');

const { Permissions } = require('../../../components/constants');

Check failure on line 3 in app/src/db/models/tables/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x)

'Permissions' is assigned a value but never used

Check failure on line 3 in app/src/db/models/tables/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x)

'Permissions' is assigned a value but never used

Check failure on line 3 in app/src/db/models/tables/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (20.x)

'Permissions' is assigned a value but never used

Check failure on line 3 in app/src/db/models/tables/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x)

'Permissions' is assigned a value but never used

Check failure on line 3 in app/src/db/models/tables/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x)

'Permissions' is assigned a value but never used

Check failure on line 3 in app/src/db/models/tables/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (20.x)

'Permissions' is assigned a value but never used
const { stamps } = require('../jsonSchema');
const { Timestamps } = require('../mixins');

Expand All @@ -22,6 +23,7 @@ class ObjectModel extends Timestamps(Model) {
resource: { type: 'string', format: 'uuid' },
type: { type: 'string', enum: ['bucketId', 'objectId'] },
expiresAt: { type: 'string', format: 'date-time' },
permissionsCode: { type: 'array', items: { type: 'string' } },
...stamps
},
additionalProperties: false
Expand Down
2 changes: 2 additions & 0 deletions app/src/services/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const service = {
* @param {string} [data.email] The optional email address of the intended recipient
* @param {string} data.resource The uuid of the target resource
* @param {(bucketId|objectId)} data.type The type of resource. Must either be `bucketId` or `objectId`.
* @param {string} [data.permCode] Permission level for the invite.
* @param {string} [data.expiresAt] The optional time this token will expire at.
* Defaults to 24 hours from now if unspecified.
* @param {string} [data.userId] The optional userId that requested this generation
Expand All @@ -30,6 +31,7 @@ const service = {
email: data.email,
resource: data.resource,
type: data.type,
permCode: data.permCode ?? 'READ',
expiresAt: data.expiresAt,
createdBy: data.userId ?? SYSTEM_USER
});
Expand Down
3 changes: 2 additions & 1 deletion app/src/validators/invite.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

const Joi = require('joi');

const { type } = require('./common');
const { scheme, type } = require('./common');

Check failure on line 4 in app/src/validators/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x)

'scheme' is assigned a value but never used

Check failure on line 4 in app/src/validators/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x)

'scheme' is assigned a value but never used

Check failure on line 4 in app/src/validators/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (20.x)

'scheme' is assigned a value but never used

Check failure on line 4 in app/src/validators/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x)

'scheme' is assigned a value but never used

Check failure on line 4 in app/src/validators/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x)

'scheme' is assigned a value but never used

Check failure on line 4 in app/src/validators/invite.js

View workflow job for this annotation

GitHub Actions / Unit Tests (20.x)

'scheme' is assigned a value but never used
const { validate } = require('../middleware/validation');

const schema = {
Expand All @@ -11,6 +11,7 @@ const schema = {
email: type.email,
expiresAt: Joi.date().timestamp('unix').greater('now'),
objectId: type.uuidv4,
permissionsCode: Joi.array().items(Joi.string()),
}).xor('bucketId', 'objectId')
},

Expand Down

0 comments on commit 6f416aa

Please sign in to comment.