-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enh: db schema change #79
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9a9dba1
enh: db schema change
kyteinsky 8b85859
add updateAccessProvider to ContentManager
kyteinsky 82ba144
add action job again on exceptions
kyteinsky 6a5ba61
network: only throw on 5xx errors
kyteinsky 0147d11
fix action service deleteSources json payload
kyteinsky bb7907d
rename migration to be the latest version
kyteinsky ea77218
paper cuts
kyteinsky 5fc3cab
fix allow files in NodeWrittenEvent
kyteinsky 89a2df2
fix: do not index files_versions|files_trashbin files
kyteinsky a785c28
remove username and 'files' from source title
kyteinsky 649a6bf
address review comments
kyteinsky e04be83
update share listener logic
kyteinsky 42f774a
add locked files to the end of the index queue
kyteinsky e5b7b89
fix remnants from expts
kyteinsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* Nextcloud - ContextChat | ||
* | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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,122 @@ | ||
<?php | ||
|
||
/** | ||
* Nextcloud - ContextChat | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Anupam Kumar <[email protected]> | ||
* @copyright Anupam Kumar 2024 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
namespace OCA\ContextChat\BackgroundJobs; | ||
|
||
use OCA\ContextChat\Db\QueueActionMapper; | ||
use OCA\ContextChat\Service\DiagnosticService; | ||
use OCA\ContextChat\Service\LangRopeService; | ||
use OCA\ContextChat\Type\ActionType; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\BackgroundJob\IJobList; | ||
use OCP\BackgroundJob\QueuedJob; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class ActionJob extends QueuedJob { | ||
private const BATCH_SIZE = 100; | ||
|
||
public function __construct( | ||
ITimeFactory $timeFactory, | ||
private LangRopeService $networkService, | ||
private QueueActionMapper $actionMapper, | ||
private IJobList $jobList, | ||
private LoggerInterface $logger, | ||
private DiagnosticService $diagnosticService, | ||
) { | ||
parent::__construct($timeFactory); | ||
} | ||
|
||
protected function run($argument): void { | ||
$this->diagnosticService->sendHeartbeat(static::class, $this->getId()); | ||
$entities = $this->actionMapper->getFromQueue(static::BATCH_SIZE); | ||
|
||
if (empty($entities)) { | ||
return; | ||
} | ||
|
||
try { | ||
foreach ($entities as $entity) { | ||
$this->diagnosticService->sendHeartbeat(static::class, $this->getId()); | ||
|
||
switch ($entity->getType()) { | ||
case ActionType::DELETE_SOURCE_IDS: | ||
$decoded = json_decode($entity->getPayload(), true); | ||
if (!is_array($decoded) || !isset($decoded['sourceIds'])) { | ||
$this->logger->warning('Invalid payload for DELETE_SOURCE_IDS action', ['payload' => $entity->getPayload()]); | ||
break; | ||
} | ||
$this->networkService->deleteSources($decoded['sourceIds']); | ||
break; | ||
|
||
case ActionType::DELETE_PROVIDER_ID: | ||
$decoded = json_decode($entity->getPayload(), true); | ||
if (!is_array($decoded) || !isset($decoded['providerId'])) { | ||
$this->logger->warning('Invalid payload for DELETE_PROVIDER_ID action', ['payload' => $entity->getPayload()]); | ||
break; | ||
} | ||
$this->networkService->deleteProvider($decoded['providerId']); | ||
break; | ||
|
||
case ActionType::DELETE_USER_ID: | ||
$decoded = json_decode($entity->getPayload(), true); | ||
if (!is_array($decoded) || !isset($decoded['userId'])) { | ||
$this->logger->warning('Invalid payload for DELETE_USER_ID action', ['payload' => $entity->getPayload()]); | ||
break; | ||
} | ||
$this->networkService->deleteUser($decoded['userId']); | ||
break; | ||
|
||
case ActionType::UPDATE_ACCESS_SOURCE_ID: | ||
$decoded = json_decode($entity->getPayload(), true); | ||
if (!is_array($decoded) || !isset($decoded['op']) || !isset($decoded['userIds']) || !isset($decoded['sourceId'])) { | ||
$this->logger->warning('Invalid payload for UPDATE_ACCESS_SOURCE_ID action', ['payload' => $entity->getPayload()]); | ||
break; | ||
} | ||
$this->networkService->updateAccess($decoded['op'], $decoded['userIds'], $decoded['sourceId']); | ||
break; | ||
|
||
case ActionType::UPDATE_ACCESS_PROVIDER_ID: | ||
$decoded = json_decode($entity->getPayload(), true); | ||
if (!is_array($decoded) || !isset($decoded['op']) || !isset($decoded['userIds']) || !isset($decoded['providerId'])) { | ||
marcelklehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$this->logger->warning('Invalid payload for UPDATE_ACCESS_PROVIDER_ID action', ['payload' => $entity->getPayload()]); | ||
break; | ||
} | ||
$this->networkService->updateAccessProvider($decoded['op'], $decoded['userIds'], $decoded['providerId']); | ||
break; | ||
|
||
case ActionType::UPDATE_ACCESS_DECL_SOURCE_ID: | ||
$decoded = json_decode($entity->getPayload(), true); | ||
if (!is_array($decoded) || !isset($decoded['userIds']) || !isset($decoded['sourceId'])) { | ||
$this->logger->warning('Invalid payload for UPDATE_ACCESS_DECL_SOURCE_ID action', ['payload' => $entity->getPayload()]); | ||
break; | ||
} | ||
$this->networkService->updateAccessDeclarative($decoded['userIds'], $decoded['sourceId']); | ||
break; | ||
|
||
default: | ||
$this->logger->warning('Unknown action type', ['type' => $entity->getType()]); | ||
} | ||
} | ||
|
||
foreach ($entities as $entity) { | ||
$this->diagnosticService->sendHeartbeat(static::class, $this->getId()); | ||
$this->actionMapper->removeFromQueue($entity); | ||
} | ||
} catch (\Throwable $e) { | ||
$this->jobList->add(static::class); | ||
throw $e; | ||
} | ||
|
||
$this->jobList->add(static::class); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we also need Group member added/removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about adding it later with complete group based ACLs. We won't need to translate group -> users then, only the list of groups the user is part of, on the fly when querying.
In the backend it would be checked if a file can be accessed by the user or one of the groups the user is part of.
We can maintain a local list in the backend for user-group mappings but fetching it on the fly is not expensive, so we won't even need the listener if a user was added/removed from a group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmh. I'd stick with user-based ACLs for this iteration, I think.