1
0

Token.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author Julius Härtl <jus@bitgrid.net>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\DirectEditing;
  24. use OCP\DirectEditing\IToken;
  25. use OCP\Files\File;
  26. class Token implements IToken {
  27. /** @var Manager */
  28. private $manager;
  29. private $data;
  30. public function __construct(Manager $manager, $data) {
  31. $this->manager = $manager;
  32. $this->data = $data;
  33. }
  34. public function extend(): void {
  35. $this->manager->refreshToken($this->data['token']);
  36. }
  37. public function invalidate(): void {
  38. $this->manager->invalidateToken($this->data['token']);
  39. }
  40. public function getFile(): File {
  41. if ($this->data['share_id'] !== null) {
  42. return $this->manager->getShareForToken($this->data['share_id']);
  43. }
  44. return $this->manager->getFileForToken($this->data['user_id'], $this->data['file_id'], $this->data['file_path']);
  45. }
  46. public function getToken(): string {
  47. return $this->data['token'];
  48. }
  49. public function useTokenScope(): void {
  50. $this->manager->invokeTokenScope($this->data['user_id']);
  51. }
  52. public function hasBeenAccessed(): bool {
  53. return (bool) $this->data['accessed'];
  54. }
  55. public function getEditor(): string {
  56. return $this->data['editor_id'];
  57. }
  58. public function getUser(): string {
  59. return $this->data['user_id'];
  60. }
  61. }