Skip to content

Commit

Permalink
Merge pull request #387 from internxt/feat/sharings-to-multiple-teams…
Browse files Browse the repository at this point in the history
…-support

[PB-2865] feat: add support for sharings and multiple teams
  • Loading branch information
apsantiso authored Oct 2, 2024
2 parents c288ef1 + 8b7efeb commit d502210
Show file tree
Hide file tree
Showing 17 changed files with 1,402 additions and 469 deletions.
10 changes: 8 additions & 2 deletions src/modules/sharing/guards/sharings-token.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import { Workspace } from '../../workspaces/domains/workspaces.domain';
import { SharedWithType } from '../sharing.domain';

export interface SharingAccessTokenData {
sharedRootFolderId?: FolderAttributes['uuid'];
sharedWithType: SharedWithType;
parentFolderId?: FolderAttributes['parent']['uuid'];
owner?: {
uuid?: User['uuid'];
id?: User['id'];
};
sharedRootFolderId?: FolderAttributes['uuid'];
sharedWithType: SharedWithType;
workspace?: {
workspaceId: Workspace['id'];
};
folder?: {
uuid: FolderAttributes['uuid'];
id: FolderAttributes['id'];
};
}
7 changes: 7 additions & 0 deletions src/modules/sharing/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Default,
ForeignKey,
HasMany,
HasOne,
Model,
PrimaryKey,
Table,
Expand Down Expand Up @@ -157,6 +158,12 @@ export class SharingModel extends Model implements SharingAttributes {
@Column(DataType.ENUM('public', 'private'))
type: SharingAttributes['type'];

@HasOne(() => SharingRolesModel, {
foreignKey: 'sharingId',
sourceKey: 'id',
})
role: RoleModel;

@Column
createdAt: Date;

Expand Down
30 changes: 8 additions & 22 deletions src/modules/sharing/sharing.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Headers,
Patch,
UseFilters,
InternalServerErrorException,
} from '@nestjs/common';
import { Response } from 'express';
import {
Expand Down Expand Up @@ -919,39 +920,24 @@ export class SharingController {
})
async getItemsSharedsWith(
@UserDecorator() user: User,
@Query('limit') limit = 0,
@Query('offset') offset = 50,
@Param('itemId') itemId: Sharing['itemId'],
@Param('itemType') itemType: Sharing['itemType'],
@Res({ passthrough: true }) res: Response,
): Promise<{ users: Array<any> } | { error: string }> {
): Promise<{ users: Array<any> }> {
try {
const users = await this.sharingService.getItemSharedWith(
user,
itemId,
itemType,
offset,
limit,
);

return { users };
} catch (error) {
let errorMessage = error.message;

if (error instanceof InvalidSharedFolderError) {
res.status(HttpStatus.BAD_REQUEST);
} else if (error instanceof UserNotInvitedError) {
res.status(HttpStatus.FORBIDDEN);
} else {
Logger.error(
`[SHARING/GETSHAREDWITHME] Error while getting shared with by folder id ${
user.uuid
}, ${error.stack || 'No stack trace'}`,
);
res.status(HttpStatus.INTERNAL_SERVER_ERROR);
errorMessage = 'Internal server error';
}
return { error: errorMessage };
Logger.error(
`[SHARING/GETSHAREDWITHME] Error while getting shared with by folder id ${
user.uuid
}, ${error.stack || 'No stack trace'}`,
);
throw error;
}
}

Expand Down
Loading

0 comments on commit d502210

Please sign in to comment.