This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Copyright (c) Enalean, 2014. All rights reserved |
||
4 | * |
||
5 | * This file is a part of Tuleap. |
||
6 | * |
||
7 | * Tuleap is free software; you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation; either version 2 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * Tuleap is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License |
||
18 | * along with Tuleap. If not, see <http://www.gnu.org/licenses/ |
||
19 | */ |
||
20 | |||
21 | class MediawikiManager { |
||
22 | |||
23 | const READ_ACCESS = 'PLUGIN_MEDIAWIKI_READ'; |
||
24 | const WRITE_ACCESS = 'PLUGIN_MEDIAWIKI_WRITE'; |
||
25 | |||
26 | /** @var MediawikiDao */ |
||
27 | private $dao; |
||
28 | |||
29 | public function __construct(MediawikiDao $dao) { |
||
30 | $this->dao = $dao; |
||
31 | } |
||
32 | |||
33 | public function saveCompatibilityViewOption(Project $project, $compatibility_view_option) { |
||
34 | $project_id = $project->getID(); |
||
35 | $enable_compatibility_view = $compatibility_view_option ? $compatibility_view_option : 0; |
||
36 | |||
37 | return $this->dao->updateCompatibilityViewOption($project_id, $enable_compatibility_view); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @return int[] |
||
42 | */ |
||
43 | public function getReadAccessControl(Project $project) { |
||
44 | $ugroup_ids = $this->getAccessControl($project, self::READ_ACCESS); |
||
45 | |||
46 | if (! $ugroup_ids) { |
||
0 ignored issues
–
show
|
|||
47 | return $this->getDefaultReadAccessControl($project); |
||
48 | } |
||
49 | |||
50 | return $ugroup_ids; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @return int[] |
||
55 | */ |
||
56 | private function getDefaultReadAccessControl(Project $project) { |
||
57 | if ($project->isPublic()) { |
||
58 | return array(ProjectUGroup::REGISTERED); |
||
59 | } |
||
60 | |||
61 | return array(ProjectUGroup::PROJECT_MEMBERS); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return int[] |
||
66 | */ |
||
67 | public function getWriteAccessControl(Project $project) { |
||
68 | $ugroup_ids = $this->getAccessControl($project, self::WRITE_ACCESS); |
||
69 | |||
70 | if (! $ugroup_ids) { |
||
0 ignored issues
–
show
The expression
$ugroup_ids of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
71 | return $this->getDefaultWriteAccessControl(); |
||
72 | } |
||
73 | |||
74 | return $ugroup_ids; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @return int[] |
||
79 | */ |
||
80 | private function getDefaultWriteAccessControl() { |
||
81 | return array(ProjectUGroup::PROJECT_MEMBERS); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @return array |
||
86 | */ |
||
87 | private function getAccessControl(Project $project, $access) { |
||
88 | $result = $this->dao->getAccessControl($project->getID(), $access); |
||
89 | $ugroup_ids = array(); |
||
90 | |||
91 | foreach ($result as $row) { |
||
0 ignored issues
–
show
The expression
$result of type false|object is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
92 | $ugroup_ids[] = $row['ugroup_id']; |
||
93 | } |
||
94 | |||
95 | return $ugroup_ids; |
||
96 | } |
||
97 | |||
98 | |||
99 | public function saveReadAccessControl(Project $project, array $ugroup_ids) { |
||
100 | return $this->saveAccessControl($project, self::READ_ACCESS, $ugroup_ids); |
||
101 | } |
||
102 | |||
103 | public function saveWriteAccessControl(Project $project, array $ugroup_ids) { |
||
104 | return $this->saveAccessControl($project, self::WRITE_ACCESS, $ugroup_ids); |
||
105 | } |
||
106 | |||
107 | private function saveAccessControl(Project $project, $access, array $ugroup_ids) { |
||
108 | return $this->dao->saveAccessControl($project->getID(), $access, $ugroup_ids); |
||
109 | } |
||
110 | |||
111 | public function updateAccessControlInProjectChangeContext( |
||
112 | Project $project, |
||
113 | $old_access, |
||
114 | $new_access |
||
115 | ) { |
||
116 | if ($new_access == Project::ACCESS_PRIVATE) { |
||
117 | return $this->dao->disableAnonymousRegisteredAuthenticated($project->getID()); |
||
118 | } |
||
119 | if ($new_access == Project::ACCESS_PUBLIC && $old_access == Project::ACCESS_PUBLIC_UNRESTRICTED) { |
||
120 | return $this->dao->disableAuthenticated($project->getID()); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | public function updateSiteAccess($old_value) { |
||
125 | if ($old_value == ForgeAccess::ANONYMOUS) { |
||
126 | $this->dao->updateAllAnonymousToRegistered(); |
||
127 | } |
||
128 | if ($old_value == ForgeAccess::RESTRICTED) { |
||
129 | $this->dao->updateAllAuthenticatedToRegistered(); |
||
130 | } |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function isCompatibilityViewEnabled(Project $project) { |
||
137 | $plugin_has_view_enabled = (bool) forge_get_config('enable_compatibility_view', 'mediawiki'); |
||
138 | $result = $this->dao->getCompatibilityViewUsage($project->getID()); |
||
139 | |||
140 | if (! $result) { |
||
141 | return false; |
||
142 | } |
||
143 | |||
144 | return ($plugin_has_view_enabled && (bool) $result['enable_compatibility_view']); |
||
145 | } |
||
146 | |||
147 | public function instanceUsesProjectID(Project $project) { |
||
148 | return is_dir(forge_get_config('projects_path', 'mediawiki') . "/". $project->getID()); |
||
149 | } |
||
150 | |||
151 | private function restrictedUserCanRead(PFUser $user, Project $project) { |
||
152 | return in_array(ProjectUGroup::AUTHENTICATED, $this->getReadAccessControl($project)) || in_array(ProjectUGroup::ANONYMOUS, $this->getReadAccessControl($project)); |
||
153 | } |
||
154 | |||
155 | private function restrictedUserCanWrite(PFUser $user, Project $project) { |
||
156 | return in_array(ProjectUGroup::AUTHENTICATED, $this->getWriteAccessControl($project)) || in_array(ProjectUGroup::ANONYMOUS, $this->getWriteAccessControl($project)); |
||
157 | } |
||
158 | |||
159 | private function getUpgroupsPermissionsManager() { |
||
160 | return new User_ForgeUserGroupPermissionsManager( |
||
161 | new User_ForgeUserGroupPermissionsDao() |
||
162 | ); |
||
163 | } |
||
164 | |||
165 | private function hasDelegatedAccess(PFUser $user) { |
||
166 | return $this->getUpgroupsPermissionsManager()->doesUserHavePermission( |
||
167 | $user, |
||
168 | new User_ForgeUserGroupPermission_MediawikiAdminAllProjects() |
||
169 | ); |
||
170 | } |
||
171 | /** |
||
172 | * @param PFUser $user |
||
173 | * @param Project $project |
||
174 | * @return bool true if user can read |
||
175 | */ |
||
176 | public function userCanRead(PFUser $user, Project $project) { |
||
177 | if ($this->hasDelegatedAccess($user)) { |
||
178 | return true; |
||
179 | } |
||
180 | |||
181 | if ($this->userIsRestrictedAndNotProjectMember($user, $project)) { |
||
182 | return $this->restrictedUserCanRead($user, $project); |
||
183 | } |
||
184 | |||
185 | $common_ugroups_ids = array_intersect( |
||
186 | $this->getReadAccessControl($project), |
||
187 | $user->getUgroups($project->getID(), array()) |
||
188 | ); |
||
189 | |||
190 | return !empty($common_ugroups_ids); |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @param PFUser $user |
||
195 | * @param Project $project |
||
196 | * @return bool true if user can write |
||
197 | */ |
||
198 | public function userCanWrite(PFUser $user, Project $project) { |
||
199 | if ($this->hasDelegatedAccess($user)) { |
||
200 | return true; |
||
201 | } |
||
202 | |||
203 | if ($this->userIsRestrictedAndNotProjectMember($user, $project)) { |
||
204 | return $this->restrictedUserCanWrite($user, $project); |
||
205 | } |
||
206 | |||
207 | $common_ugroups_ids = array_intersect( |
||
208 | $this->getWriteAccessControl($project), |
||
209 | $user->getUgroups($project->getID(), array()) |
||
210 | ); |
||
211 | |||
212 | return !empty($common_ugroups_ids); |
||
213 | } |
||
214 | |||
215 | private function userIsRestrictedAndNotProjectMember(PFUser $user, Project $project) { |
||
216 | return $project->allowsRestricted() && $user->isRestricted() && ! $user->isMember($project->getID()); |
||
217 | } |
||
218 | } |
||
219 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.