Skip to content

Commit

Permalink
Merge pull request #187 from pixlise/development
Browse files Browse the repository at this point in the history
v4 patch fixes
  • Loading branch information
pnemere authored Mar 22, 2024
2 parents 01792fc + bdb3e81 commit a8df66e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ __debug_bin.exe
#generated-protos/
api/ws/wsMessage.go
/OLDCODE
auth0dummy.go
auth0dummy-LOCAL-ONLY.go-
/local-mongo/dbseed/from-prod-Jan2024/
/local-mongo/dbseed/migrated/
/local-mongo/dbseed/migration-source/
Expand Down
4 changes: 4 additions & 0 deletions api/ws/wsHelpers/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func GetUserObjectById[T any](forEditing bool, objectId string, objectType proto

result := hctx.Svcs.MongoDB.Collection(collectionName).FindOne(context.TODO(), bson.M{"_id": objectId})
if result.Err() != nil {
if result.Err() == mongo.ErrNoDocuments {
return nil, nil, errorwithstatus.MakeNotFoundError(objectId)
}

return nil, nil, result.Err()
}

Expand Down
2 changes: 1 addition & 1 deletion api/ws/wsHelpers/ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func CheckObjectAccessForUser(requireEdit bool, objectId string, objectType prot
}

// Access denied
return nil, errorwithstatus.MakeUnauthorisedError(fmt.Errorf("%v access denied for: %v", accessType, objectId))
return nil, errorwithstatus.MakeUnauthorisedError(fmt.Errorf("%v access denied for: %v (%v)", accessType, objectType.String(), objectId))
}

// Gets all object IDs which the user has access to - if requireEdit is true, it checks for edit access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func testExpressionRuntimeMsgs(apiHost string) {
`{"msgId":5,"status":"WS_OK", "expressionDeleteResp":{}}`,
)

u1.AddSendReqAction("Read expression back expecting runtime stats",
`{"expressionGetReq":{ "id": "non-existant-id"}}`,
`{"msgId": 6, "status":"WS_NOT_FOUND", "errorText": "non-existant-id not found", "expressionGetResp":{}}`,
)

u1.CloseActionGroup([]string{}, 5000)
wstestlib.ExecQueuedActions(&u1)
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func testImageUpload(apiHost string, userId1 string, userId2 string) {
`{
"msgId": 7,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"imageUploadResp": {}
}`,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func testQuantGetListDelete(apiHost string) {
fmt.Sprintf(`{"quantGetReq":{"quantId": "%v"}}`, quantId),
fmt.Sprintf(`{
"msgId":4,"status":"WS_NO_PERMISSION",
"errorText": "View access denied for: %v", "quantGetResp":{}}`, quantId),
"errorText": "View access denied for: OT_QUANTIFICATION (%v)", "quantGetResp":{}}`, quantId),
)

u1.CloseActionGroup([]string{}, 5000)
Expand Down Expand Up @@ -551,7 +551,7 @@ func testQuantGetListDelete(apiHost string) {

u1.AddSendReqAction("Delete quant (should fail, we're viewers!)",
fmt.Sprintf(`{"quantDeleteReq":{"quantId": "%v" }}`, quantId),
fmt.Sprintf(`{"msgId":10,"status":"WS_NO_PERMISSION", "errorText": "Edit access denied for: %v", "quantDeleteResp":{}}`, quantId),
fmt.Sprintf(`{"msgId":10,"status":"WS_NO_PERMISSION", "errorText": "Edit access denied for: OT_QUANTIFICATION (%v)", "quantDeleteResp":{}}`, quantId),
)

u1.CloseActionGroup([]string{}, 5000)
Expand All @@ -574,7 +574,7 @@ func testQuantGetListDelete(apiHost string) {
fmt.Sprintf(`{"quantGetReq":{"quantId": "%v"}}`, quantId),
fmt.Sprintf(`{
"msgId":2,"status":"WS_NO_PERMISSION",
"errorText": "View access denied for: %v", "quantGetResp":{}}`, quantId),
"errorText": "View access denied for: OT_QUANTIFICATION (%v)", "quantGetResp":{}}`, quantId),
)

