|
@@ -278,22 +278,19 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
* 200:
|
|
|
* description: Succeeded to update access token for slack
|
|
* description: Succeeded to update access token for slack
|
|
|
*/
|
|
*/
|
|
|
- router.put('/access-tokens', /* loginRequiredStrictly, adminRequired, csrf, */async(req, res) => {
|
|
|
|
|
|
|
+ router.put('/access-tokens', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
|
|
|
const SlackAppIntegration = mongoose.model('SlackAppIntegration');
|
|
const SlackAppIntegration = mongoose.model('SlackAppIntegration');
|
|
|
let checkTokens;
|
|
let checkTokens;
|
|
|
let tokenGtoP;
|
|
let tokenGtoP;
|
|
|
let tokenPtoG;
|
|
let tokenPtoG;
|
|
|
do {
|
|
do {
|
|
|
// TODO imple generate tokens at GW-5859. The following tokens is temporary.
|
|
// TODO imple generate tokens at GW-5859. The following tokens is temporary.
|
|
|
- const { user } = req.body;
|
|
|
|
|
- const hoge = SlackAppIntegration.generateAccessToken(user);
|
|
|
|
|
- await hoge.save();
|
|
|
|
|
- tokenGtoP = 'v3';
|
|
|
|
|
- tokenPtoG = 'v3';
|
|
|
|
|
|
|
+ const generateTokens = SlackAppIntegration.generateAccessToken();
|
|
|
|
|
+ tokenGtoP = generateTokens[0];
|
|
|
|
|
+ tokenPtoG = generateTokens[1];
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
checkTokens = await SlackAppIntegration.findOne({ $or: [{ tokenGtoP }, { tokenPtoG }] });
|
|
checkTokens = await SlackAppIntegration.findOne({ $or: [{ tokenGtoP }, { tokenPtoG }] });
|
|
|
} while (checkTokens != null);
|
|
} while (checkTokens != null);
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
const slackAppTokens = await SlackAppIntegration.create({ tokenGtoP, tokenPtoG });
|
|
const slackAppTokens = await SlackAppIntegration.create({ tokenGtoP, tokenPtoG });
|
|
|
return res.apiv3(slackAppTokens, 200);
|
|
return res.apiv3(slackAppTokens, 200);
|