mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix: Add missing content type to controllers (no-changelog) (#4617)
* fix: add missing content type to controllers * refactor: use ResponseHelper instead of fixing content type * fix: remove res.send calls
This commit is contained in:
parent
b0bbcf6028
commit
b4cec38ee8
|
@ -134,50 +134,54 @@ EECredentialsController.post(
|
||||||
* Grant or remove users' access to a credential.
|
* Grant or remove users' access to a credential.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EECredentialsController.put('/:credentialId/share', async (req: CredentialRequest.Share, res) => {
|
EECredentialsController.put(
|
||||||
const { credentialId } = req.params;
|
'/:credentialId/share',
|
||||||
const { shareWithIds } = req.body;
|
ResponseHelper.send(async (req: CredentialRequest.Share) => {
|
||||||
|
const { credentialId } = req.params;
|
||||||
|
const { shareWithIds } = req.body;
|
||||||
|
|
||||||
if (!Array.isArray(shareWithIds) || !shareWithIds.every((userId) => typeof userId === 'string')) {
|
if (
|
||||||
return res.status(400).send('Bad Request');
|
!Array.isArray(shareWithIds) ||
|
||||||
}
|
!shareWithIds.every((userId) => typeof userId === 'string')
|
||||||
|
) {
|
||||||
const { ownsCredential, credential } = await EECredentials.isOwned(req.user, credentialId);
|
throw new ResponseHelper.ResponseError('Bad request', undefined, 400);
|
||||||
|
|
||||||
if (!ownsCredential || !credential) {
|
|
||||||
return res.status(403).send();
|
|
||||||
}
|
|
||||||
|
|
||||||
let amountRemoved: number | null = null;
|
|
||||||
let newShareeIds: string[] = [];
|
|
||||||
await Db.transaction(async (trx) => {
|
|
||||||
// remove all sharings that are not supposed to exist anymore
|
|
||||||
const { affected } = await EECredentials.pruneSharings(trx, credentialId, [
|
|
||||||
req.user.id,
|
|
||||||
...shareWithIds,
|
|
||||||
]);
|
|
||||||
if (affected) amountRemoved = affected;
|
|
||||||
|
|
||||||
const sharings = await EECredentials.getSharings(trx, credentialId);
|
|
||||||
|
|
||||||
// extract the new sharings that need to be added
|
|
||||||
newShareeIds = rightDiff(
|
|
||||||
[sharings, (sharing) => sharing.userId],
|
|
||||||
[shareWithIds, (shareeId) => shareeId],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newShareeIds.length) {
|
|
||||||
await EECredentials.share(trx, credential, newShareeIds);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
void InternalHooksManager.getInstance().onUserSharedCredentials({
|
const { ownsCredential, credential } = await EECredentials.isOwned(req.user, credentialId);
|
||||||
credential_type: credential.type,
|
|
||||||
credential_id: credential.id.toString(),
|
|
||||||
user_id_sharer: req.user.id,
|
|
||||||
user_ids_sharees_added: newShareeIds,
|
|
||||||
sharees_removed: amountRemoved,
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.status(200).send();
|
if (!ownsCredential || !credential) {
|
||||||
});
|
throw new ResponseHelper.ResponseError('Forbidden', undefined, 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
let amountRemoved: number | null = null;
|
||||||
|
let newShareeIds: string[] = [];
|
||||||
|
await Db.transaction(async (trx) => {
|
||||||
|
// remove all sharings that are not supposed to exist anymore
|
||||||
|
const { affected } = await EECredentials.pruneSharings(trx, credentialId, [
|
||||||
|
req.user.id,
|
||||||
|
...shareWithIds,
|
||||||
|
]);
|
||||||
|
if (affected) amountRemoved = affected;
|
||||||
|
|
||||||
|
const sharings = await EECredentials.getSharings(trx, credentialId);
|
||||||
|
|
||||||
|
// extract the new sharings that need to be added
|
||||||
|
newShareeIds = rightDiff(
|
||||||
|
[sharings, (sharing) => sharing.userId],
|
||||||
|
[shareWithIds, (shareeId) => shareeId],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newShareeIds.length) {
|
||||||
|
await EECredentials.share(trx, credential, newShareeIds);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
void InternalHooksManager.getInstance().onUserSharedCredentials({
|
||||||
|
credential_type: credential.type,
|
||||||
|
credential_id: credential.id.toString(),
|
||||||
|
user_id_sharer: req.user.id,
|
||||||
|
user_ids_sharees_added: newShareeIds,
|
||||||
|
sharees_removed: amountRemoved,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
|
@ -37,40 +37,44 @@ EEWorkflowController.use((req, res, next) => {
|
||||||
* Grant or remove users' access to a workflow.
|
* Grant or remove users' access to a workflow.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EEWorkflowController.put('/:workflowId/share', async (req: WorkflowRequest.Share, res) => {
|
EEWorkflowController.put(
|
||||||
const { workflowId } = req.params;
|
'/:workflowId/share',
|
||||||
const { shareWithIds } = req.body;
|
ResponseHelper.send(async (req: WorkflowRequest.Share) => {
|
||||||
|
const { workflowId } = req.params;
|
||||||
|
const { shareWithIds } = req.body;
|
||||||
|
|
||||||
if (!Array.isArray(shareWithIds) || !shareWithIds.every((userId) => typeof userId === 'string')) {
|
if (
|
||||||
return res.status(400).send('Bad Request');
|
!Array.isArray(shareWithIds) ||
|
||||||
}
|
!shareWithIds.every((userId) => typeof userId === 'string')
|
||||||
|
) {
|
||||||
const { ownsWorkflow, workflow } = await EEWorkflows.isOwned(req.user, workflowId);
|
throw new ResponseHelper.ResponseError('Bad request', undefined, 400);
|
||||||
|
|
||||||
if (!ownsWorkflow || !workflow) {
|
|
||||||
return res.status(403).send();
|
|
||||||
}
|
|
||||||
|
|
||||||
let newShareeIds: string[] = [];
|
|
||||||
await Db.transaction(async (trx) => {
|
|
||||||
// remove all sharings that are not supposed to exist anymore
|
|
||||||
await EEWorkflows.pruneSharings(trx, workflowId, [req.user.id, ...shareWithIds]);
|
|
||||||
|
|
||||||
const sharings = await EEWorkflows.getSharings(trx, workflowId);
|
|
||||||
|
|
||||||
// extract the new sharings that need to be added
|
|
||||||
newShareeIds = rightDiff(
|
|
||||||
[sharings, (sharing) => sharing.userId],
|
|
||||||
[shareWithIds, (shareeId) => shareeId],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newShareeIds.length) {
|
|
||||||
await EEWorkflows.share(trx, workflow, newShareeIds);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return res.status(200).send();
|
const { ownsWorkflow, workflow } = await EEWorkflows.isOwned(req.user, workflowId);
|
||||||
});
|
|
||||||
|
if (!ownsWorkflow || !workflow) {
|
||||||
|
throw new ResponseHelper.ResponseError('Forbidden', undefined, 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
let newShareeIds: string[] = [];
|
||||||
|
await Db.transaction(async (trx) => {
|
||||||
|
// remove all sharings that are not supposed to exist anymore
|
||||||
|
await EEWorkflows.pruneSharings(trx, workflowId, [req.user.id, ...shareWithIds]);
|
||||||
|
|
||||||
|
const sharings = await EEWorkflows.getSharings(trx, workflowId);
|
||||||
|
|
||||||
|
// extract the new sharings that need to be added
|
||||||
|
newShareeIds = rightDiff(
|
||||||
|
[sharings, (sharing) => sharing.userId],
|
||||||
|
[shareWithIds, (shareeId) => shareeId],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newShareeIds.length) {
|
||||||
|
await EEWorkflows.share(trx, workflow, newShareeIds);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
EEWorkflowController.get(
|
EEWorkflowController.get(
|
||||||
'/:id(\\d+)',
|
'/:id(\\d+)',
|
||||||
|
|
Loading…
Reference in a new issue