add option to disable the global search inclusion

This commit is contained in:
binsky 2021-03-12 22:04:40 +01:00
parent 5d95c9a6ea
commit ca2717d610
4 changed files with 41 additions and 26 deletions

View file

@ -94,6 +94,7 @@ $(document).ready(function () {
$('#passman_https_check').prop('checked', (settings.getKey('https_check').toString().toLowerCase() === '1'));
$('#passman_disable_contextmenu').prop('checked', (settings.getKey('disable_contextmenu').toString().toLowerCase() === '1'));
$('#passman_disable_debugger').prop('checked', (settings.getKey('disable_debugger').toString().toLowerCase() === '1'));
$('#passman_disable_global_search_inclusion').prop('checked', (settings.getKey('disable_global_search_inclusion').toString().toLowerCase() === '1'));
$('#vault_key_strength').val(settings.getKey('vault_key_strength'));
@ -113,6 +114,10 @@ $(document).ready(function () {
settings.setAdminKey('disable_debugger', ($(this).is(":checked")) ? 1 : 0);
});
$('#passman_disable_global_search_inclusion').change(function () {
settings.setAdminKey('disable_global_search_inclusion', ($(this).is(":checked")) ? 1 : 0);
});
$('#passman_sharing_enabled').change(function () {
settings.setAdminKey('user_sharing_enabled', ($(this).is(":checked")) ? 1 : 0);
});

View file

@ -26,6 +26,7 @@ namespace OCA\Passman\Search;
use OCA\Passman\AppInfo\Application;
use OCA\Passman\Db\CredentialMapper;
use OCA\Passman\Db\VaultMapper;
use OCA\Passman\Service\SettingsService;
use OCA\Passman\Service\VaultService;
use OCA\Passman\Utility\Utils;
use OCP\AppFramework\Db\DoesNotExistException;
@ -38,22 +39,19 @@ use OCP\Search\IProvider;
use OCP\Search\ISearchQuery;
use OCP\Search\SearchResult;
use OCP\Search\SearchResultEntry;
use Safe\Exceptions\StringsException;
class Provider implements IProvider {
/** @var IL10N */
private IL10N $l10n;
/** @var IURLGenerator */
private IURLGenerator $urlGenerator;
private IDBConnection $db;
private SettingsService $settings;
public function __construct(IL10N $l10n, IURLGenerator $urlGenerator, IDBConnection $db) {
public function __construct(IL10N $l10n, IURLGenerator $urlGenerator, IDBConnection $db, SettingsService $settings) {
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
$this->db = $db;
$this->settings = $settings;
}
public function getId(): string {
@ -74,12 +72,13 @@ class Provider implements IProvider {
}
public function search(IUser $user, ISearchQuery $query): SearchResult {
$searchResultEntries = [];
if ($this->settings->getAppSetting('disable_global_search_inclusion', 1) === 0) {
$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());
@ -93,7 +92,7 @@ class Provider implements IProvider {
\sprintf("Part of Passman vault %s", $Vault->getName()),
$this->urlGenerator->linkToRoute('passman.page.index') . "#/vault/" . $Vault->getGuid() . "?show=" . $Credential->getGuid()
);
} catch (Exception $e) {
} catch (\Exception $e) {
}
}
}
@ -101,6 +100,7 @@ class Provider implements IProvider {
} catch (MultipleObjectsReturnedException $e) {
}
}
}
return SearchResult::complete(
$this->l10n->t(Application::APP_ID),

View file

@ -40,6 +40,7 @@ class SettingsService {
'check_version',
'https_check',
'disable_contextmenu',
'disable_global_search_inclusion',
'settings_loaded'
);
@ -57,6 +58,7 @@ class SettingsService {
'server_side_encryption' => $this->config->getAppValue('passman', 'server_side_encryption', 'aes-256-cbc'),
'rounds_pbkdf2_stretching' => $this->config->getAppValue('passman', 'rounds_pbkdf2_stretching', 100),
'disable_debugger' => $this->config->getAppValue('passman', 'disable_debugger', 1),
'disable_global_search_inclusion' => $this->config->getAppValue('passman', 'disable_global_search_inclusion', 1),
'settings_loaded' => 1
);
}

View file

@ -105,6 +105,14 @@ $ciphers = openssl_get_cipher_methods();
<?php p($l->t('Disable JavaScript debugger')); ?>
</label>
</p>
<p>
<input type="checkbox" name="passman_disable_global_search_inclusion"
id="passman_disable_global_search_inclusion" class="checkbox"
value="0"/>
<label for="passman_disable_global_search_inclusion">
<?php p($l->t('Disable global search inclusion')); ?>
</label>
</p>
<p>
<label for="vault_key_strength">Minimum vault key
strength:</label>