Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/Db/CoreQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CoreQueryBuilder extends NC22ExtendedQueryBuilder {
const SHARE = 'share';
const FILE_CACHE = 'filecache';
const STORAGES = 'storages';
const TOKEN = 'token';
const OPTIONS = 'options';
const HELPER = 'circleshelper';

Expand Down Expand Up @@ -169,6 +170,7 @@ class CoreQueryBuilder extends NC22ExtendedQueryBuilder {
],
self::SHARE => [
self::SHARE,
self::TOKEN,
self::FILE_CACHE => [
self::STORAGES
],
Expand Down Expand Up @@ -1038,6 +1040,38 @@ public function leftJoinMembersByInheritance(string $alias, string $field = ''):
}


/**
* @param string $alias
* @param string $token
*
* @throws RequestBuilderException
*/
public function limitToShareToken(string $alias, string $token): void {
$this->leftJoinShareToken($alias);

$aliasShareToken = $this->generateAlias($alias, self::TOKEN, $options);
$this->limit('token', $token, $aliasShareToken);
}

/**
* @param string $alias
* @param string $field
*
* @throws RequestBuilderException
*/
public function leftJoinShareToken(string $alias, string $field = ''): void {
$expr = $this->expr();

$field = ($field === '') ? 'id' : $field;
$aliasShareToken = $this->generateAlias($alias, self::TOKEN, $options);

$this->leftJoin(
$alias, CoreRequestBuilder::TABLE_TOKEN, $aliasShareToken,
$expr->eq($aliasShareToken . '.share_id', $alias . '.' . $field)
);
}


/**
* limit the result to the point of view of a FederatedUser
*
Expand Down
13 changes: 11 additions & 2 deletions lib/Db/CoreRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CoreRequestBuilder {

// wip
const TABLE_SHARE_LOCK = 'circles_share_lock';
const TABLE_TOKENS = 'circles_token';
const TABLE_TOKEN = 'circles_token';

const TABLE_GSSHARES = 'circle_gsshares'; // rename ?
const TABLE_GSSHARES_MOUNTPOINT = 'circle_gsshares_mp'; // rename ?
Expand Down Expand Up @@ -144,7 +144,16 @@ class CoreRequestBuilder {
],
self::TABLE_MOUNTPOINT => [],
self::TABLE_SHARE_LOCK => [],
self::TABLE_TOKENS => [],
self::TABLE_TOKEN => [
'id',
'share_id',
'circle_id',
'single_id',
'member_id',
'token',
'password',
'accepted'
],
self::TABLE_GSSHARES => [],
self::TABLE_GSSHARES_MOUNTPOINT => []
];
Expand Down
67 changes: 67 additions & 0 deletions lib/Db/ShareTokenRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);


/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <[email protected]>
* @copyright 2021
* @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\Circles\Db;


use OCA\Circles\Model\ShareToken;


/**
* Class ShareTokenRequest
*
* @package OCA\Circles\Db
*/
class ShareTokenRequest extends ShareTokenRequestBuilder {


/**
* @param ShareToken $token
*
* @return void
*/
public function save(ShareToken $token): void {
$qb = $this->getTokenInsertSql();
$qb->setValue('share_id', $qb->createNamedParameter($token->getShareId()))
->setValue('circle_id', $qb->createNamedParameter($token->getCircleId()))
->setValue('single_id', $qb->createNamedParameter($token->getSingleId()))
->setValue('member_id', $qb->createNamedParameter($token->getMemberId()))
->setValue('token', $qb->createNamedParameter($token->getToken()))
->setValue('password', $qb->createNamedParameter($token->getPassword()))
->setValue('accepted', $qb->createNamedParameter($token->getAccepted()));

$qb->execute();
$id = $qb->getLastInsertId();
$token->setDbId($id);
}

}

126 changes: 126 additions & 0 deletions lib/Db/ShareTokenRequestBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

declare(strict_types=1);


/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <[email protected]>
* @copyright 2021
* @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\Circles\Db;


use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException;
use OCA\Circles\Exceptions\ShareTokenNotFoundException;
use OCA\Circles\Model\ShareToken;


/**
* Class ShareTokenRequestBuilder
*
* @package OCA\Circles\Db
*/
class ShareTokenRequestBuilder extends CoreRequestBuilder {


/**
* @return CoreQueryBuilder
*/
protected function getTokenInsertSql(): CoreQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->insert(self::TABLE_TOKEN);

return $qb;
}


/**
* @return CoreQueryBuilder
*/
protected function getTokenUpdateSql(): CoreQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->update(self::TABLE_SHARE);

return $qb;
}


