-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: do not save user name in DB (#97)
* misc: do not save user name in DB * chore: add maintain job
- Loading branch information
Showing
10 changed files
with
186 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { TrelloUser } = require('../models/trello-user'); | ||
const { errorLogger } = require('../lib/logger'); | ||
|
||
async function removeUserName(req, res) { | ||
if (!process.env.MAINTAIN_TOKEN) { | ||
res.status(404); | ||
res.send('Not found'); | ||
return; | ||
} | ||
if (req.query.maintain_token !== process.env.MAINTAIN_TOKEN) { | ||
res.status(403); | ||
res.send('Forbidden'); | ||
return; | ||
} | ||
let lastKey = req.query.last_key; | ||
try { | ||
const trelloUsers = await TrelloUser.findAll({ | ||
limit: 50, | ||
lastKey: lastKey ? { id: lastKey } : undefined, | ||
}); | ||
if (trelloUsers.lastKey) { | ||
lastKey = trelloUsers.lastKey.id; | ||
} else { | ||
lastKey = ''; | ||
} | ||
for (const trelloUser of trelloUsers) { | ||
if (!!trelloUser.username || !!trelloUser.fullName) { | ||
await TrelloUser.update({ | ||
username: '', | ||
fullName: '', | ||
}, { where: { id: trelloUser.id } }); | ||
} | ||
} | ||
res.status(200); | ||
res.json({ | ||
lastKey, | ||
}); | ||
} catch (e) { | ||
errorLogger(e); | ||
res.status(500); | ||
res.send('Internal error'); | ||
} | ||
} | ||
|
||
exports.removeUserName = removeUserName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const request = require('supertest'); | ||
const { server } = require('../src/server'); | ||
const { TrelloUser } = require('../src/app/models/trello-user'); | ||
|
||
describe('Maintain', () => { | ||
it('should return 404 when no MAINTAIN_TOKEN env', async () => { | ||
const res = await request(server).get('/maintain/remove-user-name'); | ||
expect(res.status).toEqual(404); | ||
}); | ||
|
||
it('should return 403 when maintain_token is invalid', async () => { | ||
process.env.MAINTAIN_TOKEN = 'valid'; | ||
const res = await request(server).get('/maintain/remove-user-name?maintain_token=invalid'); | ||
expect(res.status).toEqual(403); | ||
delete process.env.MAINTAIN_TOKEN; | ||
}); | ||
|
||
it('should return 200 when maintain_token is valid', async () => { | ||
await TrelloUser.create({ | ||
id: '111', | ||
username: 'test', | ||
fullName: 'test', | ||
writeable_token: 'test111', | ||
}); | ||
await TrelloUser.create({ | ||
id: '222', | ||
username: '', | ||
fullName: '', | ||
writeable_token: 'test222', | ||
}); | ||
await TrelloUser.create({ | ||
id: '333', | ||
username: '333name', | ||
fullName: '333name', | ||
writeable_token: 'test333', | ||
}); | ||
process.env.MAINTAIN_TOKEN = 'valid'; | ||
const res = await request(server).get(`/maintain/remove-user-name?maintain_token=${process.env.MAINTAIN_TOKEN}`); | ||
expect(res.status).toEqual(200); | ||
expect(res.body.lastKey).toEqual(''); | ||
const user1 = await TrelloUser.findByPk('111'); | ||
expect(user1.username).toEqual(''); | ||
expect(user1.fullName).toEqual(''); | ||
expect(user1.writeable_token).toEqual('test111'); | ||
const user2 = await TrelloUser.findByPk('222'); | ||
expect(user2.username).toEqual(''); | ||
expect(user2.fullName).toEqual(''); | ||
expect(user2.writeable_token).toEqual('test222'); | ||
const user3 = await TrelloUser.findByPk('333'); | ||
expect(user3.username).toEqual(''); | ||
expect(user3.fullName).toEqual(''); | ||
expect(user3.writeable_token).toEqual('test333'); | ||
delete process.env.MAINTAIN_TOKEN; | ||
await TrelloUser.destroy({ where: { id: '111' } }); | ||
await TrelloUser.destroy({ where: { id: '222' } }); | ||
await TrelloUser.destroy({ where: { id: '333' } }); | ||
}); | ||
|
||
it('should return 200 when maintain_token is valid', async () => { | ||
await TrelloUser.create({ | ||
id: '111', | ||
username: 'test', | ||
fullName: 'test', | ||
writeable_token: 'test111', | ||
}); | ||
await TrelloUser.create({ | ||
id: '222', | ||
username: '', | ||
fullName: '', | ||
writeable_token: 'test222', | ||
}); | ||
await TrelloUser.create({ | ||
id: '333', | ||
username: '333name', | ||
fullName: '333name', | ||
writeable_token: 'test333', | ||
}); | ||
process.env.MAINTAIN_TOKEN = 'valid'; | ||
const res = await request(server).get(`/maintain/remove-user-name?maintain_token=${process.env.MAINTAIN_TOKEN}&last_key=111`); | ||
expect(res.status).toEqual(200); | ||
delete process.env.MAINTAIN_TOKEN; | ||
await TrelloUser.destroy({ where: { id: '111' } }); | ||
await TrelloUser.destroy({ where: { id: '222' } }); | ||
await TrelloUser.destroy({ where: { id: '333' } }); | ||
}); | ||
}); |