|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Zikula package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright Zikula Foundation - http://zikula.org/ |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Zikula\PermissionsModule\Api; |
|
13
|
|
|
|
|
14
|
|
|
use Zikula\PermissionsModule\Api\ApiInterface\PermissionApiInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class PermissionAlwaysApi |
|
18
|
|
|
* |
|
19
|
|
|
* This class exists for testing and to ensure a functional Api is provided in a default situation. |
|
20
|
|
|
* ALL hasPermission tests return TRUE regardless of settings. |
|
21
|
|
|
* Access level names are returned untranslated. |
|
22
|
|
|
* Permissions cannot be reset for a user. |
|
23
|
|
|
*/ |
|
24
|
|
|
class PermissionAlwaysApi implements PermissionApiInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
public function hasPermission($component = null, $instance = null, $level = ACCESS_NONE, $user = null) |
|
30
|
|
|
{ |
|
31
|
|
|
return true; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
public function accessLevelNames($level = null) |
|
38
|
|
|
{ |
|
39
|
|
View Code Duplication |
if (isset($level) && !is_numeric($level)) { |
|
|
|
|
|
|
40
|
|
|
throw new \InvalidArgumentException(); |
|
41
|
|
|
} elseif (isset($level)) { |
|
42
|
|
|
$level = intval($level); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$accessNames = [ |
|
46
|
|
|
ACCESS_INVALID => 'Invalid', |
|
47
|
|
|
ACCESS_NONE => 'No access', |
|
48
|
|
|
ACCESS_OVERVIEW => 'Overview access', |
|
49
|
|
|
ACCESS_READ => 'Read access', |
|
50
|
|
|
ACCESS_COMMENT => 'Comment access', |
|
51
|
|
|
ACCESS_MODERATE => 'Moderate access', |
|
52
|
|
|
ACCESS_EDIT => 'Edit access', |
|
53
|
|
|
ACCESS_ADD => 'Add access', |
|
54
|
|
|
ACCESS_DELETE => 'Delete access', |
|
55
|
|
|
ACCESS_ADMIN => 'Admin access', |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
return isset($level) ? $accessNames[$level] : $accessNames; |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
|
|
*/ |
|
64
|
|
|
public function resetPermissionsForUser($uid) |
|
65
|
|
|
{ |
|
66
|
|
|
// nothing to do |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.