-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gary Kim <[email protected]>
- Loading branch information
Showing
5 changed files
with
389 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2021, Gary Kim <[email protected]> | ||
* | ||
* @author Gary Kim <[email protected]> | ||
* | ||
* @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\Talk\Controller; | ||
|
||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\IRequest; | ||
|
||
class RemoteController extends OCSController { | ||
public function __construct(string $appName, IRequest $request) { | ||
parent::__construct($appName, $request); | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return DataResponse | ||
*/ | ||
public function acceptShare(string $id): DataResponse { | ||
|
||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return DataResponse | ||
*/ | ||
public function rejectShare(string $id): DataResponse { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2021, Gary Kim <[email protected]> | ||
* | ||
* @author Gary Kim <[email protected]> | ||
* | ||
* @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\Talk\Federation; | ||
|
||
use OCA\Talk\Exceptions\UnauthorizedException; | ||
use OCA\Talk\Room; | ||
use OCP\DB\Exception as DBException; | ||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
use OCP\IConfig; | ||
use OCP\IDBConnection; | ||
use OCP\IUser; | ||
|
||
class FederationManager { | ||
/** @var IDBConnection */ | ||
private $db; | ||
/** @var IConfig */ | ||
private $config; | ||
|
||
public function __construct ( | ||
IDBConnection $db, | ||
IConfig $config | ||
) { | ||
$this->db = $db; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Determine if Talk federation is enabled on this instance | ||
* @return bool | ||
*/ | ||
public function isEnabled(): bool { | ||
// TODO: Set to true once implementation is complete | ||
return $this->config->getSystemValueBool('talk_federation_enabled', false); | ||
} | ||
|
||
/** | ||
* @param IUser $user | ||
* @param string $roomToken | ||
* @param string $remoteUrl | ||
* @param string $sharedSecret | ||
* @return int share id for this specific remote room share | ||
* @throws DBException | ||
*/ | ||
public function addRemoteRoom(IUser $user, string $roomToken, string $remoteUrl, string $sharedSecret): int { | ||
$qb = $this->db->getQueryBuilder(); | ||
|
||
$query = $qb->insert('talk_rooms_external') | ||
->values([ | ||
'user_id' => $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR), | ||
'room_id' => $qb->createNamedParameter($roomToken, IQueryBuilder::PARAM_STR), | ||
'remote_url' => $qb->createNamedParameter($remoteUrl, IQueryBuilder::PARAM_STR), | ||
'shareToken' => $qb->createNamedParameter($sharedSecret, IQueryBuilder::PARAM_STR), | ||
]) | ||
->executeQuery(); | ||
|
||
$row = $query->fetch(); | ||
return (int)($row['id']); | ||
} | ||
|
||
/** | ||
* @throws DBException | ||
* @throws UnauthorizedException | ||
*/ | ||
public function acceptRemoteRoomShare(IUser $user, int $shareId) { | ||
$share = this->$this->getShare($shareId); | ||
if ($share['user_id'] !== $user->getUID()) { | ||
throw new UnauthorizedException(); | ||
} | ||
|
||
$qb = $this->db->getQueryBuilder(); | ||
|
||
$qb->update('talk_rooms_external') | ||
->set('accepted', true) | ||
->where( | ||
$qb->expr()->eq('id', $qb->createNamedParameter($shareId, IQueryBuilder::PARAM_INT)) | ||
) | ||
->executeQuery(); | ||
} | ||
|
||
/** | ||
* @throws DBException | ||
* @throws UnauthorizedException | ||
*/ | ||
public function rejectRemoteRoomShare(IUser $user, int $shareId) { | ||
$share = this->$this->getShare($shareId); | ||
if ($share['user_id'] !== $user->getUID()) { | ||
throw new UnauthorizedException(); | ||
} | ||
|
||
$qb = $this->db->getQueryBuilder(); | ||
|
||
$qb->delete('talk_rooms_external') | ||
->where( | ||
$qb->expr()->eq('id', $qb->createNamedParameter($shareId, IQueryBuilder::PARAM_INT)) | ||
) | ||
->executeQuery(); | ||
} | ||
|
||
/** | ||
* @throws DBException | ||
*/ | ||
public function getShare(int $shareId): array { | ||
$qb = $this->db->getQueryBuilder(); | ||
|
||
$query = $qb->select('*') | ||
->from('talk_rooms_external') | ||
->where( | ||
$qb->expr()->eq('id', $qb->createNamedParameter($shareId, IQueryBuilder::PARAM_INT)) | ||
) | ||
->executeQuery(); | ||
|
||
return $query->fetch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.