Skip to content

Commit 876cdd8

Browse files
committed
Update the guard to be compliant with the rest
Update the CHANGELOG.md and README.md for new version.
1 parent 78733a8 commit 876cdd8

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Added
1212
- Added docker-compose-dev.yml for development and testing purpose.
13+
- [DELETE] /browser/:id to delete files created by this endpoint.
14+
- JWT: [DELETE] /browse/:id requires "browse-delete" as permission or a custom permission which can be addressed by setting the environment variable "PERMISSION_BROWSE_DELETE"
1315

1416
## [0.2.1] - 2020-07-29
1517
### Fixed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Define the required environment keys:
1919
```
2020
JWT_SECRET=2VRxS0s15nV2BnyVYcgBvKJwoaPeQdVXsaJylt96Jb9iypXOGylcTCTo8rS1E7Mk
2121
JWT_ISSUER=http://localhost:8000/api/auth/login
22-
APP_KEY=
2322
PORT=3000
2423
PERMISSION_BROWSE_CREATE=print
2524
PERMISSION_BROWSE_READ=print
25+
PERMISSION_BROWSE_DELETE=print
2626
```
2727

2828
## Run the service
@@ -123,6 +123,21 @@ Provide a boolean value if you want to wait for the complete answer of the postB
123123

124124
If set to false the return value "uploaded" will always be false.
125125

126+
### [GET] /api/browse
127+
128+
This endpoint will return a list of exsiting files in this container plus a signed url to access them without using credentials.
129+
130+
Example:
131+
132+
```json
133+
[
134+
{
135+
"file": "04623fc1-86e8-4be9-bb65-fc1ffad4ba55.pdf",
136+
"path": "http://localhost:3000/api/browse/04623fc1-86e8-4be9-bb65-fc1ffad4ba55?signed=r:3026092917;4776ee8a2c9cb3ace3770e3b276b174c"
137+
}
138+
]
139+
```
140+
126141
### [GET] /api/browse/:id
127142

128143
This endpoint will return the file. Please be aware that there will be a query string required query string param *signed*.
@@ -131,6 +146,11 @@ eg. http://localhost:3000/api/browse/199f0e09-516c-4f40-9960-7aa6f89d8c02?signed
131146

132147
Without this query string param the request will fail and you will get an 403.
133148

149+
### [DELETE] /api/browse/:id
150+
151+
To delete an file use this endpoint.
152+
The *id*-param can contain the .pdf file extension.
153+
134154
## Docker
135155
This repository provides a docker image and a docker-compose file as an example.
136156

@@ -140,10 +160,10 @@ services:
140160
app:
141161
image: ambersive/print-api:latest
142162
environment:
143-
- JWT_ACTIVE:false
144-
- BASIC_ACTIVE:true
145-
- BASIC_USER:test
146-
- BASIC_SECRET:test
163+
- JWT_ACTIVE=false
164+
- BASIC_ACTIVE=true
165+
- BASIC_USER=test
166+
- BASIC_SECRET=test
147167
restart: always
148168
ports:
149169
- "9005:3000"

src/guards/browse.guard.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ export class BrowseGuard implements CanActivate {
2020
const token = request.headers.authorization ? request.headers.authorization.replace('Bearer ', '') : '';
2121

2222
let permissionFromConfig: string = "";
23+
2324
switch(request.method) {
2425
case 'GET':
2526
permissionFromConfig = "permissions.browseRead";
2627
break;
28+
case 'DELETE':
29+
permissionFromConfig = "permissions.browseDestroy";
30+
break;
2731
case 'POST':
2832
permissionFromConfig = "permissions.browseCreate";
2933
break;

0 commit comments

Comments
 (0)