mirror of
https://github.com/nextcloud/passman.git
synced 2025-11-06 19:15:56 +08:00
implement global nextcloud search credential handling
This commit is contained in:
parent
646654e6d1
commit
16839713e5
3 changed files with 97 additions and 46 deletions
|
|
@ -118,6 +118,7 @@
|
|||
VaultService.updateSharingKeys($scope.active_vault);
|
||||
});
|
||||
}
|
||||
$scope.checkURLAction();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
@ -544,6 +545,24 @@
|
|||
VaultService.clearVaultService();
|
||||
});
|
||||
|
||||
$scope.$watch(function(){ return $location.search(); }, function(params){
|
||||
$scope.checkURLAction();
|
||||
});
|
||||
|
||||
$scope.checkURLAction = function () {
|
||||
var search = $location.search();
|
||||
if (search.show !== undefined && $scope.active_vault.credentials !== undefined &&
|
||||
$scope.active_vault.credentials.length > 0) {
|
||||
$scope.closeSelected();
|
||||
$scope.active_vault.credentials.forEach(function(credential, index, myArray) {
|
||||
if (credential.guid === search.show) {
|
||||
$scope.selectCredential(credential);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.clearState = function () {
|
||||
$scope.delete_time = 0;
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -24,6 +24,13 @@
|
|||
namespace OCA\Passman\Search;
|
||||
|
||||
use OCA\Passman\AppInfo\Application;
|
||||
use OCA\Passman\Db\CredentialMapper;
|
||||
use OCA\Passman\Db\VaultMapper;
|
||||
use OCA\Passman\Service\VaultService;
|
||||
use OCA\Passman\Utility\Utils;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
|
|
@ -31,6 +38,7 @@ use OCP\Search\IProvider;
|
|||
use OCP\Search\ISearchQuery;
|
||||
use OCP\Search\SearchResult;
|
||||
use OCP\Search\SearchResultEntry;
|
||||
use Safe\Exceptions\StringsException;
|
||||
|
||||
class Provider implements IProvider {
|
||||
|
||||
|
|
@ -40,9 +48,12 @@ class Provider implements IProvider {
|
|||
/** @var IURLGenerator */
|
||||
private IURLGenerator $urlGenerator;
|
||||
|
||||
public function __construct(IL10N $l10n, IURLGenerator $urlGenerator) {
|
||||
private IDBConnection $db;
|
||||
|
||||
public function __construct(IL10N $l10n, IURLGenerator $urlGenerator, IDBConnection $db) {
|
||||
$this->l10n = $l10n;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
|
|
@ -63,16 +74,37 @@ class Provider implements IProvider {
|
|||
}
|
||||
|
||||
public function search(IUser $user, ISearchQuery $query): SearchResult {
|
||||
$VaultService = new VaultService(new VaultMapper($this->db, new Utils()));
|
||||
$Vaults = $VaultService->getByUser($user->getUID());
|
||||
$CredentialMapper = new CredentialMapper($this->db, new Utils());
|
||||
|
||||
$searchResultEntries = [];
|
||||
|
||||
foreach ($Vaults as $Vault) {
|
||||
try {
|
||||
$Credentials = $CredentialMapper->getCredentialsByVaultId($Vault->getId(), $Vault->getUserId());
|
||||
|
||||
foreach ($Credentials as $Credential) {
|
||||
if (strpos($Credential->getLabel(), $query->getTerm()) !== false) {
|
||||
try {
|
||||
$searchResultEntries[] = new SearchResultEntry(
|
||||
$this->urlGenerator->imagePath(Application::APP_ID, 'app.svg'),
|
||||
$Credential->getLabel(),
|
||||
\Safe\sprintf("Part of Passman vault %s", $Vault->getName()),
|
||||
$this->urlGenerator->linkToRoute('passman.page.index') . "#/vault/" . $Vault->getGuid() . "?show=" . $Credential->getGuid()
|
||||
);
|
||||
} catch (StringsException $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DoesNotExistException $e) {
|
||||
} catch (MultipleObjectsReturnedException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
return SearchResult::complete(
|
||||
$this->l10n->t(Application::APP_ID),
|
||||
[
|
||||
new SearchResultEntry(
|
||||
$this->urlGenerator->imagePath(Application::APP_ID, 'app.svg'),
|
||||
$this->l10n->t('Search in current page'),
|
||||
$this->l10n->t('This requires an already unlocked Passman vault'),
|
||||
'#?search=' . $query->getTerm()
|
||||
)
|
||||
]
|
||||
$searchResultEntries
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue