Skip to content
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
12 changes: 6 additions & 6 deletions APLSource/Get.aplf
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
res←Get req;allowed;nl
r←Get req;allowed;nl
r←'' ⍝ Default empty payload in case of error
:If GLOBAL.debug ⍝ :If here because prefer not to compute ⍕⎕TS for every request
⎕←'> GET REQUEST at ',⍕⎕TS
⎕←req.Endpoint
last←req
:EndIf
:Trap GLOBAL.debug↓0 511
res←req.Response
req.Endpoint←{⍵⌿⍨1(⊢∨⌽)'/'≠⍵}req.Endpoint ⍝ Remove multiple slashes
:If req.Endpoint(⊃⍷⍨)'/videos'
res←read.videos.Handle req
r←read.videos.Handle req
:ElseIf 1=+/req.Endpoint∘≡¨'/person' '/organisation' '/event' '/event_type' '/presentation' '/presentation_type'
res←read.Table 1↓req.Endpoint
r←read.Table 1↓req.Endpoint
:ElseIf 1=+/req.Endpoint∘≡¨'/presenters' '/dtv_events'
res←CACHE⍎1↓req.Endpoint
r←CACHE⍎1↓req.Endpoint
:ElseIf req.Endpoint≡'/version'
res←Version
r←Version
:ElseIf req.Endpoint≡'/teapot'
req.Fail 418
:Else
Expand Down
17 changes: 10 additions & 7 deletions APLSource/Post.aplf
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
res←Post req;allowed;dmx;msg;nl
r←Post req;allowed;dmx;msg;nl
⍝ r: response payload
⍝ res: response object (can be mutated here to affect response headers etc.)
r←'' ⍝ Default empty payload in case of error
:If 0<GLOBAL.debug ⋄ last←req ⋄ :EndIf
res←auth.VerifyToken req
:If ~∨/401 403∊res.Status
Expand All @@ -7,15 +10,15 @@
:Hold 'SQL.db'
:Select req.Endpoint
:CaseList '/person' '/organisation' '/event' '/event_type' '/presentation_type' '/category'
res←req.Endpoint import.Table req
r←req.Endpoint import.Table req
:Case '/presentation'
res←import.Presentation req
r←import.Presentation req
:Case '/presentation_material'
res←import.PresentationMaterial req
r←import.PresentationMaterial req
:Case '/refresh'
res←RefreshData''
r←RefreshData''
:Case '/wp_update_team_dyalog_videos'
res←wp.PushTeamDyalogVideos req
r←wp.PushTeamDyalogVideos req
:Case '/fail'
{'Failed on purpose.'⎕SIGNAL 42}''
:Else
Expand All @@ -27,6 +30,6 @@
''req.Fail 500 ⍝ Fail with no HTTP "reason phrase"
nl←⎕UCS 10
allowed←'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -_.~!#$&''()*+,/:;=?@[]',nl
req.Response.Payload←allowed∩⍨⊃(⊣,nl,⊢)/(⎕EM dmx.EN)(⊃(⊣,nl,⊢)/dmx.DM)(dmx.Message)
r←allowed∩⍨⊃(⊣,nl,⊢)/(⎕EM dmx.EN)(⊃(⊣,nl,⊢)/dmx.DM)(dmx.Message)
:EndTrap
:EndIf
2 changes: 1 addition & 1 deletion APLSource/Version.aplf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version←Version
version←'3.24.0'
version←'3.24.1'
2 changes: 2 additions & 0 deletions APLSource/read/Paginate.aplf
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Paginate←{
(ep pg ppg)←⍺ ⍝ (URL endpoint)(current_page)(per_page)
0∊⍴ppg:⍵ ⍝ No pagination, return response unchanged
pg←1⌈⊃pg ⍝ Default first page if not specified in ?page= parameter
(1>pg)∨pg≠⌊pg:⎕SIGNAL⊂('EN' 511)('Message' 'Page number must be a positive integer.')('Vendor'(##.GetEnv'service_url'))
(1>ppg)∨ppg≠⌊ppg:⎕SIGNAL⊂('EN' 511)('Message' 'Items per page must be a positive integer.')('Vendor'(##.GetEnv'service_url'))
(pg ppg)←⍬∘⍴¨pg ppg
n←≢⍵ ⍝ Total results count
ppg←n⌊ppg ⍝ Results per page
Expand Down
3 changes: 3 additions & 0 deletions APLSource/read/videos/Query.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@
⍝ Convert to JSON and paginate
res←##.Table2JSON CACHE.videos.fields⍪data
(pg ppg)←2⊃∘⎕VFI∘Q¨'page' 'per_page'
:if 0∊pg
⎕SIGNAL⊂('EN' 511)('Message' 'If supplied, page number must be a positive integer.')('Vendor'(##.##.GetEnv'service_url'))
:endif
res←('videos'pg ppg)##.Paginate res
8 changes: 8 additions & 0 deletions Admin/Tests/General/Test_GETVideos_BadParameter.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Test_GETVideos_BadParameter←{
url←⍵
h←##.##.##.HttpCommand.New'GET'
h.URL←url,'/videos?per_page=ILLEGAL'
_←'origin'h.SetHeader ##.##.GetEnv'URL'
res←h.Run
400=res.HttpStatus
}
8 changes: 8 additions & 0 deletions Admin/Tests/General/Test_GETVideos_BadParameter_Page.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Test_GETVideos_BadParameter_Page←{
url←⍵
h←##.##.##.HttpCommand.New'GET'
h.URL←url,'/videos?per_page=20&page=poo'
_←'origin'h.SetHeader ##.##.GetEnv'URL'
res←h.Run
400=res.HttpStatus
}
8 changes: 8 additions & 0 deletions Admin/Tests/General/Test_GETVideos_BadParameter_PerPage.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Test_GETVideos_BadParameter_PerPage←{
url←⍵
h←##.##.##.HttpCommand.New'GET'
h.URL←url,'/videos?per_page=ILLEGAL'
_←'origin'h.SetHeader ##.##.GetEnv'URL'
res←h.Run
400=res.HttpStatus
}
2 changes: 2 additions & 0 deletions CI/run-tests-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ echo MYSQL_PASSWORD=apl >> ${PWD}/env
echo MYSQL_PORT=3306 >> ${PWD}/env
echo SECRETS=/app/secrets/secrets.json5 >> ${PWD}/env
echo MYSQL_RANDOM_ROOT_PASSWORD=1 >> ${PWD}/env
echo HOME=/data >> ${PWD}/env

echo COMPOSE IS: $COMPOSE
echo "Use docker inspect to get the IP of the running container"

$COMPOSE pull
$COMPOSE -f docker-compose.yml up install
$COMPOSE -f docker-compose.yml up db web --force-recreate --abort-on-container-exit