| 1 | <?php |
| 2 | |
| 3 | namespace wcf\data; |
| 4 | |
| 5 | use wcf\system\WCF; |
| 6 | |
| 7 | /** |
| 8 | * Provides a method for validating database object permissions. |
| 9 | * |
| 10 | * @author Matthias Schmidt |
| 11 | * @copyright 2001-2019 WoltLab GmbH |
| 12 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
| 13 | * @since 3.0 |
| 14 | */ |
| 15 | trait TDatabaseObjectPermissions |
| 16 | { |
| 17 | /** |
| 18 | * Returns true if the active user has at least one permission required |
| 19 | * by this object. |
| 20 | * |
| 21 | * @return bool |
| 22 | */ |
| 23 | public function validatePermissions() |
| 24 | { |
| 25 | if ($this->permissions) { |
| 26 | $permissions = \explode(',', $this->permissions); |
| 27 | foreach ($permissions as $permission) { |
| 28 | if (WCF::getSession()->getPermission($permission)) { |
| 29 | return true; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | return true; |
| 37 | } |
| 38 | } |