diff options
author | Raul Ferreira Fuentes <Raudius@users.noreply.github.com> | 2022-05-02 16:57:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 16:57:43 +0300 |
commit | 3bac4be4f04f20110956e38b40e9d498321a36c0 (patch) | |
tree | fc51ce1513e3b207ab75fea1a81c8ac82af808b5 /lib | |
parent | 673503f39d3b0ec06168b682785cc8fc3ec67b5e (diff) | |
parent | 7b395bb84202ec30b38843823640638a9e048f92 (diff) |
Merge branch 'master' into enh/config_value/ttl
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Backgroundjobs/Cleanup.php | 20 | ||||
-rw-r--r-- | lib/Controller/WopiController.php | 2 | ||||
-rw-r--r-- | lib/Db/WopiMapper.php | 22 |
3 files changed, 38 insertions, 6 deletions
diff --git a/lib/Backgroundjobs/Cleanup.php b/lib/Backgroundjobs/Cleanup.php index e5adb55a..5d3efdb3 100644 --- a/lib/Backgroundjobs/Cleanup.php +++ b/lib/Backgroundjobs/Cleanup.php @@ -24,7 +24,7 @@ namespace OCA\Richdocuments\Backgroundjobs; use OC\BackgroundJob\TimedJob; -use OCA\Richdocuments\Service\CapabilitiesService; +use OCA\Richdocuments\Db\WopiMapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; @@ -32,9 +32,12 @@ class Cleanup extends TimedJob { /** @var IDBConnection */ private $db; + /** @var WopiMapper $wopiMapper */ + private $wopiMapper; - public function __construct(IDBConnection $db) { + public function __construct(IDBConnection $db, WopiMapper $wopiMapper) { $this->db = $db; + $this->wopiMapper = $wopiMapper; $this->setInterval(60*60); } @@ -45,5 +48,18 @@ class Cleanup extends TimedJob { $query->delete('richdocuments_template') ->where($query->expr()->lte('timestamp', $query->createNamedParameter(time() - 60, IQueryBuilder::PARAM_INT))); $query->executeStatement(); + + // Expired WOPI access tokens + $this->cleanUpWopiTokens(); + + } + + private function cleanUpWopiTokens() + { + $tokenIds = $this->wopiMapper->getExpiredTokenIds(1000); + $query = $this->db->getQueryBuilder(); + $query->delete('richdocuments_wopi') + ->where($query->expr()->in('id', $query->createNamedParameter($tokenIds, IQueryBuilder::PARAM_INT_ARRAY))); + $query->executeStatement(); } } diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 60b742db..522b9516 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -204,7 +204,7 @@ class WopiController extends Controller { 'LastModifiedTime' => Helper::toISO8601($file->getMTime()), 'SupportsRename' => !$isVersion, 'UserCanRename' => !$isPublic && !$isVersion, - 'EnableInsertRemoteImage' => true, + 'EnableInsertRemoteImage' => !$isPublic, 'EnableShare' => $file->isShareable() && !$isVersion, 'HideUserList' => '', 'DisablePrint' => $wopi->getHideDownload(), diff --git a/lib/Db/WopiMapper.php b/lib/Db/WopiMapper.php index 025719c1..272ef7af 100644 --- a/lib/Db/WopiMapper.php +++ b/lib/Db/WopiMapper.php @@ -25,9 +25,9 @@ namespace OCA\Richdocuments\Db; use OCA\Richdocuments\AppConfig; use OCA\Richdocuments\Exceptions\ExpiredTokenException; use OCA\Richdocuments\Exceptions\UnknownTokenException; -use OCP\AppFramework\Db\TokenExpiredException; use OCP\AppFramework\Db\Mapper; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\ILogger; use OCP\Security\ISecureRandom; @@ -173,8 +173,24 @@ class WopiMapper extends Mapper { * * @return int */ - private function calculateNewTokenExpiry(): int - { + private function calculateNewTokenExpiry(): int { return $this->timeFactory->getTime() + (int) $this->appConfig->getAppValue('token_ttl'); } + + /** + * @param int|null $limit + * @param int|null $offset + * @return int[] + * @throws \OCP\DB\Exception + */ + public function getExpiredTokenIds(?int $limit = null, ?int $offset = null): array { + $qb = $this->db->getQueryBuilder(); + $qb->select('id') + ->from('richdocuments_wopi') + ->where($qb->expr()->lt('expiry', $qb->createNamedParameter(time() - 60, IQueryBuilder::PARAM_INT))) + ->setFirstResult($offset) + ->setMaxResults($limit); + + return array_column($qb->executeQuery()->fetchAll(), 'id'); + } } |