Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a GET all assets by spaceId wth roles check #172

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Piscina = require('piscina')
const os = require('os')
const { ObjectId } = require('mongodb')

// @ts-ignore
const piscina = new Piscina({
filename: path.resolve(
__dirname,
Expand Down
12 changes: 12 additions & 0 deletions mirror-web-server/src/asset/asset.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,16 @@ export class AssetController {
purchaseOptionId
)
}

@Get('/space/:spaceId')
@FirebaseTokenAuthGuard()
public async getAllAssetsBySpaceIdWithRolesCheck(
@UserToken('user_id') userId: UserId,
@Param('spaceId') spaceId: string
) {
return await this.assetService.getAllAssetsBySpaceIdWithRolesCheck(
spaceId,
userId
)
}
}
21 changes: 21 additions & 0 deletions mirror-web-server/src/asset/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { FileUploadService } from '../util/file-upload/file-upload.service'
import {
AssetId,
SpaceId,
UserId,
aggregationMatchId
} from '../util/mongo-object-id-helpers'
Expand Down Expand Up @@ -1342,6 +1343,26 @@ export class AssetService {
return await this._updateAssetTagsByType(assetId, tagType, tags)
}

async getAllAssetsBySpaceIdWithRolesCheck(spaceId: SpaceId, userId: UserId) {
const pipeline = [
{ $match: { space: new ObjectId(spaceId) } },
{
$lookup: {
from: 'assets',
localField: 'asset',
foreignField: '_id',
as: 'assetInfo'
}
},
{ $unwind: '$assetInfo' },
{
$replaceRoot: { newRoot: '$assetInfo' }
},
...this.roleService.getRoleCheckAggregationPipeline(userId, ROLE.OBSERVER)
]
return await this.spaceObjectModel.aggregate(pipeline).exec()
}

private async _updateAssetTagsByType(
assetId: AssetId,
tagType: TAG_TYPES,
Expand Down
4 changes: 3 additions & 1 deletion mirror-web-server/src/block/block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class BlockService {
}

remove(id: string): Promise<BlockDocument> {
return this.blockModel.findOneAndDelete({ _id: id }).exec()
return this.blockModel
.findOneAndDelete({ _id: id })
.exec() as any as Promise<BlockDocument>
}
}
2 changes: 1 addition & 1 deletion mirror-web-server/src/metadata.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mirror-web-server/src/roles/models/role.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export enum ROLE {
// can create/read, but not update/delete
CONTRIBUTOR = 400,

// the user is a provider
// the user is a provider
PROVIDER = 150,

// Entity, e.g. a Space, can be entered/observed
Expand Down
2 changes: 1 addition & 1 deletion mirror-web-server/src/space/space.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ export class SpaceService implements IRoleConsumer {
} else {
throw new NotFoundException()
}
})
}) as any as Promise<SpaceDocument>
} else {
this.logger.log(
`canRemoveWithRolesCheck failed for user: ${userId}`,
Expand Down
4 changes: 3 additions & 1 deletion mirror-web-server/src/tag/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export class TagService {
}

remove(id: string): Promise<TagDocument> {
return this.tagModel.findOneAndDelete({ _id: id }).exec()
return this.tagModel
.findOneAndDelete({ _id: id })
.exec() as any as Promise<TagDocument>
}
}
Loading