Skip to content

Commit

Permalink
Merge pull request #373 from internxt/fix/show-only-shared-files-in-c…
Browse files Browse the repository at this point in the history
…urrent-workspace

[_] fix: only show sharings in the current workspace
  • Loading branch information
apsantiso authored Jul 23, 2024
2 parents 89cb207 + d86c5dc commit 3305c10
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/modules/sharing/sharing.repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('SharingRepository', () => {
describe('findFilesByOwnerAndSharedWithTeamInworkspace', () => {
it('When files are searched by owner and team in workspace, then it should return the shared files', async () => {
const teamId = v4();
const workspaceId = v4();
const ownerId = v4();
const offset = 0;
const limit = 10;
Expand All @@ -54,6 +55,7 @@ describe('SharingRepository', () => {

const result =
await repository.findFilesByOwnerAndSharedWithTeamInworkspace(
workspaceId,
teamId,
ownerId,
offset,
Expand All @@ -68,6 +70,7 @@ describe('SharingRepository', () => {
});

describe('findFoldersByOwnerAndSharedWithTeamInworkspace', () => {
const workspaceId = v4();
it('When folders are searched by owner and team in workspace, then it should return the shared folders', async () => {
const teamId = v4();
const ownerId = v4();
Expand All @@ -92,6 +95,7 @@ describe('SharingRepository', () => {

const result =
await repository.findFoldersByOwnerAndSharedWithTeamInworkspace(
workspaceId,
teamId,
ownerId,
offset,
Expand Down
9 changes: 9 additions & 0 deletions src/modules/sharing/sharing.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { PreCreatedUserAttributes } from '../user/pre-created-users.attributes';
import { WorkspaceTeamAttributes } from '../workspaces/attributes/workspace-team.attributes';
import { WorkspaceItemUserModel } from '../workspaces/models/workspace-items-users.model';
import { WorkspaceItemUserAttributes } from '../workspaces/attributes/workspace-items-users.attributes';
import { WorkspaceAttributes } from '../workspaces/attributes/workspace.attributes';

interface SharingRepository {
getInvitesByItem(
Expand Down Expand Up @@ -443,6 +444,7 @@ export class SequelizeSharingRepository implements SharingRepository {
}

async findFilesByOwnerAndSharedWithTeamInworkspace(
workspaceId: WorkspaceAttributes['id'],
teamId: WorkspaceTeamAttributes['id'],
ownerId: WorkspaceItemUserAttributes['createdBy'],
offset: number,
Expand Down Expand Up @@ -481,6 +483,9 @@ export class SequelizeSharingRepository implements SharingRepository {
model: WorkspaceItemUserModel,
as: 'workspaceUser',
required: true,
where: {
workspaceId,
},
include: [
{
model: UserModel,
Expand Down Expand Up @@ -513,6 +518,7 @@ export class SequelizeSharingRepository implements SharingRepository {
}

async findFoldersByOwnerAndSharedWithTeamInworkspace(
workspaceId: WorkspaceAttributes['id'],
teamId: WorkspaceTeamAttributes['id'],
ownerId: WorkspaceItemUserAttributes['createdBy'],
offset: number,
Expand Down Expand Up @@ -551,6 +557,9 @@ export class SequelizeSharingRepository implements SharingRepository {
{
model: WorkspaceItemUserModel,
required: true,
where: {
workspaceId,
},
include: [
{
model: UserModel,
Expand Down
8 changes: 8 additions & 0 deletions src/modules/sharing/sharing.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ describe('Sharing Use Cases', () => {
describe('getSharedFilesInWorkspaces', () => {
const user = newUser();
const teamId = v4();
const workspaceId = v4();
const offset = 0;
const limit = 10;
const order: [string, string][] = [['name', 'asc']];
Expand All @@ -517,6 +518,7 @@ describe('Sharing Use Cases', () => {

const result = await sharingService.getSharedFilesInWorkspaces(
user,
workspaceId,
teamId,
offset,
limit,
Expand Down Expand Up @@ -554,6 +556,7 @@ describe('Sharing Use Cases', () => {

const result = await sharingService.getSharedFilesInWorkspaces(
user,
workspaceId,
teamId,
offset,
limit,
Expand Down Expand Up @@ -585,6 +588,7 @@ describe('Sharing Use Cases', () => {
await expect(
sharingService.getSharedFilesInWorkspaces(
user,
workspaceId,
teamId,
offset,
limit,
Expand All @@ -597,6 +601,7 @@ describe('Sharing Use Cases', () => {
describe('getSharedFoldersInWorkspace', () => {
const user = newUser();
const teamId = v4();
const workspaceId = v4();
const offset = 0;
const limit = 10;
const order: [string, string][] = [['name', 'asc']];
Expand All @@ -623,6 +628,7 @@ describe('Sharing Use Cases', () => {

const result = await sharingService.getSharedFoldersInWorkspace(
user,
workspaceId,
teamId,
offset,
limit,
Expand Down Expand Up @@ -660,6 +666,7 @@ describe('Sharing Use Cases', () => {

const result = await sharingService.getSharedFoldersInWorkspace(
user,
workspaceId,
teamId,
offset,
limit,
Expand Down Expand Up @@ -691,6 +698,7 @@ describe('Sharing Use Cases', () => {
await expect(
sharingService.getSharedFoldersInWorkspace(
user,
workspaceId,
teamId,
offset,
limit,
Expand Down
5 changes: 5 additions & 0 deletions src/modules/sharing/sharing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { aes } from '@internxt/lib';
import { Environment } from '@internxt/inxt-js';
import { SequelizeUserReferralsRepository } from '../user/user-referrals.repository';
import { SharingNotFoundException } from './exception/sharing-not-found.exception';
import { Workspace } from '../workspaces/domains/workspaces.domain';

export class InvalidOwnerError extends Error {
constructor() {
Expand Down Expand Up @@ -1787,13 +1788,15 @@ export class SharingService {

async getSharedFoldersInWorkspace(
user: User,
workspaceId: Workspace['id'],
teamId: Sharing['sharedWith'],
offset: number,
limit: number,
order: [string, string][],
): Promise<GetItemsReponse> {
const foldersWithSharedInfo =
await this.sharingRepository.findFoldersByOwnerAndSharedWithTeamInworkspace(
workspaceId,
teamId,
user.uuid,
offset,
Expand Down Expand Up @@ -1838,13 +1841,15 @@ export class SharingService {

async getSharedFilesInWorkspaces(
user: User,
workspaceId: Workspace['id'],
teamId: Sharing['sharedWith'],
offset: number,
limit: number,
order: [string, string][],
): Promise<GetItemsReponse> {
const filesWithSharedInfo =
await this.sharingRepository.findFilesByOwnerAndSharedWithTeamInworkspace(
workspaceId,
teamId,
user.uuid,
offset,
Expand Down
6 changes: 6 additions & 0 deletions src/modules/workspaces/workspaces.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,14 @@ describe('Workspace Controller', () => {
it('When shared files are requested, then it should call the service with the respective arguments', async () => {
const user = newUser();
const teamId = v4();
const workspaceId = v4();
const orderBy = 'createdAt:ASC';
const page = 1;
const perPage = 50;
const order = [['createdAt', 'ASC']];

await workspacesController.getSharedFiles(
workspaceId,
teamId,
user,
orderBy,
Expand All @@ -522,6 +524,7 @@ describe('Workspace Controller', () => {

expect(sharingUseCases.getSharedFilesInWorkspaces).toHaveBeenCalledWith(
user,
workspaceId,
teamId,
page,
perPage,
Expand All @@ -534,12 +537,14 @@ describe('Workspace Controller', () => {
it('When shared folders are requested, then it should call the service with the respective arguments', async () => {
const user = newUser();
const teamId = v4();
const workspaceId = v4();
const orderBy = 'createdAt:ASC';
const page = 1;
const perPage = 50;
const order = [['createdAt', 'ASC']];

await workspacesController.getSharedFolders(
workspaceId,
teamId,
user,
orderBy,
Expand All @@ -549,6 +554,7 @@ describe('Workspace Controller', () => {

expect(sharingUseCases.getSharedFoldersInWorkspace).toHaveBeenCalledWith(
user,
workspaceId,
teamId,
page,
perPage,
Expand Down
6 changes: 6 additions & 0 deletions src/modules/workspaces/workspaces.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ export class WorkspacesController {
@UseGuards(WorkspaceGuard)
@WorkspaceRequiredAccess(AccessContext.TEAM, WorkspaceRole.MEMBER)
async getSharedFiles(
@Param('workspaceId', ValidateUUIDPipe)
workspaceId: WorkspaceTeamAttributes['id'],
@Param('teamId', ValidateUUIDPipe)
teamId: WorkspaceTeamAttributes['id'],
@UserDecorator() user: User,
Expand All @@ -607,6 +609,7 @@ export class WorkspacesController {

return this.sharingUseCases.getSharedFilesInWorkspaces(
user,
workspaceId,
teamId,
page,
perPage,
Expand All @@ -621,6 +624,8 @@ export class WorkspacesController {
@UseGuards(WorkspaceGuard)
@WorkspaceRequiredAccess(AccessContext.TEAM, WorkspaceRole.MEMBER)
async getSharedFolders(
@Param('workspaceId', ValidateUUIDPipe)
workspaceId: WorkspaceTeamAttributes['id'],
@Param('teamId', ValidateUUIDPipe)
teamId: WorkspaceTeamAttributes['id'],
@UserDecorator() user: User,
Expand All @@ -634,6 +639,7 @@ export class WorkspacesController {

return this.sharingUseCases.getSharedFoldersInWorkspace(
user,
workspaceId,
teamId,
page,
perPage,
Expand Down

0 comments on commit 3305c10

Please sign in to comment.