finish permission mapping

This commit is contained in:
Mike Macgirvin 2024-04-19 08:22:08 +10:00
parent 3843e453aa
commit 2ae741eef4
3 changed files with 72 additions and 24 deletions

View file

@ -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.
*

View file

@ -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;
}
}

View file

@ -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;
}