u2.CloseActionGroup([]string{}, 5000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func testMultiQuant(apiHost string) {
}
]
}}`, scanId),
fmt.Sprintf(`{"msgId":7,"status":"WS_NO_PERMISSION","errorText":"View access denied for: %s","quantCombineResp":{}}`, scanId),
fmt.Sprintf(`{"msgId":7,"status":"WS_NO_PERMISSION","errorText":"View access denied for: OT_SCAN (%s)","quantCombineResp":{}}`, scanId),
)

u1.CloseActionGroup([]string{}, 10000)
Expand Down
26 changes: 13 additions & 13 deletions internal/cmd-line-tools/api-integration-test/testScanData.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func testScanDataNoPermission(apiHost string) {
`{
"msgId": 1,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"pseudoIntensityResp": {}
}`,
)
Expand All @@ -425,7 +425,7 @@ func testScanDataNoPermission(apiHost string) {
`{
"msgId": 2,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"spectrumResp": {}
}`,
)
Expand All @@ -435,7 +435,7 @@ func testScanDataNoPermission(apiHost string) {
`{
"msgId": 3,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"spectrumResp": {}
}`,
)
Expand All @@ -444,7 +444,7 @@ func testScanDataNoPermission(apiHost string) {
`{"scanMetaLabelsAndTypesReq":{"scanId": "048300551"}}`,
`{"msgId":4,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"scanMetaLabelsAndTypesResp":{}
}`,
)
Expand All @@ -453,7 +453,7 @@ func testScanDataNoPermission(apiHost string) {
`{"scanEntryReq":{"scanId": "048300551", "entries": {"indexes": [128,-1,131]}}}`,
`{"msgId":5,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"scanEntryResp":{}
}`,
)
Expand All @@ -462,7 +462,7 @@ func testScanDataNoPermission(apiHost string) {
`{"scanEntryMetadataReq":{"scanId": "048300551", "entries": {"indexes": [128,-1,131]}}}`,
`{"msgId":6,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"scanEntryMetadataResp":{}
}`,
)
Expand All @@ -471,7 +471,7 @@ func testScanDataNoPermission(apiHost string) {
`{"scanBeamLocationsReq":{"scanId": "048300551", "entries": {"indexes": [128,-1,131]}}}`,
`{"msgId":7,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"scanBeamLocationsResp":{}
}`,
)
Expand All @@ -480,7 +480,7 @@ func testScanDataNoPermission(apiHost string) {
`{"imageListReq":{"scanIds": ["048300551"]}}`,
`{"msgId":8,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"imageListResp":{}
}`,
)
Expand All @@ -489,7 +489,7 @@ func testScanDataNoPermission(apiHost string) {
`{"imageGetReq":{"imageName": "048300551/PCW_0125_0678031992_000RCM_N00417120483005510091075J02.png"}}`,
`{"msgId":9,
"status": "WS_NO_PERMISSION",
"errorText": "User cannot access scan 048300551 associated with image 048300551/PCW_0125_0678031992_000RCM_N00417120483005510091075J02.png. Error: View access denied for: 048300551",
"errorText": "User cannot access scan 048300551 associated with image 048300551/PCW_0125_0678031992_000RCM_N00417120483005510091075J02.png. Error: View access denied for: OT_SCAN (048300551)",
"imageGetResp":{}
}`,
)
Expand All @@ -498,7 +498,7 @@ func testScanDataNoPermission(apiHost string) {
`{"detectedDiffractionPeaksReq":{"scanId": "048300551", "entries": {"indexes": [128,-1,131]}}}`,
`{"msgId":10,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"detectedDiffractionPeaksResp":{}
}`,
)
Expand All @@ -507,7 +507,7 @@ func testScanDataNoPermission(apiHost string) {
`{"scanMetaWriteReq":{"scanId": "048300551", "title": "Something", "description": "The blah"}}`,
`{"msgId":11,
"status": "WS_NO_PERMISSION",
"errorText": "Edit access denied for: 048300551",
"errorText": "Edit access denied for: OT_SCAN (048300551)",
"scanMetaWriteResp": {}
}`,
)
Expand All @@ -517,7 +517,7 @@ func testScanDataNoPermission(apiHost string) {
`{"imageBeamLocationsReq":{"imageName": "PCW_0125_0678031992_000RCM_N00417120483005510091075J02.png"}}`,
`{"msgId":9,
"status": "WS_NO_PERMISSION",
"errorText": "View access denied for: 048300551",
"errorText": "View access denied for: OT_SCAN (048300551)",
"imageBeamLocationsResp":{}
}`,
)
Expand Down Expand Up @@ -1511,7 +1511,7 @@ func testScanDataHasPermission(apiHost string, actionMsg string, editAllowed boo
`{"scanMetaWriteReq":{"scanId": "048300551", "title": "Something", "description": "The blah"}}`,
`{"msgId":14,
"status": "WS_NO_PERMISSION",
"errorText": "Edit access denied for: 048300551",
"errorText": "Edit access denied for: OT_SCAN (048300551)",
"scanMetaWriteResp": {}
}`,
)
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd-line-tools/api-integration-test/testUserContent.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,19 @@ func testUserContent(apiHost string, contentMessaging map[string]contentMessagin

u2.AddSendReqAction(fmt.Sprintf("%v Get created item for user 2", msgName),
fmt.Sprintf(`{"%vGetReq": { "id": "${IDLOAD=%vCreated1}"}}`, msgName, msgName),
fmt.Sprintf(`{"msgId":%v, "status": "WS_NO_PERMISSION", "errorText": "View access denied for: %v", "%vGetResp":{}}`, u2ExpectedRespSeqNo, createdId, msgName),
fmt.Sprintf(`{"msgId":%v, "status": "WS_NO_PERMISSION", "errorText": "View access denied for: %v (%v)", "%vGetResp":{}}`, u2ExpectedRespSeqNo, msgContents.objectType, createdId, msgName),
)
u2ExpectedRespSeqNo++

u2.AddSendReqAction(fmt.Sprintf("%v Get permissions for user 1's created item", msgName),
fmt.Sprintf(`{"getOwnershipReq": { "objectId": "${IDLOAD=%vCreated1}", "objectType": "%v"}}`, msgName, msgContents.objectType),
fmt.Sprintf(`{"msgId":%v,"status":"WS_NO_PERMISSION","errorText": "View access denied for: %v","getOwnershipResp":{}}`, u2ExpectedRespSeqNo, createdId),
fmt.Sprintf(`{"msgId":%v,"status":"WS_NO_PERMISSION","errorText": "View access denied for: %v (%v)","getOwnershipResp":{}}`, u2ExpectedRespSeqNo, msgContents.objectType, createdId),
)
u2ExpectedRespSeqNo++

u2.AddSendReqAction(fmt.Sprintf("%v Share user 1s created item", msgName),
fmt.Sprintf(`{"objectEditAccessReq": { "objectId": "${IDLOAD=%vCreated1}", "objectType": "%v", "addViewers": { "userIds": [ "%v" ] }}}`, msgName, msgContents.objectType, u2.GetUserId()),
fmt.Sprintf(`{"msgId":%v,"status":"WS_NO_PERMISSION","errorText": "Edit access denied for: %v","objectEditAccessResp":{}}`, u2ExpectedRespSeqNo, createdId),
fmt.Sprintf(`{"msgId":%v,"status":"WS_NO_PERMISSION","errorText": "Edit access denied for: %v (%v)","objectEditAccessResp":{}}`, u2ExpectedRespSeqNo, msgContents.objectType, createdId),
)
u2ExpectedRespSeqNo++
}
Expand Down Expand Up @@ -492,8 +492,8 @@ func testUserContent(apiHost string, contentMessaging map[string]contentMessagin
"name": "User1 Item Edited by User2"
}
}}`, msgName, msgContents.itemName, msgName),
fmt.Sprintf(`{"msgId":%v, "status":"WS_NO_PERMISSION", "errorText": "Edit access denied for: %v", "%vWriteResp":{}}`,
u2ExpectedRespSeqNo, createdId, msgName),
fmt.Sprintf(`{"msgId":%v, "status":"WS_NO_PERMISSION", "errorText": "Edit access denied for: %v (%v)", "%vWriteResp":{}}`,
u2ExpectedRespSeqNo, msgContents.objectType, createdId, msgName),
)
u2ExpectedRespSeqNo++
}
Expand Down

0 comments on commit a8df66e

Please sign in to comment.