mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
refactor: Improve warnings and error messages to users about sharing (#4687) (no-changelog)
* refactor: Improve warnings and error messages to users about sharing
This commit is contained in:
parent
91408dccf5
commit
ad6c6f60a1
|
@ -77,22 +77,25 @@ export function authenticationMethods(this: N8nApp): void {
|
|||
}
|
||||
|
||||
if (config.get('userManagement.isInstanceOwnerSetUp')) {
|
||||
const error = new Error('Not logged in');
|
||||
// @ts-ignore
|
||||
error.httpStatusCode = 401;
|
||||
throw error;
|
||||
throw new ResponseHelper.ResponseError('Not logged in', undefined, 401);
|
||||
}
|
||||
|
||||
try {
|
||||
user = await Db.collections.User.findOneOrFail({ relations: ['globalRole'] });
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
throw new ResponseHelper.ResponseError(
|
||||
'No users found in database - did you wipe the users table? Create at least one user.',
|
||||
undefined,
|
||||
500,
|
||||
);
|
||||
}
|
||||
|
||||
if (user.email || user.password) {
|
||||
throw new Error('Invalid database state - user has password set.');
|
||||
throw new ResponseHelper.ResponseError(
|
||||
'Invalid database state - user has password set.',
|
||||
undefined,
|
||||
500,
|
||||
);
|
||||
}
|
||||
|
||||
await issueCookie(res, user);
|
||||
|
|
|
@ -64,7 +64,7 @@ EECredentialsController.get(
|
|||
|
||||
if (!credential) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
`Credential with ID "${credentialId}" could not be found.`,
|
||||
'Could not load the credential. If you think this is an error, ask the owner to share it with you again',
|
||||
undefined,
|
||||
404,
|
||||
);
|
||||
|
|
|
@ -160,7 +160,7 @@ credentialsController.patch(
|
|||
userId: req.user.id,
|
||||
});
|
||||
throw new ResponseHelper.ResponseError(
|
||||
`Credential with ID "${credentialId}" could not be found to be updated.`,
|
||||
'Credential to be updated not found. You can only update credentials owned by you',
|
||||
undefined,
|
||||
404,
|
||||
);
|
||||
|
@ -218,7 +218,7 @@ credentialsController.delete(
|
|||
userId: req.user.id,
|
||||
});
|
||||
throw new ResponseHelper.ResponseError(
|
||||
`Credential with ID "${credentialId}" could not be found to be deleted.`,
|
||||
'Credential to be deleted not found. You can only removed credentials owned by you',
|
||||
undefined,
|
||||
404,
|
||||
);
|
||||
|
|
|
@ -87,7 +87,7 @@ EEWorkflowController.get(
|
|||
|
||||
if (!workflow) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
`Workflow with ID "${workflowId}" could not be found.`,
|
||||
`Workflow with ID "${workflowId}" does not exist`,
|
||||
undefined,
|
||||
404,
|
||||
);
|
||||
|
@ -96,7 +96,11 @@ EEWorkflowController.get(
|
|||
const userSharing = workflow.shared?.find((shared) => shared.user.id === req.user.id);
|
||||
|
||||
if (!userSharing && req.user.globalRole.name !== 'owner') {
|
||||
throw new ResponseHelper.ResponseError(`Forbidden.`, undefined, 403);
|
||||
throw new ResponseHelper.ResponseError(
|
||||
'It looks like you cannot access this workflow. Ask the owner to share it with you.',
|
||||
undefined,
|
||||
403,
|
||||
);
|
||||
}
|
||||
|
||||
return EEWorkflows.addCredentialsToWorkflow(
|
||||
|
@ -140,7 +144,7 @@ EEWorkflowController.post(
|
|||
EEWorkflows.validateCredentialPermissionsToUser(newWorkflow, allCredentials);
|
||||
} catch (error) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
'The workflow contains credentials that you do not have access to',
|
||||
'The workflow you are trying to save contains credentials that are not shared with you',
|
||||
undefined,
|
||||
400,
|
||||
);
|
||||
|
@ -169,7 +173,9 @@ EEWorkflowController.post(
|
|||
|
||||
if (!savedWorkflow) {
|
||||
LoggerProxy.error('Failed to create workflow', { userId: req.user.id });
|
||||
throw new ResponseHelper.ResponseError('Failed to save workflow');
|
||||
throw new ResponseHelper.ResponseError(
|
||||
'An error occurred while saving your workflow. Please try again.',
|
||||
);
|
||||
}
|
||||
|
||||
if (tagIds && !config.getEnv('workflowTagsDisabled') && savedWorkflow.tags) {
|
||||
|
|
|
@ -223,7 +223,7 @@ workflowsController.get(
|
|||
userId: req.user.id,
|
||||
});
|
||||
throw new ResponseHelper.ResponseError(
|
||||
`Workflow with ID "${workflowId}" could not be found.`,
|
||||
'Could not load the workflow - you can only access workflows owned by you',
|
||||
undefined,
|
||||
404,
|
||||
);
|
||||
|
@ -298,7 +298,7 @@ workflowsController.delete(
|
|||
userId: req.user.id,
|
||||
});
|
||||
throw new ResponseHelper.ResponseError(
|
||||
`Workflow with ID "${workflowId}" could not be found to be deleted.`,
|
||||
'Could not delete the workflow - you can only remove workflows owned by you',
|
||||
undefined,
|
||||
400,
|
||||
);
|
||||
|
|
|
@ -197,7 +197,7 @@ export class WorkflowsService {
|
|||
userId: user.id,
|
||||
});
|
||||
throw new ResponseHelper.ResponseError(
|
||||
`Workflow with ID "${workflowId}" could not be found to be updated.`,
|
||||
'You do not have permission to update this workflow. Ask the owner to share it with you.',
|
||||
undefined,
|
||||
404,
|
||||
);
|
||||
|
@ -205,7 +205,7 @@ export class WorkflowsService {
|
|||
|
||||
if (!forceSave && workflow.hash !== '' && workflow.hash !== shared.workflow.hash) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
`Workflow ID ${workflowId} cannot be saved because it was changed by another user.`,
|
||||
'We are sorry, but the workflow has been changed in the meantime. Please reload the workflow and try again.',
|
||||
undefined,
|
||||
400,
|
||||
);
|
||||
|
|
|
@ -471,7 +471,7 @@ describe('POST /workflows', () => {
|
|||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.body.message).toBe(
|
||||
'The workflow contains credentials that you do not have access to',
|
||||
'The workflow you are trying to save contains credentials that are not shared with you',
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -760,7 +760,7 @@ describe('PATCH /workflows/:id - validate interim updates', () => {
|
|||
|
||||
expect(updateAttemptResponse.status).toBe(400);
|
||||
expect(updateAttemptResponse.body.message).toContain(
|
||||
'cannot be saved because it was changed by another user',
|
||||
'the workflow has been changed in the meantime',
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -802,7 +802,7 @@ describe('PATCH /workflows/:id - validate interim updates', () => {
|
|||
|
||||
expect(updateAttemptResponse.status).toBe(400);
|
||||
expect(updateAttemptResponse.body.message).toContain(
|
||||
'cannot be saved because it was changed by another user',
|
||||
'the workflow has been changed in the meantime',
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -832,7 +832,7 @@ describe('PATCH /workflows/:id - validate interim updates', () => {
|
|||
|
||||
expect(activationAttemptResponse.status).toBe(400);
|
||||
expect(activationAttemptResponse.body.message).toContain(
|
||||
'cannot be saved because it was changed by another user',
|
||||
'the workflow has been changed in the meantime',
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -871,7 +871,7 @@ describe('PATCH /workflows/:id - validate interim updates', () => {
|
|||
|
||||
expect(updateAttemptResponse.status).toBe(400);
|
||||
expect(updateAttemptResponse.body.message).toContain(
|
||||
'cannot be saved because it was changed by another user',
|
||||
'the workflow has been changed in the meantime',
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -906,7 +906,7 @@ describe('PATCH /workflows/:id - validate interim updates', () => {
|
|||
|
||||
expect(updateAttemptResponse.status).toBe(400);
|
||||
expect(updateAttemptResponse.body.message).toContain(
|
||||
'cannot be saved because it was changed by another user',
|
||||
'the workflow has been changed in the meantime',
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -941,7 +941,7 @@ describe('PATCH /workflows/:id - validate interim updates', () => {
|
|||
|
||||
expect(updateAttemptResponse.status).toBe(400);
|
||||
expect(updateAttemptResponse.body.message).toContain(
|
||||
'cannot be saved because it was changed by another user',
|
||||
'the workflow has been changed in the meantime',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue