-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
🔗☑️ Accept all incoming shares #16828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dcdbea5
e96c9e0
c79a564
520042b
8986910
60da256
43517cf
19e1892
e79ab7d
0fe4b71
6d9afca
d3b6289
e163213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -946,6 +946,38 @@ public function updateShare( | |
| return new DataResponse($this->formatShare($share)); | ||
| } | ||
|
|
||
| /** | ||
| * @NoAdminRequired | ||
| * | ||
| * @param string $id | ||
| * @return DataResponse | ||
| * @throws OCSNotFoundException | ||
| * @throws OCSException | ||
| * @throws OCSBadRequestException | ||
| */ | ||
| public function acceptShare(string $id): DataResponse { | ||
| try { | ||
| $share = $this->getShareById($id); | ||
| } catch (ShareNotFound $e) { | ||
| throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); | ||
| } | ||
|
|
||
| if (!$this->canAccessShare($share)) { | ||
| throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adjust error message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied this behaviour from |
||
| } | ||
|
|
||
| try { | ||
| $this->shareManager->acceptShare($share, $this->currentUser); | ||
| } catch (GenericShareException $e) { | ||
| $code = $e->getCode() === 0 ? 403 : $e->getCode(); | ||
| throw new OCSException($e->getHint(), $code); | ||
| } catch (\Exception $e) { | ||
| throw new OCSBadRequestException($e->getMessage(), $e); | ||
| } | ||
|
|
||
| return new DataResponse(); | ||
| } | ||
|
|
||
| /** | ||
| * Does the user have read permission on the share | ||
| * | ||
|
|
@@ -1078,8 +1110,8 @@ protected function canDeleteShare(\OCP\Share\IShare $share): bool { | |
| * @suppress PhanUndeclaredClassMethod | ||
| */ | ||
| protected function canDeleteShareFromSelf(\OCP\Share\IShare $share): bool { | ||
| if ($share->getShareType() !== Share::SHARE_TYPE_GROUP && | ||
| $share->getShareType() !== Share::SHARE_TYPE_ROOM | ||
| if ($share->getShareType() !== IShare::TYPE_GROUP && | ||
| $share->getShareType() !== IShare::TYPE_ROOM | ||
| ) { | ||
| return false; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
| /** | ||
| * @copyright Copyright (c) 2019, Joas Schilling <coding@schilljs.com> | ||
| * | ||
| * @author Joas Schilling <coding@schilljs.com> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Files_Sharing\Migration; | ||
|
|
||
| use OCP\DB\QueryBuilder\IQueryBuilder; | ||
| use OCP\IConfig; | ||
| use OCP\IDBConnection; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\IRepairStep; | ||
| use OCP\Share\IShare; | ||
|
|
||
| class SetAcceptedStatus implements IRepairStep { | ||
|
|
||
| /** @var IDBConnection */ | ||
| private $connection; | ||
|
|
||
| /** @var IConfig */ | ||
| private $config; | ||
|
|
||
|
|
||
| public function __construct(IDBConnection $connection, IConfig $config) { | ||
| $this->connection = $connection; | ||
| $this->config = $config; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the step's name | ||
| * | ||
| * @return string | ||
| * @since 9.1.0 | ||
| */ | ||
| public function getName(): string { | ||
| return 'Set existing shares as accepted'; | ||
| } | ||
|
|
||
| /** | ||
| * @param IOutput $output | ||
| */ | ||
| public function run(IOutput $output): void { | ||
| if (!$this->shouldRun()) { | ||
| return; | ||
| } | ||
|
|
||
| $query = $this->connection->getQueryBuilder(); | ||
| $query | ||
| ->update('share') | ||
| ->set('accepted', $query->createNamedParameter(IShare::STATUS_ACCEPTED)) | ||
| ->where($query->expr()->in('share_type', $query->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_USERGROUP], IQueryBuilder::PARAM_INT_ARRAY))); | ||
| $query->execute(); | ||
| } | ||
|
|
||
| protected function shouldRun() { | ||
| $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0'); | ||
| return version_compare($appVersion, '1.10.1', '<'); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah those crappy old events...