-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stable27] fix: avoid douple expireDate
parsing
#44911
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,6 @@ | |
use OCP\IL10N; | ||
use OCP\IPreview; | ||
use OCP\IRequest; | ||
use OCP\IServerContainer; | ||
use OCP\IURLGenerator; | ||
use OCP\IUserManager; | ||
use OCP\Lock\ILockingProvider; | ||
|
@@ -83,6 +82,7 @@ | |
use OCP\Share\IShare; | ||
use OCP\UserStatus\IManager as IUserStatusManager; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
|
@@ -92,32 +92,8 @@ | |
*/ | ||
class ShareAPIController extends OCSController { | ||
|
||
/** @var IManager */ | ||
private $shareManager; | ||
/** @var IGroupManager */ | ||
private $groupManager; | ||
/** @var IUserManager */ | ||
private $userManager; | ||
/** @var IRootFolder */ | ||
private $rootFolder; | ||
/** @var IURLGenerator */ | ||
private $urlGenerator; | ||
/** @var string */ | ||
private $currentUser; | ||
/** @var IL10N */ | ||
private $l; | ||
/** @var \OCP\Files\Node */ | ||
private $lockedNode; | ||
/** @var IConfig */ | ||
private $config; | ||
/** @var IAppManager */ | ||
private $appManager; | ||
/** @var IServerContainer */ | ||
private $serverContainer; | ||
/** @var IUserStatusManager */ | ||
private $userStatusManager; | ||
/** @var IPreview */ | ||
private $previewManager; | ||
private ?Node $lockedNode = null; | ||
private string $currentUser; | ||
|
||
/** | ||
* Share20OCS constructor. | ||
|
@@ -134,26 +110,15 @@ | |
IL10N $l10n, | ||
IConfig $config, | ||
IAppManager $appManager, | ||
IServerContainer $serverContainer, | ||
Check failure on line 113 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedClass
|
||
IUserStatusManager $userStatusManager, | ||
IPreview $previewManager, | ||
private IDateTimeZone $dateTimeZone, | ||
private LoggerInterface $logger, | ||
?string $userId = null | ||
Check failure on line 118 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisDuplicateParam
|
||
) { | ||
parent::__construct($appName, $request); | ||
|
||
$this->shareManager = $shareManager; | ||
$this->userManager = $userManager; | ||
$this->groupManager = $groupManager; | ||
$this->request = $request; | ||
$this->rootFolder = $rootFolder; | ||
$this->urlGenerator = $urlGenerator; | ||
$this->currentUser = $userId; | ||
$this->l = $l10n; | ||
$this->config = $config; | ||
$this->appManager = $appManager; | ||
$this->serverContainer = $serverContainer; | ||
$this->userStatusManager = $userStatusManager; | ||
$this->previewManager = $previewManager; | ||
} | ||
|
||
/** | ||
|
@@ -167,7 +132,7 @@ | |
* @suppress PhanUndeclaredClassMethod | ||
*/ | ||
protected function formatShare(IShare $share, Node $recipientNode = null): array { | ||
$sharedBy = $this->userManager->get($share->getSharedBy()); | ||
Check failure on line 135 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedThisPropertyFetch
|
||
$shareOwner = $this->userManager->get($share->getShareOwner()); | ||
|
||
$result = [ | ||
|
@@ -190,7 +155,7 @@ | |
'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), | ||
]; | ||
|
||
$userFolder = $this->rootFolder->getUserFolder($this->currentUser); | ||
Check failure on line 158 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedThisPropertyFetch
|
||
if ($recipientNode) { | ||
$node = $recipientNode; | ||
} else { | ||
|
@@ -214,7 +179,7 @@ | |
} | ||
|
||
$result['mimetype'] = $node->getMimetype(); | ||
$result['has_preview'] = $this->previewManager->isAvailable($node); | ||
Check failure on line 182 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedThisPropertyFetch
|
||
$result['storage_id'] = $node->getStorage()->getId(); | ||
$result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); | ||
$result['item_source'] = $node->getId(); | ||
|
@@ -237,7 +202,7 @@ | |
) : $share->getSharedWith(); | ||
$result['status'] = []; | ||
|
||
$userStatuses = $this->userStatusManager->getUserStatuses([$share->getSharedWith()]); | ||
Check failure on line 205 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedThisPropertyFetch
|
||
$userStatus = array_shift($userStatuses); | ||
if ($userStatus) { | ||
$result['status'] = [ | ||
|
@@ -250,7 +215,7 @@ | |
]; | ||
} | ||
} elseif ($share->getShareType() === IShare::TYPE_GROUP) { | ||
$group = $this->groupManager->get($share->getSharedWith()); | ||
Check failure on line 218 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedThisPropertyFetch
|
||
$result['share_with'] = $share->getSharedWith(); | ||
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); | ||
} elseif ($share->getShareType() === IShare::TYPE_LINK) { | ||
|
@@ -258,14 +223,14 @@ | |
// "share_with" and "share_with_displayname" for passwords of link | ||
// shares was deprecated in Nextcloud 15, use "password" instead. | ||
$result['share_with'] = $share->getPassword(); | ||
$result['share_with_displayname'] = '(' . $this->l->t('Shared link') . ')'; | ||
Check failure on line 226 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedThisPropertyFetch
|
||
|
||
$result['password'] = $share->getPassword(); | ||
|
||
$result['send_password_by_talk'] = $share->getSendPasswordByTalk(); | ||
|
||
$result['token'] = $share->getToken(); | ||
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); | ||
Check failure on line 233 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedThisPropertyFetch
|
||
} elseif ($share->getShareType() === IShare::TYPE_REMOTE) { | ||
$result['share_with'] = $share->getSharedWith(); | ||
$result['share_with_displayname'] = $this->getCachedFederatedDisplayName($share->getSharedWith()); | ||
|
@@ -355,7 +320,7 @@ | |
'strict_search' => true, | ||
]); | ||
} catch (Exception $e) { | ||
Server::get(LoggerInterface::class)->error( | ||
$this->logger->error( | ||
$e->getMessage(), | ||
['exception' => $e] | ||
); | ||
|
@@ -429,7 +394,7 @@ | |
private function retrieveFederatedDisplayName(array $userIds, bool $cacheOnly = false): array { | ||
// check if gss is enabled and available | ||
if (count($userIds) === 0 | ||
|| !$this->appManager->isInstalled('globalsiteselector') | ||
Check failure on line 397 in apps/files_sharing/lib/Controller/ShareAPIController.php GitHub Actions / static-code-analysisUndefinedThisPropertyFetch
|
||
|| !class_exists('\OCA\GlobalSiteSelector\Service\SlaveService')) { | ||
return []; | ||
} | ||
|
@@ -437,7 +402,7 @@ | |
try { | ||
$slaveService = Server::get(\OCA\GlobalSiteSelector\Service\SlaveService::class); | ||
} catch (\Throwable $e) { | ||
Server::get(LoggerInterface::class)->error( | ||
$this->logger->error( | ||
$e->getMessage(), | ||
['exception' => $e] | ||
); | ||
|
@@ -653,6 +618,16 @@ | |
$share = $this->setShareAttributes($share, $attributes); | ||
} | ||
|
||
//Expire date | ||
if ($expireDate !== '') { | ||
try { | ||
$expireDate = $this->parseDate($expireDate); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs #44916 otherwise it breaks opencloudmesh, deck and talk |
||
$share->setExpirationDate($expireDate); | ||
} catch (\Exception $e) { | ||
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); | ||
Check failure Code scanning / Psalm UndefinedThisPropertyFetch Error
Instance property OCA\Files_Sharing\Controller\ShareAPIController::$l is not defined
|
||
} | ||
} | ||
|
||
$share->setSharedBy($this->currentUser); | ||
$this->checkInheritedAttributes($share); | ||
|
||
|
@@ -739,15 +714,6 @@ | |
|
||
$share->setSharedWith($shareWith); | ||
$share->setPermissions($permissions); | ||
if ($expireDate !== '') { | ||
try { | ||
$expireDate = $this->parseDate($expireDate); | ||
$share->setExpirationDate($expireDate); | ||
} catch (\Exception $e) { | ||
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); | ||
} | ||
} | ||
|
||
$share->setSharedWithDisplayName($this->getCachedFederatedDisplayName($shareWith, false)); | ||
} elseif ($shareType === IShare::TYPE_REMOTE_GROUP) { | ||
if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { | ||
|
@@ -760,14 +726,6 @@ | |
|
||
$share->setSharedWith($shareWith); | ||
$share->setPermissions($permissions); | ||
if ($expireDate !== '') { | ||
try { | ||
$expireDate = $this->parseDate($expireDate); | ||
$share->setExpirationDate($expireDate); | ||
} catch (\Exception $e) { | ||
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); | ||
} | ||
} | ||
} elseif ($shareType === IShare::TYPE_CIRCLE) { | ||
if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { | ||
throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); | ||
|
@@ -803,16 +761,6 @@ | |
throw new OCSBadRequestException($this->l->t('Unknown share type')); | ||
} | ||
|
||
//Expire date | ||
if ($expireDate !== '') { | ||
try { | ||
$expireDate = $this->parseDate($expireDate); | ||
$share->setExpirationDate($expireDate); | ||
} catch (\Exception $e) { | ||
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); | ||
} | ||
} | ||
|
||
$share->setShareType($shareType); | ||
|
||
if ($note !== '') { | ||
|
Check failure
Code scanning / Psalm
DuplicateParam Error