Skip to content

Commit 8a22e71

Browse files
committed
Needed a bit more handling of copying index.html.acl
Also simplified file-handling a bit
1 parent 104516e commit 8a22e71

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

bin/lib/invalidUsernames.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,37 @@ module.exports = function (program) {
4242
})
4343
}
4444

45-
function createNewIndexFile (username, accountManager, invalidUsernameTemplate, dateOfRemoval, supportEmail, fileOptions) {
45+
function backupIndexFile (username, accountManager, invalidUsernameTemplate, dateOfRemoval, supportEmail) {
4646
const userDirectory = accountManager.accountDirFor(username)
4747
const currentIndex = path.join(userDirectory, 'index.html')
4848
const currentIndexExists = fs.existsSync(currentIndex)
49-
const currentIndexAcl = path.join(userDirectory, 'index.html.acl')
5049
const backupIndex = path.join(userDirectory, 'index.backup.html')
5150
const backupIndexExists = fs.existsSync(backupIndex)
52-
const backupIndexAcl = path.join(userDirectory, 'index.backup.html.acl')
5351
if (currentIndexExists && !backupIndexExists) {
5452
fs.renameSync(currentIndex, backupIndex)
55-
fs.copyFileSync(currentIndexAcl, backupIndexAcl)
56-
const newIndexSource = invalidUsernameTemplate({
57-
username,
58-
dateOfRemoval,
59-
supportEmail
60-
})
61-
fs.writeFileSync(currentIndex, newIndexSource, fileOptions)
53+
createNewIndexAcl(userDirectory)
54+
createNewIndex(username, invalidUsernameTemplate, dateOfRemoval, supportEmail, currentIndex)
6255
console.info(`index.html updated for user ${username}`)
6356
}
6457
}
6558

59+
function createNewIndex (username, invalidUsernameTemplate, dateOfRemoval, supportEmail, currentIndex) {
60+
const newIndexSource = invalidUsernameTemplate({
61+
username,
62+
dateOfRemoval,
63+
supportEmail
64+
})
65+
fs.writeFileSync(currentIndex, newIndexSource, 'utf-8')
66+
}
67+
68+
function createNewIndexAcl (userDirectory) {
69+
const currentIndexAcl = path.join(userDirectory, 'index.html.acl')
70+
const backupIndexAcl = path.join(userDirectory, 'index.backup.html.acl')
71+
const currentIndexSource = fs.readFileSync(currentIndexAcl, 'utf-8')
72+
const backupIndexSource = currentIndexSource.replace(/index.html/g, 'index.backup.html')
73+
fs.writeFileSync(backupIndexAcl, backupIndexSource, 'utf-8')
74+
}
75+
6676
async function deleteUsers (usernames, accountManager, config, host) {
6777
const oidcManager = fromServerConfig({
6878
...config,
@@ -149,10 +159,7 @@ async function sendEmails (config, usernames, accountManager, dateOfRemoval, sup
149159

150160
function updateIndexFiles (usernames, accountManager, dateOfRemoval, supportEmail) {
151161
const invalidUsernameFilePath = path.join(process.cwd(), 'default-views', 'account', 'invalid-username.hbs')
152-
const fileOptions = {
153-
encoding: 'utf-8'
154-
}
155-
const source = fs.readFileSync(invalidUsernameFilePath, fileOptions)
162+
const source = fs.readFileSync(invalidUsernameFilePath, 'utf-8')
156163
const invalidUsernameTemplate = Handlebars.compile(source)
157-
usernames.forEach(username => createNewIndexFile(username, accountManager, invalidUsernameTemplate, dateOfRemoval, supportEmail, fileOptions))
164+
usernames.forEach(username => backupIndexFile(username, accountManager, invalidUsernameTemplate, dateOfRemoval, supportEmail))
158165
}

0 commit comments

Comments
 (0)