mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 10:10:49 -04:00
feat(OCM-invites): Simplify accepted timestampcheck
Also run cs:fix to fix the code style, and address some minor points. Fix typo in setRecipientName Signed-off-by: Micke Nordin <kano@sunet.se>
This commit is contained in:
parent
8404324774
commit
616447413e
5 changed files with 30 additions and 50 deletions
|
|
@ -48,7 +48,7 @@ class Capabilities implements ICapability {
|
|||
* shareTypes: list<string>,
|
||||
* protocols: array<string, string>
|
||||
* }>,
|
||||
* version: string
|
||||
* version: string,
|
||||
* capabilities: array{
|
||||
* string,
|
||||
* }
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use OC\OCM\OCMSignatoryManager;
|
|||
use OCA\CloudFederationAPI\Config;
|
||||
use OCA\CloudFederationAPI\Db\FederatedInviteMapper;
|
||||
use OCA\CloudFederationAPI\Events\FederatedInviteAcceptedEvent;
|
||||
use OCA\CloudFederationAPI\ResponseDefinitions;
|
||||
use OCA\FederatedFileSharing\AddressHandler;
|
||||
use OCA\Federation\TrustedServers;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
|
@ -30,7 +31,6 @@ use OCP\AppFramework\Http\Attribute\OpenAPI;
|
|||
use OCP\AppFramework\Http\Attribute\PublicPage;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Federation\Exceptions\ActionNotSupportedException;
|
||||
use OCP\Federation\Exceptions\AuthenticationFailedException;
|
||||
|
|
@ -119,7 +119,8 @@ class RequestHandlerController extends Controller {
|
|||
}
|
||||
|
||||
// check if all required parameters are set
|
||||
if ($shareWith === null ||
|
||||
if (
|
||||
$shareWith === null ||
|
||||
$name === null ||
|
||||
$providerId === null ||
|
||||
$resourceType === null ||
|
||||
|
|
@ -253,6 +254,7 @@ class RequestHandlerController extends Controller {
|
|||
$this->logger->debug('Invite accepted for ' . $userId . ' with token ' . $token . ' and email ' . $email . ' and name ' . $name);
|
||||
|
||||
$updated = $this->timeFactory->getTime();
|
||||
|
||||
if ($token === '') {
|
||||
$response = new JSONResponse(['message' => 'Invalid or non existing token', 'error' => true], Http::STATUS_BAD_REQUEST);
|
||||
$response->throttle();
|
||||
|
|
@ -279,18 +281,14 @@ class RequestHandlerController extends Controller {
|
|||
$status = Http::STATUS_CONFLICT;
|
||||
return new JSONResponse($response, $status);
|
||||
}
|
||||
$unixstart = $this->timeFactory->createFromFormat('U', '1');
|
||||
$expiredAt = $this->timeFactory->createFromFormat('U', strval($invitation->getExpiredAt()));
|
||||
if ($expiredAt == $unixstart) {
|
||||
$invitation->setExpiredAt($updated);
|
||||
}
|
||||
|
||||
elseif ($invitation->getExpiredAt() < $updated) {
|
||||
if (!empty($invitation->getExpiredAt()) && $updated > $invitation->getExpiredAt()) {
|
||||
$response = ['message' => 'Invitation expired', 'error' => true];
|
||||
$status = Http::STATUS_BAD_REQUEST;
|
||||
return new JSONResponse($response, $status);
|
||||
}
|
||||
|
||||
|
||||
$localUser = $this->userManager->get($invitation->getUserId());
|
||||
if ($localUser === null) {
|
||||
$response = ['message' => 'Invalid or non existing token', 'error' => true];
|
||||
|
|
@ -308,7 +306,7 @@ class RequestHandlerController extends Controller {
|
|||
|
||||
$invitation->setAccepted(true);
|
||||
$invitation->setRecipientEmail($email);
|
||||
$invitation->getRecipientName($name);
|
||||
$invitation->setRecipientName($name);
|
||||
$invitation->setRecipientProvider($recipientProvider);
|
||||
$invitation->setRecipientUserId($userId);
|
||||
$invitation->setAcceptedAt($updated);
|
||||
|
|
@ -340,7 +338,8 @@ class RequestHandlerController extends Controller {
|
|||
#[BruteForceProtection(action: 'receiveFederatedShareNotification')]
|
||||
public function receiveNotification($notificationType, $resourceType, $providerId, ?array $notification) {
|
||||
// check if all required parameters are set
|
||||
if ($notificationType === null ||
|
||||
if (
|
||||
$notificationType === null ||
|
||||
$resourceType === null ||
|
||||
$providerId === null ||
|
||||
!is_array($notification)
|
||||
|
|
|
|||
|
|
@ -38,44 +38,44 @@ use OCP\DB\Types;
|
|||
class FederatedInvite extends Entity {
|
||||
|
||||
/**
|
||||
* @var bool $accepted
|
||||
*/
|
||||
* @var bool $accepted
|
||||
*/
|
||||
protected $accepted;
|
||||
/**
|
||||
* @var ?int $acceptedAt
|
||||
*/
|
||||
* @var ?int $acceptedAt
|
||||
*/
|
||||
protected $acceptedAt;
|
||||
/**
|
||||
* @var int $createdAt
|
||||
*/
|
||||
* @var int $createdAt
|
||||
*/
|
||||
protected $createdAt;
|
||||
/**
|
||||
* @var $int $expiredAt
|
||||
*/
|
||||
* @var $int $expiredAt
|
||||
*/
|
||||
protected $expiredAt;
|
||||
/**
|
||||
* @var ?string $recipientEmail
|
||||
*/
|
||||
* @var ?string $recipientEmail
|
||||
*/
|
||||
protected $recipientEmail;
|
||||
/**
|
||||
* @var ?string $recipientName
|
||||
*/
|
||||
* @var ?string $recipientName
|
||||
*/
|
||||
protected $recipientName;
|
||||
/**
|
||||
* @var ?string $recipientProvider
|
||||
*/
|
||||
* @var ?string $recipientProvider
|
||||
*/
|
||||
protected $recipientProvider;
|
||||
/**
|
||||
* @var ?string $recipientUserId
|
||||
*/
|
||||
* @var ?string $recipientUserId
|
||||
*/
|
||||
protected $recipientUserId;
|
||||
/**
|
||||
* @var string $token
|
||||
*/
|
||||
* @var string $token
|
||||
*/
|
||||
protected $token;
|
||||
/**
|
||||
* @var string $userId
|
||||
*/
|
||||
* @var string $userId
|
||||
*/
|
||||
protected $userId;
|
||||
|
||||
public function __construct() {
|
||||
|
|
|
|||
|
|
@ -24,17 +24,6 @@ class TimeFactory implements ITimeFactory {
|
|||
$this->timezone = new \DateTimeZone('UTC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $format
|
||||
* @param string $time
|
||||
* @param \DateTimeZone|null $timezone
|
||||
* @return \DateTime with the result of a call to \DateTime::createFromFormat()
|
||||
* @since 32.0.0
|
||||
*/
|
||||
public function createFromFormat(string $format, string $time = 'now', ?\DateTimeZone $timezone = null): \DateTime {
|
||||
return \DateTime::createFromFormat($format, $time, $timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int the result of a call to time()
|
||||
* @since 8.0.0
|
||||
|
|
|
|||
|
|
@ -20,14 +20,6 @@ use Psr\Clock\ClockInterface;
|
|||
*/
|
||||
|
||||
interface ITimeFactory extends ClockInterface {
|
||||
/**
|
||||
* @param string $format
|
||||
* @param string $time
|
||||
* @param \DateTimeZone|null $timezone
|
||||
* @return \DateTime with the result of a call to \DateTime::createFromFormat()
|
||||
* @since 32.0.0
|
||||
*/
|
||||
public function createFromFormat(string $format, string $time = 'now', ?\DateTimeZone $timezone = null): \DateTime;
|
||||
/**
|
||||
* @return int the result of a call to time()
|
||||
* @since 8.0.0
|
||||
|
|
|
|||
Loading…
Reference in a new issue