Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jan
kresus
Commits
9f74cd36
Commit
9f74cd36
authored
Aug 07, 2016
by
Benjamin Bouvier
Browse files
Fixes #441: Properly save/restore the default account in backups;
parent
163d420f
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/controllers/all.js
View file @
9f74cd36
...
...
@@ -51,7 +51,7 @@ function cleanMeta(obj) {
}
// Sync function
function
cleanData
(
world
,
save
Password
)
{
function
cleanData
(
world
,
keep
Password
)
{
// Bank information is static and shouldn't be exported.
delete
world
.
banks
;
...
...
@@ -68,7 +68,7 @@ function cleanData(world, savePassword) {
accessMap
[
a
.
id
]
=
nextAccessId
;
a
.
id
=
nextAccessId
++
;
if
(
!
save
Password
)
{
if
(
!
keep
Password
)
{
// Strip away password
delete
a
.
password
;
}
...
...
@@ -76,11 +76,13 @@ function cleanData(world, savePassword) {
cleanMeta
(
a
);
}
let
accountMap
=
{};
let
nextAccountId
=
0
;
world
.
accounts
=
world
.
accounts
||
[];
for
(
let
a
of
world
.
accounts
)
{
a
.
bankAccess
=
accessMap
[
a
.
bankAccess
];
// Strip away id
delete
a
.
id
;
accountMap
[
a
.
id
]
=
nextAccountId
;
a
.
id
=
nextAccountId
++
;
cleanMeta
(
a
);
}
...
...
@@ -130,6 +132,15 @@ function cleanData(world, savePassword) {
for
(
let
s
of
world
.
settings
)
{
delete
s
.
id
;
cleanMeta
(
s
);
// Properly save the default account id.
if
(
s
.
name
===
'
defaultAccountId
'
)
{
let
accountId
=
s
.
value
;
if
(
typeof
accountMap
[
accountId
]
===
'
undefined
'
)
log
.
warn
(
`unexpected default account id:
${
accountId
}
`
);
else
s
.
value
=
accountMap
[
accountId
];
}
}
world
.
alerts
=
world
.
alerts
||
[];
...
...
@@ -188,6 +199,7 @@ module.exports.export = async function(req, res) {
}
passphrase
=
req
.
body
.
passphrase
;
// Check password strength
if
(
!
PASSPHRASE_VALIDATION_REGEXP
.
test
(
passphrase
))
{
throw
new
KError
(
'
submitted passphrase is too weak
'
,
400
);
...
...
@@ -196,6 +208,7 @@ module.exports.export = async function(req, res) {
let
ret
=
await
getAllData
();
ret
.
accesses
=
await
Access
.
all
();
// Only save user password if encryption is enabled.
ret
=
cleanData
(
ret
,
!!
passphrase
);
ret
=
JSON
.
stringify
(
ret
,
null
,
'
'
);
...
...
@@ -258,18 +271,27 @@ module.exports.import = async function(req, res) {
for
(
let
access
of
world
.
accesses
)
{
let
accessId
=
access
.
id
;
delete
access
.
id
;
let
created
=
await
Access
.
create
(
access
);
accessMap
[
accessId
]
=
created
.
id
;
}
log
.
info
(
'
Done.
'
);
log
.
info
(
'
Import accounts...
'
);
let
accountMap
=
{};
for
(
let
account
of
world
.
accounts
)
{
if
(
!
accessMap
[
account
.
bankAccess
])
{
throw
new
KError
(
`unknown access
${
account
.
bankAccess
}
`
,
400
);
}
let
accountId
=
account
.
id
;
delete
account
.
id
;
account
.
bankAccess
=
accessMap
[
account
.
bankAccess
];
await
Account
.
create
(
account
);
let
created
=
await
Account
.
create
(
account
);
accountMap
[
accountId
]
=
created
.
id
;
}
log
.
info
(
'
Done.
'
);
...
...
@@ -337,11 +359,25 @@ module.exports.import = async function(req, res) {
log
.
info
(
'
Import settings...
'
);
for
(
let
setting
of
world
.
settings
)
{
if
(
setting
.
name
===
'
weboob-log
'
||
setting
.
name
===
'
weboob-installed
'
)
if
(
setting
.
name
===
'
weboob-log
'
||
setting
.
name
===
'
weboob-installed
'
)
continue
;
// Note that former existing values are not clobbered!
if
(
setting
.
name
===
'
defaultAccountId
'
)
{
if
(
typeof
accountMap
[
setting
.
value
]
===
'
undefined
'
)
{
throw
new
KError
(
`unknown default account id:
${
setting
.
value
}
`
,
400
);
}
setting
.
value
=
accountMap
[
setting
.
value
];
// Maybe overwrite the previous value, if there was one.
let
found
=
await
Config
.
byName
(
'
defaultAccountId
'
);
if
(
found
)
{
found
.
value
=
setting
.
value
;
await
found
.
save
();
continue
;
}
}
// Note that former existing values are not overwritten!
await
Config
.
findOrCreateByName
(
setting
.
name
,
setting
.
value
);
}
log
.
info
(
'
Done.
'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment