-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hoang Pham <[email protected]>
- Loading branch information
Showing
30 changed files
with
912 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Exception; | ||
|
||
use OCP\AppFramework\Http; | ||
use RuntimeException; | ||
|
||
final class InvalidUserException extends RuntimeException { | ||
public function __construct(string $message = 'Invalid user') { | ||
parent::__construct($message, Http::STATUS_BAD_REQUEST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Exception; | ||
|
||
use OCP\AppFramework\Http; | ||
use RuntimeException; | ||
|
||
final class UnauthorizedException extends RuntimeException { | ||
public function __construct(string $message = 'Unauthorized') { | ||
parent::__construct($message, Http::STATUS_UNAUTHORIZED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
|
||
namespace OCA\Whiteboard\Listener; | ||
|
||
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; | ||
use OCP\AppFramework\Services\IInitialState; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\NotFoundException; | ||
|
||
/** @template-implements IEventListener<BeforeTemplateRenderedEvent|Event> */ | ||
/** | ||
* @psalm-suppress UndefinedClass | ||
* @psalm-suppress MissingTemplateParam | ||
*/ | ||
class BeforeTemplateRenderedListener implements IEventListener { | ||
public function __construct( | ||
private IInitialState $initialState, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws NotFoundException | ||
*/ | ||
public function handle(Event $event): void { | ||
if (!($event instanceof BeforeTemplateRenderedEvent)) { | ||
return; | ||
} | ||
|
||
$this->initialState->provideInitialState( | ||
'file_id', | ||
$event->getShare()->getNodeId() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Model; | ||
|
||
use OCP\IUser; | ||
|
||
final class AuthenticatedUser implements User { | ||
public function __construct(private IUser $user) { | ||
} | ||
|
||
public function getUID(): string { | ||
return $this->user->getUID(); | ||
} | ||
|
||
public function getDisplayName(): string { | ||
return $this->user->getDisplayName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Model; | ||
|
||
final class PublicSharingUser implements User { | ||
public function __construct( | ||
private string $publicSharingToken | ||
) { | ||
} | ||
|
||
public function getUID(): string { | ||
return $this->generateRandomUID(); | ||
} | ||
|
||
public function getDisplayName(): string { | ||
return $this->generateRandomDisplayName(); | ||
} | ||
|
||
public function getPublicSharingToken(): string { | ||
return $this->publicSharingToken; | ||
} | ||
|
||
private function generateRandomUID(): string { | ||
return 'shared_' . $this->publicSharingToken . '_' . bin2hex(random_bytes(8)); | ||
} | ||
|
||
private function generateRandomDisplayName(): string { | ||
$adjectives = ['Anonymous', 'Mysterious', 'Incognito', 'Unknown', 'Unnamed']; | ||
$nouns = ['User', 'Visitor', 'Guest', 'Collaborator', 'Participant']; | ||
|
||
$adjective = $adjectives[array_rand($adjectives)]; | ||
$noun = $nouns[array_rand($nouns)]; | ||
|
||
return $adjective . ' ' . $noun; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Model; | ||
|
||
interface User { | ||
public function getUID(): string; | ||
public function getDisplayName(): string; | ||
} |
Oops, something went wrong.