File tree Expand file tree Collapse file tree 6 files changed +30
-18
lines changed Expand file tree Collapse file tree 6 files changed +30
-18
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ class FliptaskError extends Error {
6
6
static missingParams ( message = "Missing Parameters" ) {
7
7
return new FliptaskError ( message ) ;
8
8
}
9
+
10
+ static serverError ( message = "Oops something went wrong" ) {
11
+ return new FliptaskError ( message ) ;
12
+ }
9
13
}
10
14
11
15
global . FliptaskError = FliptaskError ;
Original file line number Diff line number Diff line change 1
1
class Modifier {
2
2
static paramIdIsOrgId ( req , res , next ) {
3
- res . locals . orgId = req . params . id ;
3
+ req . organisationId = req . headers . organisationid ; ;
4
4
next ( ) ;
5
5
}
6
6
Original file line number Diff line number Diff line change @@ -3,16 +3,19 @@ const CrudRouter = require("./base/CrudRouter");
3
3
4
4
const workspaceRouter = new CrudRouter ( "/workspace" , workspaceController ) ;
5
5
6
+ const workspacePermission = new Permissions ( ) ;
6
7
workspaceRouter . mergeRoutes ( {
7
8
"/" : {
8
9
get : [
9
10
bearerAuth ,
10
- Permission . userIsOrgMember ,
11
+ Modifier . paramIdIsOrgId ,
12
+ Modifier . createdByUser ,
13
+ workspacePermission . _userIsOrgMember ,
11
14
workspaceController . list
12
15
] ,
13
16
post : [
14
17
bearerAuth ,
15
- Permission . userIsOrgMember ,
18
+ workspacePermission . _userIsOrgMember ,
16
19
workspaceController . create
17
20
]
18
21
}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class CrudRouter {
14
14
this . controller . create
15
15
]
16
16
} ,
17
- "/:id" : {
17
+ "/:id(^[-+]?\d+$) " : {
18
18
get : [
19
19
bearerAuth ,
20
20
this . controller . get
Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ class CrudService extends Permissions {
61
61
62
62
get = async ( id , query ) => {
63
63
let { include } = query ;
64
- console . log ( "get " , id , include ) ;
65
64
return await this . model . findByPk ( id , { include } ) ;
66
65
}
67
66
Original file line number Diff line number Diff line change 1
1
class Permissions {
2
- _userIsOrgMember = async ( { createdBy, organisationId } ) => {
3
- const organisation = await Organisation . findByPk ( organisationId ) ;
4
- if ( ! organisation ) {
5
- throw FliptaskError . missingParams ( "Missing or incorrect params" ) ;
6
- } else {
7
- const userOrganisationMap = await UserOrganisationMap . findOne ( {
8
- where : {
9
- userId : createdBy ,
10
- organisationId,
2
+ _userIsOrgMember = async ( req , res , next ) => {
3
+ try {
4
+ const { organisationId } = req ;
5
+ const { createdBy} = req . query ;
6
+ const organisation = await Organisation . findByPk ( organisationId ) ;
7
+ if ( ! organisation ) {
8
+ throw FliptaskError . missingParams ( "Missing or incorrect params" ) ;
9
+ } else {
10
+ const userOrganisationMap = await UserOrganisationMap . findOne ( {
11
+ where : {
12
+ userId : createdBy ,
13
+ organisationId,
14
+ }
15
+ } ) ;
16
+ if ( ! userOrganisationMap ) {
17
+ throw FliptaskError . permissionDenied ( ) ;
11
18
}
12
- } ) ;
13
-
14
- if ( ! userOrganisationMap ) {
15
- throw FliptaskError . permissionDenied ( ) ;
16
19
}
20
+ } catch ( err ) {
21
+ throw FliptaskError . serverError ( ) ;
17
22
}
23
+ next ( ) ;
18
24
}
19
25
}
20
26
You can’t perform that action at this time.
0 commit comments