@@ -32,41 +32,41 @@ |
||
32 | 32 | * @since 20.0.0 |
33 | 33 | */ |
34 | 34 | class GetQuotaEvent extends Event { |
35 | - /** @var IUser */ |
|
36 | - private $user; |
|
37 | - /** @var string|null */ |
|
38 | - private $quota = null; |
|
35 | + /** @var IUser */ |
|
36 | + private $user; |
|
37 | + /** @var string|null */ |
|
38 | + private $quota = null; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @since 20.0.0 |
|
42 | - */ |
|
43 | - public function __construct(IUser $user) { |
|
44 | - parent::__construct(); |
|
45 | - $this->user = $user; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @since 20.0.0 |
|
42 | + */ |
|
43 | + public function __construct(IUser $user) { |
|
44 | + parent::__construct(); |
|
45 | + $this->user = $user; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @since 20.0.0 |
|
50 | - */ |
|
51 | - public function getUser(): IUser { |
|
52 | - return $this->user; |
|
53 | - } |
|
48 | + /** |
|
49 | + * @since 20.0.0 |
|
50 | + */ |
|
51 | + public function getUser(): IUser { |
|
52 | + return $this->user; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get the set quota as human readable string, or null if no overwrite is set |
|
57 | - * |
|
58 | - * @since 20.0.0 |
|
59 | - */ |
|
60 | - public function getQuota(): ?string { |
|
61 | - return $this->quota; |
|
62 | - } |
|
55 | + /** |
|
56 | + * Get the set quota as human readable string, or null if no overwrite is set |
|
57 | + * |
|
58 | + * @since 20.0.0 |
|
59 | + */ |
|
60 | + public function getQuota(): ?string { |
|
61 | + return $this->quota; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Set the quota overwrite as human readable string |
|
66 | - * |
|
67 | - * @since 20.0.0 |
|
68 | - */ |
|
69 | - public function setQuota(string $quota): void { |
|
70 | - $this->quota = $quota; |
|
71 | - } |
|
64 | + /** |
|
65 | + * Set the quota overwrite as human readable string |
|
66 | + * |
|
67 | + * @since 20.0.0 |
|
68 | + */ |
|
69 | + public function setQuota(string $quota): void { |
|
70 | + $this->quota = $quota; |
|
71 | + } |
|
72 | 72 | } |
@@ -40,40 +40,40 @@ |
||
40 | 40 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
41 | 41 | |
42 | 42 | class AdditionalScriptsMiddleware extends Middleware { |
43 | - /** @var EventDispatcherInterface */ |
|
44 | - private $legacyDispatcher; |
|
45 | - /** @var IUserSession */ |
|
46 | - private $userSession; |
|
47 | - /** @var IEventDispatcher */ |
|
48 | - private $dispatcher; |
|
43 | + /** @var EventDispatcherInterface */ |
|
44 | + private $legacyDispatcher; |
|
45 | + /** @var IUserSession */ |
|
46 | + private $userSession; |
|
47 | + /** @var IEventDispatcher */ |
|
48 | + private $dispatcher; |
|
49 | 49 | |
50 | - public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) { |
|
51 | - $this->legacyDispatcher = $legacyDispatcher; |
|
52 | - $this->userSession = $userSession; |
|
53 | - $this->dispatcher = $dispatcher; |
|
54 | - } |
|
50 | + public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) { |
|
51 | + $this->legacyDispatcher = $legacyDispatcher; |
|
52 | + $this->userSession = $userSession; |
|
53 | + $this->dispatcher = $dispatcher; |
|
54 | + } |
|
55 | 55 | |
56 | - public function afterController($controller, $methodName, Response $response): Response { |
|
57 | - if ($response instanceof TemplateResponse) { |
|
58 | - if (!$controller instanceof PublicShareController) { |
|
59 | - /* |
|
56 | + public function afterController($controller, $methodName, Response $response): Response { |
|
57 | + if ($response instanceof TemplateResponse) { |
|
58 | + if (!$controller instanceof PublicShareController) { |
|
59 | + /* |
|
60 | 60 | * The old event was not dispatched on the public share controller as there was |
61 | 61 | * OCA\Files_Sharing::loadAdditionalScripts for that. This is kept for compatibility reasons |
62 | 62 | * only for the old event as this is now also included in BeforeTemplateRenderedEvent |
63 | 63 | */ |
64 | - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); |
|
65 | - } |
|
64 | + $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); |
|
65 | + } |
|
66 | 66 | |
67 | - if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) { |
|
68 | - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent()); |
|
69 | - $isLoggedIn = true; |
|
70 | - } else { |
|
71 | - $isLoggedIn = false; |
|
72 | - } |
|
67 | + if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) { |
|
68 | + $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent()); |
|
69 | + $isLoggedIn = true; |
|
70 | + } else { |
|
71 | + $isLoggedIn = false; |
|
72 | + } |
|
73 | 73 | |
74 | - $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response)); |
|
75 | - } |
|
74 | + $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response)); |
|
75 | + } |
|
76 | 76 | |
77 | - return $response; |
|
78 | - } |
|
77 | + return $response; |
|
78 | + } |
|
79 | 79 | } |
@@ -37,32 +37,32 @@ |
||
37 | 37 | * @since 20.0.0 |
38 | 38 | */ |
39 | 39 | class BeforeTemplateRenderedEvent extends Event { |
40 | - /** @var bool */ |
|
41 | - private $loggedIn; |
|
42 | - /** @var TemplateResponse */ |
|
43 | - private $response; |
|
40 | + /** @var bool */ |
|
41 | + private $loggedIn; |
|
42 | + /** @var TemplateResponse */ |
|
43 | + private $response; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @since 20.0.0 |
|
47 | - */ |
|
48 | - public function __construct(bool $loggedIn, TemplateResponse $response) { |
|
49 | - parent::__construct(); |
|
45 | + /** |
|
46 | + * @since 20.0.0 |
|
47 | + */ |
|
48 | + public function __construct(bool $loggedIn, TemplateResponse $response) { |
|
49 | + parent::__construct(); |
|
50 | 50 | |
51 | - $this->loggedIn = $loggedIn; |
|
52 | - $this->response = $response; |
|
53 | - } |
|
51 | + $this->loggedIn = $loggedIn; |
|
52 | + $this->response = $response; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @since 20.0.0 |
|
57 | - */ |
|
58 | - public function isLoggedIn(): bool { |
|
59 | - return $this->loggedIn; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @since 20.0.0 |
|
57 | + */ |
|
58 | + public function isLoggedIn(): bool { |
|
59 | + return $this->loggedIn; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @since 20.0.0 |
|
64 | - */ |
|
65 | - public function getResponse(): TemplateResponse { |
|
66 | - return $this->response; |
|
67 | - } |
|
62 | + /** |
|
63 | + * @since 20.0.0 |
|
64 | + */ |
|
65 | + public function getResponse(): TemplateResponse { |
|
66 | + return $this->response; |
|
67 | + } |
|
68 | 68 | } |
@@ -36,95 +36,95 @@ |
||
36 | 36 | use OCP\Files\Cache\ICacheEntry; |
37 | 37 | |
38 | 38 | class Helper { |
39 | - /** |
|
40 | - * Retrieves the contents of a trash bin directory. |
|
41 | - * |
|
42 | - * @param string $dir path to the directory inside the trashbin |
|
43 | - * or empty to retrieve the root of the trashbin |
|
44 | - * @param string $user |
|
45 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
46 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
47 | - * @return \OCP\Files\FileInfo[] |
|
48 | - */ |
|
49 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
50 | - $result = []; |
|
51 | - $timestamp = null; |
|
39 | + /** |
|
40 | + * Retrieves the contents of a trash bin directory. |
|
41 | + * |
|
42 | + * @param string $dir path to the directory inside the trashbin |
|
43 | + * or empty to retrieve the root of the trashbin |
|
44 | + * @param string $user |
|
45 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
46 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
47 | + * @return \OCP\Files\FileInfo[] |
|
48 | + */ |
|
49 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
50 | + $result = []; |
|
51 | + $timestamp = null; |
|
52 | 52 | |
53 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
53 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
54 | 54 | |
55 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
56 | - throw new \Exception('Directory does not exists'); |
|
57 | - } |
|
55 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
56 | + throw new \Exception('Directory does not exists'); |
|
57 | + } |
|
58 | 58 | |
59 | - $mount = $view->getMount($dir); |
|
60 | - $storage = $mount->getStorage(); |
|
61 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
62 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
59 | + $mount = $view->getMount($dir); |
|
60 | + $storage = $mount->getStorage(); |
|
61 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
62 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
63 | 63 | |
64 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
65 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
66 | - foreach ($dirContent as $entry) { |
|
67 | - $entryName = $entry->getName(); |
|
68 | - $name = $entryName; |
|
69 | - if ($dir === '' || $dir === '/') { |
|
70 | - $pathparts = pathinfo($entryName); |
|
71 | - $timestamp = substr($pathparts['extension'], 1); |
|
72 | - $name = $pathparts['filename']; |
|
73 | - } elseif ($timestamp === null) { |
|
74 | - // for subfolders we need to calculate the timestamp only once |
|
75 | - $parts = explode('/', ltrim($dir, '/')); |
|
76 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
77 | - } |
|
78 | - $originalPath = ''; |
|
79 | - $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
80 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
81 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
82 | - if (substr($originalPath, -1) === '/') { |
|
83 | - $originalPath = substr($originalPath, 0, -1); |
|
84 | - } |
|
85 | - } |
|
86 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
87 | - $i = [ |
|
88 | - 'name' => $name, |
|
89 | - 'mtime' => $timestamp, |
|
90 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
91 | - 'type' => $type, |
|
92 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
93 | - 'size' => $entry->getSize(), |
|
94 | - 'etag' => '', |
|
95 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
96 | - 'fileid' => $entry->getId(), |
|
97 | - ]; |
|
98 | - if ($originalPath) { |
|
99 | - if ($originalPath !== '.') { |
|
100 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
101 | - } else { |
|
102 | - $i['extraData'] = $originalName; |
|
103 | - } |
|
104 | - } |
|
105 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
106 | - } |
|
64 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
65 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
66 | + foreach ($dirContent as $entry) { |
|
67 | + $entryName = $entry->getName(); |
|
68 | + $name = $entryName; |
|
69 | + if ($dir === '' || $dir === '/') { |
|
70 | + $pathparts = pathinfo($entryName); |
|
71 | + $timestamp = substr($pathparts['extension'], 1); |
|
72 | + $name = $pathparts['filename']; |
|
73 | + } elseif ($timestamp === null) { |
|
74 | + // for subfolders we need to calculate the timestamp only once |
|
75 | + $parts = explode('/', ltrim($dir, '/')); |
|
76 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
77 | + } |
|
78 | + $originalPath = ''; |
|
79 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
80 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
81 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
82 | + if (substr($originalPath, -1) === '/') { |
|
83 | + $originalPath = substr($originalPath, 0, -1); |
|
84 | + } |
|
85 | + } |
|
86 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
87 | + $i = [ |
|
88 | + 'name' => $name, |
|
89 | + 'mtime' => $timestamp, |
|
90 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
91 | + 'type' => $type, |
|
92 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
93 | + 'size' => $entry->getSize(), |
|
94 | + 'etag' => '', |
|
95 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
96 | + 'fileid' => $entry->getId(), |
|
97 | + ]; |
|
98 | + if ($originalPath) { |
|
99 | + if ($originalPath !== '.') { |
|
100 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
101 | + } else { |
|
102 | + $i['extraData'] = $originalName; |
|
103 | + } |
|
104 | + } |
|
105 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
106 | + } |
|
107 | 107 | |
108 | - if ($sortAttribute !== '') { |
|
109 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
110 | - } |
|
111 | - return $result; |
|
112 | - } |
|
108 | + if ($sortAttribute !== '') { |
|
109 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
110 | + } |
|
111 | + return $result; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Format file infos for JSON |
|
116 | - * |
|
117 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
118 | - */ |
|
119 | - public static function formatFileInfos($fileInfos) { |
|
120 | - $files = []; |
|
121 | - foreach ($fileInfos as $i) { |
|
122 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
123 | - $entry['id'] = $i->getId(); |
|
124 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
125 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
126 | - $files[] = $entry; |
|
127 | - } |
|
128 | - return $files; |
|
129 | - } |
|
114 | + /** |
|
115 | + * Format file infos for JSON |
|
116 | + * |
|
117 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
118 | + */ |
|
119 | + public static function formatFileInfos($fileInfos) { |
|
120 | + $files = []; |
|
121 | + foreach ($fileInfos as $i) { |
|
122 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
123 | + $entry['id'] = $i->getId(); |
|
124 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
125 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
126 | + $files[] = $entry; |
|
127 | + } |
|
128 | + return $files; |
|
129 | + } |
|
130 | 130 | } |
@@ -32,143 +32,143 @@ |
||
32 | 32 | |
33 | 33 | class Expiration { |
34 | 34 | |
35 | - // how long do we keep files in the trash bin if no other value is defined in the config file (unit: days) |
|
36 | - public const DEFAULT_RETENTION_OBLIGATION = 30; |
|
37 | - public const NO_OBLIGATION = -1; |
|
38 | - |
|
39 | - /** @var ITimeFactory */ |
|
40 | - private $timeFactory; |
|
41 | - |
|
42 | - /** @var string */ |
|
43 | - private $retentionObligation; |
|
44 | - |
|
45 | - /** @var int */ |
|
46 | - private $minAge; |
|
47 | - |
|
48 | - /** @var int */ |
|
49 | - private $maxAge; |
|
50 | - |
|
51 | - /** @var bool */ |
|
52 | - private $canPurgeToSaveSpace; |
|
53 | - |
|
54 | - public function __construct(IConfig $config,ITimeFactory $timeFactory) { |
|
55 | - $this->timeFactory = $timeFactory; |
|
56 | - $this->setRetentionObligation($config->getSystemValue('trashbin_retention_obligation', 'auto')); |
|
57 | - } |
|
58 | - |
|
59 | - public function setRetentionObligation(string $obligation) { |
|
60 | - $this->retentionObligation = $obligation; |
|
61 | - |
|
62 | - if ($this->retentionObligation !== 'disabled') { |
|
63 | - $this->parseRetentionObligation(); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Is trashbin expiration enabled |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - public function isEnabled() { |
|
72 | - return $this->retentionObligation !== 'disabled'; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Check if given timestamp in expiration range |
|
77 | - * @param int $timestamp |
|
78 | - * @param bool $quotaExceeded |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - public function isExpired($timestamp, $quotaExceeded = false) { |
|
82 | - // No expiration if disabled |
|
83 | - if (!$this->isEnabled()) { |
|
84 | - return false; |
|
85 | - } |
|
86 | - |
|
87 | - // Purge to save space (if allowed) |
|
88 | - if ($quotaExceeded && $this->canPurgeToSaveSpace) { |
|
89 | - return true; |
|
90 | - } |
|
91 | - |
|
92 | - $time = $this->timeFactory->getTime(); |
|
93 | - // Never expire dates in future e.g. misconfiguration or negative time |
|
94 | - // adjustment |
|
95 | - if ($time < $timestamp) { |
|
96 | - return false; |
|
97 | - } |
|
98 | - |
|
99 | - // Purge as too old |
|
100 | - if ($this->maxAge !== self::NO_OBLIGATION) { |
|
101 | - $maxTimestamp = $time - ($this->maxAge * 86400); |
|
102 | - $isOlderThanMax = $timestamp < $maxTimestamp; |
|
103 | - } else { |
|
104 | - $isOlderThanMax = false; |
|
105 | - } |
|
106 | - |
|
107 | - if ($this->minAge !== self::NO_OBLIGATION) { |
|
108 | - // older than Min obligation and we are running out of quota? |
|
109 | - $minTimestamp = $time - ($this->minAge * 86400); |
|
110 | - $isMinReached = ($timestamp < $minTimestamp) && $quotaExceeded; |
|
111 | - } else { |
|
112 | - $isMinReached = false; |
|
113 | - } |
|
114 | - |
|
115 | - return $isOlderThanMax || $isMinReached; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return bool|int |
|
120 | - */ |
|
121 | - public function getMaxAgeAsTimestamp() { |
|
122 | - $maxAge = false; |
|
123 | - if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) { |
|
124 | - $time = $this->timeFactory->getTime(); |
|
125 | - $maxAge = $time - ($this->maxAge * 86400); |
|
126 | - } |
|
127 | - return $maxAge; |
|
128 | - } |
|
129 | - |
|
130 | - private function parseRetentionObligation() { |
|
131 | - $splitValues = explode(',', $this->retentionObligation); |
|
132 | - if (!isset($splitValues[0])) { |
|
133 | - $minValue = self::DEFAULT_RETENTION_OBLIGATION; |
|
134 | - } else { |
|
135 | - $minValue = trim($splitValues[0]); |
|
136 | - } |
|
137 | - |
|
138 | - if (!isset($splitValues[1]) && $minValue === 'auto') { |
|
139 | - $maxValue = 'auto'; |
|
140 | - } elseif (!isset($splitValues[1])) { |
|
141 | - $maxValue = self::DEFAULT_RETENTION_OBLIGATION; |
|
142 | - } else { |
|
143 | - $maxValue = trim($splitValues[1]); |
|
144 | - } |
|
145 | - |
|
146 | - if ($minValue === 'auto' && $maxValue === 'auto') { |
|
147 | - // Default: Keep for 30 days but delete anytime if space needed |
|
148 | - $this->minAge = self::DEFAULT_RETENTION_OBLIGATION; |
|
149 | - $this->maxAge = self::NO_OBLIGATION; |
|
150 | - $this->canPurgeToSaveSpace = true; |
|
151 | - } elseif ($minValue !== 'auto' && $maxValue === 'auto') { |
|
152 | - // Keep for X days but delete anytime if space needed |
|
153 | - $this->minAge = (int)$minValue; |
|
154 | - $this->maxAge = self::NO_OBLIGATION; |
|
155 | - $this->canPurgeToSaveSpace = true; |
|
156 | - } elseif ($minValue === 'auto' && $maxValue !== 'auto') { |
|
157 | - // Delete anytime if space needed, Delete all older than max automatically |
|
158 | - $this->minAge = self::NO_OBLIGATION; |
|
159 | - $this->maxAge = (int)$maxValue; |
|
160 | - $this->canPurgeToSaveSpace = true; |
|
161 | - } elseif ($minValue !== 'auto' && $maxValue !== 'auto') { |
|
162 | - // Delete all older than max OR older than min if space needed |
|
163 | - |
|
164 | - // Max < Min as per https://github.com/owncloud/core/issues/16300 |
|
165 | - if ($maxValue < $minValue) { |
|
166 | - $maxValue = $minValue; |
|
167 | - } |
|
168 | - |
|
169 | - $this->minAge = (int)$minValue; |
|
170 | - $this->maxAge = (int)$maxValue; |
|
171 | - $this->canPurgeToSaveSpace = false; |
|
172 | - } |
|
173 | - } |
|
35 | + // how long do we keep files in the trash bin if no other value is defined in the config file (unit: days) |
|
36 | + public const DEFAULT_RETENTION_OBLIGATION = 30; |
|
37 | + public const NO_OBLIGATION = -1; |
|
38 | + |
|
39 | + /** @var ITimeFactory */ |
|
40 | + private $timeFactory; |
|
41 | + |
|
42 | + /** @var string */ |
|
43 | + private $retentionObligation; |
|
44 | + |
|
45 | + /** @var int */ |
|
46 | + private $minAge; |
|
47 | + |
|
48 | + /** @var int */ |
|
49 | + private $maxAge; |
|
50 | + |
|
51 | + /** @var bool */ |
|
52 | + private $canPurgeToSaveSpace; |
|
53 | + |
|
54 | + public function __construct(IConfig $config,ITimeFactory $timeFactory) { |
|
55 | + $this->timeFactory = $timeFactory; |
|
56 | + $this->setRetentionObligation($config->getSystemValue('trashbin_retention_obligation', 'auto')); |
|
57 | + } |
|
58 | + |
|
59 | + public function setRetentionObligation(string $obligation) { |
|
60 | + $this->retentionObligation = $obligation; |
|
61 | + |
|
62 | + if ($this->retentionObligation !== 'disabled') { |
|
63 | + $this->parseRetentionObligation(); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Is trashbin expiration enabled |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + public function isEnabled() { |
|
72 | + return $this->retentionObligation !== 'disabled'; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Check if given timestamp in expiration range |
|
77 | + * @param int $timestamp |
|
78 | + * @param bool $quotaExceeded |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + public function isExpired($timestamp, $quotaExceeded = false) { |
|
82 | + // No expiration if disabled |
|
83 | + if (!$this->isEnabled()) { |
|
84 | + return false; |
|
85 | + } |
|
86 | + |
|
87 | + // Purge to save space (if allowed) |
|
88 | + if ($quotaExceeded && $this->canPurgeToSaveSpace) { |
|
89 | + return true; |
|
90 | + } |
|
91 | + |
|
92 | + $time = $this->timeFactory->getTime(); |
|
93 | + // Never expire dates in future e.g. misconfiguration or negative time |
|
94 | + // adjustment |
|
95 | + if ($time < $timestamp) { |
|
96 | + return false; |
|
97 | + } |
|
98 | + |
|
99 | + // Purge as too old |
|
100 | + if ($this->maxAge !== self::NO_OBLIGATION) { |
|
101 | + $maxTimestamp = $time - ($this->maxAge * 86400); |
|
102 | + $isOlderThanMax = $timestamp < $maxTimestamp; |
|
103 | + } else { |
|
104 | + $isOlderThanMax = false; |
|
105 | + } |
|
106 | + |
|
107 | + if ($this->minAge !== self::NO_OBLIGATION) { |
|
108 | + // older than Min obligation and we are running out of quota? |
|
109 | + $minTimestamp = $time - ($this->minAge * 86400); |
|
110 | + $isMinReached = ($timestamp < $minTimestamp) && $quotaExceeded; |
|
111 | + } else { |
|
112 | + $isMinReached = false; |
|
113 | + } |
|
114 | + |
|
115 | + return $isOlderThanMax || $isMinReached; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return bool|int |
|
120 | + */ |
|
121 | + public function getMaxAgeAsTimestamp() { |
|
122 | + $maxAge = false; |
|
123 | + if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) { |
|
124 | + $time = $this->timeFactory->getTime(); |
|
125 | + $maxAge = $time - ($this->maxAge * 86400); |
|
126 | + } |
|
127 | + return $maxAge; |
|
128 | + } |
|
129 | + |
|
130 | + private function parseRetentionObligation() { |
|
131 | + $splitValues = explode(',', $this->retentionObligation); |
|
132 | + if (!isset($splitValues[0])) { |
|
133 | + $minValue = self::DEFAULT_RETENTION_OBLIGATION; |
|
134 | + } else { |
|
135 | + $minValue = trim($splitValues[0]); |
|
136 | + } |
|
137 | + |
|
138 | + if (!isset($splitValues[1]) && $minValue === 'auto') { |
|
139 | + $maxValue = 'auto'; |
|
140 | + } elseif (!isset($splitValues[1])) { |
|
141 | + $maxValue = self::DEFAULT_RETENTION_OBLIGATION; |
|
142 | + } else { |
|
143 | + $maxValue = trim($splitValues[1]); |
|
144 | + } |
|
145 | + |
|
146 | + if ($minValue === 'auto' && $maxValue === 'auto') { |
|
147 | + // Default: Keep for 30 days but delete anytime if space needed |
|
148 | + $this->minAge = self::DEFAULT_RETENTION_OBLIGATION; |
|
149 | + $this->maxAge = self::NO_OBLIGATION; |
|
150 | + $this->canPurgeToSaveSpace = true; |
|
151 | + } elseif ($minValue !== 'auto' && $maxValue === 'auto') { |
|
152 | + // Keep for X days but delete anytime if space needed |
|
153 | + $this->minAge = (int)$minValue; |
|
154 | + $this->maxAge = self::NO_OBLIGATION; |
|
155 | + $this->canPurgeToSaveSpace = true; |
|
156 | + } elseif ($minValue === 'auto' && $maxValue !== 'auto') { |
|
157 | + // Delete anytime if space needed, Delete all older than max automatically |
|
158 | + $this->minAge = self::NO_OBLIGATION; |
|
159 | + $this->maxAge = (int)$maxValue; |
|
160 | + $this->canPurgeToSaveSpace = true; |
|
161 | + } elseif ($minValue !== 'auto' && $maxValue !== 'auto') { |
|
162 | + // Delete all older than max OR older than min if space needed |
|
163 | + |
|
164 | + // Max < Min as per https://github.com/owncloud/core/issues/16300 |
|
165 | + if ($maxValue < $minValue) { |
|
166 | + $maxValue = $minValue; |
|
167 | + } |
|
168 | + |
|
169 | + $this->minAge = (int)$minValue; |
|
170 | + $this->maxAge = (int)$maxValue; |
|
171 | + $this->canPurgeToSaveSpace = false; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | } |
@@ -44,224 +44,224 @@ |
||
44 | 44 | use OCP\SystemTag\TagNotFoundException; |
45 | 45 | |
46 | 46 | class Listener { |
47 | - /** @var IGroupManager */ |
|
48 | - protected $groupManager; |
|
49 | - /** @var IManager */ |
|
50 | - protected $activityManager; |
|
51 | - /** @var IUserSession */ |
|
52 | - protected $session; |
|
53 | - /** @var IConfig */ |
|
54 | - protected $config; |
|
55 | - /** @var \OCP\SystemTag\ISystemTagManager */ |
|
56 | - protected $tagManager; |
|
57 | - /** @var \OCP\App\IAppManager */ |
|
58 | - protected $appManager; |
|
59 | - /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
60 | - protected $mountCollection; |
|
61 | - /** @var \OCP\Files\IRootFolder */ |
|
62 | - protected $rootFolder; |
|
63 | - /** @var IShareHelper */ |
|
64 | - protected $shareHelper; |
|
47 | + /** @var IGroupManager */ |
|
48 | + protected $groupManager; |
|
49 | + /** @var IManager */ |
|
50 | + protected $activityManager; |
|
51 | + /** @var IUserSession */ |
|
52 | + protected $session; |
|
53 | + /** @var IConfig */ |
|
54 | + protected $config; |
|
55 | + /** @var \OCP\SystemTag\ISystemTagManager */ |
|
56 | + protected $tagManager; |
|
57 | + /** @var \OCP\App\IAppManager */ |
|
58 | + protected $appManager; |
|
59 | + /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
60 | + protected $mountCollection; |
|
61 | + /** @var \OCP\Files\IRootFolder */ |
|
62 | + protected $rootFolder; |
|
63 | + /** @var IShareHelper */ |
|
64 | + protected $shareHelper; |
|
65 | 65 | |
66 | - /** |
|
67 | - * Listener constructor. |
|
68 | - * |
|
69 | - * @param IGroupManager $groupManager |
|
70 | - * @param IManager $activityManager |
|
71 | - * @param IUserSession $session |
|
72 | - * @param IConfig $config |
|
73 | - * @param ISystemTagManager $tagManager |
|
74 | - * @param IAppManager $appManager |
|
75 | - * @param IMountProviderCollection $mountCollection |
|
76 | - * @param IRootFolder $rootFolder |
|
77 | - * @param IShareHelper $shareHelper |
|
78 | - */ |
|
79 | - public function __construct(IGroupManager $groupManager, |
|
80 | - IManager $activityManager, |
|
81 | - IUserSession $session, |
|
82 | - IConfig $config, |
|
83 | - ISystemTagManager $tagManager, |
|
84 | - IAppManager $appManager, |
|
85 | - IMountProviderCollection $mountCollection, |
|
86 | - IRootFolder $rootFolder, |
|
87 | - IShareHelper $shareHelper) { |
|
88 | - $this->groupManager = $groupManager; |
|
89 | - $this->activityManager = $activityManager; |
|
90 | - $this->session = $session; |
|
91 | - $this->config = $config; |
|
92 | - $this->tagManager = $tagManager; |
|
93 | - $this->appManager = $appManager; |
|
94 | - $this->mountCollection = $mountCollection; |
|
95 | - $this->rootFolder = $rootFolder; |
|
96 | - $this->shareHelper = $shareHelper; |
|
97 | - } |
|
66 | + /** |
|
67 | + * Listener constructor. |
|
68 | + * |
|
69 | + * @param IGroupManager $groupManager |
|
70 | + * @param IManager $activityManager |
|
71 | + * @param IUserSession $session |
|
72 | + * @param IConfig $config |
|
73 | + * @param ISystemTagManager $tagManager |
|
74 | + * @param IAppManager $appManager |
|
75 | + * @param IMountProviderCollection $mountCollection |
|
76 | + * @param IRootFolder $rootFolder |
|
77 | + * @param IShareHelper $shareHelper |
|
78 | + */ |
|
79 | + public function __construct(IGroupManager $groupManager, |
|
80 | + IManager $activityManager, |
|
81 | + IUserSession $session, |
|
82 | + IConfig $config, |
|
83 | + ISystemTagManager $tagManager, |
|
84 | + IAppManager $appManager, |
|
85 | + IMountProviderCollection $mountCollection, |
|
86 | + IRootFolder $rootFolder, |
|
87 | + IShareHelper $shareHelper) { |
|
88 | + $this->groupManager = $groupManager; |
|
89 | + $this->activityManager = $activityManager; |
|
90 | + $this->session = $session; |
|
91 | + $this->config = $config; |
|
92 | + $this->tagManager = $tagManager; |
|
93 | + $this->appManager = $appManager; |
|
94 | + $this->mountCollection = $mountCollection; |
|
95 | + $this->rootFolder = $rootFolder; |
|
96 | + $this->shareHelper = $shareHelper; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param ManagerEvent $event |
|
101 | - */ |
|
102 | - public function event(ManagerEvent $event) { |
|
103 | - $actor = $this->session->getUser(); |
|
104 | - if ($actor instanceof IUser) { |
|
105 | - $actor = $actor->getUID(); |
|
106 | - } else { |
|
107 | - $actor = ''; |
|
108 | - } |
|
109 | - $tag = $event->getTag(); |
|
99 | + /** |
|
100 | + * @param ManagerEvent $event |
|
101 | + */ |
|
102 | + public function event(ManagerEvent $event) { |
|
103 | + $actor = $this->session->getUser(); |
|
104 | + if ($actor instanceof IUser) { |
|
105 | + $actor = $actor->getUID(); |
|
106 | + } else { |
|
107 | + $actor = ''; |
|
108 | + } |
|
109 | + $tag = $event->getTag(); |
|
110 | 110 | |
111 | - $activity = $this->activityManager->generateEvent(); |
|
112 | - $activity->setApp('systemtags') |
|
113 | - ->setType('systemtags') |
|
114 | - ->setAuthor($actor) |
|
115 | - ->setObject('systemtag', (int)$tag->getId(), $tag->getName()); |
|
116 | - if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
|
117 | - $activity->setSubject(Provider::CREATE_TAG, [ |
|
118 | - $actor, |
|
119 | - $this->prepareTagAsParameter($event->getTag()), |
|
120 | - ]); |
|
121 | - } elseif ($event->getEvent() === ManagerEvent::EVENT_UPDATE) { |
|
122 | - $activity->setSubject(Provider::UPDATE_TAG, [ |
|
123 | - $actor, |
|
124 | - $this->prepareTagAsParameter($event->getTag()), |
|
125 | - $this->prepareTagAsParameter($event->getTagBefore()), |
|
126 | - ]); |
|
127 | - } elseif ($event->getEvent() === ManagerEvent::EVENT_DELETE) { |
|
128 | - $activity->setSubject(Provider::DELETE_TAG, [ |
|
129 | - $actor, |
|
130 | - $this->prepareTagAsParameter($event->getTag()), |
|
131 | - ]); |
|
132 | - } else { |
|
133 | - return; |
|
134 | - } |
|
111 | + $activity = $this->activityManager->generateEvent(); |
|
112 | + $activity->setApp('systemtags') |
|
113 | + ->setType('systemtags') |
|
114 | + ->setAuthor($actor) |
|
115 | + ->setObject('systemtag', (int)$tag->getId(), $tag->getName()); |
|
116 | + if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
|
117 | + $activity->setSubject(Provider::CREATE_TAG, [ |
|
118 | + $actor, |
|
119 | + $this->prepareTagAsParameter($event->getTag()), |
|
120 | + ]); |
|
121 | + } elseif ($event->getEvent() === ManagerEvent::EVENT_UPDATE) { |
|
122 | + $activity->setSubject(Provider::UPDATE_TAG, [ |
|
123 | + $actor, |
|
124 | + $this->prepareTagAsParameter($event->getTag()), |
|
125 | + $this->prepareTagAsParameter($event->getTagBefore()), |
|
126 | + ]); |
|
127 | + } elseif ($event->getEvent() === ManagerEvent::EVENT_DELETE) { |
|
128 | + $activity->setSubject(Provider::DELETE_TAG, [ |
|
129 | + $actor, |
|
130 | + $this->prepareTagAsParameter($event->getTag()), |
|
131 | + ]); |
|
132 | + } else { |
|
133 | + return; |
|
134 | + } |
|
135 | 135 | |
136 | - $group = $this->groupManager->get('admin'); |
|
137 | - if ($group instanceof IGroup) { |
|
138 | - foreach ($group->getUsers() as $user) { |
|
139 | - $activity->setAffectedUser($user->getUID()); |
|
140 | - $this->activityManager->publish($activity); |
|
141 | - } |
|
142 | - } |
|
136 | + $group = $this->groupManager->get('admin'); |
|
137 | + if ($group instanceof IGroup) { |
|
138 | + foreach ($group->getUsers() as $user) { |
|
139 | + $activity->setAffectedUser($user->getUID()); |
|
140 | + $this->activityManager->publish($activity); |
|
141 | + } |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | - if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { |
|
146 | - $this->updateLastUsedTags($actor, $event->getTag()); |
|
147 | - } |
|
148 | - } |
|
145 | + if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { |
|
146 | + $this->updateLastUsedTags($actor, $event->getTag()); |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @param MapperEvent $event |
|
152 | - */ |
|
153 | - public function mapperEvent(MapperEvent $event) { |
|
154 | - $tagIds = $event->getTags(); |
|
155 | - if ($event->getObjectType() !== 'files' || empty($tagIds) |
|
156 | - || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
157 | - || !$this->appManager->isInstalled('activity')) { |
|
158 | - // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
|
159 | - return; |
|
160 | - } |
|
150 | + /** |
|
151 | + * @param MapperEvent $event |
|
152 | + */ |
|
153 | + public function mapperEvent(MapperEvent $event) { |
|
154 | + $tagIds = $event->getTags(); |
|
155 | + if ($event->getObjectType() !== 'files' || empty($tagIds) |
|
156 | + || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
157 | + || !$this->appManager->isInstalled('activity')) { |
|
158 | + // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
|
159 | + return; |
|
160 | + } |
|
161 | 161 | |
162 | - try { |
|
163 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
164 | - } catch (TagNotFoundException $e) { |
|
165 | - // User assigned/unassigned a non-existing tag, ignore... |
|
166 | - return; |
|
167 | - } |
|
162 | + try { |
|
163 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
164 | + } catch (TagNotFoundException $e) { |
|
165 | + // User assigned/unassigned a non-existing tag, ignore... |
|
166 | + return; |
|
167 | + } |
|
168 | 168 | |
169 | - if (empty($tags)) { |
|
170 | - return; |
|
171 | - } |
|
169 | + if (empty($tags)) { |
|
170 | + return; |
|
171 | + } |
|
172 | 172 | |
173 | - // Get all mount point owners |
|
174 | - $cache = $this->mountCollection->getMountCache(); |
|
175 | - $mounts = $cache->getMountsForFileId($event->getObjectId()); |
|
176 | - if (empty($mounts)) { |
|
177 | - return; |
|
178 | - } |
|
173 | + // Get all mount point owners |
|
174 | + $cache = $this->mountCollection->getMountCache(); |
|
175 | + $mounts = $cache->getMountsForFileId($event->getObjectId()); |
|
176 | + if (empty($mounts)) { |
|
177 | + return; |
|
178 | + } |
|
179 | 179 | |
180 | - $users = []; |
|
181 | - foreach ($mounts as $mount) { |
|
182 | - $owner = $mount->getUser()->getUID(); |
|
183 | - $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
184 | - $nodes = $ownerFolder->getById($event->getObjectId()); |
|
185 | - if (!empty($nodes)) { |
|
186 | - /** @var Node $node */ |
|
187 | - $node = array_shift($nodes); |
|
188 | - $al = $this->shareHelper->getPathsForAccessList($node); |
|
189 | - $users += $al['users']; |
|
190 | - } |
|
191 | - } |
|
180 | + $users = []; |
|
181 | + foreach ($mounts as $mount) { |
|
182 | + $owner = $mount->getUser()->getUID(); |
|
183 | + $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
184 | + $nodes = $ownerFolder->getById($event->getObjectId()); |
|
185 | + if (!empty($nodes)) { |
|
186 | + /** @var Node $node */ |
|
187 | + $node = array_shift($nodes); |
|
188 | + $al = $this->shareHelper->getPathsForAccessList($node); |
|
189 | + $users += $al['users']; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - $actor = $this->session->getUser(); |
|
194 | - if ($actor instanceof IUser) { |
|
195 | - $actor = $actor->getUID(); |
|
196 | - } else { |
|
197 | - $actor = ''; |
|
198 | - } |
|
193 | + $actor = $this->session->getUser(); |
|
194 | + if ($actor instanceof IUser) { |
|
195 | + $actor = $actor->getUID(); |
|
196 | + } else { |
|
197 | + $actor = ''; |
|
198 | + } |
|
199 | 199 | |
200 | - $activity = $this->activityManager->generateEvent(); |
|
201 | - $activity->setApp('systemtags') |
|
202 | - ->setType('systemtags') |
|
203 | - ->setAuthor($actor) |
|
204 | - ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
|
200 | + $activity = $this->activityManager->generateEvent(); |
|
201 | + $activity->setApp('systemtags') |
|
202 | + ->setType('systemtags') |
|
203 | + ->setAuthor($actor) |
|
204 | + ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
|
205 | 205 | |
206 | - foreach ($users as $user => $path) { |
|
207 | - $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
208 | - $activity->setAffectedUser($user); |
|
206 | + foreach ($users as $user => $path) { |
|
207 | + $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
208 | + $activity->setAffectedUser($user); |
|
209 | 209 | |
210 | - foreach ($tags as $tag) { |
|
211 | - // don't publish activity for non-admins if tag is invisible |
|
212 | - if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) { |
|
213 | - continue; |
|
214 | - } |
|
215 | - if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
216 | - $activity->setSubject(Provider::ASSIGN_TAG, [ |
|
217 | - $actor, |
|
218 | - $path, |
|
219 | - $this->prepareTagAsParameter($tag), |
|
220 | - ]); |
|
221 | - } elseif ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) { |
|
222 | - $activity->setSubject(Provider::UNASSIGN_TAG, [ |
|
223 | - $actor, |
|
224 | - $path, |
|
225 | - $this->prepareTagAsParameter($tag), |
|
226 | - ]); |
|
227 | - } |
|
210 | + foreach ($tags as $tag) { |
|
211 | + // don't publish activity for non-admins if tag is invisible |
|
212 | + if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) { |
|
213 | + continue; |
|
214 | + } |
|
215 | + if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
216 | + $activity->setSubject(Provider::ASSIGN_TAG, [ |
|
217 | + $actor, |
|
218 | + $path, |
|
219 | + $this->prepareTagAsParameter($tag), |
|
220 | + ]); |
|
221 | + } elseif ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) { |
|
222 | + $activity->setSubject(Provider::UNASSIGN_TAG, [ |
|
223 | + $actor, |
|
224 | + $path, |
|
225 | + $this->prepareTagAsParameter($tag), |
|
226 | + ]); |
|
227 | + } |
|
228 | 228 | |
229 | - $this->activityManager->publish($activity); |
|
230 | - } |
|
231 | - } |
|
229 | + $this->activityManager->publish($activity); |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | - if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
234 | - foreach ($tags as $tag) { |
|
235 | - $this->updateLastUsedTags($actor, $tag); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
233 | + if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
234 | + foreach ($tags as $tag) { |
|
235 | + $this->updateLastUsedTags($actor, $tag); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * @param string $actor |
|
242 | - * @param ISystemTag $tag |
|
243 | - */ |
|
244 | - protected function updateLastUsedTags($actor, ISystemTag $tag) { |
|
245 | - $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); |
|
246 | - $lastUsedTags = json_decode($lastUsedTags, true); |
|
240 | + /** |
|
241 | + * @param string $actor |
|
242 | + * @param ISystemTag $tag |
|
243 | + */ |
|
244 | + protected function updateLastUsedTags($actor, ISystemTag $tag) { |
|
245 | + $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); |
|
246 | + $lastUsedTags = json_decode($lastUsedTags, true); |
|
247 | 247 | |
248 | - array_unshift($lastUsedTags, $tag->getId()); |
|
249 | - array_unique($lastUsedTags); |
|
250 | - $lastUsedTags = array_slice($lastUsedTags, 0, 10); |
|
248 | + array_unshift($lastUsedTags, $tag->getId()); |
|
249 | + array_unique($lastUsedTags); |
|
250 | + $lastUsedTags = array_slice($lastUsedTags, 0, 10); |
|
251 | 251 | |
252 | - $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); |
|
253 | - } |
|
252 | + $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * @param ISystemTag $tag |
|
257 | - * @return string |
|
258 | - */ |
|
259 | - protected function prepareTagAsParameter(ISystemTag $tag) { |
|
260 | - return json_encode([ |
|
261 | - 'id' => $tag->getId(), |
|
262 | - 'name' => $tag->getName(), |
|
263 | - 'assignable' => $tag->isUserAssignable(), |
|
264 | - 'visible' => $tag->isUserVisible(), |
|
265 | - ]); |
|
266 | - } |
|
255 | + /** |
|
256 | + * @param ISystemTag $tag |
|
257 | + * @return string |
|
258 | + */ |
|
259 | + protected function prepareTagAsParameter(ISystemTag $tag) { |
|
260 | + return json_encode([ |
|
261 | + 'id' => $tag->getId(), |
|
262 | + 'name' => $tag->getName(), |
|
263 | + 'assignable' => $tag->isUserAssignable(), |
|
264 | + 'visible' => $tag->isUserVisible(), |
|
265 | + ]); |
|
266 | + } |
|
267 | 267 | } |
@@ -40,89 +40,89 @@ |
||
40 | 40 | |
41 | 41 | class Admin implements ISettings { |
42 | 42 | |
43 | - /** @var IL10N */ |
|
44 | - private $l; |
|
45 | - |
|
46 | - /** @var ILogger */ |
|
47 | - private $logger; |
|
48 | - |
|
49 | - /** @var IUserSession */ |
|
50 | - private $userSession; |
|
51 | - |
|
52 | - /** @var IConfig */ |
|
53 | - private $config; |
|
54 | - |
|
55 | - /** @var IUserManager */ |
|
56 | - private $userManager; |
|
57 | - |
|
58 | - /** @var ISession */ |
|
59 | - private $session; |
|
60 | - |
|
61 | - public function __construct( |
|
62 | - IL10N $l, |
|
63 | - ILogger $logger, |
|
64 | - IUserSession $userSession, |
|
65 | - IConfig $config, |
|
66 | - IUserManager $userManager, |
|
67 | - ISession $session |
|
68 | - ) { |
|
69 | - $this->l = $l; |
|
70 | - $this->logger = $logger; |
|
71 | - $this->userSession = $userSession; |
|
72 | - $this->config = $config; |
|
73 | - $this->userManager = $userManager; |
|
74 | - $this->session = $session; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * @return TemplateResponse |
|
79 | - */ |
|
80 | - public function getForm() { |
|
81 | - $crypt = new Crypt( |
|
82 | - $this->logger, |
|
83 | - $this->userSession, |
|
84 | - $this->config, |
|
85 | - $this->l); |
|
86 | - |
|
87 | - $util = new Util( |
|
88 | - new View(), |
|
89 | - $crypt, |
|
90 | - $this->logger, |
|
91 | - $this->userSession, |
|
92 | - $this->config, |
|
93 | - $this->userManager); |
|
94 | - |
|
95 | - // Check if an adminRecovery account is enabled for recovering files after lost pwd |
|
96 | - $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0'); |
|
97 | - $session = new Session($this->session); |
|
98 | - |
|
99 | - $encryptHomeStorage = $util->shouldEncryptHomeStorage(); |
|
100 | - |
|
101 | - $parameters = [ |
|
102 | - 'recoveryEnabled' => $recoveryAdminEnabled, |
|
103 | - 'initStatus' => $session->getStatus(), |
|
104 | - 'encryptHomeStorage' => $encryptHomeStorage, |
|
105 | - 'masterKeyEnabled' => $util->isMasterKeyEnabled(), |
|
106 | - ]; |
|
107 | - |
|
108 | - return new TemplateResponse('encryption', 'settings-admin', $parameters, ''); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return string the section ID, e.g. 'sharing' |
|
113 | - */ |
|
114 | - public function getSection() { |
|
115 | - return 'security'; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return int whether the form should be rather on the top or bottom of |
|
120 | - * the admin section. The forms are arranged in ascending order of the |
|
121 | - * priority values. It is required to return a value between 0 and 100. |
|
122 | - * |
|
123 | - * E.g.: 70 |
|
124 | - */ |
|
125 | - public function getPriority() { |
|
126 | - return 11; |
|
127 | - } |
|
43 | + /** @var IL10N */ |
|
44 | + private $l; |
|
45 | + |
|
46 | + /** @var ILogger */ |
|
47 | + private $logger; |
|
48 | + |
|
49 | + /** @var IUserSession */ |
|
50 | + private $userSession; |
|
51 | + |
|
52 | + /** @var IConfig */ |
|
53 | + private $config; |
|
54 | + |
|
55 | + /** @var IUserManager */ |
|
56 | + private $userManager; |
|
57 | + |
|
58 | + /** @var ISession */ |
|
59 | + private $session; |
|
60 | + |
|
61 | + public function __construct( |
|
62 | + IL10N $l, |
|
63 | + ILogger $logger, |
|
64 | + IUserSession $userSession, |
|
65 | + IConfig $config, |
|
66 | + IUserManager $userManager, |
|
67 | + ISession $session |
|
68 | + ) { |
|
69 | + $this->l = $l; |
|
70 | + $this->logger = $logger; |
|
71 | + $this->userSession = $userSession; |
|
72 | + $this->config = $config; |
|
73 | + $this->userManager = $userManager; |
|
74 | + $this->session = $session; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * @return TemplateResponse |
|
79 | + */ |
|
80 | + public function getForm() { |
|
81 | + $crypt = new Crypt( |
|
82 | + $this->logger, |
|
83 | + $this->userSession, |
|
84 | + $this->config, |
|
85 | + $this->l); |
|
86 | + |
|
87 | + $util = new Util( |
|
88 | + new View(), |
|
89 | + $crypt, |
|
90 | + $this->logger, |
|
91 | + $this->userSession, |
|
92 | + $this->config, |
|
93 | + $this->userManager); |
|
94 | + |
|
95 | + // Check if an adminRecovery account is enabled for recovering files after lost pwd |
|
96 | + $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0'); |
|
97 | + $session = new Session($this->session); |
|
98 | + |
|
99 | + $encryptHomeStorage = $util->shouldEncryptHomeStorage(); |
|
100 | + |
|
101 | + $parameters = [ |
|
102 | + 'recoveryEnabled' => $recoveryAdminEnabled, |
|
103 | + 'initStatus' => $session->getStatus(), |
|
104 | + 'encryptHomeStorage' => $encryptHomeStorage, |
|
105 | + 'masterKeyEnabled' => $util->isMasterKeyEnabled(), |
|
106 | + ]; |
|
107 | + |
|
108 | + return new TemplateResponse('encryption', 'settings-admin', $parameters, ''); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return string the section ID, e.g. 'sharing' |
|
113 | + */ |
|
114 | + public function getSection() { |
|
115 | + return 'security'; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return int whether the form should be rather on the top or bottom of |
|
120 | + * the admin section. The forms are arranged in ascending order of the |
|
121 | + * priority values. It is required to return a value between 0 and 100. |
|
122 | + * |
|
123 | + * E.g.: 70 |
|
124 | + */ |
|
125 | + public function getPriority() { |
|
126 | + return 11; |
|
127 | + } |
|
128 | 128 | } |
@@ -33,64 +33,64 @@ |
||
33 | 33 | |
34 | 34 | class Admin implements ISettings { |
35 | 35 | |
36 | - /** @var IManager */ |
|
37 | - private $encryptionManager; |
|
36 | + /** @var IManager */ |
|
37 | + private $encryptionManager; |
|
38 | 38 | |
39 | - /** @var GlobalStoragesService */ |
|
40 | - private $globalStoragesService; |
|
39 | + /** @var GlobalStoragesService */ |
|
40 | + private $globalStoragesService; |
|
41 | 41 | |
42 | - /** @var BackendService */ |
|
43 | - private $backendService; |
|
42 | + /** @var BackendService */ |
|
43 | + private $backendService; |
|
44 | 44 | |
45 | - /** @var GlobalAuth */ |
|
46 | - private $globalAuth; |
|
45 | + /** @var GlobalAuth */ |
|
46 | + private $globalAuth; |
|
47 | 47 | |
48 | - public function __construct( |
|
49 | - IManager $encryptionManager, |
|
50 | - GlobalStoragesService $globalStoragesService, |
|
51 | - BackendService $backendService, |
|
52 | - GlobalAuth $globalAuth |
|
53 | - ) { |
|
54 | - $this->encryptionManager = $encryptionManager; |
|
55 | - $this->globalStoragesService = $globalStoragesService; |
|
56 | - $this->backendService = $backendService; |
|
57 | - $this->globalAuth = $globalAuth; |
|
58 | - } |
|
48 | + public function __construct( |
|
49 | + IManager $encryptionManager, |
|
50 | + GlobalStoragesService $globalStoragesService, |
|
51 | + BackendService $backendService, |
|
52 | + GlobalAuth $globalAuth |
|
53 | + ) { |
|
54 | + $this->encryptionManager = $encryptionManager; |
|
55 | + $this->globalStoragesService = $globalStoragesService; |
|
56 | + $this->backendService = $backendService; |
|
57 | + $this->globalAuth = $globalAuth; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return TemplateResponse |
|
62 | - */ |
|
63 | - public function getForm() { |
|
64 | - $parameters = [ |
|
65 | - 'encryptionEnabled' => $this->encryptionManager->isEnabled(), |
|
66 | - 'visibilityType' => BackendService::VISIBILITY_ADMIN, |
|
67 | - 'storages' => $this->globalStoragesService->getStorages(), |
|
68 | - 'backends' => $this->backendService->getAvailableBackends(), |
|
69 | - 'authMechanisms' => $this->backendService->getAuthMechanisms(), |
|
70 | - 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()), |
|
71 | - 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), |
|
72 | - 'globalCredentials' => $this->globalAuth->getAuth(''), |
|
73 | - 'globalCredentialsUid' => '', |
|
74 | - ]; |
|
60 | + /** |
|
61 | + * @return TemplateResponse |
|
62 | + */ |
|
63 | + public function getForm() { |
|
64 | + $parameters = [ |
|
65 | + 'encryptionEnabled' => $this->encryptionManager->isEnabled(), |
|
66 | + 'visibilityType' => BackendService::VISIBILITY_ADMIN, |
|
67 | + 'storages' => $this->globalStoragesService->getStorages(), |
|
68 | + 'backends' => $this->backendService->getAvailableBackends(), |
|
69 | + 'authMechanisms' => $this->backendService->getAuthMechanisms(), |
|
70 | + 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()), |
|
71 | + 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), |
|
72 | + 'globalCredentials' => $this->globalAuth->getAuth(''), |
|
73 | + 'globalCredentialsUid' => '', |
|
74 | + ]; |
|
75 | 75 | |
76 | - return new TemplateResponse('files_external', 'settings', $parameters, ''); |
|
77 | - } |
|
76 | + return new TemplateResponse('files_external', 'settings', $parameters, ''); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return string the section ID, e.g. 'sharing' |
|
81 | - */ |
|
82 | - public function getSection() { |
|
83 | - return 'externalstorages'; |
|
84 | - } |
|
79 | + /** |
|
80 | + * @return string the section ID, e.g. 'sharing' |
|
81 | + */ |
|
82 | + public function getSection() { |
|
83 | + return 'externalstorages'; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return int whether the form should be rather on the top or bottom of |
|
88 | - * the admin section. The forms are arranged in ascending order of the |
|
89 | - * priority values. It is required to return a value between 0 and 100. |
|
90 | - * |
|
91 | - * E.g.: 70 |
|
92 | - */ |
|
93 | - public function getPriority() { |
|
94 | - return 40; |
|
95 | - } |
|
86 | + /** |
|
87 | + * @return int whether the form should be rather on the top or bottom of |
|
88 | + * the admin section. The forms are arranged in ascending order of the |
|
89 | + * priority values. It is required to return a value between 0 and 100. |
|
90 | + * |
|
91 | + * E.g.: 70 |
|
92 | + */ |
|
93 | + public function getPriority() { |
|
94 | + return 40; |
|
95 | + } |
|
96 | 96 | } |
@@ -34,71 +34,71 @@ |
||
34 | 34 | |
35 | 35 | class Personal implements ISettings { |
36 | 36 | |
37 | - /** @var IManager */ |
|
38 | - private $encryptionManager; |
|
37 | + /** @var IManager */ |
|
38 | + private $encryptionManager; |
|
39 | 39 | |
40 | - /** @var UserGlobalStoragesService */ |
|
41 | - private $userGlobalStoragesService; |
|
40 | + /** @var UserGlobalStoragesService */ |
|
41 | + private $userGlobalStoragesService; |
|
42 | 42 | |
43 | - /** @var BackendService */ |
|
44 | - private $backendService; |
|
43 | + /** @var BackendService */ |
|
44 | + private $backendService; |
|
45 | 45 | |
46 | - /** @var GlobalAuth */ |
|
47 | - private $globalAuth; |
|
46 | + /** @var GlobalAuth */ |
|
47 | + private $globalAuth; |
|
48 | 48 | |
49 | - /** @var IUserSession */ |
|
50 | - private $userSession; |
|
49 | + /** @var IUserSession */ |
|
50 | + private $userSession; |
|
51 | 51 | |
52 | - public function __construct( |
|
53 | - IManager $encryptionManager, |
|
54 | - UserGlobalStoragesService $userGlobalStoragesService, |
|
55 | - BackendService $backendService, |
|
56 | - GlobalAuth $globalAuth, |
|
57 | - IUserSession $userSession |
|
58 | - ) { |
|
59 | - $this->encryptionManager = $encryptionManager; |
|
60 | - $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
61 | - $this->backendService = $backendService; |
|
62 | - $this->globalAuth = $globalAuth; |
|
63 | - $this->userSession = $userSession; |
|
64 | - } |
|
52 | + public function __construct( |
|
53 | + IManager $encryptionManager, |
|
54 | + UserGlobalStoragesService $userGlobalStoragesService, |
|
55 | + BackendService $backendService, |
|
56 | + GlobalAuth $globalAuth, |
|
57 | + IUserSession $userSession |
|
58 | + ) { |
|
59 | + $this->encryptionManager = $encryptionManager; |
|
60 | + $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
61 | + $this->backendService = $backendService; |
|
62 | + $this->globalAuth = $globalAuth; |
|
63 | + $this->userSession = $userSession; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return TemplateResponse |
|
68 | - */ |
|
69 | - public function getForm() { |
|
70 | - $uid = $this->userSession->getUser()->getUID(); |
|
66 | + /** |
|
67 | + * @return TemplateResponse |
|
68 | + */ |
|
69 | + public function getForm() { |
|
70 | + $uid = $this->userSession->getUser()->getUID(); |
|
71 | 71 | |
72 | - $parameters = [ |
|
73 | - 'encryptionEnabled' => $this->encryptionManager->isEnabled(), |
|
74 | - 'visibilityType' => BackendService::VISIBILITY_PERSONAL, |
|
75 | - 'storages' => $this->userGlobalStoragesService->getStorages(), |
|
76 | - 'backends' => $this->backendService->getAvailableBackends(), |
|
77 | - 'authMechanisms' => $this->backendService->getAuthMechanisms(), |
|
78 | - 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()), |
|
79 | - 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), |
|
80 | - 'globalCredentials' => $this->globalAuth->getAuth($uid), |
|
81 | - 'globalCredentialsUid' => $uid, |
|
82 | - ]; |
|
72 | + $parameters = [ |
|
73 | + 'encryptionEnabled' => $this->encryptionManager->isEnabled(), |
|
74 | + 'visibilityType' => BackendService::VISIBILITY_PERSONAL, |
|
75 | + 'storages' => $this->userGlobalStoragesService->getStorages(), |
|
76 | + 'backends' => $this->backendService->getAvailableBackends(), |
|
77 | + 'authMechanisms' => $this->backendService->getAuthMechanisms(), |
|
78 | + 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()), |
|
79 | + 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), |
|
80 | + 'globalCredentials' => $this->globalAuth->getAuth($uid), |
|
81 | + 'globalCredentialsUid' => $uid, |
|
82 | + ]; |
|
83 | 83 | |
84 | - return new TemplateResponse('files_external', 'settings', $parameters, ''); |
|
85 | - } |
|
84 | + return new TemplateResponse('files_external', 'settings', $parameters, ''); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return string the section ID, e.g. 'sharing' |
|
89 | - */ |
|
90 | - public function getSection() { |
|
91 | - return 'externalstorages'; |
|
92 | - } |
|
87 | + /** |
|
88 | + * @return string the section ID, e.g. 'sharing' |
|
89 | + */ |
|
90 | + public function getSection() { |
|
91 | + return 'externalstorages'; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return int whether the form should be rather on the top or bottom of |
|
96 | - * the admin section. The forms are arranged in ascending order of the |
|
97 | - * priority values. It is required to return a value between 0 and 100. |
|
98 | - * |
|
99 | - * E.g.: 70 |
|
100 | - */ |
|
101 | - public function getPriority() { |
|
102 | - return 40; |
|
103 | - } |
|
94 | + /** |
|
95 | + * @return int whether the form should be rather on the top or bottom of |
|
96 | + * the admin section. The forms are arranged in ascending order of the |
|
97 | + * priority values. It is required to return a value between 0 and 100. |
|
98 | + * |
|
99 | + * E.g.: 70 |
|
100 | + */ |
|
101 | + public function getPriority() { |
|
102 | + return 40; |
|
103 | + } |
|
104 | 104 | } |