-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Add routing middleware, permission checks, RBAC store, …
…RBAC component (#7702) Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Csaba Tuncsik <[email protected]>
- Loading branch information
1 parent
fdb2c18
commit 67a8891
Showing
62 changed files
with
1,924 additions
and
635 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
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
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,61 @@ | ||
<script lang="ts"> | ||
import type { PropType } from 'vue'; | ||
import { computed, defineComponent } from 'vue'; | ||
import { useRBACStore } from '@/stores/rbac.store'; | ||
import type { HasScopeMode, Scope, Resource } from '@n8n/permissions'; | ||
import { | ||
inferProjectIdFromRoute, | ||
inferResourceIdFromRoute, | ||
inferResourceTypeFromRoute, | ||
} from '@/utils/rbacUtils'; | ||
import { useRoute } from 'vue-router'; | ||
export default defineComponent({ | ||
props: { | ||
scope: { | ||
type: [String, Array] as PropType<Scope | Scope[]>, | ||
required: true, | ||
}, | ||
mode: { | ||
type: String as PropType<HasScopeMode>, | ||
default: 'allOf', | ||
}, | ||
resourceType: { | ||
type: String as PropType<Resource>, | ||
default: undefined, | ||
}, | ||
resourceId: { | ||
type: String, | ||
default: undefined, | ||
}, | ||
projectId: { | ||
type: String, | ||
default: undefined, | ||
}, | ||
}, | ||
setup(props, { slots }) { | ||
const rbacStore = useRBACStore(); | ||
const route = useRoute(); | ||
const hasScope = computed(() => { | ||
const projectId = props.projectId ?? inferProjectIdFromRoute(route); | ||
const resourceType = props.resourceType ?? inferResourceTypeFromRoute(route); | ||
const resourceId = resourceType | ||
? props.resourceId ?? inferResourceIdFromRoute(route) | ||
: undefined; | ||
return rbacStore.hasScope( | ||
props.scope, | ||
{ | ||
projectId, | ||
resourceType, | ||
resourceId, | ||
}, | ||
{ mode: props.mode }, | ||
); | ||
}); | ||
return () => (hasScope.value ? slots.default?.() : slots.fallback?.()); | ||
}, | ||
}); | ||
</script> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import RBAC from '@/components/RBAC.vue'; | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
import { useRBACStore } from '@/stores/rbac.store'; | ||
|
||
const renderComponent = createComponentRenderer(RBAC); | ||
|
||
vi.mock('vue-router', () => ({ | ||
useRoute: vi.fn(() => ({ | ||
path: '/workflows', | ||
params: {}, | ||
})), | ||
})); | ||
|
||
vi.mock('@/stores/rbac.store', () => ({ | ||
useRBACStore: vi.fn(), | ||
})); | ||
|
||
describe('RBAC', () => { | ||
it('renders default slot when hasScope is true', async () => { | ||
vi.mocked(useRBACStore).mockImplementation(() => ({ | ||
hasScope: () => true, | ||
})); | ||
|
||
const wrapper = renderComponent({ | ||
props: { scope: 'worfklow:list' }, | ||
slots: { | ||
default: 'Default Content', | ||
fallback: 'Fallback Content', | ||
}, | ||
}); | ||
|
||
expect(wrapper.getByText('Default Content')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders fallback slot when hasScope is false', async () => { | ||
vi.mocked(useRBACStore).mockImplementation(() => ({ | ||
hasScope: () => false, | ||
})); | ||
|
||
const wrapper = renderComponent({ | ||
props: { scope: 'worfklow:list' }, | ||
slots: { | ||
default: 'Default Content', | ||
fallback: 'Fallback Content', | ||
}, | ||
}); | ||
|
||
expect(wrapper.getByText('Fallback Content')).toBeInTheDocument(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { extendExternalHooks } from '@/mixins/externalHooks'; | ||
|
||
let cloudHooksInitialized = false; | ||
export async function initializeCloudHooks() { | ||
if (cloudHooksInitialized) { | ||
return; | ||
} | ||
|
||
const { n8nCloudHooks } = await import('@/hooks/cloud'); | ||
extendExternalHooks(n8nCloudHooks); | ||
cloudHooksInitialized = true; | ||
} |
Oops, something went wrong.