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

fix(editor): Enable moving resources only if team projects are available by the license #10271

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions packages/editor-ui/src/components/CredentialCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createComponentRenderer } from '@/__tests__/render';
import CredentialCard from '@/components/CredentialCard.vue';
import type { ICredentialsResponse } from '@/Interface';
import type { ProjectSharingData } from '@/types/projects.types';
import { useSettingsStore } from '@/stores/settings.store';
import { useProjectsStore } from '@/stores/projects.store';

const renderComponent = createComponentRenderer(CredentialCard);

Expand All @@ -22,12 +22,12 @@ const createCredential = (overrides = {}): ICredentialsResponse => ({
});

describe('CredentialCard', () => {
let settingsStore: ReturnType<typeof useSettingsStore>;
let projectsStore: ReturnType<typeof useProjectsStore>;

beforeEach(() => {
const pinia = createTestingPinia();
setActivePinia(pinia);
settingsStore = useSettingsStore();
projectsStore = useProjectsStore();
});

it('should render name and home project name', () => {
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('CredentialCard', () => {
});

it('should show Move action only if there is resource permission and not on community plan', async () => {
vi.spyOn(settingsStore, 'isCommunityPlan', 'get').mockReturnValue(false);
vi.spyOn(projectsStore, 'isTeamProjectsAvailable', 'get').mockReturnValue(true);

const data = createCredential({
scopes: ['credential:move'],
Expand Down
4 changes: 1 addition & 3 deletions packages/editor-ui/src/components/CredentialCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useProjectsStore } from '@/stores/projects.store';
import ProjectCardBadge from '@/components/Projects/ProjectCardBadge.vue';
import { useI18n } from '@/composables/useI18n';
import { ResourceType } from '@/utils/projects.utils';
import { useSettingsStore } from '@/stores/settings.store';

const CREDENTIAL_LIST_ITEM_ACTIONS = {
OPEN: 'open',
Expand Down Expand Up @@ -46,7 +45,6 @@ const message = useMessage();
const uiStore = useUIStore();
const credentialsStore = useCredentialsStore();
const projectsStore = useProjectsStore();
const settingsStore = useSettingsStore();

const resourceTypeLabel = computed(() => locale.baseText('generic.credential').toLowerCase());
const credentialType = computed(() => credentialsStore.getCredentialTypeByName(props.data.type));
Expand All @@ -66,7 +64,7 @@ const actions = computed(() => {
});
}

if (credentialPermissions.value.move && !settingsStore.isCommunityPlan) {
if (credentialPermissions.value.move && projectsStore.isTeamProjectsAvailable) {
items.push({
label: locale.baseText('credentials.item.move'),
value: CREDENTIAL_LIST_ITEM_ACTIONS.MOVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ onMounted(async () => {
<hr
v-if="
displayProjects.length ||
(projectsStore.hasPermissionToCreateProjects && projectsStore.teamProjectsAvailable)
(projectsStore.hasPermissionToCreateProjects && projectsStore.isTeamProjectsAvailable)
"
class="mt-m mb-m"
/>
Expand All @@ -137,7 +137,7 @@ onMounted(async () => {
</ElMenu>
<N8nTooltip placement="right" :disabled="projectsStore.canCreateProjects">
<ElMenu
v-if="projectsStore.hasPermissionToCreateProjects && projectsStore.teamProjectsAvailable"
v-if="projectsStore.hasPermissionToCreateProjects && projectsStore.isTeamProjectsAvailable"
:collapse="props.collapsed"
class="pl-xs pr-xs"
>
Expand Down Expand Up @@ -171,7 +171,7 @@ onMounted(async () => {
<hr
v-if="
displayProjects.length ||
(projectsStore.hasPermissionToCreateProjects && projectsStore.teamProjectsAvailable)
(projectsStore.hasPermissionToCreateProjects && projectsStore.isTeamProjectsAvailable)
"
class="mt-m mb-m"
/>
Expand Down
10 changes: 5 additions & 5 deletions packages/editor-ui/src/components/WorkflowCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { VIEWS } from '@/constants';
import WorkflowCard from '@/components/WorkflowCard.vue';
import type { IWorkflowDb } from '@/Interface';
import { useRouter } from 'vue-router';
import { useSettingsStore } from '@/stores/settings.store';
import { useProjectsStore } from '@/stores/projects.store';

vi.mock('vue-router', () => {
const push = vi.fn();
Expand Down Expand Up @@ -40,13 +40,13 @@ describe('WorkflowCard', () => {
let pinia: ReturnType<typeof createPinia>;
let windowOpenSpy: MockInstance;
let router: ReturnType<typeof useRouter>;
let settingsStore: ReturnType<typeof useSettingsStore>;
let projectsStore: ReturnType<typeof useProjectsStore>;

beforeEach(async () => {
pinia = createPinia();
setActivePinia(pinia);
router = useRouter();
settingsStore = useSettingsStore();
projectsStore = useProjectsStore();
windowOpenSpy = vi.spyOn(window, 'open').mockImplementation(() => null);
});

Expand Down Expand Up @@ -143,8 +143,8 @@ describe('WorkflowCard', () => {
expect(badge).toHaveTextContent('John Doe');
});

it('should show Move action only if there is resource permission and not on community plan', async () => {
vi.spyOn(settingsStore, 'isCommunityPlan', 'get').mockReturnValue(false);
it('should show Move action only if there is resource permission and team projects available', async () => {
vi.spyOn(projectsStore, 'isTeamProjectsAvailable', 'get').mockReturnValue(true);

const data = createWorkflow({
scopes: ['workflow:move'],
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/WorkflowCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const actions = computed(() => {
});
}

if (workflowPermissions.value.move && !settingsStore.isCommunityPlan) {
if (workflowPermissions.value.move && projectsStore.isTeamProjectsAvailable) {
items.push({
label: locale.baseText('workflows.item.move'),
value: WORKFLOW_LIST_ITEM_ACTIONS.MOVE,
Expand Down
8 changes: 4 additions & 4 deletions packages/editor-ui/src/stores/projects.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ export const useProjectsStore = defineStore('projects', () => {
);
const teamProjects = computed(() => projects.value.filter((p) => p.type === ProjectTypes.Team));
const teamProjectsLimit = computed(() => settingsStore.settings.enterprise.projects.team.limit);
const teamProjectsAvailable = computed<boolean>(
const isTeamProjectsAvailable = computed<boolean>(
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 much better with the prefix. Tho to be grammatically correct, we should name this areTeamProjectsAvailable, as it's plural projects

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, probably. I was considering it as the feature name, and actually, with that in mind, it should be isTeamProjectFeatureEnabled

() => settingsStore.settings.enterprise.projects.team.limit !== 0,
);
const hasUnlimitedProjects = computed<boolean>(
() => settingsStore.settings.enterprise.projects.team.limit === -1,
);
const teamProjectLimitExceeded = computed<boolean>(
const isTeamProjectLimitExceeded = computed<boolean>(
() => projectsCount.value.team >= teamProjectsLimit.value,
);
const canCreateProjects = computed<boolean>(
() =>
hasUnlimitedProjects.value ||
(teamProjectsAvailable.value && !teamProjectLimitExceeded.value),
(isTeamProjectsAvailable.value && !isTeamProjectLimitExceeded.value),
);
const hasPermissionToCreateProjects = computed(() =>
hasPermission(['rbac'], { rbac: { scope: 'project:create' } }),
Expand Down Expand Up @@ -199,7 +199,7 @@ export const useProjectsStore = defineStore('projects', () => {
hasUnlimitedProjects,
canCreateProjects,
hasPermissionToCreateProjects,
teamProjectsAvailable,
isTeamProjectsAvailable,
projectNavActiveId,
setCurrentProject,
getAllProjects,
Expand Down
Loading