Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Fix Enteprise type errors #9442

Merged
merged 6 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1922,3 +1922,20 @@ export type NewConnectionInfo = {
export type AIAssistantConnectionInfo = NewConnectionInfo & {
stepName: string;
};

export type EnterpriseEditionFeatureKey =
| 'AdvancedExecutionFilters'
| 'Sharing'
| 'Ldap'
| 'LogStreaming'
| 'Variables'
| 'Saml'
| 'SourceControl'
| 'ExternalSecrets'
| 'AuditLogs'
| 'DebugInEditor'
| 'WorkflowHistory'
| 'WorkerView'
| 'AdvancedPermissions';

export type EnterpriseEditionFeatureValue = keyof Omit<IN8nUISettings['enterprise'], 'projects'>;
5 changes: 5 additions & 0 deletions packages/editor-ui/src/__tests__/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export const defaultSettings: IN8nUISettings = {
externalSecrets: false,
workerView: false,
advancedPermissions: false,
projects: {
team: {
limit: 1,
},
},
},
expressions: {
evaluator: 'tournament',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import {
getNodeAuthOptions,
isAuthRelatedParameter,
} from '@/utils/nodeTypesUtils';
import type { INodeProperties, INodeTypeDescription, NodeParameterValue } from 'n8n-workflow';
import type {
ICredentialType,
INodeProperties,
INodeTypeDescription,
NodeParameterValue,
} from 'n8n-workflow';
import { computed, onMounted, ref } from 'vue';

export interface Props {
credentialType: object;
credentialType: ICredentialType;
}

const emit = defineEmits<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ import { defineComponent } from 'vue';
import type { PropType } from 'vue';
import { mapStores } from 'pinia';

import type { ICredentialType, INodeTypeDescription } from 'n8n-workflow';
import type { ICredentialType, INodeProperties, INodeTypeDescription } from 'n8n-workflow';
import { getAppNameFromCredType, isCommunityPackageName } from '@/utils/nodeTypesUtils';

import Banner from '../Banner.vue';
Expand Down Expand Up @@ -177,13 +177,15 @@ export default defineComponent({
},
props: {
credentialType: {
type: Object,
type: Object as PropType<ICredentialType>,
required: true,
},
credentialProperties: {
type: Array,
type: Array as PropType<INodeProperties[]>,
required: true,
},
parentTypes: {
type: Array,
type: Array as PropType<string[]>,
},
credentialData: {},
credentialId: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
@select="onTabSelect"
></n8n-menu>
</div>
<div v-if="activeTab === 'connection'" ref="content" :class="$style.mainContent">
<div
v-if="activeTab === 'connection' && credentialType"
ref="content"
:class="$style.mainContent"
>
<CredentialConfig
:credential-type="credentialType"
:credential-properties="credentialProperties"
Expand Down
13 changes: 5 additions & 8 deletions packages/editor-ui/src/components/EnterpriseEdition.ee.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import type { EnterpriseEditionFeature } from '@/constants';
import { type PropType, defineComponent } from 'vue';
import type { EnterpriseEditionFeatureValue } from '@/Interface';
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/settings.store';

export default defineComponent({
name: 'EnterpriseEdition',
props: {
features: {
type: Array,
default: () => [] as EnterpriseEditionFeature[],
type: Array as PropType<EnterpriseEditionFeatureValue[]>,
default: () => [],
},
},
computed: {
...mapStores(useSettingsStore),
canAccess(): boolean {
return this.features.reduce((acc: boolean, feature) => {
return (
acc &&
!!this.settingsStore.isEnterpriseFeatureEnabled(feature as EnterpriseEditionFeature)
);
return acc && !!this.settingsStore.isEnterpriseFeatureEnabled(feature);
}, true);
},
},
Expand Down
40 changes: 24 additions & 16 deletions packages/editor-ui/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { NodeCreatorOpenSource } from './Interface';
import type {
EnterpriseEditionFeatureKey,
EnterpriseEditionFeatureValue,
NodeCreatorOpenSource,
} from './Interface';
import { NodeConnectionType } from 'n8n-workflow';

export const MAX_WORKFLOW_SIZE = 1024 * 1024 * 16; // Workflow size limit in bytes
Expand Down Expand Up @@ -541,21 +545,25 @@ export const enum WORKFLOW_MENU_ACTIONS {
/**
* Enterprise edition
*/
export const enum EnterpriseEditionFeature {
AdvancedExecutionFilters = 'advancedExecutionFilters',
Sharing = 'sharing',
Ldap = 'ldap',
LogStreaming = 'logStreaming',
Variables = 'variables',
Saml = 'saml',
SourceControl = 'sourceControl',
ExternalSecrets = 'externalSecrets',
AuditLogs = 'auditLogs',
DebugInEditor = 'debugInEditor',
WorkflowHistory = 'workflowHistory',
WorkerView = 'workerView',
AdvancedPermissions = 'advancedPermissions',
}
export const EnterpriseEditionFeature: Record<
EnterpriseEditionFeatureKey,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turned enum into const. this was causing lots of type errors.

EnterpriseEditionFeatureValue
> = {
AdvancedExecutionFilters: 'advancedExecutionFilters',
Sharing: 'sharing',
Ldap: 'ldap',
LogStreaming: 'logStreaming',
Variables: 'variables',
Saml: 'saml',
SourceControl: 'sourceControl',
ExternalSecrets: 'externalSecrets',
AuditLogs: 'auditLogs',
DebugInEditor: 'debugInEditor',
WorkflowHistory: 'workflowHistory',
WorkerView: 'workerView',
AdvancedPermissions: 'advancedPermissions',
};

export const MAIN_NODE_PANEL_WIDTH = 360;

export const enum MAIN_HEADER_TABS {
Expand Down
5 changes: 3 additions & 2 deletions packages/editor-ui/src/stores/settings.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@/api/ldap';
import { getPromptsData, getSettings, submitContactInfo, submitValueSurvey } from '@/api/settings';
import { testHealthEndpoint } from '@/api/templates';
import type { EnterpriseEditionFeature } from '@/constants';
import type { EnterpriseEditionFeatureValue } from '@/Interface';
import {
CONTACT_PROMPT_MODAL_KEY,
STORES,
Expand Down Expand Up @@ -79,7 +79,8 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, {
}),
getters: {
isEnterpriseFeatureEnabled() {
return (feature: EnterpriseEditionFeature): boolean => this.settings.enterprise?.[feature];
return (feature: EnterpriseEditionFeatureValue): boolean =>
Boolean(this.settings.enterprise?.[feature]);
},
versionCli(): string {
return this.settings.versionCli;
Expand Down
5 changes: 2 additions & 3 deletions packages/editor-ui/src/types/rbac.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { EnterpriseEditionFeature } from '@/constants';
import type { Resource, ScopeOptions, Scope } from '@n8n/permissions';
import type { IRole } from '@/Interface';
import type { EnterpriseEditionFeatureValue, IRole } from '@/Interface';

export type AuthenticatedPermissionOptions = {
bypass?: () => boolean;
Expand All @@ -9,7 +8,7 @@ export type CustomPermissionOptions<C = {}> = RBACPermissionCheck<C>;
export type DefaultUserMiddlewareOptions = {};
export type InstanceOwnerMiddlewareOptions = {};
export type EnterprisePermissionOptions = {
feature?: EnterpriseEditionFeature | EnterpriseEditionFeature[];
feature?: EnterpriseEditionFeatureValue | EnterpriseEditionFeatureValue[];
mode?: 'oneOf' | 'allOf';
};
export type GuestPermissionOptions = {};
Expand Down
4 changes: 1 addition & 3 deletions packages/editor-ui/src/utils/nodeTypesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import type {
INodeProperties,
INodeTypeDescription,
NodeParameterValueType,
INodePropertyOptions,
INodePropertyCollection,
ResourceMapperField,
} from 'n8n-workflow';
import {
Expand Down Expand Up @@ -271,7 +269,7 @@ export const getNodeCredentialForSelectedAuthType = (
export const getAuthTypeForNodeCredential = (
nodeType: INodeTypeDescription | null | undefined,
credentialType: INodeCredentialDescription | null | undefined,
): INodePropertyOptions | INodeProperties | INodePropertyCollection | null => {
): NodeAuthenticationOption | null => {
if (nodeType && credentialType) {
const authField = getMainAuthField(nodeType);
const authFieldName = authField ? authField.name : '';
Expand Down
Loading