Skip to content

Commit e880ee0

Browse files
ArtificialOwlbackportbot[bot]
authored andcommitted
get share by token
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 8899760 commit e880ee0

10 files changed

+686
-5
lines changed

lib/Db/CoreQueryBuilder.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CoreQueryBuilder extends NC22ExtendedQueryBuilder {
8080
const SHARE = 'share';
8181
const FILE_CACHE = 'filecache';
8282
const STORAGES = 'storages';
83+
const TOKEN = 'token';
8384
const OPTIONS = 'options';
8485
const HELPER = 'circleshelper';
8586

@@ -169,6 +170,7 @@ class CoreQueryBuilder extends NC22ExtendedQueryBuilder {
169170
],
170171
self::SHARE => [
171172
self::SHARE,
173+
self::TOKEN,
172174
self::FILE_CACHE => [
173175
self::STORAGES
174176
],
@@ -1038,6 +1040,38 @@ public function leftJoinMembersByInheritance(string $alias, string $field = ''):
10381040
}
10391041

10401042

1043+
/**
1044+
* @param string $alias
1045+
* @param string $token
1046+
*
1047+
* @throws RequestBuilderException
1048+
*/
1049+
public function limitToShareToken(string $alias, string $token): void {
1050+
$this->leftJoinShareToken($alias);
1051+
1052+
$aliasShareToken = $this->generateAlias($alias, self::TOKEN, $options);
1053+
$this->limit('token', $token, $aliasShareToken);
1054+
}
1055+
1056+
/**
1057+
* @param string $alias
1058+
* @param string $field
1059+
*
1060+
* @throws RequestBuilderException
1061+
*/
1062+
public function leftJoinShareToken(string $alias, string $field = ''): void {
1063+
$expr = $this->expr();
1064+
1065+
$field = ($field === '') ? 'id' : $field;
1066+
$aliasShareToken = $this->generateAlias($alias, self::TOKEN, $options);
1067+
1068+
$this->leftJoin(
1069+
$alias, CoreRequestBuilder::TABLE_TOKEN, $aliasShareToken,
1070+
$expr->eq($aliasShareToken . '.share_id', $alias . '.' . $field)
1071+
);
1072+
}
1073+
1074+
10411075
/**
10421076
* limit the result to the point of view of a FederatedUser
10431077
*

lib/Db/CoreRequestBuilder.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CoreRequestBuilder {
6363

6464
// wip
6565
const TABLE_SHARE_LOCK = 'circles_share_lock';
66-
const TABLE_TOKENS = 'circles_token';
66+
const TABLE_TOKEN = 'circles_token';
6767

6868
const TABLE_GSSHARES = 'circle_gsshares'; // rename ?
6969
const TABLE_GSSHARES_MOUNTPOINT = 'circle_gsshares_mp'; // rename ?
@@ -144,7 +144,16 @@ class CoreRequestBuilder {
144144
],
145145
self::TABLE_MOUNTPOINT => [],
146146
self::TABLE_SHARE_LOCK => [],
147-
self::TABLE_TOKENS => [],
147+
self::TABLE_TOKEN => [
148+
'id',
149+
'share_id',
150+
'circle_id',
151+
'single_id',
152+
'member_id',
153+
'token',
154+
'password',
155+
'accepted'
156+
],
148157
self::TABLE_GSSHARES => [],
149158
self::TABLE_GSSHARES_MOUNTPOINT => []
150159
];

lib/Db/ShareTokenRequest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Circles - Bring cloud-users closer together.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2021
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Circles\Db;
33+
34+
35+
use OCA\Circles\Model\ShareToken;
36+
37+
38+
/**
39+
* Class ShareTokenRequest
40+
*
41+
* @package OCA\Circles\Db
42+
*/
43+
class ShareTokenRequest extends ShareTokenRequestBuilder {
44+
45+
46+
/**
47+
* @param ShareToken $token
48+
*
49+
* @return void
50+
*/
51+
public function save(ShareToken $token): void {
52+
$qb = $this->getTokenInsertSql();
53+
$qb->setValue('share_id', $qb->createNamedParameter($token->getShareId()))
54+
->setValue('circle_id', $qb->createNamedParameter($token->getCircleId()))
55+
->setValue('single_id', $qb->createNamedParameter($token->getSingleId()))
56+
->setValue('member_id', $qb->createNamedParameter($token->getMemberId()))
57+
->setValue('token', $qb->createNamedParameter($token->getToken()))
58+
->setValue('password', $qb->createNamedParameter($token->getPassword()))
59+
->setValue('accepted', $qb->createNamedParameter($token->getAccepted()));
60+
61+
$qb->execute();
62+
$id = $qb->getLastInsertId();
63+
$token->setDbId($id);
64+
}
65+
66+
}
67+
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Circles - Bring cloud-users closer together.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2021
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Circles\Db;
33+
34+
35+
use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException;
36+
use OCA\Circles\Exceptions\ShareTokenNotFoundException;
37+
use OCA\Circles\Model\ShareToken;
38+
39+
40+
/**
41+
* Class ShareTokenRequestBuilder
42+
*
43+
* @package OCA\Circles\Db
44+
*/
45+
class ShareTokenRequestBuilder extends CoreRequestBuilder {
46+
47+
48+
/**
49+
* @return CoreQueryBuilder
50+
*/
51+
protected function getTokenInsertSql(): CoreQueryBuilder {
52+
$qb = $this->getQueryBuilder();
53+
$qb->insert(self::TABLE_TOKEN);
54+
55+
return $qb;
56+
}
57+
58+
59+
/**
60+
* @return CoreQueryBuilder
61+
*/
62+
protected function getTokenUpdateSql(): CoreQueryBuilder {
63+
$qb = $this->getQueryBuilder();
64+
$qb->update(self::TABLE_SHARE);
65+
66+
return $qb;
67+
}
68+
69+
70+
/**
71+
* @param string $alias
72+
*
73+
* @return CoreQueryBuilder
74+
*/
75+
protected function getTokenSelectSql(string $alias = CoreQueryBuilder::TOKEN): CoreQueryBuilder {
76+
$qb = $this->getQueryBuilder();
77+
$qb->generateSelect(self::TABLE_TOKEN, self::$tables[self::TABLE_SHARE], $alias)
78+
->generateGroupBy(self::$tables[self::TABLE_SHARE], $alias);
79+
80+
return $qb;
81+
}
82+
83+
84+
/**
85+
* Base of the Sql Delete request
86+
*
87+
* @return CoreQueryBuilder
88+
*/
89+
protected function getTokenDeleteSql(): CoreQueryBuilder {
90+
$qb = $this->getQueryBuilder();
91+
$qb->delete(self::TABLE_SHARE);
92+
93+
return $qb;
94+
}
95+
96+
97+
/**
98+
* @param CoreQueryBuilder $qb
99+
*
100+
* @return ShareToken
101+
* @throws ShareTokenNotFoundException
102+
*/
103+
public function getItemFromRequest(CoreQueryBuilder $qb): ShareToken {
104+
/** @var ShareToken $shareToken */
105+
try {
106+
$shareToken = $qb->asItem(ShareToken::class);
107+
} catch (RowNotFoundException $e) {
108+
throw new ShareTokenNotFoundException();
109+
}
110+
111+
return $shareToken;
112+
}
113+
114+
115+
/**
116+
* @param CoreQueryBuilder $qb
117+
*
118+
* @return ShareToken[]
119+
*/
120+
public function getItemsFromRequest(CoreQueryBuilder $qb): array {
121+
/** @var ShareToken[] $result */
122+
return $qb->asItems(ShareToken::class);
123+
}
124+
125+
}
126+

lib/Db/ShareWrapperRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function getShareByToken(string $token, ?FederatedUser $federatedUser = n
238238

239239
$qb->setOptions([CoreQueryBuilder::SHARE], ['getData' => true]);
240240
$qb->leftJoinCircle(CoreQueryBuilder::SHARE, null, 'share_with');
241-
$qb->limitToToken($token);
241+
$qb->limitToShareToken(CoreQueryBuilder::SHARE, $token);
242242

243243
if (!is_null($federatedUser)) {
244244
$qb->limitToInitiator(CoreQueryBuilder::SHARE, $federatedUser, 'share_with');
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Circles - Bring cloud-users closer together.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2021
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
namespace OCA\Circles\Exceptions;
32+
33+
34+
class ShareTokenNotFoundException extends FederatedItemNotFoundException {
35+
36+
}
37+
38+

lib/Migration/Version0022Date20220526113601.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,67 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
469469
}
470470

471471

472+
/**
473+
* CIRCLES_TOKEN
474+
*/
475+
if (!$schema->hasTable('circles_token')) {
476+
$table = $schema->createTable('circles_token');
477+
$table->addColumn(
478+
'id', 'integer', [
479+
'autoincrement' => true,
480+
'notnull' => true,
481+
'length' => 11,
482+
'unsigned' => true,
483+
]
484+
);
485+
$table->addColumn(
486+
'share_id', 'integer', [
487+
'notnull' => false,
488+
'length' => 11
489+
]
490+
);
491+
$table->addColumn(
492+
'circle_id', 'string', [
493+
'notnull' => false,
494+
'length' => 31
495+
]
496+
);
497+
$table->addColumn(
498+
'single_id', 'string', [
499+
'notnull' => false,
500+
'length' => 31
501+
]
502+
);
503+
$table->addColumn(
504+
'member_id', 'string', [
505+
'notnull' => false,
506+
'length' => 31
507+
]
508+
);
509+
$table->addColumn(
510+
'token', 'string', [
511+
'notnull' => false,
512+
'length' => 31
513+
]
514+
);
515+
$table->addColumn(
516+
'password', 'string', [
517+
'notnull' => false,
518+
'length' => 31
519+
]
520+
);
521+
$table->addColumn(
522+
'accepted', 'integer', [
523+
'notnull' => false,
524+
'length' => 1
525+
]
526+
);
527+
528+
$table->setPrimaryKey(['id']);
529+
$table->addUniqueIndex(['share_id', 'circle_id', 'single_id', 'member_id', 'token'], 'sicisimit');
530+
}
531+
532+
472533
/**
473534
* CIRCLES_MOUNT
474535
*/

0 commit comments

Comments
 (0)