-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from internxt/feat/invite-users-to-org
[PB-1551]: Feat/invite users to org
- Loading branch information
Showing
16 changed files
with
1,141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
migrations/20240319130531-create-workspace-invites-table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const tableName = 'workspaces_invites'; | ||
|
||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable(tableName, { | ||
id: { | ||
type: Sequelize.UUID, | ||
defaultValue: Sequelize.UUIDV4, | ||
allowNull: false, | ||
primaryKey: true, | ||
}, | ||
workspace_id: { | ||
type: Sequelize.UUID, | ||
allowNull: false, | ||
references: { | ||
model: 'workspaces', | ||
key: 'id', | ||
}, | ||
}, | ||
invited_user: { | ||
type: Sequelize.UUID, | ||
allowNull: false, | ||
}, | ||
encryption_algorithm: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
encryption_key: { | ||
type: Sequelize.STRING(800), | ||
allowNull: false, | ||
}, | ||
space_limit: { | ||
type: Sequelize.BIGINT.UNSIGNED, | ||
allowNull: false, | ||
}, | ||
created_at: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.NOW, | ||
}, | ||
updated_at: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.NOW, | ||
}, | ||
}); | ||
}, | ||
down: async (queryInterface) => { | ||
await queryInterface.dropTable(tableName); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/modules/workspaces/attributes/workspace-invite.attribute.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface WorkspaceInviteAttributes { | ||
id: string; | ||
workspaceId: string; | ||
invitedUser: string; | ||
encryptionAlgorithm: string; | ||
encryptionKey: string; | ||
spaceLimit: bigint; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { WorkspaceInviteAttributes } from '../attributes/workspace-invite.attribute'; | ||
|
||
export class WorkspaceInvite implements WorkspaceInviteAttributes { | ||
id: string; | ||
workspaceId: string; | ||
invitedUser: string; | ||
encryptionAlgorithm: string; | ||
encryptionKey: string; | ||
spaceLimit: bigint; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
|
||
constructor({ | ||
id, | ||
workspaceId, | ||
invitedUser, | ||
encryptionAlgorithm, | ||
encryptionKey, | ||
spaceLimit, | ||
createdAt, | ||
updatedAt, | ||
}: WorkspaceInviteAttributes) { | ||
this.id = id; | ||
this.workspaceId = workspaceId; | ||
this.invitedUser = invitedUser; | ||
this.encryptionAlgorithm = encryptionAlgorithm; | ||
this.encryptionKey = encryptionKey; | ||
this.spaceLimit = spaceLimit; | ||
this.createdAt = createdAt; | ||
this.updatedAt = updatedAt; | ||
} | ||
|
||
static build(attributes: WorkspaceInviteAttributes): WorkspaceInvite { | ||
return new WorkspaceInvite(attributes); | ||
} | ||
|
||
toJSON() { | ||
return { | ||
id: this.id, | ||
workspaceId: this.workspaceId, | ||
invitedUser: this.invitedUser, | ||
encryptionAlgorithm: this.encryptionAlgorithm, | ||
encryptionKey: this.encryptionKey, | ||
spaceLimit: this.spaceLimit.toString(), | ||
createdAt: this.createdAt, | ||
updatedAt: this.updatedAt, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsPositive } from 'class-validator'; | ||
import { User } from '../../user/user.domain'; | ||
import { WorkspaceInvite } from '../domains/workspace-invite.domain'; | ||
|
||
export class CreateWorkspaceInviteDto { | ||
@ApiProperty({ | ||
example: '[email protected]', | ||
description: 'The email of the user you want to invite', | ||
}) | ||
@IsNotEmpty() | ||
invitedUser: User['email']; | ||
|
||
@ApiProperty({ | ||
example: '1073741824', | ||
description: 'Space assigned to user in bytes', | ||
}) | ||
@IsNotEmpty() | ||
@IsPositive() | ||
spaceLimit: WorkspaceInvite['spaceLimit']; | ||
|
||
@ApiProperty({ | ||
example: 'encrypted encryption key', | ||
description: | ||
"Owner's encryption key encrypted with the invited user's public key.", | ||
}) | ||
@IsNotEmpty() | ||
encryptionKey: WorkspaceInvite['encryptionKey']; | ||
|
||
@ApiProperty({ | ||
example: 'aes-256-gcm', | ||
description: 'Encryption algorithm used to encrypt the encryption key.', | ||
}) | ||
@IsNotEmpty() | ||
encryptionAlgorithm: WorkspaceInvite['encryptionAlgorithm']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
Model, | ||
Table, | ||
Column, | ||
DataType, | ||
PrimaryKey, | ||
ForeignKey, | ||
BelongsTo, | ||
} from 'sequelize-typescript'; | ||
import { WorkspaceModel } from './workspace.model'; | ||
import { WorkspaceInviteAttributes } from '../attributes/workspace-invite.attribute'; | ||
|
||
@Table({ | ||
underscored: true, | ||
timestamps: true, | ||
tableName: 'workspaces_invites', | ||
}) | ||
export class WorkspaceInviteModel | ||
extends Model | ||
implements WorkspaceInviteAttributes | ||
{ | ||
@PrimaryKey | ||
@Column({ type: DataType.UUID, defaultValue: DataType.UUIDV4 }) | ||
id: string; | ||
|
||
@ForeignKey(() => WorkspaceModel) | ||
@Column({ type: DataType.UUID, allowNull: false }) | ||
workspaceId: string; | ||
|
||
@BelongsTo(() => WorkspaceModel, { | ||
foreignKey: 'workspaceId', | ||
targetKey: 'id', | ||
as: 'workspace', | ||
}) | ||
workspace: WorkspaceModel; | ||
|
||
@Column({ type: DataType.UUID, allowNull: false }) | ||
invitedUser: string; | ||
|
||
@Column({ type: DataType.STRING, allowNull: false }) | ||
encryptionAlgorithm: string; | ||
|
||
@Column({ type: DataType.STRING, allowNull: false }) | ||
encryptionKey: string; | ||
|
||
@Column({ type: DataType.BIGINT.UNSIGNED, allowNull: false }) | ||
spaceLimit: bigint; | ||
|
||
@Column({ allowNull: false, defaultValue: DataType.NOW }) | ||
createdAt: Date; | ||
|
||
@Column({ allowNull: false, defaultValue: DataType.NOW }) | ||
updatedAt: Date; | ||
} |
Oops, something went wrong.