@@ -25,24 +25,24 @@ |
||
25 | 25 | |
26 | 26 | class Hooks { |
27 | 27 | |
28 | - /** @var TrustedServers */ |
|
29 | - private $trustedServers; |
|
28 | + /** @var TrustedServers */ |
|
29 | + private $trustedServers; |
|
30 | 30 | |
31 | - public function __construct(TrustedServers $trustedServers) { |
|
32 | - $this->trustedServers = $trustedServers; |
|
33 | - } |
|
31 | + public function __construct(TrustedServers $trustedServers) { |
|
32 | + $this->trustedServers = $trustedServers; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * add servers to the list of trusted servers once a federated share was established |
|
37 | - * |
|
38 | - * @param array $params |
|
39 | - */ |
|
40 | - public function addServerHook($params) { |
|
41 | - if ( |
|
42 | - $this->trustedServers->getAutoAddServers() === true && |
|
43 | - $this->trustedServers->isTrustedServer($params['server']) === false |
|
44 | - ) { |
|
45 | - $this->trustedServers->addServer($params['server']); |
|
46 | - } |
|
47 | - } |
|
35 | + /** |
|
36 | + * add servers to the list of trusted servers once a federated share was established |
|
37 | + * |
|
38 | + * @param array $params |
|
39 | + */ |
|
40 | + public function addServerHook($params) { |
|
41 | + if ( |
|
42 | + $this->trustedServers->getAutoAddServers() === true && |
|
43 | + $this->trustedServers->isTrustedServer($params['server']) === false |
|
44 | + ) { |
|
45 | + $this->trustedServers->addServer($params['server']); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | } |
@@ -29,40 +29,40 @@ |
||
29 | 29 | |
30 | 30 | class FedAuth extends AbstractBasic { |
31 | 31 | |
32 | - /** @var DbHandler */ |
|
33 | - private $db; |
|
32 | + /** @var DbHandler */ |
|
33 | + private $db; |
|
34 | 34 | |
35 | - /** |
|
36 | - * FedAuth constructor. |
|
37 | - * |
|
38 | - * @param DbHandler $db |
|
39 | - */ |
|
40 | - public function __construct(DbHandler $db) { |
|
41 | - $this->db = $db; |
|
42 | - $this->principalPrefix = 'principals/system/'; |
|
35 | + /** |
|
36 | + * FedAuth constructor. |
|
37 | + * |
|
38 | + * @param DbHandler $db |
|
39 | + */ |
|
40 | + public function __construct(DbHandler $db) { |
|
41 | + $this->db = $db; |
|
42 | + $this->principalPrefix = 'principals/system/'; |
|
43 | 43 | |
44 | - // setup realm |
|
45 | - $defaults = new \OCP\Defaults(); |
|
46 | - $this->realm = $defaults->getName(); |
|
47 | - } |
|
44 | + // setup realm |
|
45 | + $defaults = new \OCP\Defaults(); |
|
46 | + $this->realm = $defaults->getName(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Validates a username and password |
|
51 | - * |
|
52 | - * This method should return true or false depending on if login |
|
53 | - * succeeded. |
|
54 | - * |
|
55 | - * @param string $username |
|
56 | - * @param string $password |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - protected function validateUserPass($username, $password) { |
|
60 | - return $this->db->auth($username, $password); |
|
61 | - } |
|
49 | + /** |
|
50 | + * Validates a username and password |
|
51 | + * |
|
52 | + * This method should return true or false depending on if login |
|
53 | + * succeeded. |
|
54 | + * |
|
55 | + * @param string $username |
|
56 | + * @param string $password |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + protected function validateUserPass($username, $password) { |
|
60 | + return $this->db->auth($username, $password); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @inheritdoc |
|
65 | - */ |
|
66 | - public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
67 | - } |
|
63 | + /** |
|
64 | + * @inheritdoc |
|
65 | + */ |
|
66 | + public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
67 | + } |
|
68 | 68 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function requestSharedSecret($url, $token) { |
136 | 136 | if ($this->trustedServers->isTrustedServer($url) === false) { |
137 | - $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); |
|
137 | + $this->logger->error('remote server not trusted ('.$url.') while requesting shared secret', ['app' => 'federation']); |
|
138 | 138 | throw new OCSForbiddenException(); |
139 | 139 | } |
140 | 140 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $localToken = $this->dbHandler->getToken($url); |
144 | 144 | if (strcmp($localToken, $token) > 0) { |
145 | 145 | $this->logger->info( |
146 | - 'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.', |
|
146 | + 'remote server ('.$url.') presented lower token. We will initiate the exchange of the shared secret.', |
|
147 | 147 | ['app' => 'federation'] |
148 | 148 | ); |
149 | 149 | throw new OCSForbiddenException(); |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function getSharedSecret($url, $token) { |
185 | 185 | if ($this->trustedServers->isTrustedServer($url) === false) { |
186 | - $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); |
|
186 | + $this->logger->error('remote server not trusted ('.$url.') while getting shared secret', ['app' => 'federation']); |
|
187 | 187 | throw new OCSForbiddenException(); |
188 | 188 | } |
189 | 189 | |
190 | 190 | if ($this->isValidToken($url, $token) === false) { |
191 | 191 | $expectedToken = $this->dbHandler->getToken($url); |
192 | 192 | $this->logger->error( |
193 | - 'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret', |
|
193 | + 'remote server ('.$url.') didn\'t send a valid token (got "'.$token.'" but expected "'.$expectedToken.'") while getting shared secret', |
|
194 | 194 | ['app' => 'federation'] |
195 | 195 | ); |
196 | 196 | throw new OCSForbiddenException(); |
@@ -48,164 +48,164 @@ |
||
48 | 48 | */ |
49 | 49 | class OCSAuthAPIController extends OCSController { |
50 | 50 | |
51 | - /** @var ISecureRandom */ |
|
52 | - private $secureRandom; |
|
53 | - |
|
54 | - /** @var IJobList */ |
|
55 | - private $jobList; |
|
56 | - |
|
57 | - /** @var TrustedServers */ |
|
58 | - private $trustedServers; |
|
59 | - |
|
60 | - /** @var DbHandler */ |
|
61 | - private $dbHandler; |
|
62 | - |
|
63 | - /** @var ILogger */ |
|
64 | - private $logger; |
|
65 | - |
|
66 | - /** @var ITimeFactory */ |
|
67 | - private $timeFactory; |
|
68 | - |
|
69 | - /** |
|
70 | - * OCSAuthAPI constructor. |
|
71 | - * |
|
72 | - * @param string $appName |
|
73 | - * @param IRequest $request |
|
74 | - * @param ISecureRandom $secureRandom |
|
75 | - * @param IJobList $jobList |
|
76 | - * @param TrustedServers $trustedServers |
|
77 | - * @param DbHandler $dbHandler |
|
78 | - * @param ILogger $logger |
|
79 | - * @param ITimeFactory $timeFactory |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - $appName, |
|
83 | - IRequest $request, |
|
84 | - ISecureRandom $secureRandom, |
|
85 | - IJobList $jobList, |
|
86 | - TrustedServers $trustedServers, |
|
87 | - DbHandler $dbHandler, |
|
88 | - ILogger $logger, |
|
89 | - ITimeFactory $timeFactory |
|
90 | - ) { |
|
91 | - parent::__construct($appName, $request); |
|
92 | - |
|
93 | - $this->secureRandom = $secureRandom; |
|
94 | - $this->jobList = $jobList; |
|
95 | - $this->trustedServers = $trustedServers; |
|
96 | - $this->dbHandler = $dbHandler; |
|
97 | - $this->logger = $logger; |
|
98 | - $this->timeFactory = $timeFactory; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @NoCSRFRequired |
|
103 | - * @PublicPage |
|
104 | - * |
|
105 | - * request received to ask remote server for a shared secret, for legacy end-points |
|
106 | - * |
|
107 | - * @param string $url |
|
108 | - * @param string $token |
|
109 | - * @return Http\DataResponse |
|
110 | - * @throws OCSForbiddenException |
|
111 | - */ |
|
112 | - public function requestSharedSecretLegacy($url, $token) { |
|
113 | - return $this->requestSharedSecret($url, $token); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @NoCSRFRequired |
|
119 | - * @PublicPage |
|
120 | - * |
|
121 | - * create shared secret and return it, for legacy end-points |
|
122 | - * |
|
123 | - * @param string $url |
|
124 | - * @param string $token |
|
125 | - * @return Http\DataResponse |
|
126 | - * @throws OCSForbiddenException |
|
127 | - */ |
|
128 | - public function getSharedSecretLegacy($url, $token) { |
|
129 | - return $this->getSharedSecret($url, $token); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @NoCSRFRequired |
|
134 | - * @PublicPage |
|
135 | - * |
|
136 | - * request received to ask remote server for a shared secret |
|
137 | - * |
|
138 | - * @param string $url |
|
139 | - * @param string $token |
|
140 | - * @return Http\DataResponse |
|
141 | - * @throws OCSForbiddenException |
|
142 | - */ |
|
143 | - public function requestSharedSecret($url, $token) { |
|
144 | - if ($this->trustedServers->isTrustedServer($url) === false) { |
|
145 | - $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); |
|
146 | - throw new OCSForbiddenException(); |
|
147 | - } |
|
148 | - |
|
149 | - // if both server initiated the exchange of the shared secret the greater |
|
150 | - // token wins |
|
151 | - $localToken = $this->dbHandler->getToken($url); |
|
152 | - if (strcmp($localToken, $token) > 0) { |
|
153 | - $this->logger->info( |
|
154 | - 'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.', |
|
155 | - ['app' => 'federation'] |
|
156 | - ); |
|
157 | - throw new OCSForbiddenException(); |
|
158 | - } |
|
159 | - |
|
160 | - $this->jobList->add( |
|
161 | - 'OCA\Federation\BackgroundJob\GetSharedSecret', |
|
162 | - [ |
|
163 | - 'url' => $url, |
|
164 | - 'token' => $token, |
|
165 | - 'created' => $this->timeFactory->getTime() |
|
166 | - ] |
|
167 | - ); |
|
168 | - |
|
169 | - return new Http\DataResponse(); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @NoCSRFRequired |
|
174 | - * @PublicPage |
|
175 | - * |
|
176 | - * create shared secret and return it |
|
177 | - * |
|
178 | - * @param string $url |
|
179 | - * @param string $token |
|
180 | - * @return Http\DataResponse |
|
181 | - * @throws OCSForbiddenException |
|
182 | - */ |
|
183 | - public function getSharedSecret($url, $token) { |
|
184 | - if ($this->trustedServers->isTrustedServer($url) === false) { |
|
185 | - $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); |
|
186 | - throw new OCSForbiddenException(); |
|
187 | - } |
|
188 | - |
|
189 | - if ($this->isValidToken($url, $token) === false) { |
|
190 | - $expectedToken = $this->dbHandler->getToken($url); |
|
191 | - $this->logger->error( |
|
192 | - 'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret', |
|
193 | - ['app' => 'federation'] |
|
194 | - ); |
|
195 | - throw new OCSForbiddenException(); |
|
196 | - } |
|
197 | - |
|
198 | - $sharedSecret = $this->secureRandom->generate(32); |
|
199 | - |
|
200 | - $this->trustedServers->addSharedSecret($url, $sharedSecret); |
|
201 | - |
|
202 | - return new Http\DataResponse([ |
|
203 | - 'sharedSecret' => $sharedSecret |
|
204 | - ]); |
|
205 | - } |
|
206 | - |
|
207 | - protected function isValidToken($url, $token) { |
|
208 | - $storedToken = $this->dbHandler->getToken($url); |
|
209 | - return hash_equals($storedToken, $token); |
|
210 | - } |
|
51 | + /** @var ISecureRandom */ |
|
52 | + private $secureRandom; |
|
53 | + |
|
54 | + /** @var IJobList */ |
|
55 | + private $jobList; |
|
56 | + |
|
57 | + /** @var TrustedServers */ |
|
58 | + private $trustedServers; |
|
59 | + |
|
60 | + /** @var DbHandler */ |
|
61 | + private $dbHandler; |
|
62 | + |
|
63 | + /** @var ILogger */ |
|
64 | + private $logger; |
|
65 | + |
|
66 | + /** @var ITimeFactory */ |
|
67 | + private $timeFactory; |
|
68 | + |
|
69 | + /** |
|
70 | + * OCSAuthAPI constructor. |
|
71 | + * |
|
72 | + * @param string $appName |
|
73 | + * @param IRequest $request |
|
74 | + * @param ISecureRandom $secureRandom |
|
75 | + * @param IJobList $jobList |
|
76 | + * @param TrustedServers $trustedServers |
|
77 | + * @param DbHandler $dbHandler |
|
78 | + * @param ILogger $logger |
|
79 | + * @param ITimeFactory $timeFactory |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + $appName, |
|
83 | + IRequest $request, |
|
84 | + ISecureRandom $secureRandom, |
|
85 | + IJobList $jobList, |
|
86 | + TrustedServers $trustedServers, |
|
87 | + DbHandler $dbHandler, |
|
88 | + ILogger $logger, |
|
89 | + ITimeFactory $timeFactory |
|
90 | + ) { |
|
91 | + parent::__construct($appName, $request); |
|
92 | + |
|
93 | + $this->secureRandom = $secureRandom; |
|
94 | + $this->jobList = $jobList; |
|
95 | + $this->trustedServers = $trustedServers; |
|
96 | + $this->dbHandler = $dbHandler; |
|
97 | + $this->logger = $logger; |
|
98 | + $this->timeFactory = $timeFactory; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @NoCSRFRequired |
|
103 | + * @PublicPage |
|
104 | + * |
|
105 | + * request received to ask remote server for a shared secret, for legacy end-points |
|
106 | + * |
|
107 | + * @param string $url |
|
108 | + * @param string $token |
|
109 | + * @return Http\DataResponse |
|
110 | + * @throws OCSForbiddenException |
|
111 | + */ |
|
112 | + public function requestSharedSecretLegacy($url, $token) { |
|
113 | + return $this->requestSharedSecret($url, $token); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @NoCSRFRequired |
|
119 | + * @PublicPage |
|
120 | + * |
|
121 | + * create shared secret and return it, for legacy end-points |
|
122 | + * |
|
123 | + * @param string $url |
|
124 | + * @param string $token |
|
125 | + * @return Http\DataResponse |
|
126 | + * @throws OCSForbiddenException |
|
127 | + */ |
|
128 | + public function getSharedSecretLegacy($url, $token) { |
|
129 | + return $this->getSharedSecret($url, $token); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @NoCSRFRequired |
|
134 | + * @PublicPage |
|
135 | + * |
|
136 | + * request received to ask remote server for a shared secret |
|
137 | + * |
|
138 | + * @param string $url |
|
139 | + * @param string $token |
|
140 | + * @return Http\DataResponse |
|
141 | + * @throws OCSForbiddenException |
|
142 | + */ |
|
143 | + public function requestSharedSecret($url, $token) { |
|
144 | + if ($this->trustedServers->isTrustedServer($url) === false) { |
|
145 | + $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); |
|
146 | + throw new OCSForbiddenException(); |
|
147 | + } |
|
148 | + |
|
149 | + // if both server initiated the exchange of the shared secret the greater |
|
150 | + // token wins |
|
151 | + $localToken = $this->dbHandler->getToken($url); |
|
152 | + if (strcmp($localToken, $token) > 0) { |
|
153 | + $this->logger->info( |
|
154 | + 'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.', |
|
155 | + ['app' => 'federation'] |
|
156 | + ); |
|
157 | + throw new OCSForbiddenException(); |
|
158 | + } |
|
159 | + |
|
160 | + $this->jobList->add( |
|
161 | + 'OCA\Federation\BackgroundJob\GetSharedSecret', |
|
162 | + [ |
|
163 | + 'url' => $url, |
|
164 | + 'token' => $token, |
|
165 | + 'created' => $this->timeFactory->getTime() |
|
166 | + ] |
|
167 | + ); |
|
168 | + |
|
169 | + return new Http\DataResponse(); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @NoCSRFRequired |
|
174 | + * @PublicPage |
|
175 | + * |
|
176 | + * create shared secret and return it |
|
177 | + * |
|
178 | + * @param string $url |
|
179 | + * @param string $token |
|
180 | + * @return Http\DataResponse |
|
181 | + * @throws OCSForbiddenException |
|
182 | + */ |
|
183 | + public function getSharedSecret($url, $token) { |
|
184 | + if ($this->trustedServers->isTrustedServer($url) === false) { |
|
185 | + $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); |
|
186 | + throw new OCSForbiddenException(); |
|
187 | + } |
|
188 | + |
|
189 | + if ($this->isValidToken($url, $token) === false) { |
|
190 | + $expectedToken = $this->dbHandler->getToken($url); |
|
191 | + $this->logger->error( |
|
192 | + 'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret', |
|
193 | + ['app' => 'federation'] |
|
194 | + ); |
|
195 | + throw new OCSForbiddenException(); |
|
196 | + } |
|
197 | + |
|
198 | + $sharedSecret = $this->secureRandom->generate(32); |
|
199 | + |
|
200 | + $this->trustedServers->addSharedSecret($url, $sharedSecret); |
|
201 | + |
|
202 | + return new Http\DataResponse([ |
|
203 | + 'sharedSecret' => $sharedSecret |
|
204 | + ]); |
|
205 | + } |
|
206 | + |
|
207 | + protected function isValidToken($url, $token) { |
|
208 | + $storedToken = $this->dbHandler->getToken($url); |
|
209 | + return hash_equals($storedToken, $token); |
|
210 | + } |
|
211 | 211 | } |
@@ -29,32 +29,32 @@ |
||
29 | 29 | |
30 | 30 | class LastUsedController extends Controller { |
31 | 31 | |
32 | - /** @var IConfig */ |
|
33 | - protected $config; |
|
32 | + /** @var IConfig */ |
|
33 | + protected $config; |
|
34 | 34 | |
35 | - /** @var IUserSession */ |
|
36 | - protected $userSession; |
|
35 | + /** @var IUserSession */ |
|
36 | + protected $userSession; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param string $appName |
|
40 | - * @param IRequest $request |
|
41 | - * @param IConfig $config |
|
42 | - * @param IUserSession $userSession |
|
43 | - */ |
|
44 | - public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { |
|
45 | - parent::__construct($appName, $request); |
|
46 | - $this->config = $config; |
|
47 | - $this->userSession = $userSession; |
|
48 | - } |
|
38 | + /** |
|
39 | + * @param string $appName |
|
40 | + * @param IRequest $request |
|
41 | + * @param IConfig $config |
|
42 | + * @param IUserSession $userSession |
|
43 | + */ |
|
44 | + public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { |
|
45 | + parent::__construct($appName, $request); |
|
46 | + $this->config = $config; |
|
47 | + $this->userSession = $userSession; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @NoAdminRequired |
|
52 | - */ |
|
53 | - public function getLastUsedTagIds() { |
|
54 | - $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
|
55 | - $tagIds = json_decode($lastUsed, true); |
|
56 | - return new DataResponse(array_map(function ($id) { |
|
57 | - return (string) $id; |
|
58 | - }, $tagIds)); |
|
59 | - } |
|
50 | + /** |
|
51 | + * @NoAdminRequired |
|
52 | + */ |
|
53 | + public function getLastUsedTagIds() { |
|
54 | + $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
|
55 | + $tagIds = json_decode($lastUsed, true); |
|
56 | + return new DataResponse(array_map(function ($id) { |
|
57 | + return (string) $id; |
|
58 | + }, $tagIds)); |
|
59 | + } |
|
60 | 60 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | public function getLastUsedTagIds() { |
54 | 54 | $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
55 | 55 | $tagIds = json_decode($lastUsed, true); |
56 | - return new DataResponse(array_map(function ($id) { |
|
56 | + return new DataResponse(array_map(function($id) { |
|
57 | 57 | return (string) $id; |
58 | 58 | }, $tagIds)); |
59 | 59 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $token = $argument['token']; |
98 | 98 | $action = $argument['action']; |
99 | 99 | $data = json_decode($argument['data'], true); |
100 | - $try = (int)$argument['try'] + 1; |
|
100 | + $try = (int) $argument['try'] + 1; |
|
101 | 101 | |
102 | 102 | $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
103 | 103 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | 'token' => $argument['token'], |
122 | 122 | 'data' => $argument['data'], |
123 | 123 | 'action' => $argument['action'], |
124 | - 'try' => (int)$argument['try'] + 1, |
|
124 | + 'try' => (int) $argument['try'] + 1, |
|
125 | 125 | 'lastRun' => time() |
126 | 126 | ] |
127 | 127 | ); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @return bool |
135 | 135 | */ |
136 | 136 | protected function shouldRun(array $argument) { |
137 | - $lastRun = (int)$argument['lastRun']; |
|
137 | + $lastRun = (int) $argument['lastRun']; |
|
138 | 138 | return ((time() - $lastRun) > $this->interval); |
139 | 139 | } |
140 | 140 | } |
@@ -44,102 +44,102 @@ |
||
44 | 44 | */ |
45 | 45 | class RetryJob extends Job { |
46 | 46 | |
47 | - /** @var bool */ |
|
48 | - private $retainJob = true; |
|
47 | + /** @var bool */ |
|
48 | + private $retainJob = true; |
|
49 | 49 | |
50 | - /** @var Notifications */ |
|
51 | - private $notifications; |
|
50 | + /** @var Notifications */ |
|
51 | + private $notifications; |
|
52 | 52 | |
53 | - /** @var int max number of attempts to send the request */ |
|
54 | - private $maxTry = 20; |
|
53 | + /** @var int max number of attempts to send the request */ |
|
54 | + private $maxTry = 20; |
|
55 | 55 | |
56 | - /** @var int how much time should be between two tries (10 minutes) */ |
|
57 | - private $interval = 600; |
|
56 | + /** @var int how much time should be between two tries (10 minutes) */ |
|
57 | + private $interval = 600; |
|
58 | 58 | |
59 | - /** |
|
60 | - * UnShare constructor. |
|
61 | - * |
|
62 | - * @param Notifications $notifications |
|
63 | - */ |
|
64 | - public function __construct(Notifications $notifications = null) { |
|
65 | - if ($notifications) { |
|
66 | - $this->notifications = $notifications; |
|
67 | - } else { |
|
68 | - $addressHandler = new AddressHandler( |
|
69 | - \OC::$server->getURLGenerator(), |
|
70 | - \OC::$server->getL10N('federatedfilesharing'), |
|
71 | - \OC::$server->getCloudIdManager() |
|
72 | - ); |
|
73 | - $this->notifications = new Notifications( |
|
74 | - $addressHandler, |
|
75 | - \OC::$server->getHTTPClientService(), |
|
76 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
77 | - \OC::$server->getJobList(), |
|
78 | - \OC::$server->getCloudFederationProviderManager(), |
|
79 | - \OC::$server->getCloudFederationFactory() |
|
80 | - ); |
|
81 | - } |
|
82 | - } |
|
59 | + /** |
|
60 | + * UnShare constructor. |
|
61 | + * |
|
62 | + * @param Notifications $notifications |
|
63 | + */ |
|
64 | + public function __construct(Notifications $notifications = null) { |
|
65 | + if ($notifications) { |
|
66 | + $this->notifications = $notifications; |
|
67 | + } else { |
|
68 | + $addressHandler = new AddressHandler( |
|
69 | + \OC::$server->getURLGenerator(), |
|
70 | + \OC::$server->getL10N('federatedfilesharing'), |
|
71 | + \OC::$server->getCloudIdManager() |
|
72 | + ); |
|
73 | + $this->notifications = new Notifications( |
|
74 | + $addressHandler, |
|
75 | + \OC::$server->getHTTPClientService(), |
|
76 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
77 | + \OC::$server->getJobList(), |
|
78 | + \OC::$server->getCloudFederationProviderManager(), |
|
79 | + \OC::$server->getCloudFederationFactory() |
|
80 | + ); |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * run the job, then remove it from the jobList |
|
86 | - * |
|
87 | - * @param JobList $jobList |
|
88 | - * @param ILogger|null $logger |
|
89 | - */ |
|
90 | - public function execute($jobList, ILogger $logger = null) { |
|
91 | - if ($this->shouldRun($this->argument)) { |
|
92 | - parent::execute($jobList, $logger); |
|
93 | - $jobList->remove($this, $this->argument); |
|
94 | - if ($this->retainJob) { |
|
95 | - $this->reAddJob($jobList, $this->argument); |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
84 | + /** |
|
85 | + * run the job, then remove it from the jobList |
|
86 | + * |
|
87 | + * @param JobList $jobList |
|
88 | + * @param ILogger|null $logger |
|
89 | + */ |
|
90 | + public function execute($jobList, ILogger $logger = null) { |
|
91 | + if ($this->shouldRun($this->argument)) { |
|
92 | + parent::execute($jobList, $logger); |
|
93 | + $jobList->remove($this, $this->argument); |
|
94 | + if ($this->retainJob) { |
|
95 | + $this->reAddJob($jobList, $this->argument); |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - protected function run($argument) { |
|
101 | - $remote = $argument['remote']; |
|
102 | - $remoteId = $argument['remoteId']; |
|
103 | - $token = $argument['token']; |
|
104 | - $action = $argument['action']; |
|
105 | - $data = json_decode($argument['data'], true); |
|
106 | - $try = (int)$argument['try'] + 1; |
|
100 | + protected function run($argument) { |
|
101 | + $remote = $argument['remote']; |
|
102 | + $remoteId = $argument['remoteId']; |
|
103 | + $token = $argument['token']; |
|
104 | + $action = $argument['action']; |
|
105 | + $data = json_decode($argument['data'], true); |
|
106 | + $try = (int)$argument['try'] + 1; |
|
107 | 107 | |
108 | - $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
108 | + $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
109 | 109 | |
110 | - if ($result === true || $try > $this->maxTry) { |
|
111 | - $this->retainJob = false; |
|
112 | - } |
|
113 | - } |
|
110 | + if ($result === true || $try > $this->maxTry) { |
|
111 | + $this->retainJob = false; |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * re-add background job with new arguments |
|
117 | - * |
|
118 | - * @param IJobList $jobList |
|
119 | - * @param array $argument |
|
120 | - */ |
|
121 | - protected function reAddJob(IJobList $jobList, array $argument) { |
|
122 | - $jobList->add(RetryJob::class, |
|
123 | - [ |
|
124 | - 'remote' => $argument['remote'], |
|
125 | - 'remoteId' => $argument['remoteId'], |
|
126 | - 'token' => $argument['token'], |
|
127 | - 'data' => $argument['data'], |
|
128 | - 'action' => $argument['action'], |
|
129 | - 'try' => (int)$argument['try'] + 1, |
|
130 | - 'lastRun' => time() |
|
131 | - ] |
|
132 | - ); |
|
133 | - } |
|
115 | + /** |
|
116 | + * re-add background job with new arguments |
|
117 | + * |
|
118 | + * @param IJobList $jobList |
|
119 | + * @param array $argument |
|
120 | + */ |
|
121 | + protected function reAddJob(IJobList $jobList, array $argument) { |
|
122 | + $jobList->add(RetryJob::class, |
|
123 | + [ |
|
124 | + 'remote' => $argument['remote'], |
|
125 | + 'remoteId' => $argument['remoteId'], |
|
126 | + 'token' => $argument['token'], |
|
127 | + 'data' => $argument['data'], |
|
128 | + 'action' => $argument['action'], |
|
129 | + 'try' => (int)$argument['try'] + 1, |
|
130 | + 'lastRun' => time() |
|
131 | + ] |
|
132 | + ); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * test if it is time for the next run |
|
137 | - * |
|
138 | - * @param array $argument |
|
139 | - * @return bool |
|
140 | - */ |
|
141 | - protected function shouldRun(array $argument) { |
|
142 | - $lastRun = (int)$argument['lastRun']; |
|
143 | - return ((time() - $lastRun) > $this->interval); |
|
144 | - } |
|
135 | + /** |
|
136 | + * test if it is time for the next run |
|
137 | + * |
|
138 | + * @param array $argument |
|
139 | + * @return bool |
|
140 | + */ |
|
141 | + protected function shouldRun(array $argument) { |
|
142 | + $lastRun = (int)$argument['lastRun']; |
|
143 | + return ((time() - $lastRun) > $this->interval); |
|
144 | + } |
|
145 | 145 | } |
@@ -31,30 +31,30 @@ |
||
31 | 31 | use OCP\Command\ICommand; |
32 | 32 | |
33 | 33 | class Expire implements ICommand { |
34 | - use FileAccess; |
|
34 | + use FileAccess; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $user; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $user; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $user |
|
43 | - */ |
|
44 | - public function __construct($user) { |
|
45 | - $this->user = $user; |
|
46 | - } |
|
41 | + /** |
|
42 | + * @param string $user |
|
43 | + */ |
|
44 | + public function __construct($user) { |
|
45 | + $this->user = $user; |
|
46 | + } |
|
47 | 47 | |
48 | - public function handle() { |
|
49 | - $userManager = \OC::$server->getUserManager(); |
|
50 | - if (!$userManager->userExists($this->user)) { |
|
51 | - // User has been deleted already |
|
52 | - return; |
|
53 | - } |
|
48 | + public function handle() { |
|
49 | + $userManager = \OC::$server->getUserManager(); |
|
50 | + if (!$userManager->userExists($this->user)) { |
|
51 | + // User has been deleted already |
|
52 | + return; |
|
53 | + } |
|
54 | 54 | |
55 | - \OC_Util::tearDownFS(); |
|
56 | - \OC_Util::setupFS($this->user); |
|
57 | - Trashbin::expire($this->user); |
|
58 | - \OC_Util::tearDownFS(); |
|
59 | - } |
|
55 | + \OC_Util::tearDownFS(); |
|
56 | + \OC_Util::setupFS($this->user); |
|
57 | + Trashbin::expire($this->user); |
|
58 | + \OC_Util::tearDownFS(); |
|
59 | + } |
|
60 | 60 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } else { |
91 | 91 | $p = new ProgressBar($output); |
92 | 92 | $p->start(); |
93 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
93 | + $this->userManager->callForSeenUsers(function(IUser $user) use ($p) { |
|
94 | 94 | $p->advance(); |
95 | 95 | $this->expireTrashForUser($user); |
96 | 96 | }); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | \OC_Util::setupFS($user); |
119 | 119 | |
120 | 120 | // Check if this user has a trashbin directory |
121 | - $view = new \OC\Files\View('/' . $user); |
|
121 | + $view = new \OC\Files\View('/'.$user); |
|
122 | 122 | if (!$view->is_dir('/files_trashbin/files')) { |
123 | 123 | return false; |
124 | 124 | } |
@@ -38,95 +38,95 @@ |
||
38 | 38 | |
39 | 39 | class ExpireTrash extends Command { |
40 | 40 | |
41 | - /** |
|
42 | - * @var Expiration |
|
43 | - */ |
|
44 | - private $expiration; |
|
41 | + /** |
|
42 | + * @var Expiration |
|
43 | + */ |
|
44 | + private $expiration; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var IUserManager |
|
48 | - */ |
|
49 | - private $userManager; |
|
46 | + /** |
|
47 | + * @var IUserManager |
|
48 | + */ |
|
49 | + private $userManager; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param IUserManager|null $userManager |
|
53 | - * @param Expiration|null $expiration |
|
54 | - */ |
|
55 | - public function __construct(IUserManager $userManager = null, |
|
56 | - Expiration $expiration = null) { |
|
57 | - parent::__construct(); |
|
51 | + /** |
|
52 | + * @param IUserManager|null $userManager |
|
53 | + * @param Expiration|null $expiration |
|
54 | + */ |
|
55 | + public function __construct(IUserManager $userManager = null, |
|
56 | + Expiration $expiration = null) { |
|
57 | + parent::__construct(); |
|
58 | 58 | |
59 | - $this->userManager = $userManager; |
|
60 | - $this->expiration = $expiration; |
|
61 | - } |
|
59 | + $this->userManager = $userManager; |
|
60 | + $this->expiration = $expiration; |
|
61 | + } |
|
62 | 62 | |
63 | - protected function configure() { |
|
64 | - $this |
|
65 | - ->setName('trashbin:expire') |
|
66 | - ->setDescription('Expires the users trashbin') |
|
67 | - ->addArgument( |
|
68 | - 'user_id', |
|
69 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
70 | - 'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired' |
|
71 | - ); |
|
72 | - } |
|
63 | + protected function configure() { |
|
64 | + $this |
|
65 | + ->setName('trashbin:expire') |
|
66 | + ->setDescription('Expires the users trashbin') |
|
67 | + ->addArgument( |
|
68 | + 'user_id', |
|
69 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
70 | + 'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired' |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
75 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
76 | - if (!$maxAge) { |
|
77 | - $output->writeln("No expiry configured."); |
|
78 | - return 1; |
|
79 | - } |
|
74 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
75 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
76 | + if (!$maxAge) { |
|
77 | + $output->writeln("No expiry configured."); |
|
78 | + return 1; |
|
79 | + } |
|
80 | 80 | |
81 | - $users = $input->getArgument('user_id'); |
|
82 | - if (!empty($users)) { |
|
83 | - foreach ($users as $user) { |
|
84 | - if ($this->userManager->userExists($user)) { |
|
85 | - $output->writeln("Remove deleted files of <info>$user</info>"); |
|
86 | - $userObject = $this->userManager->get($user); |
|
87 | - $this->expireTrashForUser($userObject); |
|
88 | - } else { |
|
89 | - $output->writeln("<error>Unknown user $user</error>"); |
|
90 | - return 1; |
|
91 | - } |
|
92 | - } |
|
93 | - } else { |
|
94 | - $p = new ProgressBar($output); |
|
95 | - $p->start(); |
|
96 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
97 | - $p->advance(); |
|
98 | - $this->expireTrashForUser($user); |
|
99 | - }); |
|
100 | - $p->finish(); |
|
101 | - $output->writeln(''); |
|
102 | - } |
|
103 | - return 0; |
|
104 | - } |
|
81 | + $users = $input->getArgument('user_id'); |
|
82 | + if (!empty($users)) { |
|
83 | + foreach ($users as $user) { |
|
84 | + if ($this->userManager->userExists($user)) { |
|
85 | + $output->writeln("Remove deleted files of <info>$user</info>"); |
|
86 | + $userObject = $this->userManager->get($user); |
|
87 | + $this->expireTrashForUser($userObject); |
|
88 | + } else { |
|
89 | + $output->writeln("<error>Unknown user $user</error>"); |
|
90 | + return 1; |
|
91 | + } |
|
92 | + } |
|
93 | + } else { |
|
94 | + $p = new ProgressBar($output); |
|
95 | + $p->start(); |
|
96 | + $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
97 | + $p->advance(); |
|
98 | + $this->expireTrashForUser($user); |
|
99 | + }); |
|
100 | + $p->finish(); |
|
101 | + $output->writeln(''); |
|
102 | + } |
|
103 | + return 0; |
|
104 | + } |
|
105 | 105 | |
106 | - public function expireTrashForUser(IUser $user) { |
|
107 | - $uid = $user->getUID(); |
|
108 | - if (!$this->setupFS($uid)) { |
|
109 | - return; |
|
110 | - } |
|
111 | - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
112 | - Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
113 | - } |
|
106 | + public function expireTrashForUser(IUser $user) { |
|
107 | + $uid = $user->getUID(); |
|
108 | + if (!$this->setupFS($uid)) { |
|
109 | + return; |
|
110 | + } |
|
111 | + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
112 | + Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Act on behalf on trash item owner |
|
117 | - * @param string $user |
|
118 | - * @return boolean |
|
119 | - */ |
|
120 | - protected function setupFS($user) { |
|
121 | - \OC_Util::tearDownFS(); |
|
122 | - \OC_Util::setupFS($user); |
|
115 | + /** |
|
116 | + * Act on behalf on trash item owner |
|
117 | + * @param string $user |
|
118 | + * @return boolean |
|
119 | + */ |
|
120 | + protected function setupFS($user) { |
|
121 | + \OC_Util::tearDownFS(); |
|
122 | + \OC_Util::setupFS($user); |
|
123 | 123 | |
124 | - // Check if this user has a trashbin directory |
|
125 | - $view = new \OC\Files\View('/' . $user); |
|
126 | - if (!$view->is_dir('/files_trashbin/files')) { |
|
127 | - return false; |
|
128 | - } |
|
124 | + // Check if this user has a trashbin directory |
|
125 | + $view = new \OC\Files\View('/' . $user); |
|
126 | + if (!$view->is_dir('/files_trashbin/files')) { |
|
127 | + return false; |
|
128 | + } |
|
129 | 129 | |
130 | - return true; |
|
131 | - } |
|
130 | + return true; |
|
131 | + } |
|
132 | 132 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
81 | + $this->userManager->callForSeenUsers(function(IUser $user) { |
|
82 | 82 | $uid = $user->getUID(); |
83 | 83 | if (!$this->setupFS($uid)) { |
84 | 84 | return; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | \OC_Util::setupFS($user); |
101 | 101 | |
102 | 102 | // Check if this user has a trashbin directory |
103 | - $view = new \OC\Files\View('/' . $user); |
|
103 | + $view = new \OC\Files\View('/'.$user); |
|
104 | 104 | if (!$view->is_dir('/files_trashbin/files')) { |
105 | 105 | return false; |
106 | 106 | } |
@@ -36,77 +36,77 @@ |
||
36 | 36 | |
37 | 37 | class ExpireTrash extends \OC\BackgroundJob\TimedJob { |
38 | 38 | |
39 | - /** |
|
40 | - * @var Expiration |
|
41 | - */ |
|
42 | - private $expiration; |
|
39 | + /** |
|
40 | + * @var Expiration |
|
41 | + */ |
|
42 | + private $expiration; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var IUserManager |
|
46 | - */ |
|
47 | - private $userManager; |
|
44 | + /** |
|
45 | + * @var IUserManager |
|
46 | + */ |
|
47 | + private $userManager; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param IUserManager|null $userManager |
|
51 | - * @param Expiration|null $expiration |
|
52 | - */ |
|
53 | - public function __construct(IUserManager $userManager = null, |
|
54 | - Expiration $expiration = null) { |
|
55 | - // Run once per 30 minutes |
|
56 | - $this->setInterval(60 * 30); |
|
49 | + /** |
|
50 | + * @param IUserManager|null $userManager |
|
51 | + * @param Expiration|null $expiration |
|
52 | + */ |
|
53 | + public function __construct(IUserManager $userManager = null, |
|
54 | + Expiration $expiration = null) { |
|
55 | + // Run once per 30 minutes |
|
56 | + $this->setInterval(60 * 30); |
|
57 | 57 | |
58 | - if (is_null($expiration) || is_null($userManager)) { |
|
59 | - $this->fixDIForJobs(); |
|
60 | - } else { |
|
61 | - $this->userManager = $userManager; |
|
62 | - $this->expiration = $expiration; |
|
63 | - } |
|
64 | - } |
|
58 | + if (is_null($expiration) || is_null($userManager)) { |
|
59 | + $this->fixDIForJobs(); |
|
60 | + } else { |
|
61 | + $this->userManager = $userManager; |
|
62 | + $this->expiration = $expiration; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - protected function fixDIForJobs() { |
|
67 | - /** @var Application $application */ |
|
68 | - $application = \OC::$server->query(Application::class); |
|
69 | - $this->userManager = \OC::$server->getUserManager(); |
|
70 | - $this->expiration = $application->getContainer()->query('Expiration'); |
|
71 | - } |
|
66 | + protected function fixDIForJobs() { |
|
67 | + /** @var Application $application */ |
|
68 | + $application = \OC::$server->query(Application::class); |
|
69 | + $this->userManager = \OC::$server->getUserManager(); |
|
70 | + $this->expiration = $application->getContainer()->query('Expiration'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param $argument |
|
75 | - * @throws \Exception |
|
76 | - */ |
|
77 | - protected function run($argument) { |
|
78 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
79 | - if (!$maxAge) { |
|
80 | - return; |
|
81 | - } |
|
73 | + /** |
|
74 | + * @param $argument |
|
75 | + * @throws \Exception |
|
76 | + */ |
|
77 | + protected function run($argument) { |
|
78 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
79 | + if (!$maxAge) { |
|
80 | + return; |
|
81 | + } |
|
82 | 82 | |
83 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
84 | - $uid = $user->getUID(); |
|
85 | - if (!$this->setupFS($uid)) { |
|
86 | - return; |
|
87 | - } |
|
88 | - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
89 | - Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
90 | - }); |
|
83 | + $this->userManager->callForSeenUsers(function (IUser $user) { |
|
84 | + $uid = $user->getUID(); |
|
85 | + if (!$this->setupFS($uid)) { |
|
86 | + return; |
|
87 | + } |
|
88 | + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
89 | + Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
90 | + }); |
|
91 | 91 | |
92 | - \OC_Util::tearDownFS(); |
|
93 | - } |
|
92 | + \OC_Util::tearDownFS(); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Act on behalf on trash item owner |
|
97 | - * @param string $user |
|
98 | - * @return boolean |
|
99 | - */ |
|
100 | - protected function setupFS($user) { |
|
101 | - \OC_Util::tearDownFS(); |
|
102 | - \OC_Util::setupFS($user); |
|
95 | + /** |
|
96 | + * Act on behalf on trash item owner |
|
97 | + * @param string $user |
|
98 | + * @return boolean |
|
99 | + */ |
|
100 | + protected function setupFS($user) { |
|
101 | + \OC_Util::tearDownFS(); |
|
102 | + \OC_Util::setupFS($user); |
|
103 | 103 | |
104 | - // Check if this user has a trashbin directory |
|
105 | - $view = new \OC\Files\View('/' . $user); |
|
106 | - if (!$view->is_dir('/files_trashbin/files')) { |
|
107 | - return false; |
|
108 | - } |
|
104 | + // Check if this user has a trashbin directory |
|
105 | + $view = new \OC\Files\View('/' . $user); |
|
106 | + if (!$view->is_dir('/files_trashbin/files')) { |
|
107 | + return false; |
|
108 | + } |
|
109 | 109 | |
110 | - return true; |
|
111 | - } |
|
110 | + return true; |
|
111 | + } |
|
112 | 112 | } |
@@ -27,91 +27,91 @@ |
||
27 | 27 | use OCP\Notification\IManager; |
28 | 28 | |
29 | 29 | class Listener { |
30 | - /** @var IManager */ |
|
31 | - protected $notificationManager; |
|
30 | + /** @var IManager */ |
|
31 | + protected $notificationManager; |
|
32 | 32 | |
33 | - /** @var IUserManager */ |
|
34 | - protected $userManager; |
|
33 | + /** @var IUserManager */ |
|
34 | + protected $userManager; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Listener constructor. |
|
38 | - * |
|
39 | - * @param IManager $notificationManager |
|
40 | - * @param IUserManager $userManager |
|
41 | - */ |
|
42 | - public function __construct( |
|
43 | - IManager $notificationManager, |
|
44 | - IUserManager $userManager |
|
45 | - ) { |
|
46 | - $this->notificationManager = $notificationManager; |
|
47 | - $this->userManager = $userManager; |
|
48 | - } |
|
36 | + /** |
|
37 | + * Listener constructor. |
|
38 | + * |
|
39 | + * @param IManager $notificationManager |
|
40 | + * @param IUserManager $userManager |
|
41 | + */ |
|
42 | + public function __construct( |
|
43 | + IManager $notificationManager, |
|
44 | + IUserManager $userManager |
|
45 | + ) { |
|
46 | + $this->notificationManager = $notificationManager; |
|
47 | + $this->userManager = $userManager; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param CommentsEvent $event |
|
52 | - */ |
|
53 | - public function evaluate(CommentsEvent $event) { |
|
54 | - $comment = $event->getComment(); |
|
50 | + /** |
|
51 | + * @param CommentsEvent $event |
|
52 | + */ |
|
53 | + public function evaluate(CommentsEvent $event) { |
|
54 | + $comment = $event->getComment(); |
|
55 | 55 | |
56 | - $mentions = $this->extractMentions($comment->getMentions()); |
|
57 | - if (empty($mentions)) { |
|
58 | - // no one to notify |
|
59 | - return; |
|
60 | - } |
|
56 | + $mentions = $this->extractMentions($comment->getMentions()); |
|
57 | + if (empty($mentions)) { |
|
58 | + // no one to notify |
|
59 | + return; |
|
60 | + } |
|
61 | 61 | |
62 | - $notification = $this->instantiateNotification($comment); |
|
62 | + $notification = $this->instantiateNotification($comment); |
|
63 | 63 | |
64 | - foreach ($mentions as $uid) { |
|
65 | - if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
66 | - || !$this->userManager->userExists($uid) |
|
67 | - ) { |
|
68 | - // do not notify unknown users or yourself |
|
69 | - continue; |
|
70 | - } |
|
64 | + foreach ($mentions as $uid) { |
|
65 | + if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
66 | + || !$this->userManager->userExists($uid) |
|
67 | + ) { |
|
68 | + // do not notify unknown users or yourself |
|
69 | + continue; |
|
70 | + } |
|
71 | 71 | |
72 | - $notification->setUser($uid); |
|
73 | - if ($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
74 | - || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) { |
|
75 | - $this->notificationManager->markProcessed($notification); |
|
76 | - } else { |
|
77 | - $this->notificationManager->notify($notification); |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
72 | + $notification->setUser($uid); |
|
73 | + if ($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
74 | + || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) { |
|
75 | + $this->notificationManager->markProcessed($notification); |
|
76 | + } else { |
|
77 | + $this->notificationManager->notify($notification); |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * creates a notification instance and fills it with comment data |
|
84 | - * |
|
85 | - * @param IComment $comment |
|
86 | - * @return \OCP\Notification\INotification |
|
87 | - */ |
|
88 | - public function instantiateNotification(IComment $comment) { |
|
89 | - $notification = $this->notificationManager->createNotification(); |
|
90 | - $notification |
|
91 | - ->setApp('comments') |
|
92 | - ->setObject('comment', $comment->getId()) |
|
93 | - ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
94 | - ->setDateTime($comment->getCreationDateTime()); |
|
82 | + /** |
|
83 | + * creates a notification instance and fills it with comment data |
|
84 | + * |
|
85 | + * @param IComment $comment |
|
86 | + * @return \OCP\Notification\INotification |
|
87 | + */ |
|
88 | + public function instantiateNotification(IComment $comment) { |
|
89 | + $notification = $this->notificationManager->createNotification(); |
|
90 | + $notification |
|
91 | + ->setApp('comments') |
|
92 | + ->setObject('comment', $comment->getId()) |
|
93 | + ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
94 | + ->setDateTime($comment->getCreationDateTime()); |
|
95 | 95 | |
96 | - return $notification; |
|
97 | - } |
|
96 | + return $notification; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * flattens the mention array returned from comments to a list of user ids. |
|
101 | - * |
|
102 | - * @param array $mentions |
|
103 | - * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
|
104 | - */ |
|
105 | - public function extractMentions(array $mentions) { |
|
106 | - if (empty($mentions)) { |
|
107 | - return []; |
|
108 | - } |
|
109 | - $uids = []; |
|
110 | - foreach ($mentions as $mention) { |
|
111 | - if ($mention['type'] === 'user') { |
|
112 | - $uids[] = $mention['id']; |
|
113 | - } |
|
114 | - } |
|
115 | - return $uids; |
|
116 | - } |
|
99 | + /** |
|
100 | + * flattens the mention array returned from comments to a list of user ids. |
|
101 | + * |
|
102 | + * @param array $mentions |
|
103 | + * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
|
104 | + */ |
|
105 | + public function extractMentions(array $mentions) { |
|
106 | + if (empty($mentions)) { |
|
107 | + return []; |
|
108 | + } |
|
109 | + $uids = []; |
|
110 | + foreach ($mentions as $mention) { |
|
111 | + if ($mention['type'] === 'user') { |
|
112 | + $uids[] = $mention['id']; |
|
113 | + } |
|
114 | + } |
|
115 | + return $uids; |
|
116 | + } |
|
117 | 117 | } |
@@ -90,7 +90,7 @@ |
||
90 | 90 | $notification |
91 | 91 | ->setApp('comments') |
92 | 92 | ->setObject('comment', $comment->getId()) |
93 | - ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
93 | + ->setSubject('mention', [$comment->getObjectType(), $comment->getObjectId()]) |
|
94 | 94 | ->setDateTime($comment->getCreationDateTime()); |
95 | 95 | |
96 | 96 | return $notification; |