/**
* @param string $alias
*
* @return CoreQueryBuilder
*/
protected function getTokenSelectSql(string $alias = CoreQueryBuilder::TOKEN): CoreQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->generateSelect(self::TABLE_TOKEN, self::$tables[self::TABLE_SHARE], $alias)
->generateGroupBy(self::$tables[self::TABLE_SHARE], $alias);

return $qb;
}


/**
* Base of the Sql Delete request
*
* @return CoreQueryBuilder
*/
protected function getTokenDeleteSql(): CoreQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->delete(self::TABLE_SHARE);

return $qb;
}


/**
* @param CoreQueryBuilder $qb
*
* @return ShareToken
* @throws ShareTokenNotFoundException
*/
public function getItemFromRequest(CoreQueryBuilder $qb): ShareToken {
/** @var ShareToken $shareToken */
try {
$shareToken = $qb->asItem(ShareToken::class);
} catch (RowNotFoundException $e) {
throw new ShareTokenNotFoundException();
}

return $shareToken;
}


/**
* @param CoreQueryBuilder $qb
*
* @return ShareToken[]
*/
public function getItemsFromRequest(CoreQueryBuilder $qb): array {
/** @var ShareToken[] $result */
return $qb->asItems(ShareToken::class);
}

}

2 changes: 1 addition & 1 deletion lib/Db/ShareWrapperRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function getShareByToken(string $token, ?FederatedUser $federatedUser = n

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

if (!is_null($federatedUser)) {
$qb->limitToInitiator(CoreQueryBuilder::SHARE, $federatedUser, 'share_with');
Expand Down
38 changes: 38 additions & 0 deletions lib/Exceptions/ShareTokenNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);


/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <[email protected]>
* @copyright 2021
* @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\Circles\Exceptions;


class ShareTokenNotFoundException extends FederatedItemNotFoundException {

}


61 changes: 61 additions & 0 deletions lib/Migration/Version0022Date20220526113601.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,67 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
}


/**
* CIRCLES_TOKEN
*/
if (!$schema->hasTable('circles_token')) {
$table = $schema->createTable('circles_token');
$table->addColumn(
'id', 'integer', [
'autoincrement' => true,
'notnull' => true,
'length' => 11,
'unsigned' => true,
]
);
$table->addColumn(
'share_id', 'integer', [
'notnull' => false,
'length' => 11
]
);
$table->addColumn(
'circle_id', 'string', [
'notnull' => false,
'length' => 31
]
);
$table->addColumn(
'single_id', 'string', [
'notnull' => false,
'length' => 31
]
);
$table->addColumn(
'member_id', 'string', [
'notnull' => false,
'length' => 31
]
);
$table->addColumn(
'token', 'string', [
'notnull' => false,
'length' => 31
]
);
$table->addColumn(
'password', 'string', [
'notnull' => false,
'length' => 31
]
);
$table->addColumn(
'accepted', 'integer', [
'notnull' => false,
'length' => 1
]
);

$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['share_id', 'circle_id', 'single_id', 'member_id', 'token'], 'sicisimit');
}


/**
* CIRCLES_MOUNT
*/
Expand Down
Loading