You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const Setting = require('../../models/Setting').default;
|
||||
const SyncTargetRegistry = require('../../SyncTargetRegistry').default;
|
||||
const ObjectUtils = require('../../ObjectUtils');
|
||||
const { _ } = require('../../locale');
|
||||
const Setting = require('../../../models/Setting').default;
|
||||
const SyncTargetRegistry = require('../../../SyncTargetRegistry').default;
|
||||
const ObjectUtils = require('../../../ObjectUtils');
|
||||
const { _ } = require('../../../locale');
|
||||
const { createSelector } = require('reselect');
|
||||
const Logger = require('@joplin/utils/Logger').default;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import SyncTargetRegistry from '../../../SyncTargetRegistry';
|
||||
import shouldShowMissingPasswordWarning from './shouldShowMissingPasswordWarning';
|
||||
|
||||
// Maps targets to whether each target requires a password.
|
||||
// A subset of all sync targets.
|
||||
const targetToRequiresPassword: Record<string, boolean> = {
|
||||
'nextcloud': true,
|
||||
'webdav': true,
|
||||
'amazon_s3': true,
|
||||
'joplinServer': true,
|
||||
'joplinCloud': true,
|
||||
'onedrive': false,
|
||||
'dropbox': false,
|
||||
};
|
||||
|
||||
describe('shouldShowMissingPasswordWarning', () => {
|
||||
it('should return true when sync target requires a password and the password is missing', () => {
|
||||
for (const targetName in targetToRequiresPassword) {
|
||||
const targetId = SyncTargetRegistry.nameToId(targetName);
|
||||
const expected = targetToRequiresPassword[targetName];
|
||||
|
||||
expect(shouldShowMissingPasswordWarning(targetId, {})).toBe(expected);
|
||||
|
||||
// Should also consider an empty string to be missing
|
||||
const settings = {
|
||||
[`sync.${targetId}.password`]: '',
|
||||
};
|
||||
expect(shouldShowMissingPasswordWarning(targetId, settings)).toBe(expected);
|
||||
}
|
||||
});
|
||||
|
||||
it('should return false when a password is present', () => {
|
||||
for (const targetName in targetToRequiresPassword) {
|
||||
const targetId = SyncTargetRegistry.nameToId(targetName);
|
||||
const settings = {
|
||||
[`sync.${targetId}.password`]: 'some nonempty',
|
||||
};
|
||||
|
||||
expect(shouldShowMissingPasswordWarning(targetId, settings)).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import SyncTargetRegistry from '../../../SyncTargetRegistry';
|
||||
|
||||
const shouldShowMissingPasswordWarning = (syncTargetId: number, settings: any) => {
|
||||
const syncTargetClass = SyncTargetRegistry.classById(syncTargetId);
|
||||
|
||||
return syncTargetClass.requiresPassword() && !settings[`sync.${syncTargetId}.password`];
|
||||
};
|
||||
|
||||
export default shouldShowMissingPasswordWarning;
|
||||
Reference in New Issue
Block a user