Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
only remove approval tag if modified after approval
Signed-off-by: Lukas Schaefer <[email protected]>
  • Loading branch information
lukasdotcom committed Jun 20, 2025
commit c1405b61f6619ce521ba8d058060450bac463b24
4 changes: 2 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;

use OCP\FilesMetadata\Event\MetadataLiveEvent;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
use OCP\SabrePluginEvent;
use OCP\SystemTag\MapperEvent;

Expand Down Expand Up @@ -65,7 +65,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadSidebar::class, LoadSidebarScripts::class);
$context->registerNotifierService(Notifier::class);
$context->registerDashboardWidget(ApprovalPendingWidget::class);
$context->registerEventListener(MetadataLiveEvent::class, UpdateFilesListener::class);
$context->registerEventListener(MetadataBackgroundEvent::class, UpdateFilesListener::class);
}

public function boot(IBootContext $context): void {
Expand Down
9 changes: 5 additions & 4 deletions lib/Listener/UpdateFilesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use OCA\Approval\Service\ApprovalService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\FilesMetadata\Event\MetadataLiveEvent;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;

/** @template-implements IEventListener<MetadataLiveEvent> */
/** @template-implements IEventListener<MetadataBackgroundEvent> */
class UpdateFilesListener implements IEventListener {

public function __construct(
Expand All @@ -23,10 +23,11 @@ public function __construct(
* @inheritDoc
*/
public function handle(Event $event): void {
if (!($event instanceof MetadataLiveEvent)) {
if (!($event instanceof MetadataBackgroundEvent)) {
return;
}
$fileId = $event->getNode()->getId();
$this->approvalService->removeApprovalTags($fileId);
$mTime = $event->getNode()->getMTime();
$this->approvalService->removeApprovalTags($fileId, $mTime);
}
}
7 changes: 5 additions & 2 deletions lib/Service/ApprovalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,14 +820,17 @@ public function propFind(PropFind $propFind, INode $node): void {
* Remove approval tag from a file
*
* @param int $fileId
* @param int $mTime
*/
public function removeApprovalTags(int $fileId): void {
public function removeApprovalTags(int $fileId, int $mTime): void {
$fileTags = $this->tagObjectMapper->getTagIdsForObjects([$fileId], 'files');
$fileTags = $fileTags[$fileId] ?? [];
if (count($fileTags) > 0) {
$tags = $this->ruleService->filterApprovalTags($fileTags);
foreach ($tags as $tag) {
$this->tagObjectMapper->unassignTags((string)$fileId, 'files', $tag);
if ($this->ruleService->wasApprovedAfter($fileId, $mTime)) {
$this->tagObjectMapper->unassignTags((string)$fileId, 'files', $tag);
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions lib/Service/RuleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,31 @@ public function clearRuleCaches(): void {
$cache = $this->cacheFactory->createDistributed('integration_overleaf');
$cache->remove('approval_tags');
}

/**
* Checks that the approval of the file was after the time given.
* This does not verify that the file was actually approved.
*
* @param int $fileId
* @param int $time
* @return bool
*/
public function wasApprovedAfter(int $fileId, int $time): bool {
$qb = $this->db->getQueryBuilder();
$qb->select('timestamp')
->from('approval_activity')
->where(
$qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))
)
->andWhere(
$qb->expr()->eq('new_state', $qb->createNamedParameter(Application::STATE_APPROVED, IQueryBuilder::PARAM_INT))
);
$req = $qb->executeQuery();
$timestamp = $req->fetchOne();
$req->closeCursor();
if (!$timestamp) {
return true;
}
return $timestamp < $time;
}
}
Loading