-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/add-captcha-to-resource-form-…
…if-set-to-everyone
- Loading branch information
Showing
37 changed files
with
1,528 additions
and
674 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
90 changes: 90 additions & 0 deletions
90
packages/cms/lib/modules/resource-form-widgets/lib/budget.js
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,90 @@ | ||
const eventEmitter = require('../../../../events').emitter; | ||
const fetch = require('node-fetch'); | ||
const fs = require('fs'); | ||
|
||
module.exports = async function(self, options) { | ||
|
||
self.route('put', 'budget', async function(req, res) { | ||
res.setHeader('Content-Type', 'application/json'); | ||
eventEmitter.emit('resourceCrud'); | ||
const apiUrl = self.apos.settings.getOption(req, 'apiUrl'); | ||
const siteUrl = self.apos.settings.getOption(req, 'siteUrl'); | ||
const siteId = req.data.global.siteId; | ||
|
||
const data = req.body; | ||
const getUrl = `${apiUrl}/api/site/${siteId}/idea/${data.id}`; | ||
const postUrl = `${apiUrl}/api/site/${siteId}/idea/${data.id}`; | ||
|
||
/** | ||
* Format header | ||
*/ | ||
const httpHeaders = { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
if (req.session.jwt) { | ||
httpHeaders['X-Authorization'] = `Bearer ${req.session.jwt}`; | ||
} | ||
|
||
const response = await fetch(getUrl, { | ||
headers: httpHeaders | ||
}); | ||
|
||
if(response.ok) { | ||
const idea = await response.json(); | ||
let ideaBudgets = []; | ||
|
||
try { | ||
ideaBudgets = JSON.parse(idea?.extraData?.budgetDocuments); | ||
} | ||
catch(e) { | ||
|
||
} | ||
|
||
// d.name is a string while d.date gets returned as a string, using weak comparison | ||
const indexToDelete = ideaBudgets.findIndex(d =>{ | ||
return d.name === data.name && d.date == data.date}); | ||
|
||
if(indexToDelete > -1) { | ||
const removedBudget = ideaBudgets.splice(indexToDelete, 1)[0]; | ||
const hashName = removedBudget.url.substring(removedBudget.url.lastIndexOf("/") + 1); | ||
|
||
const attachmentsPath = | ||
`public/uploads/attachments/resource-form-uploads/${ | ||
data.id}/${hashName}` | ||
|
||
try { | ||
if (fs.existsSync(attachmentsPath)) { | ||
console.log("Removing the file"); | ||
fs.rmSync(attachmentsPath, { recursive: true }); | ||
} | ||
} | ||
catch(e) { | ||
return res.status(500).send( | ||
JSON.stringify({ | ||
msg: "Het bestand kon niet verwijderd worden, probeer het nog eens.", | ||
}) | ||
); | ||
} | ||
} | ||
|
||
const putResponse = await fetch(postUrl, { | ||
method: 'PUT', | ||
headers: httpHeaders, | ||
body: JSON.stringify({ | ||
extraData: { | ||
budgetDocuments: JSON.stringify(ideaBudgets) | ||
}, | ||
}), | ||
}); | ||
|
||
if(putResponse.ok) { | ||
const ideaResponse = await putResponse.json(); | ||
res.end(JSON.stringify({ | ||
id: ideaResponse.id | ||
})); | ||
} | ||
} | ||
}); | ||
} |
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
Oops, something went wrong.
402555c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Published new image:
openstad/frontend:feature-add-captcha-to-resource-form-if-set-to-everyone-402555c