Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PermissionApiInterface and PermissionAlwaysApi for test/default u…
…sage
- Loading branch information
Showing
3 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/system/PermissionsModule/Api/ApiInterface/PermissionApiInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Zikula package. | ||
* | ||
* Copyright Zikula Foundation - http://zikula.org/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zikula\PermissionsModule\Api\ApiInterface; | ||
|
||
interface PermissionApiInterface | ||
{ | ||
/** | ||
* Check permissions | ||
* @api Core-2.0 | ||
* | ||
* @param string $component Component | ||
* @param string $instance Instance | ||
* @param integer $level Level | ||
* @param integer $user User Id | ||
* | ||
* @return boolean | ||
*/ | ||
public function hasPermission($component = null, $instance = null, $level = ACCESS_NONE, $user = null); | ||
|
||
/** | ||
* Translation functions | ||
* Translate level -> name | ||
* @api Core-2.0 | ||
* | ||
* @param integer $level Access level | ||
* | ||
* @return string Translated access level name | ||
*/ | ||
public function accessLevelNames($level = null); | ||
|
||
/** | ||
* Set permissions for user to false, forcing a reload if called upon again. | ||
* @api Core-2.0 | ||
* | ||
* @param $uid | ||
*/ | ||
public function resetPermissionsForUser($uid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Zikula package. | ||
* | ||
* Copyright Zikula Foundation - http://zikula.org/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zikula\PermissionsModule\Api; | ||
|
||
use Zikula\PermissionsModule\Api\ApiInterface\PermissionApiInterface; | ||
|
||
/** | ||
* Class PermissionAlwaysApi | ||
* | ||
* This class exists for testing and to ensure a functional Api is provided in a default situation. | ||
* ALL hasPermission tests return TRUE regardless of settings. | ||
* Access level names are returned untranslated. | ||
* Permissions cannot be reset for a user. | ||
*/ | ||
class PermissionAlwaysApi implements PermissionApiInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function hasPermission($component = null, $instance = null, $level = ACCESS_NONE, $user = null) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function accessLevelNames($level = null) | ||
{ | ||
if (isset($level) && !is_numeric($level)) { | ||
throw new \InvalidArgumentException(); | ||
} elseif (isset($level)) { | ||
$level = intval($level); | ||
} | ||
|
||
$accessNames = [ | ||
ACCESS_INVALID => 'Invalid', | ||
ACCESS_NONE => 'No access', | ||
ACCESS_OVERVIEW => 'Overview access', | ||
ACCESS_READ => 'Read access', | ||
ACCESS_COMMENT => 'Comment access', | ||
ACCESS_MODERATE => 'Moderate access', | ||
ACCESS_EDIT => 'Edit access', | ||
ACCESS_ADD => 'Add access', | ||
ACCESS_DELETE => 'Delete access', | ||
ACCESS_ADMIN => 'Admin access', | ||
]; | ||
|
||
return isset($level) ? $accessNames[$level] : $accessNames; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resetPermissionsForUser($uid) | ||
{ | ||
// nothing to do | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters