From 7f4662eaa650cbc44aec642b4d531a2cd59a58b9 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 13 Dec 2017 12:43:20 +0100 Subject: [PATCH] Added api.core.Documentation (human-readable permission set) --- build/api/core/Documentation.php | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/build/api/core/Documentation.php b/build/api/core/Documentation.php index 9f2d647..f71159e 100644 --- a/build/api/core/Documentation.php +++ b/build/api/core/Documentation.php @@ -39,6 +39,9 @@ /* (1) Build uri with args */ $cfg[$method]['uri_scheme'] = self::uri_with_parameters($rq->get('id')['path'], $spec); + /* (2) Build human-readable permission list */ + $cfg[$method]['perm'] = "accessible with:".self::permissions($spec); + } $response = new Response(); @@ -53,6 +56,7 @@ /* (3) Builds uri with GET parameter inside * * @uri Base URI + * @spec Specification * ---------------------------------------------------------*/ private static function uri_with_parameters($uri=null, $spec=null){ @@ -115,6 +119,52 @@ } + /* (4) Builds a readable permission list + * + * @spec Specification + * + ---------------------------------------------------------*/ + private static function permissions($spec=null){ + + /* (1) If no perm return nothing */ + if( !isset($spec['per']) || !is_array($spec['per']) || count($spec['per']) <= 0 ) + return 'anyone'; + + + /* (1) Manage permission groups + ---------------------------------------------------------*/ + $perm = ''; + + $first_or = true; + foreach($spec['per'] as $or){ + + /* (1) Ignore non-array values */ + if( !is_array($or) ) + continue; + + $perm .= !$first_or ? ') or' : ''; + + $first_or = false; + $first_and = true; + + /* (2) Manage AND */ + foreach($or as $and){ + + $perm .= $first_and ? ' (' : ' and '; + $perm .= "$and"; + $first_and = false; + + } + + } + + if( !$first_or ) + $perm .= ')'; + + return $perm; + } + +