mirror of https://github.com/nextcloud/bookmarks
Allow disabling backups
fixes #1779 Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
parent
498fc90025
commit
c3ecef5ccf
|
@ -136,6 +136,8 @@ return [
|
|||
['name' => 'settings#get_archive_path', 'url' => '/settings/archivePath', 'verb' => 'GET'],
|
||||
['name' => 'settings#set_backup_path', 'url' => '/settings/backupPath', 'verb' => 'POST'],
|
||||
['name' => 'settings#get_backup_path', 'url' => '/settings/backupPath', 'verb' => 'GET'],
|
||||
['name' => 'settings#set_backup_enabled', 'url' => '/settings/backupEnabled', 'verb' => 'POST'],
|
||||
['name' => 'settings#get_backup_enabled', 'url' => '/settings/backupEnabled', 'verb' => 'GET'],
|
||||
['name' => 'settings#get_limit', 'url' => '/settings/limit', 'verb' => 'GET'],
|
||||
|
||||
# public link web view
|
||||
|
|
|
@ -13,6 +13,7 @@ use OCP\BackgroundJob\TimedJob;
|
|||
use OCA\Bookmarks\Db\BookmarkMapper;
|
||||
use OCP\Http\Client\IClient;
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -50,9 +51,13 @@ class BackupJob extends TimedJob {
|
|||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
/**
|
||||
* @var IConfig
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __construct(
|
||||
BookmarkMapper $bookmarkMapper, ITimeFactory $timeFactory, IUserManager $userManager, BackupManager $backupManager, LoggerInterface $logger
|
||||
BookmarkMapper $bookmarkMapper, ITimeFactory $timeFactory, IUserManager $userManager, BackupManager $backupManager, LoggerInterface $logger, IConfig $config
|
||||
) {
|
||||
parent::__construct($timeFactory);
|
||||
$this->bookmarkMapper = $bookmarkMapper;
|
||||
|
@ -61,6 +66,7 @@ class BackupJob extends TimedJob {
|
|||
$this->userManager = $userManager;
|
||||
$this->backupManager = $backupManager;
|
||||
$this->logger = $logger;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function run($argument) {
|
||||
|
@ -79,6 +85,9 @@ class BackupJob extends TimedJob {
|
|||
if ($this->bookmarkMapper->countBookmarksOfUser($user) === 0) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->config->getUserValue($user, 'bookmarks', 'backup.enabled', true)) {
|
||||
continue;
|
||||
}
|
||||
if ($this->backupManager->backupExistsForToday($user)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class SettingsController extends ApiController {
|
|||
$this->l = $l;
|
||||
}
|
||||
|
||||
private function getSetting(string $key, string $name, string $default): JSONResponse {
|
||||
private function getSetting(string $key, string $name, $default): JSONResponse {
|
||||
try {
|
||||
$userValue = $this->config->getUserValue(
|
||||
$this->userId,
|
||||
|
@ -172,6 +172,33 @@ class SettingsController extends ApiController {
|
|||
return $this->setSetting('archive.filePath', $archivePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* get user-defined archive path
|
||||
*
|
||||
* @return JSONResponse
|
||||
*
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function getBackupEnabled(): JSONResponse {
|
||||
return $this->getSetting(
|
||||
'backup.enabled',
|
||||
'backupEnabled',
|
||||
(string) true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* set user-defined backup path
|
||||
*
|
||||
* @param string $backupEnabled
|
||||
* @return JSONResponse
|
||||
*
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setBackupEnabled(bool $backupEnabled): JSONResponse {
|
||||
return $this->setSetting('backup.enabled', (string) $backupEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* get user-defined archive path
|
||||
*
|
||||
|
|
|
@ -27,9 +27,10 @@
|
|||
@click="onChangeArchivePath">
|
||||
</label>
|
||||
|
||||
<label><h3>{{ t('bookmarks', 'Backup path') }}</h3>
|
||||
<label><h3>{{ t('bookmarks', 'Backups') }}</h3>
|
||||
<p><label><input type="checkbox" :value="backupEnabled" @input="onChangeBackupEnabled">{{ t('bookmarks', 'Enable bookmarks backups') }}</label></p>
|
||||
<p>{{ t('bookmarks',
|
||||
'Enter the path of a folder in your Files where your bookmarks backups will be stored.'
|
||||
'Enter the path of a folder in your Files where backups will be stored.'
|
||||
) }}</p>
|
||||
<input
|
||||
:value="backupPath"
|
||||
|
@ -104,7 +105,7 @@ export default {
|
|||
},
|
||||
bookmarklet() {
|
||||
const bookmarkletUrl
|
||||
= window.location.origin + generateUrl('/apps/bookmarks/bookmarklet')
|
||||
= window.location.origin + generateUrl('/apps/bookmarks/bookmarklet')
|
||||
return `javascript:(function(){var a=window,b=document,c=encodeURIComponent,e=c(document.title),d=a.open('${bookmarkletUrl}?url='+c(b.location)+'&title='+e,'bkmk_popup','left='+((a.screenX||a.screenLeft)+10)+',top='+((a.screenY||a.screenTop)+10)+',height=650px,width=550px,resizable=1,alwaysRaised=1');a.setTimeout(function(){d.focus()},300);})();`
|
||||
},
|
||||
archivePath() {
|
||||
|
@ -113,6 +114,9 @@ export default {
|
|||
backupPath() {
|
||||
return this.$store.state.settings.backupPath
|
||||
},
|
||||
backupEnabled() {
|
||||
return Boolean(this.$store.state.settings.backupEnabled)
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
window.addEventListener('beforeinstallprompt', (e) => {
|
||||
|
@ -149,12 +153,21 @@ export default {
|
|||
})
|
||||
},
|
||||
async onChangeBackupPath(e) {
|
||||
if (!this.backupEnabled) {
|
||||
return
|
||||
}
|
||||
const path = await this.backupPathPicker.pick()
|
||||
await this.$store.dispatch(actions.SET_SETTING, {
|
||||
key: 'backupPath',
|
||||
value: path,
|
||||
})
|
||||
},
|
||||
async onChangeBackupEnabled(e) {
|
||||
await this.$store.dispatch(actions.SET_SETTING, {
|
||||
key: 'backupEnabled',
|
||||
value: !this.backupEnabled,
|
||||
})
|
||||
},
|
||||
clickAddToHomeScreen() {
|
||||
if (!this.addToHomeScreen) {
|
||||
alert(this.t('bookmarks', 'Please select "Add to home screen" in your browser menu'))
|
||||
|
@ -192,6 +205,13 @@ export default {
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
.settings input[type=checkbox] {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
top: 0.5em;
|
||||
width: 1.2em;
|
||||
}
|
||||
|
||||
.settings label {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ export const actions = {
|
|||
|
||||
SET_SETTING: 'SET_SETTING',
|
||||
LOAD_SETTING: 'LOAD_SETTING',
|
||||
LOAD_SETTINGS: 'SLOAD_SETTINGS',
|
||||
LOAD_SETTINGS: 'LOAD_SETTINGS',
|
||||
|
||||
LOAD_SHARES: 'LOAD_SHARES',
|
||||
LOAD_SHARES_OF_FOLDER: 'LOAD_SHARES_OF_FOLDER',
|
||||
|
@ -1137,7 +1137,7 @@ export default {
|
|||
},
|
||||
[actions.LOAD_SETTINGS]({ commit, dispatch, state }) {
|
||||
return Promise.all(
|
||||
['sorting', 'viewMode', 'archivePath', 'backupPath', 'limit'].map(key =>
|
||||
['sorting', 'viewMode', 'archivePath', 'backupPath', 'backupEnabled', 'limit'].map(key =>
|
||||
dispatch(actions.LOAD_SETTING, key)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -47,6 +47,8 @@ export default {
|
|||
viewMode: 'list',
|
||||
sorting: 'lastmodified',
|
||||
limit: 0,
|
||||
backupPath: '',
|
||||
backupEnabled: '1',
|
||||
},
|
||||
bookmarks: [],
|
||||
bookmarksById: {},
|
||||
|
|
Loading…
Reference in New Issue