]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/ProfileField.php
Fix overly strict return value for revokeFollow methods
[friendica.git] / src / Model / ProfileField.php
index e4192a980984c8986c806e998747f9b49e611f43..66833890e8f5d4db3d324c5ba2f3a44ff9937160 100644 (file)
@@ -1,10 +1,31 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Model;
 
 use Friendica\BaseModel;
 use Friendica\Database\Database;
-use Friendica\Network\HTTPException;
+use Friendica\Network\HTTPException\NotFoundException;
+use Friendica\Security\PermissionSet\Depository\PermissionSet as PermissionSetDepository;
+use Friendica\Security\PermissionSet\Entity\PermissionSet;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -20,21 +41,21 @@ use Psr\Log\LoggerInterface;
  * @property string value
  * @property string created
  * @property string edited
- * @property PermissionSet permissionset
+ * @property PermissionSet permissionSet
  */
 class ProfileField extends BaseModel
 {
        /** @var PermissionSet */
-       private $permissionset;
+       private $permissionSet;
 
-       /** @var \Friendica\Repository\PermissionSet */
-       private $permissionSetRepository;
+       /** @var PermissionSetDepository */
+       private $permissionSetDepository;
 
-       public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\PermissionSet $permissionSetRepository, array $data = [])
+       public function __construct(Database $dba, LoggerInterface $logger, PermissionSetDepository $permissionSetDepository, array $data = [])
        {
                parent::__construct($dba, $logger, $data);
 
-               $this->permissionSetRepository = $permissionSetRepository;
+               $this->permissionSetDepository = $permissionSetDepository;
        }
 
        public function __get($name)
@@ -42,12 +63,17 @@ class ProfileField extends BaseModel
                $this->checkValid();
 
                switch ($name) {
-                       case 'permissionset':
-                               $this->permissionset =
-                                       $this->permissionset ??
-                                               $this->permissionSetRepository->selectFirst(['id' => $this->psid, 'uid' => $this->uid]);
+                       case 'permissionSet':
+                               if (empty($this->permissionSet)) {
+                                       $permissionSet = $this->permissionSetDepository->selectOneById($this->psid);
+                                       if ($permissionSet->uid !== $this->uid) {
+                                               throw new NotFoundException(sprintf('PermissionSet %d (user-id: %d) for ProfileField %d (user-id: %d) is invalid.', $permissionSet->id, $permissionSet->uid, $this->id, $this->uid));
+                                       }
+
+                                       $this->permissionSet = $permissionSet;
+                               }
 
-                               $return = $this->permissionset;
+                               $return = $this->permissionSet;
                                break;
                        default:
                                $return = parent::__get($name);