1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- declare(strict_types=1);
- namespace OC\Core\Controller;
- use OC\Core\Db\ProfileConfigMapper;
- use OC\Profile\ProfileManager;
- use OCP\AppFramework\Http;
- use OCP\AppFramework\Http\Attribute\ApiRoute;
- use OCP\AppFramework\Http\Attribute\NoAdminRequired;
- use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
- use OCP\AppFramework\Http\Attribute\UserRateLimit;
- use OCP\AppFramework\Http\DataResponse;
- use OCP\AppFramework\OCS\OCSBadRequestException;
- use OCP\AppFramework\OCS\OCSForbiddenException;
- use OCP\AppFramework\OCS\OCSNotFoundException;
- use OCP\AppFramework\OCSController;
- use OCP\IRequest;
- use OCP\IUserManager;
- use OCP\IUserSession;
- class ProfileApiController extends OCSController {
- public function __construct(
- IRequest $request,
- private ProfileConfigMapper $configMapper,
- private ProfileManager $profileManager,
- private IUserManager $userManager,
- private IUserSession $userSession,
- ) {
- parent::__construct('core', $request);
- }
-
-
-
-
-
- public function setVisibility(string $targetUserId, string $paramId, string $visibility): DataResponse {
- $requestingUser = $this->userSession->getUser();
- $targetUser = $this->userManager->get($targetUserId);
- if (!$this->userManager->userExists($targetUserId)) {
- throw new OCSNotFoundException('Account does not exist');
- }
- if ($requestingUser !== $targetUser) {
- throw new OCSForbiddenException('People can only edit their own visibility settings');
- }
-
- $this->profileManager->getProfileConfig($targetUser, $targetUser);
- $config = $this->configMapper->get($targetUserId);
- if (!in_array($paramId, array_keys($config->getVisibilityMap()), true)) {
- throw new OCSBadRequestException('Account does not have a profile parameter with ID: ' . $paramId);
- }
- $config->setVisibility($paramId, $visibility);
- $this->configMapper->update($config);
- return new DataResponse();
- }
- }
|