@@ -6,5 +6,5 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'OCA\\Settings\\' => array($baseDir . '/../lib'), |
|
9 | + 'OCA\\Settings\\' => array($baseDir.'/../lib'), |
|
10 | 10 | ); |
@@ -63,49 +63,49 @@ |
||
63 | 63 | return; |
64 | 64 | } |
65 | 65 | |
66 | - $propFind->handle(self::TRASHBIN_FILENAME, function () use ($node) { |
|
66 | + $propFind->handle(self::TRASHBIN_FILENAME, function() use ($node) { |
|
67 | 67 | return $node->getFilename(); |
68 | 68 | }); |
69 | 69 | |
70 | - $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function () use ($node) { |
|
70 | + $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function() use ($node) { |
|
71 | 71 | return $node->getOriginalLocation(); |
72 | 72 | }); |
73 | 73 | |
74 | - $propFind->handle(self::TRASHBIN_TITLE, function () use ($node) { |
|
74 | + $propFind->handle(self::TRASHBIN_TITLE, function() use ($node) { |
|
75 | 75 | return $node->getTitle(); |
76 | 76 | }); |
77 | 77 | |
78 | - $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) { |
|
78 | + $propFind->handle(self::TRASHBIN_DELETION_TIME, function() use ($node) { |
|
79 | 79 | return $node->getDeletionTime(); |
80 | 80 | }); |
81 | 81 | |
82 | - $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) { |
|
82 | + $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function() use ($node) { |
|
83 | 83 | return $node->getSize(); |
84 | 84 | }); |
85 | 85 | |
86 | - $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) { |
|
86 | + $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function() use ($node) { |
|
87 | 87 | return $node->getFileId(); |
88 | 88 | }); |
89 | 89 | |
90 | - $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () { |
|
90 | + $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function() { |
|
91 | 91 | return 'GD'; // read + delete |
92 | 92 | }); |
93 | 93 | |
94 | - $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, function () use ($node) { |
|
94 | + $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, function() use ($node) { |
|
95 | 95 | // add fake etag, it is only needed to identify the preview image |
96 | 96 | return $node->getLastModified(); |
97 | 97 | }); |
98 | 98 | |
99 | - $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
99 | + $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
100 | 100 | // add fake etag, it is only needed to identify the preview image |
101 | 101 | return $node->getFileId(); |
102 | 102 | }); |
103 | 103 | |
104 | - $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
104 | + $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function() use ($node) { |
|
105 | 105 | return $this->previewManager->isAvailable($node->getFileInfo()); |
106 | 106 | }); |
107 | 107 | |
108 | - $propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function () { |
|
108 | + $propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function() { |
|
109 | 109 | return ''; |
110 | 110 | }); |
111 | 111 | } |
@@ -35,79 +35,79 @@ |
||
35 | 35 | use Sabre\DAV\ServerPlugin; |
36 | 36 | |
37 | 37 | class PropfindPlugin extends ServerPlugin { |
38 | - public const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename'; |
|
39 | - public const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location'; |
|
40 | - public const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time'; |
|
41 | - public const TRASHBIN_TITLE = '{http://nextcloud.org/ns}trashbin-title'; |
|
38 | + public const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename'; |
|
39 | + public const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location'; |
|
40 | + public const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time'; |
|
41 | + public const TRASHBIN_TITLE = '{http://nextcloud.org/ns}trashbin-title'; |
|
42 | 42 | |
43 | - /** @var Server */ |
|
44 | - private $server; |
|
43 | + /** @var Server */ |
|
44 | + private $server; |
|
45 | 45 | |
46 | - /** @var IPreview */ |
|
47 | - private $previewManager; |
|
46 | + /** @var IPreview */ |
|
47 | + private $previewManager; |
|
48 | 48 | |
49 | - public function __construct( |
|
50 | - IPreview $previewManager |
|
51 | - ) { |
|
52 | - $this->previewManager = $previewManager; |
|
53 | - } |
|
49 | + public function __construct( |
|
50 | + IPreview $previewManager |
|
51 | + ) { |
|
52 | + $this->previewManager = $previewManager; |
|
53 | + } |
|
54 | 54 | |
55 | - public function initialize(Server $server) { |
|
56 | - $this->server = $server; |
|
55 | + public function initialize(Server $server) { |
|
56 | + $this->server = $server; |
|
57 | 57 | |
58 | - $this->server->on('propFind', [$this, 'propFind']); |
|
59 | - } |
|
58 | + $this->server->on('propFind', [$this, 'propFind']); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - public function propFind(PropFind $propFind, INode $node) { |
|
63 | - if (!($node instanceof ITrash)) { |
|
64 | - return; |
|
65 | - } |
|
62 | + public function propFind(PropFind $propFind, INode $node) { |
|
63 | + if (!($node instanceof ITrash)) { |
|
64 | + return; |
|
65 | + } |
|
66 | 66 | |
67 | - $propFind->handle(self::TRASHBIN_FILENAME, function () use ($node) { |
|
68 | - return $node->getFilename(); |
|
69 | - }); |
|
67 | + $propFind->handle(self::TRASHBIN_FILENAME, function () use ($node) { |
|
68 | + return $node->getFilename(); |
|
69 | + }); |
|
70 | 70 | |
71 | - $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function () use ($node) { |
|
72 | - return $node->getOriginalLocation(); |
|
73 | - }); |
|
71 | + $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function () use ($node) { |
|
72 | + return $node->getOriginalLocation(); |
|
73 | + }); |
|
74 | 74 | |
75 | - $propFind->handle(self::TRASHBIN_TITLE, function () use ($node) { |
|
76 | - return $node->getTitle(); |
|
77 | - }); |
|
75 | + $propFind->handle(self::TRASHBIN_TITLE, function () use ($node) { |
|
76 | + return $node->getTitle(); |
|
77 | + }); |
|
78 | 78 | |
79 | - $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) { |
|
80 | - return $node->getDeletionTime(); |
|
81 | - }); |
|
79 | + $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) { |
|
80 | + return $node->getDeletionTime(); |
|
81 | + }); |
|
82 | 82 | |
83 | - $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) { |
|
84 | - return $node->getSize(); |
|
85 | - }); |
|
83 | + $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) { |
|
84 | + return $node->getSize(); |
|
85 | + }); |
|
86 | 86 | |
87 | - $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) { |
|
88 | - return $node->getFileId(); |
|
89 | - }); |
|
87 | + $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) { |
|
88 | + return $node->getFileId(); |
|
89 | + }); |
|
90 | 90 | |
91 | - $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () { |
|
92 | - return 'GD'; // read + delete |
|
93 | - }); |
|
91 | + $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () { |
|
92 | + return 'GD'; // read + delete |
|
93 | + }); |
|
94 | 94 | |
95 | - $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, function () use ($node) { |
|
96 | - // add fake etag, it is only needed to identify the preview image |
|
97 | - return $node->getLastModified(); |
|
98 | - }); |
|
95 | + $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, function () use ($node) { |
|
96 | + // add fake etag, it is only needed to identify the preview image |
|
97 | + return $node->getLastModified(); |
|
98 | + }); |
|
99 | 99 | |
100 | - $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
101 | - // add fake etag, it is only needed to identify the preview image |
|
102 | - return $node->getFileId(); |
|
103 | - }); |
|
100 | + $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
101 | + // add fake etag, it is only needed to identify the preview image |
|
102 | + return $node->getFileId(); |
|
103 | + }); |
|
104 | 104 | |
105 | - $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
106 | - return $this->previewManager->isAvailable($node->getFileInfo()); |
|
107 | - }); |
|
105 | + $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
106 | + return $this->previewManager->isAvailable($node->getFileInfo()); |
|
107 | + }); |
|
108 | 108 | |
109 | - $propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function () { |
|
110 | - return ''; |
|
111 | - }); |
|
112 | - } |
|
109 | + $propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function () { |
|
110 | + return ''; |
|
111 | + }); |
|
112 | + } |
|
113 | 113 | } |
@@ -26,19 +26,19 @@ |
||
26 | 26 | use OCP\Files\FileInfo; |
27 | 27 | |
28 | 28 | interface ITrash { |
29 | - public function restore(): bool; |
|
29 | + public function restore(): bool; |
|
30 | 30 | |
31 | - public function getFilename(): string; |
|
31 | + public function getFilename(): string; |
|
32 | 32 | |
33 | - public function getOriginalLocation(): string; |
|
33 | + public function getOriginalLocation(): string; |
|
34 | 34 | |
35 | - public function getTitle(): string; |
|
35 | + public function getTitle(): string; |
|
36 | 36 | |
37 | - public function getDeletionTime(): int; |
|
37 | + public function getDeletionTime(): int; |
|
38 | 38 | |
39 | - public function getSize(); |
|
39 | + public function getSize(); |
|
40 | 40 | |
41 | - public function getFileId(): int; |
|
41 | + public function getFileId(): int; |
|
42 | 42 | |
43 | - public function getFileInfo(): FileInfo; |
|
43 | + public function getFileInfo(): FileInfo; |
|
44 | 44 | } |
@@ -28,53 +28,53 @@ |
||
28 | 28 | * @since 15.0.0 |
29 | 29 | */ |
30 | 30 | interface ITrashItem extends FileInfo { |
31 | - /** |
|
32 | - * Get the trash backend for this item |
|
33 | - * |
|
34 | - * @return ITrashBackend |
|
35 | - * @since 15.0.0 |
|
36 | - */ |
|
37 | - public function getTrashBackend(): ITrashBackend; |
|
31 | + /** |
|
32 | + * Get the trash backend for this item |
|
33 | + * |
|
34 | + * @return ITrashBackend |
|
35 | + * @since 15.0.0 |
|
36 | + */ |
|
37 | + public function getTrashBackend(): ITrashBackend; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Get the original location for the trash item |
|
41 | - * |
|
42 | - * @return string |
|
43 | - * @since 15.0.0 |
|
44 | - */ |
|
45 | - public function getOriginalLocation(): string; |
|
39 | + /** |
|
40 | + * Get the original location for the trash item |
|
41 | + * |
|
42 | + * @return string |
|
43 | + * @since 15.0.0 |
|
44 | + */ |
|
45 | + public function getOriginalLocation(): string; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get the timestamp that the file was moved to trash |
|
49 | - * |
|
50 | - * @return int |
|
51 | - * @since 15.0.0 |
|
52 | - */ |
|
53 | - public function getDeletedTime(): int; |
|
47 | + /** |
|
48 | + * Get the timestamp that the file was moved to trash |
|
49 | + * |
|
50 | + * @return int |
|
51 | + * @since 15.0.0 |
|
52 | + */ |
|
53 | + public function getDeletedTime(): int; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get the path of the item relative to the users trashbin |
|
57 | - * |
|
58 | - * @return string |
|
59 | - * @since 15.0.0 |
|
60 | - */ |
|
61 | - public function getTrashPath(): string; |
|
55 | + /** |
|
56 | + * Get the path of the item relative to the users trashbin |
|
57 | + * |
|
58 | + * @return string |
|
59 | + * @since 15.0.0 |
|
60 | + */ |
|
61 | + public function getTrashPath(): string; |
|
62 | 62 | |
63 | - /** |
|
64 | - * Whether the item is a deleted item in the root of the trash, or a file in a subfolder |
|
65 | - * |
|
66 | - * @return bool |
|
67 | - * @since 15.0.0 |
|
68 | - */ |
|
69 | - public function isRootItem(): bool; |
|
63 | + /** |
|
64 | + * Whether the item is a deleted item in the root of the trash, or a file in a subfolder |
|
65 | + * |
|
66 | + * @return bool |
|
67 | + * @since 15.0.0 |
|
68 | + */ |
|
69 | + public function isRootItem(): bool; |
|
70 | 70 | |
71 | - /** |
|
72 | - * Get the user for which this trash item applies |
|
73 | - * |
|
74 | - * @return IUser |
|
75 | - * @since 15.0.0 |
|
76 | - */ |
|
77 | - public function getUser(): IUser; |
|
71 | + /** |
|
72 | + * Get the user for which this trash item applies |
|
73 | + * |
|
74 | + * @return IUser |
|
75 | + * @since 15.0.0 |
|
76 | + */ |
|
77 | + public function getUser(): IUser; |
|
78 | 78 | |
79 | - public function getTitle(): string; |
|
79 | + public function getTitle(): string; |
|
80 | 80 | } |
@@ -73,10 +73,10 @@ |
||
73 | 73 | Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
74 | 74 | Request::USER_AGENT_FREEBOX, |
75 | 75 | ])) { |
76 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
76 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"'); |
|
77 | 77 | } else { |
78 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
79 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
78 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename) |
|
79 | + . '; filename="'.rawurlencode($filename).'"'); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 |
@@ -38,67 +38,67 @@ |
||
38 | 38 | use Sabre\HTTP\ResponseInterface; |
39 | 39 | |
40 | 40 | class Plugin extends ServerPlugin { |
41 | - private Server $server; |
|
42 | - private IRequest $request; |
|
43 | - |
|
44 | - public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label'; |
|
45 | - |
|
46 | - public function __construct( |
|
47 | - IRequest $request |
|
48 | - ) { |
|
49 | - $this->request = $request; |
|
50 | - } |
|
51 | - |
|
52 | - public function initialize(Server $server) { |
|
53 | - $this->server = $server; |
|
54 | - |
|
55 | - $server->on('afterMethod:GET', [$this, 'afterGet']); |
|
56 | - $server->on('propFind', [$this, 'propFind']); |
|
57 | - $server->on('propPatch', [$this, 'propPatch']); |
|
58 | - } |
|
59 | - |
|
60 | - public function afterGet(RequestInterface $request, ResponseInterface $response) { |
|
61 | - $path = $request->getPath(); |
|
62 | - if (!str_starts_with($path, 'versions')) { |
|
63 | - return; |
|
64 | - } |
|
65 | - |
|
66 | - try { |
|
67 | - $node = $this->server->tree->getNodeForPath($path); |
|
68 | - } catch (NotFound $e) { |
|
69 | - return; |
|
70 | - } |
|
71 | - |
|
72 | - if (!($node instanceof VersionFile)) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - $filename = $node->getVersion()->getSourceFileName(); |
|
77 | - |
|
78 | - if ($this->request->isUserAgent( |
|
79 | - [ |
|
80 | - Request::USER_AGENT_IE, |
|
81 | - Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
82 | - Request::USER_AGENT_FREEBOX, |
|
83 | - ])) { |
|
84 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
85 | - } else { |
|
86 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
87 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - public function propFind(PropFind $propFind, INode $node): void { |
|
92 | - if ($node instanceof VersionFile) { |
|
93 | - $propFind->handle(self::VERSION_LABEL, fn() => $node->getLabel()); |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - public function propPatch($path, PropPatch $propPatch): void { |
|
98 | - $node = $this->server->tree->getNodeForPath($path); |
|
99 | - |
|
100 | - if ($node instanceof VersionFile) { |
|
101 | - $propPatch->handle(self::VERSION_LABEL, fn ($label) => $node->setLabel($label)); |
|
102 | - } |
|
103 | - } |
|
41 | + private Server $server; |
|
42 | + private IRequest $request; |
|
43 | + |
|
44 | + public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label'; |
|
45 | + |
|
46 | + public function __construct( |
|
47 | + IRequest $request |
|
48 | + ) { |
|
49 | + $this->request = $request; |
|
50 | + } |
|
51 | + |
|
52 | + public function initialize(Server $server) { |
|
53 | + $this->server = $server; |
|
54 | + |
|
55 | + $server->on('afterMethod:GET', [$this, 'afterGet']); |
|
56 | + $server->on('propFind', [$this, 'propFind']); |
|
57 | + $server->on('propPatch', [$this, 'propPatch']); |
|
58 | + } |
|
59 | + |
|
60 | + public function afterGet(RequestInterface $request, ResponseInterface $response) { |
|
61 | + $path = $request->getPath(); |
|
62 | + if (!str_starts_with($path, 'versions')) { |
|
63 | + return; |
|
64 | + } |
|
65 | + |
|
66 | + try { |
|
67 | + $node = $this->server->tree->getNodeForPath($path); |
|
68 | + } catch (NotFound $e) { |
|
69 | + return; |
|
70 | + } |
|
71 | + |
|
72 | + if (!($node instanceof VersionFile)) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + $filename = $node->getVersion()->getSourceFileName(); |
|
77 | + |
|
78 | + if ($this->request->isUserAgent( |
|
79 | + [ |
|
80 | + Request::USER_AGENT_IE, |
|
81 | + Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
82 | + Request::USER_AGENT_FREEBOX, |
|
83 | + ])) { |
|
84 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
85 | + } else { |
|
86 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
87 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + public function propFind(PropFind $propFind, INode $node): void { |
|
92 | + if ($node instanceof VersionFile) { |
|
93 | + $propFind->handle(self::VERSION_LABEL, fn() => $node->getLabel()); |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + public function propPatch($path, PropPatch $propPatch): void { |
|
98 | + $node = $this->server->tree->getNodeForPath($path); |
|
99 | + |
|
100 | + if ($node instanceof VersionFile) { |
|
101 | + $propPatch->handle(self::VERSION_LABEL, fn ($label) => $node->setLabel($label)); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | } |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | $codes = $this->mapper->getBackupCodes($user); |
106 | 106 | $total = count($codes); |
107 | 107 | $used = 0; |
108 | - array_walk($codes, function (BackupCode $code) use (&$used) { |
|
109 | - if (1 === (int)$code->getUsed()) { |
|
108 | + array_walk($codes, function(BackupCode $code) use (&$used) { |
|
109 | + if (1 === (int) $code->getUsed()) { |
|
110 | 110 | $used++; |
111 | 111 | } |
112 | 112 | }); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $dbCodes = $this->mapper->getBackupCodes($user); |
127 | 127 | |
128 | 128 | foreach ($dbCodes as $dbCode) { |
129 | - if (0 === (int)$dbCode->getUsed() && $this->hasher->verify($code, $dbCode->getCode())) { |
|
129 | + if (0 === (int) $dbCode->getUsed() && $this->hasher->verify($code, $dbCode->getCode())) { |
|
130 | 130 | $dbCode->setUsed(1); |
131 | 131 | $this->mapper->update($dbCode); |
132 | 132 | return true; |
@@ -37,107 +37,107 @@ |
||
37 | 37 | use OCP\Security\ISecureRandom; |
38 | 38 | |
39 | 39 | class BackupCodeStorage { |
40 | - private static $CODE_LENGTH = 16; |
|
41 | - |
|
42 | - /** @var BackupCodeMapper */ |
|
43 | - private $mapper; |
|
44 | - |
|
45 | - /** @var IHasher */ |
|
46 | - private $hasher; |
|
47 | - |
|
48 | - /** @var ISecureRandom */ |
|
49 | - private $random; |
|
50 | - |
|
51 | - /** @var IEventDispatcher */ |
|
52 | - private $eventDispatcher; |
|
53 | - |
|
54 | - public function __construct(BackupCodeMapper $mapper, |
|
55 | - ISecureRandom $random, |
|
56 | - IHasher $hasher, |
|
57 | - IEventDispatcher $eventDispatcher) { |
|
58 | - $this->mapper = $mapper; |
|
59 | - $this->hasher = $hasher; |
|
60 | - $this->random = $random; |
|
61 | - $this->eventDispatcher = $eventDispatcher; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IUser $user |
|
66 | - * @param int $number |
|
67 | - * @return string[] |
|
68 | - */ |
|
69 | - public function createCodes(IUser $user, int $number = 10): array { |
|
70 | - $result = []; |
|
71 | - |
|
72 | - // Delete existing ones |
|
73 | - $this->mapper->deleteCodes($user); |
|
74 | - |
|
75 | - $uid = $user->getUID(); |
|
76 | - foreach (range(1, min([$number, 20])) as $i) { |
|
77 | - $code = $this->random->generate(self::$CODE_LENGTH, ISecureRandom::CHAR_HUMAN_READABLE); |
|
78 | - |
|
79 | - $dbCode = new BackupCode(); |
|
80 | - $dbCode->setUserId($uid); |
|
81 | - $dbCode->setCode($this->hasher->hash($code)); |
|
82 | - $dbCode->setUsed(0); |
|
83 | - $this->mapper->insert($dbCode); |
|
84 | - |
|
85 | - $result[] = $code; |
|
86 | - } |
|
87 | - |
|
88 | - $this->eventDispatcher->dispatchTyped(new CodesGenerated($user)); |
|
89 | - |
|
90 | - return $result; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param IUser $user |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function hasBackupCodes(IUser $user): bool { |
|
98 | - $codes = $this->mapper->getBackupCodes($user); |
|
99 | - return count($codes) > 0; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param IUser $user |
|
104 | - * @return array |
|
105 | - */ |
|
106 | - public function getBackupCodesState(IUser $user): array { |
|
107 | - $codes = $this->mapper->getBackupCodes($user); |
|
108 | - $total = count($codes); |
|
109 | - $used = 0; |
|
110 | - array_walk($codes, function (BackupCode $code) use (&$used) { |
|
111 | - if (1 === (int)$code->getUsed()) { |
|
112 | - $used++; |
|
113 | - } |
|
114 | - }); |
|
115 | - return [ |
|
116 | - 'enabled' => $total > 0, |
|
117 | - 'total' => $total, |
|
118 | - 'used' => $used, |
|
119 | - ]; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @param IUser $user |
|
124 | - * @param string $code |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - public function validateCode(IUser $user, string $code): bool { |
|
128 | - $dbCodes = $this->mapper->getBackupCodes($user); |
|
129 | - |
|
130 | - foreach ($dbCodes as $dbCode) { |
|
131 | - if (0 === (int)$dbCode->getUsed() && $this->hasher->verify($code, $dbCode->getCode())) { |
|
132 | - $dbCode->setUsed(1); |
|
133 | - $this->mapper->update($dbCode); |
|
134 | - return true; |
|
135 | - } |
|
136 | - } |
|
137 | - return false; |
|
138 | - } |
|
139 | - |
|
140 | - public function deleteCodes(IUser $user): void { |
|
141 | - $this->mapper->deleteCodes($user); |
|
142 | - } |
|
40 | + private static $CODE_LENGTH = 16; |
|
41 | + |
|
42 | + /** @var BackupCodeMapper */ |
|
43 | + private $mapper; |
|
44 | + |
|
45 | + /** @var IHasher */ |
|
46 | + private $hasher; |
|
47 | + |
|
48 | + /** @var ISecureRandom */ |
|
49 | + private $random; |
|
50 | + |
|
51 | + /** @var IEventDispatcher */ |
|
52 | + private $eventDispatcher; |
|
53 | + |
|
54 | + public function __construct(BackupCodeMapper $mapper, |
|
55 | + ISecureRandom $random, |
|
56 | + IHasher $hasher, |
|
57 | + IEventDispatcher $eventDispatcher) { |
|
58 | + $this->mapper = $mapper; |
|
59 | + $this->hasher = $hasher; |
|
60 | + $this->random = $random; |
|
61 | + $this->eventDispatcher = $eventDispatcher; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IUser $user |
|
66 | + * @param int $number |
|
67 | + * @return string[] |
|
68 | + */ |
|
69 | + public function createCodes(IUser $user, int $number = 10): array { |
|
70 | + $result = []; |
|
71 | + |
|
72 | + // Delete existing ones |
|
73 | + $this->mapper->deleteCodes($user); |
|
74 | + |
|
75 | + $uid = $user->getUID(); |
|
76 | + foreach (range(1, min([$number, 20])) as $i) { |
|
77 | + $code = $this->random->generate(self::$CODE_LENGTH, ISecureRandom::CHAR_HUMAN_READABLE); |
|
78 | + |
|
79 | + $dbCode = new BackupCode(); |
|
80 | + $dbCode->setUserId($uid); |
|
81 | + $dbCode->setCode($this->hasher->hash($code)); |
|
82 | + $dbCode->setUsed(0); |
|
83 | + $this->mapper->insert($dbCode); |
|
84 | + |
|
85 | + $result[] = $code; |
|
86 | + } |
|
87 | + |
|
88 | + $this->eventDispatcher->dispatchTyped(new CodesGenerated($user)); |
|
89 | + |
|
90 | + return $result; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param IUser $user |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function hasBackupCodes(IUser $user): bool { |
|
98 | + $codes = $this->mapper->getBackupCodes($user); |
|
99 | + return count($codes) > 0; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param IUser $user |
|
104 | + * @return array |
|
105 | + */ |
|
106 | + public function getBackupCodesState(IUser $user): array { |
|
107 | + $codes = $this->mapper->getBackupCodes($user); |
|
108 | + $total = count($codes); |
|
109 | + $used = 0; |
|
110 | + array_walk($codes, function (BackupCode $code) use (&$used) { |
|
111 | + if (1 === (int)$code->getUsed()) { |
|
112 | + $used++; |
|
113 | + } |
|
114 | + }); |
|
115 | + return [ |
|
116 | + 'enabled' => $total > 0, |
|
117 | + 'total' => $total, |
|
118 | + 'used' => $used, |
|
119 | + ]; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @param IUser $user |
|
124 | + * @param string $code |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + public function validateCode(IUser $user, string $code): bool { |
|
128 | + $dbCodes = $this->mapper->getBackupCodes($user); |
|
129 | + |
|
130 | + foreach ($dbCodes as $dbCode) { |
|
131 | + if (0 === (int)$dbCode->getUsed() && $this->hasher->verify($code, $dbCode->getCode())) { |
|
132 | + $dbCode->setUsed(1); |
|
133 | + $this->mapper->update($dbCode); |
|
134 | + return true; |
|
135 | + } |
|
136 | + } |
|
137 | + return false; |
|
138 | + } |
|
139 | + |
|
140 | + public function deleteCodes(IUser $user): void { |
|
141 | + $this->mapper->deleteCodes($user); |
|
142 | + } |
|
143 | 143 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | //Current time |
66 | 66 | $minTime = $this->time->getDateTime(); |
67 | 67 | $minTime->add(new \DateInterval('P1D')); |
68 | - $minTime->setTime(0,0,0); |
|
68 | + $minTime->setTime(0, 0, 0); |
|
69 | 69 | |
70 | 70 | $maxTime = clone $minTime; |
71 | 71 | $maxTime->setTime(23, 59, 59); |
@@ -36,64 +36,64 @@ |
||
36 | 36 | use Symfony\Component\Console\Output\OutputInterface; |
37 | 37 | |
38 | 38 | class ExiprationNotification extends Command { |
39 | - /** @var NotificationManager */ |
|
40 | - private $notificationManager; |
|
41 | - /** @var IDBConnection */ |
|
42 | - private $connection; |
|
43 | - /** @var ITimeFactory */ |
|
44 | - private $time; |
|
45 | - /** @var ShareManager */ |
|
46 | - private $shareManager; |
|
39 | + /** @var NotificationManager */ |
|
40 | + private $notificationManager; |
|
41 | + /** @var IDBConnection */ |
|
42 | + private $connection; |
|
43 | + /** @var ITimeFactory */ |
|
44 | + private $time; |
|
45 | + /** @var ShareManager */ |
|
46 | + private $shareManager; |
|
47 | 47 | |
48 | - public function __construct(ITimeFactory $time, |
|
49 | - NotificationManager $notificationManager, |
|
50 | - IDBConnection $connection, |
|
51 | - ShareManager $shareManager) { |
|
52 | - parent::__construct(); |
|
48 | + public function __construct(ITimeFactory $time, |
|
49 | + NotificationManager $notificationManager, |
|
50 | + IDBConnection $connection, |
|
51 | + ShareManager $shareManager) { |
|
52 | + parent::__construct(); |
|
53 | 53 | |
54 | - $this->notificationManager = $notificationManager; |
|
55 | - $this->connection = $connection; |
|
56 | - $this->time = $time; |
|
57 | - $this->shareManager = $shareManager; |
|
58 | - } |
|
54 | + $this->notificationManager = $notificationManager; |
|
55 | + $this->connection = $connection; |
|
56 | + $this->time = $time; |
|
57 | + $this->shareManager = $shareManager; |
|
58 | + } |
|
59 | 59 | |
60 | - protected function configure() { |
|
61 | - $this |
|
62 | - ->setName('sharing:expiration-notification') |
|
63 | - ->setDescription('Notify share initiators when a share will expire the next day.'); |
|
64 | - } |
|
60 | + protected function configure() { |
|
61 | + $this |
|
62 | + ->setName('sharing:expiration-notification') |
|
63 | + ->setDescription('Notify share initiators when a share will expire the next day.'); |
|
64 | + } |
|
65 | 65 | |
66 | - public function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | - //Current time |
|
68 | - $minTime = $this->time->getDateTime(); |
|
69 | - $minTime->add(new \DateInterval('P1D')); |
|
70 | - $minTime->setTime(0,0,0); |
|
66 | + public function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | + //Current time |
|
68 | + $minTime = $this->time->getDateTime(); |
|
69 | + $minTime->add(new \DateInterval('P1D')); |
|
70 | + $minTime->setTime(0,0,0); |
|
71 | 71 | |
72 | - $maxTime = clone $minTime; |
|
73 | - $maxTime->setTime(23, 59, 59); |
|
72 | + $maxTime = clone $minTime; |
|
73 | + $maxTime->setTime(23, 59, 59); |
|
74 | 74 | |
75 | - $shares = $this->shareManager->getAllShares(); |
|
75 | + $shares = $this->shareManager->getAllShares(); |
|
76 | 76 | |
77 | - $now = $this->time->getDateTime(); |
|
77 | + $now = $this->time->getDateTime(); |
|
78 | 78 | |
79 | - /** @var IShare $share */ |
|
80 | - foreach ($shares as $share) { |
|
81 | - if ($share->getExpirationDate() === null |
|
82 | - || $share->getExpirationDate()->getTimestamp() < $minTime->getTimestamp() |
|
83 | - || $share->getExpirationDate()->getTimestamp() > $maxTime->getTimestamp()) { |
|
84 | - continue; |
|
85 | - } |
|
79 | + /** @var IShare $share */ |
|
80 | + foreach ($shares as $share) { |
|
81 | + if ($share->getExpirationDate() === null |
|
82 | + || $share->getExpirationDate()->getTimestamp() < $minTime->getTimestamp() |
|
83 | + || $share->getExpirationDate()->getTimestamp() > $maxTime->getTimestamp()) { |
|
84 | + continue; |
|
85 | + } |
|
86 | 86 | |
87 | - $notification = $this->notificationManager->createNotification(); |
|
88 | - $notification->setApp('files_sharing') |
|
89 | - ->setDateTime($now) |
|
90 | - ->setObject('share', $share->getFullId()) |
|
91 | - ->setSubject('expiresTomorrow'); |
|
87 | + $notification = $this->notificationManager->createNotification(); |
|
88 | + $notification->setApp('files_sharing') |
|
89 | + ->setDateTime($now) |
|
90 | + ->setObject('share', $share->getFullId()) |
|
91 | + ->setSubject('expiresTomorrow'); |
|
92 | 92 | |
93 | - // Only send to initiator for now |
|
94 | - $notification->setUser($share->getSharedBy()); |
|
95 | - $this->notificationManager->notify($notification); |
|
96 | - } |
|
97 | - return 0; |
|
98 | - } |
|
93 | + // Only send to initiator for now |
|
94 | + $notification->setUser($share->getSharedBy()); |
|
95 | + $this->notificationManager->notify($notification); |
|
96 | + } |
|
97 | + return 0; |
|
98 | + } |
|
99 | 99 | } |
@@ -36,15 +36,15 @@ |
||
36 | 36 | * @deprecated |
37 | 37 | */ |
38 | 38 | interface IOperationCompat { |
39 | - /** |
|
40 | - * Like onEvent, but used with events that are not based on |
|
41 | - * \OCP\EventDispatcher\Event. |
|
42 | - * |
|
43 | - * This method is introduced for compatibility reasons and will be removed |
|
44 | - * in 2023 again. |
|
45 | - * |
|
46 | - * @since 18.0.0 |
|
47 | - * @deprecated |
|
48 | - */ |
|
49 | - public function onEventCompat(string $eventName, $event, IRuleMatcher $ruleMatcher): void; |
|
39 | + /** |
|
40 | + * Like onEvent, but used with events that are not based on |
|
41 | + * \OCP\EventDispatcher\Event. |
|
42 | + * |
|
43 | + * This method is introduced for compatibility reasons and will be removed |
|
44 | + * in 2023 again. |
|
45 | + * |
|
46 | + * @since 18.0.0 |
|
47 | + * @deprecated |
|
48 | + */ |
|
49 | + public function onEventCompat(string $eventName, $event, IRuleMatcher $ruleMatcher): void; |
|
50 | 50 | } |
@@ -36,12 +36,12 @@ |
||
36 | 36 | * @deprecated |
37 | 37 | */ |
38 | 38 | interface IEntityCompat extends IEntity { |
39 | - /** |
|
40 | - * Like prepareRuleMatcherCompat, but works with events that are not based |
|
41 | - * on \OCP\EventDispatcher\Event. |
|
42 | - * |
|
43 | - * @since 18.0.0 |
|
44 | - * @deprecated |
|
45 | - */ |
|
46 | - public function prepareRuleMatcherCompat(IRuleMatcher $ruleMatcher, string $eventName, $event): void; |
|
39 | + /** |
|
40 | + * Like prepareRuleMatcherCompat, but works with events that are not based |
|
41 | + * on \OCP\EventDispatcher\Event. |
|
42 | + * |
|
43 | + * @since 18.0.0 |
|
44 | + * @deprecated |
|
45 | + */ |
|
46 | + public function prepareRuleMatcherCompat(IRuleMatcher $ruleMatcher, string $eventName, $event): void; |
|
47 | 47 | } |