@@ -25,19 +25,19 @@ |
||
25 | 25 | namespace OCA\Files_External\Config; |
26 | 26 | |
27 | 27 | class UserPlaceholderHandler extends UserContext implements IConfigHandler { |
28 | - use SimpleSubstitutionTrait; |
|
28 | + use SimpleSubstitutionTrait; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param mixed $optionValue |
|
32 | - * @return mixed the same type as $optionValue |
|
33 | - * @since 16.0.0 |
|
34 | - */ |
|
35 | - public function handle($optionValue) { |
|
36 | - $this->placeholder = 'user'; |
|
37 | - $uid = $this->getUserId(); |
|
38 | - if ($uid === null) { |
|
39 | - return $optionValue; |
|
40 | - } |
|
41 | - return $this->processInput($optionValue, $uid); |
|
42 | - } |
|
30 | + /** |
|
31 | + * @param mixed $optionValue |
|
32 | + * @return mixed the same type as $optionValue |
|
33 | + * @since 16.0.0 |
|
34 | + */ |
|
35 | + public function handle($optionValue) { |
|
36 | + $this->placeholder = 'user'; |
|
37 | + $uid = $this->getUserId(); |
|
38 | + if ($uid === null) { |
|
39 | + return $optionValue; |
|
40 | + } |
|
41 | + return $this->processInput($optionValue, $uid); |
|
42 | + } |
|
43 | 43 | } |
@@ -31,57 +31,57 @@ |
||
31 | 31 | * @since 16.0.0 |
32 | 32 | */ |
33 | 33 | trait SimpleSubstitutionTrait { |
34 | - /** |
|
35 | - * @var string the placeholder without $ prefix |
|
36 | - * @since 16.0.0 |
|
37 | - */ |
|
38 | - protected $placeholder; |
|
34 | + /** |
|
35 | + * @var string the placeholder without $ prefix |
|
36 | + * @since 16.0.0 |
|
37 | + */ |
|
38 | + protected $placeholder; |
|
39 | 39 | |
40 | - /** @var string */ |
|
41 | - protected $sanitizedPlaceholder; |
|
40 | + /** @var string */ |
|
41 | + protected $sanitizedPlaceholder; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param mixed $optionValue |
|
45 | - * @param string $replacement |
|
46 | - * @return mixed |
|
47 | - * @since 16.0.0 |
|
48 | - */ |
|
49 | - private function processInput($optionValue, string $replacement) { |
|
50 | - $this->checkPlaceholder(); |
|
51 | - if (is_array($optionValue)) { |
|
52 | - foreach ($optionValue as &$value) { |
|
53 | - $value = $this->substituteIfString($value, $replacement); |
|
54 | - } |
|
55 | - } else { |
|
56 | - $optionValue = $this->substituteIfString($optionValue, $replacement); |
|
57 | - } |
|
58 | - return $optionValue; |
|
59 | - } |
|
43 | + /** |
|
44 | + * @param mixed $optionValue |
|
45 | + * @param string $replacement |
|
46 | + * @return mixed |
|
47 | + * @since 16.0.0 |
|
48 | + */ |
|
49 | + private function processInput($optionValue, string $replacement) { |
|
50 | + $this->checkPlaceholder(); |
|
51 | + if (is_array($optionValue)) { |
|
52 | + foreach ($optionValue as &$value) { |
|
53 | + $value = $this->substituteIfString($value, $replacement); |
|
54 | + } |
|
55 | + } else { |
|
56 | + $optionValue = $this->substituteIfString($optionValue, $replacement); |
|
57 | + } |
|
58 | + return $optionValue; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @throws \RuntimeException |
|
63 | - */ |
|
64 | - protected function checkPlaceholder(): void { |
|
65 | - $this->sanitizedPlaceholder = trim(strtolower($this->placeholder)); |
|
66 | - if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) { |
|
67 | - throw new \RuntimeException(sprintf( |
|
68 | - 'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder |
|
69 | - )); |
|
70 | - } |
|
71 | - if ($this->sanitizedPlaceholder === '') { |
|
72 | - throw new \RuntimeException('Invalid empty placeholder'); |
|
73 | - } |
|
74 | - } |
|
61 | + /** |
|
62 | + * @throws \RuntimeException |
|
63 | + */ |
|
64 | + protected function checkPlaceholder(): void { |
|
65 | + $this->sanitizedPlaceholder = trim(strtolower($this->placeholder)); |
|
66 | + if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) { |
|
67 | + throw new \RuntimeException(sprintf( |
|
68 | + 'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder |
|
69 | + )); |
|
70 | + } |
|
71 | + if ($this->sanitizedPlaceholder === '') { |
|
72 | + throw new \RuntimeException('Invalid empty placeholder'); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param mixed $value |
|
78 | - * @param string $replacement |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - protected function substituteIfString($value, string $replacement) { |
|
82 | - if (is_string($value)) { |
|
83 | - return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value); |
|
84 | - } |
|
85 | - return $value; |
|
86 | - } |
|
76 | + /** |
|
77 | + * @param mixed $value |
|
78 | + * @param string $replacement |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + protected function substituteIfString($value, string $replacement) { |
|
82 | + if (is_string($value)) { |
|
83 | + return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value); |
|
84 | + } |
|
85 | + return $value; |
|
86 | + } |
|
87 | 87 | } |
@@ -33,58 +33,58 @@ |
||
33 | 33 | |
34 | 34 | class UserContext { |
35 | 35 | |
36 | - /** @var IUserSession */ |
|
37 | - private $session; |
|
36 | + /** @var IUserSession */ |
|
37 | + private $session; |
|
38 | 38 | |
39 | - /** @var ShareManager */ |
|
40 | - private $shareManager; |
|
39 | + /** @var ShareManager */ |
|
40 | + private $shareManager; |
|
41 | 41 | |
42 | - /** @var IRequest */ |
|
43 | - private $request; |
|
42 | + /** @var IRequest */ |
|
43 | + private $request; |
|
44 | 44 | |
45 | - /** @var string */ |
|
46 | - private $userId; |
|
45 | + /** @var string */ |
|
46 | + private $userId; |
|
47 | 47 | |
48 | - /** @var IUserManager */ |
|
49 | - private $userManager; |
|
48 | + /** @var IUserManager */ |
|
49 | + private $userManager; |
|
50 | 50 | |
51 | - public function __construct(IUserSession $session, ShareManager $manager, IRequest $request, IUserManager $userManager) { |
|
52 | - $this->session = $session; |
|
53 | - $this->shareManager = $manager; |
|
54 | - $this->request = $request; |
|
55 | - $this->userManager = $userManager; |
|
56 | - } |
|
51 | + public function __construct(IUserSession $session, ShareManager $manager, IRequest $request, IUserManager $userManager) { |
|
52 | + $this->session = $session; |
|
53 | + $this->shareManager = $manager; |
|
54 | + $this->request = $request; |
|
55 | + $this->userManager = $userManager; |
|
56 | + } |
|
57 | 57 | |
58 | - public function getSession(): IUserSession { |
|
59 | - return $this->session; |
|
60 | - } |
|
58 | + public function getSession(): IUserSession { |
|
59 | + return $this->session; |
|
60 | + } |
|
61 | 61 | |
62 | - public function setUserId(string $userId): void { |
|
63 | - $this->userId = $userId; |
|
64 | - } |
|
62 | + public function setUserId(string $userId): void { |
|
63 | + $this->userId = $userId; |
|
64 | + } |
|
65 | 65 | |
66 | - protected function getUserId(): ?string { |
|
67 | - if ($this->userId !== null) { |
|
68 | - return $this->userId; |
|
69 | - } |
|
70 | - if ($this->session && $this->session->getUser() !== null) { |
|
71 | - return $this->session->getUser()->getUID(); |
|
72 | - } |
|
73 | - try { |
|
74 | - $shareToken = $this->request->getParam('token'); |
|
75 | - $share = $this->shareManager->getShareByToken($shareToken); |
|
76 | - return $share->getShareOwner(); |
|
77 | - } catch (ShareNotFound $e) { |
|
78 | - } |
|
66 | + protected function getUserId(): ?string { |
|
67 | + if ($this->userId !== null) { |
|
68 | + return $this->userId; |
|
69 | + } |
|
70 | + if ($this->session && $this->session->getUser() !== null) { |
|
71 | + return $this->session->getUser()->getUID(); |
|
72 | + } |
|
73 | + try { |
|
74 | + $shareToken = $this->request->getParam('token'); |
|
75 | + $share = $this->shareManager->getShareByToken($shareToken); |
|
76 | + return $share->getShareOwner(); |
|
77 | + } catch (ShareNotFound $e) { |
|
78 | + } |
|
79 | 79 | |
80 | - return null; |
|
81 | - } |
|
80 | + return null; |
|
81 | + } |
|
82 | 82 | |
83 | - protected function getUser(): ?IUser { |
|
84 | - $userId = $this->getUserId(); |
|
85 | - if ($userId !== null) { |
|
86 | - return $this->userManager->get($userId); |
|
87 | - } |
|
88 | - return null; |
|
89 | - } |
|
83 | + protected function getUser(): ?IUser { |
|
84 | + $userId = $this->getUserId(); |
|
85 | + if ($userId !== null) { |
|
86 | + return $this->userManager->get($userId); |
|
87 | + } |
|
88 | + return null; |
|
89 | + } |
|
90 | 90 | } |
@@ -38,120 +38,120 @@ |
||
38 | 38 | */ |
39 | 39 | class AddressHandler { |
40 | 40 | |
41 | - /** @var IL10N */ |
|
42 | - private $l; |
|
43 | - |
|
44 | - /** @var IURLGenerator */ |
|
45 | - private $urlGenerator; |
|
46 | - |
|
47 | - /** @var ICloudIdManager */ |
|
48 | - private $cloudIdManager; |
|
49 | - |
|
50 | - /** |
|
51 | - * AddressHandler constructor. |
|
52 | - * |
|
53 | - * @param IURLGenerator $urlGenerator |
|
54 | - * @param IL10N $il10n |
|
55 | - * @param ICloudIdManager $cloudIdManager |
|
56 | - */ |
|
57 | - public function __construct( |
|
58 | - IURLGenerator $urlGenerator, |
|
59 | - IL10N $il10n, |
|
60 | - ICloudIdManager $cloudIdManager |
|
61 | - ) { |
|
62 | - $this->l = $il10n; |
|
63 | - $this->urlGenerator = $urlGenerator; |
|
64 | - $this->cloudIdManager = $cloudIdManager; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * split user and remote from federated cloud id |
|
69 | - * |
|
70 | - * @param string $address federated share address |
|
71 | - * @return array [user, remoteURL] |
|
72 | - * @throws HintException |
|
73 | - */ |
|
74 | - public function splitUserRemote($address) { |
|
75 | - try { |
|
76 | - $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
77 | - return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
78 | - } catch (\InvalidArgumentException $e) { |
|
79 | - $hint = $this->l->t('Invalid Federated Cloud ID'); |
|
80 | - throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * generate remote URL part of federated ID |
|
86 | - * |
|
87 | - * @return string url of the current server |
|
88 | - */ |
|
89 | - public function generateRemoteURL() { |
|
90 | - return $this->urlGenerator->getAbsoluteURL('/'); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * check if two federated cloud IDs refer to the same user |
|
95 | - * |
|
96 | - * @param string $user1 |
|
97 | - * @param string $server1 |
|
98 | - * @param string $user2 |
|
99 | - * @param string $server2 |
|
100 | - * @return bool true if both users and servers are the same |
|
101 | - */ |
|
102 | - public function compareAddresses($user1, $server1, $user2, $server2) { |
|
103 | - $normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1)); |
|
104 | - $normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2)); |
|
105 | - |
|
106 | - if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
107 | - // FIXME this should be a method in the user management instead |
|
108 | - \OCP\Util::emitHook( |
|
109 | - '\OCA\Files_Sharing\API\Server2Server', |
|
110 | - 'preLoginNameUsedAsUserName', |
|
111 | - ['uid' => &$user1] |
|
112 | - ); |
|
113 | - \OCP\Util::emitHook( |
|
114 | - '\OCA\Files_Sharing\API\Server2Server', |
|
115 | - 'preLoginNameUsedAsUserName', |
|
116 | - ['uid' => &$user2] |
|
117 | - ); |
|
118 | - |
|
119 | - if ($user1 === $user2) { |
|
120 | - return true; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - return false; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * remove protocol from URL |
|
129 | - * |
|
130 | - * @param string $url |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function removeProtocolFromUrl($url) { |
|
134 | - if (strpos($url, 'https://') === 0) { |
|
135 | - return substr($url, strlen('https://')); |
|
136 | - } elseif (strpos($url, 'http://') === 0) { |
|
137 | - return substr($url, strlen('http://')); |
|
138 | - } |
|
139 | - |
|
140 | - return $url; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * check if the url contain the protocol (http or https) |
|
145 | - * |
|
146 | - * @param string $url |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function urlContainProtocol($url) { |
|
150 | - if (strpos($url, 'https://') === 0 || |
|
151 | - strpos($url, 'http://') === 0) { |
|
152 | - return true; |
|
153 | - } |
|
154 | - |
|
155 | - return false; |
|
156 | - } |
|
41 | + /** @var IL10N */ |
|
42 | + private $l; |
|
43 | + |
|
44 | + /** @var IURLGenerator */ |
|
45 | + private $urlGenerator; |
|
46 | + |
|
47 | + /** @var ICloudIdManager */ |
|
48 | + private $cloudIdManager; |
|
49 | + |
|
50 | + /** |
|
51 | + * AddressHandler constructor. |
|
52 | + * |
|
53 | + * @param IURLGenerator $urlGenerator |
|
54 | + * @param IL10N $il10n |
|
55 | + * @param ICloudIdManager $cloudIdManager |
|
56 | + */ |
|
57 | + public function __construct( |
|
58 | + IURLGenerator $urlGenerator, |
|
59 | + IL10N $il10n, |
|
60 | + ICloudIdManager $cloudIdManager |
|
61 | + ) { |
|
62 | + $this->l = $il10n; |
|
63 | + $this->urlGenerator = $urlGenerator; |
|
64 | + $this->cloudIdManager = $cloudIdManager; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * split user and remote from federated cloud id |
|
69 | + * |
|
70 | + * @param string $address federated share address |
|
71 | + * @return array [user, remoteURL] |
|
72 | + * @throws HintException |
|
73 | + */ |
|
74 | + public function splitUserRemote($address) { |
|
75 | + try { |
|
76 | + $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
77 | + return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
78 | + } catch (\InvalidArgumentException $e) { |
|
79 | + $hint = $this->l->t('Invalid Federated Cloud ID'); |
|
80 | + throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * generate remote URL part of federated ID |
|
86 | + * |
|
87 | + * @return string url of the current server |
|
88 | + */ |
|
89 | + public function generateRemoteURL() { |
|
90 | + return $this->urlGenerator->getAbsoluteURL('/'); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * check if two federated cloud IDs refer to the same user |
|
95 | + * |
|
96 | + * @param string $user1 |
|
97 | + * @param string $server1 |
|
98 | + * @param string $user2 |
|
99 | + * @param string $server2 |
|
100 | + * @return bool true if both users and servers are the same |
|
101 | + */ |
|
102 | + public function compareAddresses($user1, $server1, $user2, $server2) { |
|
103 | + $normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1)); |
|
104 | + $normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2)); |
|
105 | + |
|
106 | + if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
107 | + // FIXME this should be a method in the user management instead |
|
108 | + \OCP\Util::emitHook( |
|
109 | + '\OCA\Files_Sharing\API\Server2Server', |
|
110 | + 'preLoginNameUsedAsUserName', |
|
111 | + ['uid' => &$user1] |
|
112 | + ); |
|
113 | + \OCP\Util::emitHook( |
|
114 | + '\OCA\Files_Sharing\API\Server2Server', |
|
115 | + 'preLoginNameUsedAsUserName', |
|
116 | + ['uid' => &$user2] |
|
117 | + ); |
|
118 | + |
|
119 | + if ($user1 === $user2) { |
|
120 | + return true; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + return false; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * remove protocol from URL |
|
129 | + * |
|
130 | + * @param string $url |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function removeProtocolFromUrl($url) { |
|
134 | + if (strpos($url, 'https://') === 0) { |
|
135 | + return substr($url, strlen('https://')); |
|
136 | + } elseif (strpos($url, 'http://') === 0) { |
|
137 | + return substr($url, strlen('http://')); |
|
138 | + } |
|
139 | + |
|
140 | + return $url; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * check if the url contain the protocol (http or https) |
|
145 | + * |
|
146 | + * @param string $url |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function urlContainProtocol($url) { |
|
150 | + if (strpos($url, 'https://') === 0 || |
|
151 | + strpos($url, 'http://') === 0) { |
|
152 | + return true; |
|
153 | + } |
|
154 | + |
|
155 | + return false; |
|
156 | + } |
|
157 | 157 | } |
@@ -36,44 +36,44 @@ |
||
36 | 36 | |
37 | 37 | class SetTokenExpiration implements IRepairStep { |
38 | 38 | |
39 | - /** @var IDBConnection */ |
|
40 | - private $connection; |
|
39 | + /** @var IDBConnection */ |
|
40 | + private $connection; |
|
41 | 41 | |
42 | - /** @var ITimeFactory */ |
|
43 | - private $time; |
|
42 | + /** @var ITimeFactory */ |
|
43 | + private $time; |
|
44 | 44 | |
45 | - /** @var TokenProvider */ |
|
46 | - private $tokenProvider; |
|
45 | + /** @var TokenProvider */ |
|
46 | + private $tokenProvider; |
|
47 | 47 | |
48 | - public function __construct(IDBConnection $connection, |
|
49 | - ITimeFactory $timeFactory, |
|
50 | - TokenProvider $tokenProvider) { |
|
51 | - $this->connection = $connection; |
|
52 | - $this->time = $timeFactory; |
|
53 | - $this->tokenProvider = $tokenProvider; |
|
54 | - } |
|
48 | + public function __construct(IDBConnection $connection, |
|
49 | + ITimeFactory $timeFactory, |
|
50 | + TokenProvider $tokenProvider) { |
|
51 | + $this->connection = $connection; |
|
52 | + $this->time = $timeFactory; |
|
53 | + $this->tokenProvider = $tokenProvider; |
|
54 | + } |
|
55 | 55 | |
56 | - public function getName(): string { |
|
57 | - return 'Update OAuth token expiration times'; |
|
58 | - } |
|
56 | + public function getName(): string { |
|
57 | + return 'Update OAuth token expiration times'; |
|
58 | + } |
|
59 | 59 | |
60 | - public function run(IOutput $output) { |
|
61 | - $qb = $this->connection->getQueryBuilder(); |
|
62 | - $qb->select('*') |
|
63 | - ->from('oauth2_access_tokens'); |
|
60 | + public function run(IOutput $output) { |
|
61 | + $qb = $this->connection->getQueryBuilder(); |
|
62 | + $qb->select('*') |
|
63 | + ->from('oauth2_access_tokens'); |
|
64 | 64 | |
65 | - $cursor = $qb->execute(); |
|
65 | + $cursor = $qb->execute(); |
|
66 | 66 | |
67 | - while ($row = $cursor->fetch()) { |
|
68 | - $token = AccessToken::fromRow($row); |
|
69 | - try { |
|
70 | - $appToken = $this->tokenProvider->getTokenById($token->getTokenId()); |
|
71 | - $appToken->setExpires($this->time->getTime() + 3600); |
|
72 | - $this->tokenProvider->updateToken($appToken); |
|
73 | - } catch (InvalidTokenException $e) { |
|
74 | - //Skip this token |
|
75 | - } |
|
76 | - } |
|
77 | - $cursor->closeCursor(); |
|
78 | - } |
|
67 | + while ($row = $cursor->fetch()) { |
|
68 | + $token = AccessToken::fromRow($row); |
|
69 | + try { |
|
70 | + $appToken = $this->tokenProvider->getTokenById($token->getTokenId()); |
|
71 | + $appToken->setExpires($this->time->getTime() + 3600); |
|
72 | + $this->tokenProvider->updateToken($appToken); |
|
73 | + } catch (InvalidTokenException $e) { |
|
74 | + //Skip this token |
|
75 | + } |
|
76 | + } |
|
77 | + $cursor->closeCursor(); |
|
78 | + } |
|
79 | 79 | } |
@@ -44,91 +44,91 @@ |
||
44 | 44 | use OCP\IUserSession; |
45 | 45 | |
46 | 46 | class PreviewController extends Controller { |
47 | - /** @var IRootFolder */ |
|
48 | - private $rootFolder; |
|
49 | - |
|
50 | - /** @var ITrashManager */ |
|
51 | - private $trashManager; |
|
52 | - |
|
53 | - /** @var IUserSession */ |
|
54 | - private $userSession; |
|
55 | - |
|
56 | - /** @var IMimeTypeDetector */ |
|
57 | - private $mimeTypeDetector; |
|
58 | - |
|
59 | - /** @var IPreview */ |
|
60 | - private $previewManager; |
|
61 | - |
|
62 | - /** @var ITimeFactory */ |
|
63 | - private $time; |
|
64 | - |
|
65 | - public function __construct( |
|
66 | - string $appName, |
|
67 | - IRequest $request, |
|
68 | - IRootFolder $rootFolder, |
|
69 | - ITrashManager $trashManager, |
|
70 | - IUserSession $userSession, |
|
71 | - IMimeTypeDetector $mimeTypeDetector, |
|
72 | - IPreview $previewManager, |
|
73 | - ITimeFactory $time |
|
74 | - ) { |
|
75 | - parent::__construct($appName, $request); |
|
76 | - |
|
77 | - $this->trashManager = $trashManager; |
|
78 | - $this->rootFolder = $rootFolder; |
|
79 | - $this->userSession = $userSession; |
|
80 | - $this->mimeTypeDetector = $mimeTypeDetector; |
|
81 | - $this->previewManager = $previewManager; |
|
82 | - $this->time = $time; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @NoAdminRequired |
|
87 | - * @NoCSRFRequired |
|
88 | - * |
|
89 | - * @return DataResponse|Http\FileDisplayResponse |
|
90 | - */ |
|
91 | - public function getPreview( |
|
92 | - int $fileId = -1, |
|
93 | - int $x = 128, |
|
94 | - int $y = 128 |
|
95 | - ) { |
|
96 | - if ($fileId === -1 || $x === 0 || $y === 0) { |
|
97 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
98 | - } |
|
99 | - |
|
100 | - try { |
|
101 | - $file = $this->trashManager->getTrashNodeById($this->userSession->getUser(), $fileId); |
|
102 | - if ($file === null) { |
|
103 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
104 | - } |
|
105 | - if ($file instanceof Folder) { |
|
106 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
107 | - } |
|
108 | - |
|
109 | - $pathParts = pathinfo($file->getName()); |
|
110 | - $extension = $pathParts['extension'] ?? ''; |
|
111 | - $fileName = $pathParts['filename']; |
|
112 | - /* |
|
47 | + /** @var IRootFolder */ |
|
48 | + private $rootFolder; |
|
49 | + |
|
50 | + /** @var ITrashManager */ |
|
51 | + private $trashManager; |
|
52 | + |
|
53 | + /** @var IUserSession */ |
|
54 | + private $userSession; |
|
55 | + |
|
56 | + /** @var IMimeTypeDetector */ |
|
57 | + private $mimeTypeDetector; |
|
58 | + |
|
59 | + /** @var IPreview */ |
|
60 | + private $previewManager; |
|
61 | + |
|
62 | + /** @var ITimeFactory */ |
|
63 | + private $time; |
|
64 | + |
|
65 | + public function __construct( |
|
66 | + string $appName, |
|
67 | + IRequest $request, |
|
68 | + IRootFolder $rootFolder, |
|
69 | + ITrashManager $trashManager, |
|
70 | + IUserSession $userSession, |
|
71 | + IMimeTypeDetector $mimeTypeDetector, |
|
72 | + IPreview $previewManager, |
|
73 | + ITimeFactory $time |
|
74 | + ) { |
|
75 | + parent::__construct($appName, $request); |
|
76 | + |
|
77 | + $this->trashManager = $trashManager; |
|
78 | + $this->rootFolder = $rootFolder; |
|
79 | + $this->userSession = $userSession; |
|
80 | + $this->mimeTypeDetector = $mimeTypeDetector; |
|
81 | + $this->previewManager = $previewManager; |
|
82 | + $this->time = $time; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @NoAdminRequired |
|
87 | + * @NoCSRFRequired |
|
88 | + * |
|
89 | + * @return DataResponse|Http\FileDisplayResponse |
|
90 | + */ |
|
91 | + public function getPreview( |
|
92 | + int $fileId = -1, |
|
93 | + int $x = 128, |
|
94 | + int $y = 128 |
|
95 | + ) { |
|
96 | + if ($fileId === -1 || $x === 0 || $y === 0) { |
|
97 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
98 | + } |
|
99 | + |
|
100 | + try { |
|
101 | + $file = $this->trashManager->getTrashNodeById($this->userSession->getUser(), $fileId); |
|
102 | + if ($file === null) { |
|
103 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
104 | + } |
|
105 | + if ($file instanceof Folder) { |
|
106 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
107 | + } |
|
108 | + |
|
109 | + $pathParts = pathinfo($file->getName()); |
|
110 | + $extension = $pathParts['extension'] ?? ''; |
|
111 | + $fileName = $pathParts['filename']; |
|
112 | + /* |
|
113 | 113 | * Files in the root of the trashbin are timetamped. |
114 | 114 | * So we have to strip that in order to properly detect the mimetype of the file. |
115 | 115 | */ |
116 | - if (preg_match('/d\d+/', $extension)) { |
|
117 | - $mimeType = $this->mimeTypeDetector->detectPath($fileName); |
|
118 | - } else { |
|
119 | - $mimeType = $this->mimeTypeDetector->detectPath($file->getName()); |
|
120 | - } |
|
121 | - |
|
122 | - $f = $this->previewManager->getPreview($file, $x, $y, true, IPreview::MODE_FILL, $mimeType); |
|
123 | - $response = new Http\FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
124 | - |
|
125 | - // Cache previews for 24H |
|
126 | - $response->cacheFor(3600 * 24); |
|
127 | - return $response; |
|
128 | - } catch (NotFoundException $e) { |
|
129 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
130 | - } catch (\InvalidArgumentException $e) { |
|
131 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
132 | - } |
|
133 | - } |
|
116 | + if (preg_match('/d\d+/', $extension)) { |
|
117 | + $mimeType = $this->mimeTypeDetector->detectPath($fileName); |
|
118 | + } else { |
|
119 | + $mimeType = $this->mimeTypeDetector->detectPath($file->getName()); |
|
120 | + } |
|
121 | + |
|
122 | + $f = $this->previewManager->getPreview($file, $x, $y, true, IPreview::MODE_FILL, $mimeType); |
|
123 | + $response = new Http\FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
124 | + |
|
125 | + // Cache previews for 24H |
|
126 | + $response->cacheFor(3600 * 24); |
|
127 | + return $response; |
|
128 | + } catch (NotFoundException $e) { |
|
129 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
130 | + } catch (\InvalidArgumentException $e) { |
|
131 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |
@@ -35,99 +35,99 @@ |
||
35 | 35 | use OCP\IUser; |
36 | 36 | |
37 | 37 | class LegacyTrashBackend implements ITrashBackend { |
38 | - /** @var array */ |
|
39 | - private $deletedFiles = []; |
|
38 | + /** @var array */ |
|
39 | + private $deletedFiles = []; |
|
40 | 40 | |
41 | - /** @var IRootFolder */ |
|
42 | - private $rootFolder; |
|
41 | + /** @var IRootFolder */ |
|
42 | + private $rootFolder; |
|
43 | 43 | |
44 | - public function __construct(IRootFolder $rootFolder) { |
|
45 | - $this->rootFolder = $rootFolder; |
|
46 | - } |
|
44 | + public function __construct(IRootFolder $rootFolder) { |
|
45 | + $this->rootFolder = $rootFolder; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param array $items |
|
50 | - * @param IUser $user |
|
51 | - * @param ITrashItem $parent |
|
52 | - * @return ITrashItem[] |
|
53 | - */ |
|
54 | - private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array { |
|
55 | - $parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : ''; |
|
56 | - $isRoot = $parent === null; |
|
57 | - return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) { |
|
58 | - $originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName(); |
|
59 | - if (!$originalLocation) { |
|
60 | - $originalLocation = $file->getName(); |
|
61 | - } |
|
62 | - return new TrashItem( |
|
63 | - $this, |
|
64 | - $originalLocation, |
|
65 | - $file->getMTime(), |
|
66 | - $parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''), |
|
67 | - $file, |
|
68 | - $user |
|
69 | - ); |
|
70 | - }, $items); |
|
71 | - } |
|
48 | + /** |
|
49 | + * @param array $items |
|
50 | + * @param IUser $user |
|
51 | + * @param ITrashItem $parent |
|
52 | + * @return ITrashItem[] |
|
53 | + */ |
|
54 | + private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array { |
|
55 | + $parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : ''; |
|
56 | + $isRoot = $parent === null; |
|
57 | + return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) { |
|
58 | + $originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName(); |
|
59 | + if (!$originalLocation) { |
|
60 | + $originalLocation = $file->getName(); |
|
61 | + } |
|
62 | + return new TrashItem( |
|
63 | + $this, |
|
64 | + $originalLocation, |
|
65 | + $file->getMTime(), |
|
66 | + $parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''), |
|
67 | + $file, |
|
68 | + $user |
|
69 | + ); |
|
70 | + }, $items); |
|
71 | + } |
|
72 | 72 | |
73 | - public function listTrashRoot(IUser $user): array { |
|
74 | - $entries = Helper::getTrashFiles('/', $user->getUID()); |
|
75 | - return $this->mapTrashItems($entries, $user); |
|
76 | - } |
|
73 | + public function listTrashRoot(IUser $user): array { |
|
74 | + $entries = Helper::getTrashFiles('/', $user->getUID()); |
|
75 | + return $this->mapTrashItems($entries, $user); |
|
76 | + } |
|
77 | 77 | |
78 | - public function listTrashFolder(ITrashItem $folder): array { |
|
79 | - $user = $folder->getUser(); |
|
80 | - $entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID()); |
|
81 | - return $this->mapTrashItems($entries, $user ,$folder); |
|
82 | - } |
|
78 | + public function listTrashFolder(ITrashItem $folder): array { |
|
79 | + $user = $folder->getUser(); |
|
80 | + $entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID()); |
|
81 | + return $this->mapTrashItems($entries, $user ,$folder); |
|
82 | + } |
|
83 | 83 | |
84 | - public function restoreItem(ITrashItem $item) { |
|
85 | - Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null); |
|
86 | - } |
|
84 | + public function restoreItem(ITrashItem $item) { |
|
85 | + Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null); |
|
86 | + } |
|
87 | 87 | |
88 | - public function removeItem(ITrashItem $item) { |
|
89 | - $user = $item->getUser(); |
|
90 | - if ($item->isRootItem()) { |
|
91 | - $path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime())); |
|
92 | - Trashbin::delete($path, $user->getUID(), $item->getDeletedTime()); |
|
93 | - } else { |
|
94 | - Trashbin::delete($item->getTrashPath(), $user->getUID(), null); |
|
95 | - } |
|
96 | - } |
|
88 | + public function removeItem(ITrashItem $item) { |
|
89 | + $user = $item->getUser(); |
|
90 | + if ($item->isRootItem()) { |
|
91 | + $path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime())); |
|
92 | + Trashbin::delete($path, $user->getUID(), $item->getDeletedTime()); |
|
93 | + } else { |
|
94 | + Trashbin::delete($item->getTrashPath(), $user->getUID(), null); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - public function moveToTrash(IStorage $storage, string $internalPath): bool { |
|
99 | - if (!$storage instanceof Storage) { |
|
100 | - return false; |
|
101 | - } |
|
102 | - $normalized = Filesystem::normalizePath($storage->getMountPoint() . '/' . $internalPath, true, false, true); |
|
103 | - $view = Filesystem::getView(); |
|
104 | - if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) { |
|
105 | - $this->deletedFiles[$normalized] = $normalized; |
|
106 | - if ($filesPath = $view->getRelativePath($normalized)) { |
|
107 | - $filesPath = trim($filesPath, '/'); |
|
108 | - $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath); |
|
109 | - } else { |
|
110 | - $result = false; |
|
111 | - } |
|
112 | - unset($this->deletedFiles[$normalized]); |
|
113 | - } else { |
|
114 | - $result = false; |
|
115 | - } |
|
98 | + public function moveToTrash(IStorage $storage, string $internalPath): bool { |
|
99 | + if (!$storage instanceof Storage) { |
|
100 | + return false; |
|
101 | + } |
|
102 | + $normalized = Filesystem::normalizePath($storage->getMountPoint() . '/' . $internalPath, true, false, true); |
|
103 | + $view = Filesystem::getView(); |
|
104 | + if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) { |
|
105 | + $this->deletedFiles[$normalized] = $normalized; |
|
106 | + if ($filesPath = $view->getRelativePath($normalized)) { |
|
107 | + $filesPath = trim($filesPath, '/'); |
|
108 | + $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath); |
|
109 | + } else { |
|
110 | + $result = false; |
|
111 | + } |
|
112 | + unset($this->deletedFiles[$normalized]); |
|
113 | + } else { |
|
114 | + $result = false; |
|
115 | + } |
|
116 | 116 | |
117 | - return $result; |
|
118 | - } |
|
117 | + return $result; |
|
118 | + } |
|
119 | 119 | |
120 | - public function getTrashNodeById(IUser $user, int $fileId) { |
|
121 | - try { |
|
122 | - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
123 | - $trash = $userFolder->getParent()->get('files_trashbin/files'); |
|
124 | - $trashFiles = $trash->getById($fileId); |
|
125 | - if (!$trashFiles) { |
|
126 | - return null; |
|
127 | - } |
|
128 | - return $trashFiles ? array_pop($trashFiles) : null; |
|
129 | - } catch (NotFoundException $e) { |
|
130 | - return null; |
|
131 | - } |
|
132 | - } |
|
120 | + public function getTrashNodeById(IUser $user, int $fileId) { |
|
121 | + try { |
|
122 | + $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
123 | + $trash = $userFolder->getParent()->get('files_trashbin/files'); |
|
124 | + $trashFiles = $trash->getById($fileId); |
|
125 | + if (!$trashFiles) { |
|
126 | + return null; |
|
127 | + } |
|
128 | + return $trashFiles ? array_pop($trashFiles) : null; |
|
129 | + } catch (NotFoundException $e) { |
|
130 | + return null; |
|
131 | + } |
|
132 | + } |
|
133 | 133 | } |
@@ -28,42 +28,42 @@ |
||
28 | 28 | use OCP\Migration\SimpleMigrationStep; |
29 | 29 | |
30 | 30 | class Version14000Date20180626223656 extends SimpleMigrationStep { |
31 | - public function changeSchema(\OCP\Migration\IOutput $output, \Closure $schemaClosure, array $options) { |
|
32 | - /** @var ISchemaWrapper $schema */ |
|
33 | - $schema = $schemaClosure(); |
|
34 | - if (!$schema->hasTable('whats_new')) { |
|
35 | - $table = $schema->createTable('whats_new'); |
|
36 | - $table->addColumn('id', 'integer', [ |
|
37 | - 'autoincrement' => true, |
|
38 | - 'notnull' => true, |
|
39 | - 'length' => 4, |
|
40 | - 'unsigned' => true, |
|
41 | - ]); |
|
42 | - $table->addColumn('version', 'string', [ |
|
43 | - 'notnull' => true, |
|
44 | - 'length' => 64, |
|
45 | - 'default' => '11', |
|
46 | - ]); |
|
47 | - $table->addColumn('etag', 'string', [ |
|
48 | - 'notnull' => true, |
|
49 | - 'length' => 64, |
|
50 | - 'default' => '', |
|
51 | - ]); |
|
52 | - $table->addColumn('last_check', 'integer', [ |
|
53 | - 'notnull' => true, |
|
54 | - 'length' => 4, |
|
55 | - 'unsigned' => true, |
|
56 | - 'default' => 0, |
|
57 | - ]); |
|
58 | - $table->addColumn('data', 'text', [ |
|
59 | - 'notnull' => true, |
|
60 | - 'default' => '', |
|
61 | - ]); |
|
62 | - $table->setPrimaryKey(['id']); |
|
63 | - $table->addUniqueIndex(['version'], 'version'); |
|
64 | - $table->addIndex(['version', 'etag'], 'version_etag_idx'); |
|
65 | - } |
|
31 | + public function changeSchema(\OCP\Migration\IOutput $output, \Closure $schemaClosure, array $options) { |
|
32 | + /** @var ISchemaWrapper $schema */ |
|
33 | + $schema = $schemaClosure(); |
|
34 | + if (!$schema->hasTable('whats_new')) { |
|
35 | + $table = $schema->createTable('whats_new'); |
|
36 | + $table->addColumn('id', 'integer', [ |
|
37 | + 'autoincrement' => true, |
|
38 | + 'notnull' => true, |
|
39 | + 'length' => 4, |
|
40 | + 'unsigned' => true, |
|
41 | + ]); |
|
42 | + $table->addColumn('version', 'string', [ |
|
43 | + 'notnull' => true, |
|
44 | + 'length' => 64, |
|
45 | + 'default' => '11', |
|
46 | + ]); |
|
47 | + $table->addColumn('etag', 'string', [ |
|
48 | + 'notnull' => true, |
|
49 | + 'length' => 64, |
|
50 | + 'default' => '', |
|
51 | + ]); |
|
52 | + $table->addColumn('last_check', 'integer', [ |
|
53 | + 'notnull' => true, |
|
54 | + 'length' => 4, |
|
55 | + 'unsigned' => true, |
|
56 | + 'default' => 0, |
|
57 | + ]); |
|
58 | + $table->addColumn('data', 'text', [ |
|
59 | + 'notnull' => true, |
|
60 | + 'default' => '', |
|
61 | + ]); |
|
62 | + $table->setPrimaryKey(['id']); |
|
63 | + $table->addUniqueIndex(['version'], 'version'); |
|
64 | + $table->addIndex(['version', 'etag'], 'version_etag_idx'); |
|
65 | + } |
|
66 | 66 | |
67 | - return $schema; |
|
68 | - } |
|
67 | + return $schema; |
|
68 | + } |
|
69 | 69 | } |
@@ -10,36 +10,36 @@ |
||
10 | 10 | use OCP\Migration\SimpleMigrationStep; |
11 | 11 | |
12 | 12 | class Version19000Date20200211083441 extends SimpleMigrationStep { |
13 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
14 | - /** @var ISchemaWrapper $schema */ |
|
15 | - $schema = $schemaClosure(); |
|
13 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
14 | + /** @var ISchemaWrapper $schema */ |
|
15 | + $schema = $schemaClosure(); |
|
16 | 16 | |
17 | - if (!$schema->hasTable('webauthn')) { |
|
18 | - $table = $schema->createTable('webauthn'); |
|
19 | - $table->addColumn('id', 'integer', [ |
|
20 | - 'autoincrement' => true, |
|
21 | - 'notnull' => true, |
|
22 | - 'length' => 64, |
|
23 | - ]); |
|
24 | - $table->addColumn('uid', 'string', [ |
|
25 | - 'notnull' => true, |
|
26 | - 'length' => 64, |
|
27 | - ]); |
|
28 | - $table->addColumn('name', 'string', [ |
|
29 | - 'notnull' => true, |
|
30 | - 'length' => 64, |
|
31 | - ]); |
|
32 | - $table->addColumn('public_key_credential_id', 'string', [ |
|
33 | - 'notnull' => true, |
|
34 | - 'length' => 255 |
|
35 | - ]); |
|
36 | - $table->addColumn('data', 'text', [ |
|
37 | - 'notnull' => true, |
|
38 | - ]); |
|
39 | - $table->setPrimaryKey(['id']); |
|
40 | - $table->addIndex(['uid'], 'webauthn_uid'); |
|
41 | - $table->addIndex(['public_key_credential_id'], 'webauthn_publicKeyCredentialId'); |
|
42 | - } |
|
43 | - return $schema; |
|
44 | - } |
|
17 | + if (!$schema->hasTable('webauthn')) { |
|
18 | + $table = $schema->createTable('webauthn'); |
|
19 | + $table->addColumn('id', 'integer', [ |
|
20 | + 'autoincrement' => true, |
|
21 | + 'notnull' => true, |
|
22 | + 'length' => 64, |
|
23 | + ]); |
|
24 | + $table->addColumn('uid', 'string', [ |
|
25 | + 'notnull' => true, |
|
26 | + 'length' => 64, |
|
27 | + ]); |
|
28 | + $table->addColumn('name', 'string', [ |
|
29 | + 'notnull' => true, |
|
30 | + 'length' => 64, |
|
31 | + ]); |
|
32 | + $table->addColumn('public_key_credential_id', 'string', [ |
|
33 | + 'notnull' => true, |
|
34 | + 'length' => 255 |
|
35 | + ]); |
|
36 | + $table->addColumn('data', 'text', [ |
|
37 | + 'notnull' => true, |
|
38 | + ]); |
|
39 | + $table->setPrimaryKey(['id']); |
|
40 | + $table->addIndex(['uid'], 'webauthn_uid'); |
|
41 | + $table->addIndex(['public_key_credential_id'], 'webauthn_publicKeyCredentialId'); |
|
42 | + } |
|
43 | + return $schema; |
|
44 | + } |
|
45 | 45 | } |