Skip to content

Commit e6c9ce7

Browse files
committed
add path translations
1 parent 92e2be0 commit e6c9ce7

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

src/WAC.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@
66

77
class WAC {
88
private $filesystem;
9-
9+
private $baseUrl;
10+
private $basePath;
11+
1012
public function __construct($filesystem) {
1113
$this->filesystem = $filesystem;
14+
$this->baseUrl = '';
15+
$this->basePath = '';
1216
}
1317

18+
public function setBaseUrl($url) {
19+
$this->baseUrl = $url;
20+
$serverRequest = new \Laminas\Diactoros\ServerRequest(array(),array(), $url);
21+
$this->basePath = $serverRequest->getUri()->getPath();
22+
}
23+
1424
public function addWACHeaders($request, $response, $webId) {
15-
$userGrants = $this->getWACGrants($this->getUserGrants($request->getUri()->getPath(), $webId), $request->getUri());
16-
$publicGrants = $this->getWACGrants($this->getPublicGrants($request->getUri()->getPath()), $request->getUri());
25+
$path = $request->getUri()->getPath();
26+
if ($this->basePath) {
27+
$path = str_replace($this->basePath, '', $path);
28+
}
29+
$userGrants = $this->getWACGrants($this->getUserGrants($path, $webId), $request->getUri());
30+
$publicGrants = $this->getWACGrants($this->getPublicGrants($path), $request->getUri());
1731

1832
$wacHeaders = array();
1933
if ($userGrants) {
@@ -53,9 +67,14 @@ private function isGranted($requestedGrants, $uri, $webId) {
5367
return true;
5468
}
5569

56-
// error_log("REQUESTED GRANT: " . join(" or ", $requestedGrants) . " on $uri");
57-
$grants = $this->getUserGrants($uri->getPath(), $webId);
58-
// error_log("GRANTED GRANTS for $webId: " . json_encode($grants));
70+
$path = $uri->getPath();
71+
if ($this->basePath) {
72+
$path = str_replace($this->basePath, '', $path);
73+
}
74+
75+
//error_log("REQUESTED GRANT: " . join(" or ", $requestedGrants) . " on $uri");
76+
$grants = $this->getUserGrants($path, $webId);
77+
//error_log("GRANTED GRANTS for $webId: " . json_encode($grants));
5978
if (is_array($grants)) {
6079
foreach ($requestedGrants as $requestedGrant) {
6180
if ($grants['accessTo'] && $grants['accessTo'][$requestedGrant] && $this->arePathsEqual($grants['accessTo'][$requestedGrant], $uri)) {
@@ -156,6 +175,9 @@ private function getParentAcl($path) {
156175
public function getRequestedGrants($request) {
157176
$method = strtoupper($request->getMethod());
158177
$path = $request->getUri()->getPath();
178+
if ($this->basePath) {
179+
$path = str_replace($this->basePath, '', $path);
180+
}
159181

160182
switch ($method) {
161183
case "GET":
@@ -244,7 +266,7 @@ private function getParentUri($uri) {
244266
}
245267

246268
$parentPath = dirname($path) . '/';
247-
if ($this->filesystem->has($parentPath)) {
269+
if ($this->filesystem->has(str_replace($this->basePath, '', $parentPath))) {
248270
return $uri->withPath($parentPath);
249271
} else {
250272
return $this->getParentUri($uri->withPath($parentPath));

0 commit comments

Comments
 (0)