From 2ae741eef48a89655b5a76ff88b253fca8c16388 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Fri, 19 Apr 2024 08:22:08 +1000 Subject: [PATCH] finish permission mapping --- src/Access/Permissions.php | 22 +++++++++-- src/ActivityStreams/Collection.php | 60 ++++++++++++++++++++---------- src/Lib/Activity.php | 14 ++++++- 3 files changed, 72 insertions(+), 24 deletions(-) diff --git a/src/Access/Permissions.php b/src/Access/Permissions.php index 71922d230..35bce70ad 100644 --- a/src/Access/Permissions.php +++ b/src/Access/Permissions.php @@ -53,14 +53,14 @@ class Permissions public $permsMap = [ 'view_stream' => 'viewStream', 'search_stream' => 'canSearch', - 'deliver_stream' => 'amSending', + 'deliver_stream' => 'deliverStream', 'view_profile' => 'viewProfile', 'view_contacts' => 'viewContacts', 'view_storage' => 'viewFiles', 'post_wall' => 'postHome', 'post_mail' => 'postMail', - 'send_stream' => 'amFollowing', - 'hyperdrive' => 'amFollowingAll', + 'send_stream' => 'sendStream', + 'hyperdrive' => 'sendPublic', 'post_comments' => 'canReply', 'write_storage' => 'writeFiles', 'republish' => 'canReAuthor', @@ -69,6 +69,22 @@ class Permissions ]; + function map($permission) + { + return $this->permsMap[$permission] ?: $permission; + } + + function unmap($permission) + { + foreach ($this->permsMap as $key => $value) { + if ($permission === $value) { + return $key; + } + } + return $permission; + } + + /** * @brief Return an array with Permissions. * diff --git a/src/ActivityStreams/Collection.php b/src/ActivityStreams/Collection.php index a7620b30e..937d851bd 100644 --- a/src/ActivityStreams/Collection.php +++ b/src/ActivityStreams/Collection.php @@ -4,16 +4,18 @@ namespace Code\ActivityStreams; class Collection extends ASObject { - public $totalItems; - public $current; - public $first; - public $last; - public $items; + public int $totalItems; + public string $current; + public string $first; + public string $last; + public array $items; + + public mixed $collectionOf; /** - * @return mixed + * @return int */ - public function getTotalItems() + public function getTotalItems(): int { return $this->totalItems; } @@ -22,16 +24,16 @@ class Collection extends ASObject * @param mixed $totalItems * @return Collection */ - public function setTotalItems($totalItems) + public function setTotalItems(mixed $totalItems): static { $this->totalItems = $totalItems; return $this; } /** - * @return mixed + * @return string */ - public function getCurrent() + public function getCurrent(): string { return $this->current; } @@ -40,16 +42,16 @@ class Collection extends ASObject * @param mixed $current * @return Collection */ - public function setCurrent($current) + public function setCurrent(mixed $current): static { $this->current = $current; return $this; } /** - * @return mixed + * @return string */ - public function getFirst() + public function getFirst(): string { return $this->first; } @@ -58,16 +60,16 @@ class Collection extends ASObject * @param mixed $first * @return Collection */ - public function setFirst($first) + public function setFirst(mixed $first): static { $this->first = $first; return $this; } /** - * @return mixed + * @return string */ - public function getLast() + public function getLast(): string { return $this->last; } @@ -76,16 +78,16 @@ class Collection extends ASObject * @param mixed $last * @return Collection */ - public function setLast($last) + public function setLast(mixed $last): static { $this->last = $last; return $this; } /** - * @return mixed + * @return array */ - public function getItems() + public function getItems(): array { return $this->items; } @@ -94,11 +96,29 @@ class Collection extends ASObject * @param mixed $items * @return Collection */ - public function setItems($items) + public function setItems(mixed $items): static { $this->items = $items; return $this; } + /** + * @return mixed + */ + public function getCollectionOf(): mixed + { + return $this->collectionOf; + } + + /** + * @param mixed $collectionOf + * @return Collection + */ + public function setCollectionOf(mixed $collectionOf): static + { + $this->collectionOf = $collectionOf; + return $this; + } + } diff --git a/src/Lib/Activity.php b/src/Lib/Activity.php index 824c066a8..272f9b612 100644 --- a/src/Lib/Activity.php +++ b/src/Lib/Activity.php @@ -457,9 +457,21 @@ class Activity public static function map_permissions(array $permissions): array { + $perm = new Permissions(); $returnValue = []; foreach($permissions as $permission) { - $returnValue[] = 'https://purl.org/nomad#' . $permission; + $returnValue[] = 'https://purl.org/nomad#' . $perm->map($permission); + } + return $returnValue; + } + + + public static function unmap_permissions(array $permissions): array + { + $perm = new Permissions(); + $returnValue = []; + foreach($permissions as $permission) { + $returnValue[] = $perm->unmap(trim('#', strstr($permission, '#'))); } return $returnValue; }