mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
fix: Change the currentUserHasAccess flag behavior (no-changelog) (#4763)
This commit is contained in:
parent
92c77127d6
commit
47b9d22ed5
|
@ -33,7 +33,7 @@ export class CredentialsService {
|
||||||
|
|
||||||
static async getAll(
|
static async getAll(
|
||||||
user: User,
|
user: User,
|
||||||
options?: { relations?: string[]; roles?: string[] },
|
options?: { relations?: string[]; roles?: string[]; disableGlobalRole?: boolean },
|
||||||
): Promise<ICredentialsDb[]> {
|
): Promise<ICredentialsDb[]> {
|
||||||
const SELECT_FIELDS: Array<keyof ICredentialsDb> = [
|
const SELECT_FIELDS: Array<keyof ICredentialsDb> = [
|
||||||
'id',
|
'id',
|
||||||
|
@ -46,7 +46,7 @@ export class CredentialsService {
|
||||||
|
|
||||||
// if instance owner, return all credentials
|
// if instance owner, return all credentials
|
||||||
|
|
||||||
if (user.globalRole.name === 'owner') {
|
if (user.globalRole.name === 'owner' && options?.disableGlobalRole !== true) {
|
||||||
return Db.collections.Credentials.find({
|
return Db.collections.Credentials.find({
|
||||||
select: SELECT_FIELDS,
|
select: SELECT_FIELDS,
|
||||||
relations: options?.relations,
|
relations: options?.relations,
|
||||||
|
|
|
@ -109,7 +109,7 @@ export class EEWorkflowsService extends WorkflowsService {
|
||||||
currentUser: User,
|
currentUser: User,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
workflow.usedCredentials = [];
|
workflow.usedCredentials = [];
|
||||||
const userCredentials = await EECredentials.getAll(currentUser);
|
const userCredentials = await EECredentials.getAll(currentUser, { disableGlobalRole: true });
|
||||||
const credentialIdsUsedByWorkflow = new Set<number>();
|
const credentialIdsUsedByWorkflow = new Set<number>();
|
||||||
workflow.nodes.forEach((node) => {
|
workflow.nodes.forEach((node) => {
|
||||||
if (!node.credentials) {
|
if (!node.credentials) {
|
||||||
|
|
|
@ -333,7 +333,7 @@ describe('GET /workflows/:id', () => {
|
||||||
expect(response.body.data.sharedWith).toHaveLength(0);
|
expect(response.body.data.sharedWith).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GET should return workflow with credentials saying owner has access even when not shared', async () => {
|
test('GET should return workflow with credentials saying owner does not have access when not shared', async () => {
|
||||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||||
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
||||||
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
||||||
|
@ -351,7 +351,7 @@ describe('GET /workflows/:id', () => {
|
||||||
{
|
{
|
||||||
id: savedCredential.id.toString(),
|
id: savedCredential.id.toString(),
|
||||||
name: savedCredential.name,
|
name: savedCredential.name,
|
||||||
currentUserHasAccess: true, // owner has access to any cred
|
currentUserHasAccess: false, // although owner can see, he does not have access
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue