Move `canEditAvatar()` into `UserProfile`
authorCyperghost <olaf_schmitz_1@t-online.de>
Fri, 8 Nov 2024 12:35:56 +0000 (13:35 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Fri, 8 Nov 2024 12:35:56 +0000 (13:35 +0100)
wcfsetup/install/files/lib/action/UserAvatarAction.class.php
wcfsetup/install/files/lib/data/user/UserProfile.class.php
wcfsetup/install/files/lib/system/file/processor/UserAvatarFileProcessor.class.php

index 7529be1d066c73176c74ac15f02a58e6ad10a4d6..1fd9f59d2c4c64f10f987a6909cb8a6074bcc3b5 100644 (file)
@@ -11,7 +11,6 @@ use wcf\data\user\UserProfile;
 use wcf\http\Helper;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\exception\PermissionDeniedException;
-use wcf\system\file\processor\UserAvatarFileProcessor;
 use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
 use wcf\system\form\builder\field\dependency\ValueFormFieldDependency;
 use wcf\system\form\builder\field\FileProcessorFormField;
@@ -54,7 +53,7 @@ final class UserAvatarAction implements RequestHandlerInterface
             $user = UserProfileHandler::getInstance()->getUserProfile();
         }
 
-        if (!UserAvatarFileProcessor::canEditAvatar($user)) {
+        if (!$user->canEditAvatar()) {
             throw new PermissionDeniedException();
         }
 
index c56761dddfd5fb0c76739e69953118b51563fa55..09483a8b201ffd650a858886a95b5193255cf4d3 100644 (file)
@@ -1198,4 +1198,24 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject
             && $this->trophyPoints
             && ($this->isAccessible('canViewTrophies') || $this->userID == WCF::getSession()->userID);
     }
+
+    /**
+     * @since 6.2
+     */
+    public function canEditAvatar(): bool
+    {
+        if (WCF::getSession()->getPermission('admin.user.canEditUser')) {
+            return true;
+        }
+
+        if ($this->userID !== WCF::getUser()->userID) {
+            return false;
+        }
+
+        if ($this->disableAvatar) {
+            return false;
+        }
+
+        return WCF::getSession()->getPermission('user.profile.avatar.canUploadAvatar');
+    }
 }
index ff4dfe534bea7ee6cd02a4258ffedc9194379dba..95df6a036bc23827263ecabb2a9725eaeb28becc 100644 (file)
@@ -83,7 +83,7 @@ final class UserAvatarFileProcessor extends AbstractFileProcessor
             return FileProcessorPreflightResult::InvalidContext;
         }
 
-        if (!UserAvatarFileProcessor::canEditAvatar($user)) {
+        if (!$user->canEditAvatar()) {
             return FileProcessorPreflightResult::InsufficientPermissions;
         }
 
@@ -128,7 +128,7 @@ final class UserAvatarFileProcessor extends AbstractFileProcessor
             ) !== null;
         }
 
-        return UserAvatarFileProcessor::canEditAvatar($user);
+        return $user->canEditAvatar();
     }
 
     #[\Override]
@@ -246,21 +246,4 @@ final class UserAvatarFileProcessor extends AbstractFileProcessor
 
         return UserProfileRuntimeCache::getInstance()->getObject($userID);
     }
-
-    public static function canEditAvatar(UserProfile $user): bool
-    {
-        if (WCF::getSession()->getPermission('admin.user.canEditUser')) {
-            return true;
-        }
-
-        if ($user->userID !== WCF::getUser()->userID) {
-            return false;
-        }
-
-        if (WCF::getUser()->disableAvatar) {
-            return false;
-        }
-
-        return WCF::getSession()->getPermission('user.profile.avatar.canUploadAvatar');
-    }
 }