mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
* added all pending cloud migration * restrict cloud migrations * added cloud data-migrations * Added cloud entities * keep tables across all * cloud licensing initial changes * fix * payments module * license counts updates * update * Added all pending cloud migration to pre-release + Payments module (#13006) * added all pending cloud migration * restrict cloud migrations * added cloud data-migrations * Added cloud entities * keep tables across all * payments module * license counts updates * update * migration fixes * pass orgId * movement * added cloud instance settings * org id to license terms * before merge * dockerfile changes for cloud * migration fixes * subscription * merge main * posthog-js package * fix * selhostcustomer migration timestamp update * fix * fixes * fix * fix * Adding cloud dockerfile changes * migration fix * fix * fix * fix * fixes * added migration progress * fix * added migration files for cloud * fix * added migrations for cloud * add organizationId for pages controller * fixes for plugins script * fix * final * added cloud licensing envs * UI WRAPPER BUG * fix * orgId groups fix * lint check fixes * Refactor Dockerfiles to use dynamic branch names for builds * Feature/promote release permission management (#13020) * migration and entity changes * removed extra migration * added default group permissions * basic ui changes * added promote and release permissions * fixed tooltips for promote and release buttons * fix * fixed app promote ability check * ce compatibility ui change * ui fixes * removed console.log * removed comments * updated ee-preview.Dockerile * using base img node:22.15.1-bullseye * fix for ce render * Update ce-preview.Dockerfile * Update ee-preview.Dockerfile * ui fix * fix * fixes * fixes * fixes * fixes * minor fixes * fix --------- Co-authored-by: Souvik <psouvik260@gmail.com> Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com> * Bugfix/git sync pre release (#13098) * bugfixes * ui fixes for disabled states in version creation * minor fixes * removed unused imports * fixes * removed comments * module file fixes * module fixes * white-labelling fixes * login-configs * fix for migration for ce * Fix for app count guard (#13131) * fix for app count guard * added check * for debug * license key * Modules : Platform Functionality (#12994) * init * mod * app import-export * licensing and UI * review and permissions * update * updates * update * update * fix breadcrumb * fix app builder error * remove launch button for modules * fixed homepage * fix permission check --------- Co-authored-by: platform-ops123 <platformops545@gmail.com> Co-authored-by: gsmithun4 <gsmithun4@gmail.com> * reverted logs * tjdb guard and dark mode (#13137) * ui fixes * added modules module * removed unused imports * fix * fix * Cypress fix * fixes for cloud instance level licensing (#13146) --------- Co-authored-by: platform-ops123 <platformops545@gmail.com> Co-authored-by: Rudra deep Biswas <rudra21ultra@gmail.com> Co-authored-by: Adish M <adish.madhu@gmail.com> Co-authored-by: Rudhra Deep Biswas <98055396+rudeUltra@users.noreply.github.com> Co-authored-by: Vijaykant Yadav <vjy239@gmail.com> Co-authored-by: Rohan Lahori <64496391+rohanlahori@users.noreply.github.com> Co-authored-by: Souvik <psouvik260@gmail.com> Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com> Co-authored-by: rohanlahori <rohanlahori99@gmail.com> Co-authored-by: ajith-k-v <ajith.jaban@gmail.com>
217 lines
8.1 KiB
TypeScript
217 lines
8.1 KiB
TypeScript
import { MigrationProgress } from '@helpers/migration.helper';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { AppsGroupPermissions } from '@entities/apps_group_permissions.entity';
|
|
import { GranularPermissions } from '@entities/granular_permissions.entity';
|
|
import { GroupPermissions } from '@entities/group_permissions.entity';
|
|
import { Organization } from '@entities/organization.entity';
|
|
import { UserGroupPermission } from '@entities/user_group_permission.entity';
|
|
import { EntityManager, MigrationInterface, QueryRunner } from 'typeorm';
|
|
import {
|
|
CreateResourcePermissionObjectGeneric,
|
|
DEFAULT_GROUP_PERMISSIONS_MIGRATIONS,
|
|
} from 'src/migration-helpers/constants';
|
|
import {
|
|
USER_ROLE,
|
|
DEFAULT_GROUP_PERMISSIONS,
|
|
ResourceType,
|
|
DEFAULT_RESOURCE_PERMISSIONS,
|
|
} from '@modules/group-permissions/constants';
|
|
import { DEFAULT_GRANULAR_PERMISSIONS_NAME } from '@modules/group-permissions/constants/granular_permissions';
|
|
import { CreateGranularPermissionDto } from '@modules/group-permissions/dto/granular-permissions';
|
|
import {
|
|
CreateResourcePermissionObject,
|
|
ResourcePermissionMetaData,
|
|
} from '@modules/group-permissions/types/granular_permissions';
|
|
import { AppModule } from '@modules/app/module';
|
|
import { LicenseInitService } from '@modules/licensing/interfaces/IService';
|
|
import { TOOLJET_EDITIONS } from '@modules/app/constants';
|
|
import { getTooljetEdition } from '@helpers/utils.helper';
|
|
|
|
export class CreateDefaultGroupInExistingWorkspace1720352990850 implements MigrationInterface {
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
const edition = getTooljetEdition() as TOOLJET_EDITIONS;
|
|
if (edition === TOOLJET_EDITIONS.Cloud) {
|
|
console.log('Migration is only restricted for non cloud edition.');
|
|
return; // Exit the migration early
|
|
}
|
|
const manager = queryRunner.manager;
|
|
|
|
const organizationIds = (
|
|
await manager.find(Organization, {
|
|
select: ['id'],
|
|
})
|
|
).map((organization) => organization.id);
|
|
|
|
if (organizationIds?.length === 0) {
|
|
console.log('No organizations found, skipping migration.');
|
|
return;
|
|
}
|
|
|
|
const nestApp = await NestFactory.createApplicationContext(await AppModule.register({ IS_GET_CONTEXT: true }));
|
|
|
|
const licenseService = nestApp.get<LicenseInitService>(LicenseInitService);
|
|
const licenseValid =
|
|
getTooljetEdition() === TOOLJET_EDITIONS.CE ? true : await licenseService.initForMigration(manager);
|
|
|
|
const migrationProgress = new MigrationProgress(
|
|
'CreateDefaultGroupInExistingWorkspace1720352990850',
|
|
organizationIds.length
|
|
);
|
|
|
|
for (const organizationId of organizationIds) {
|
|
for (const defaultGroup of Object.keys(USER_ROLE)) {
|
|
const groupPermissions = licenseValid
|
|
? DEFAULT_GROUP_PERMISSIONS_MIGRATIONS[defaultGroup]
|
|
: DEFAULT_GROUP_PERMISSIONS[defaultGroup];
|
|
const query = `
|
|
INSERT INTO permission_groups (
|
|
organization_id,
|
|
name,
|
|
type,
|
|
app_create,
|
|
app_delete,
|
|
folder_crud,
|
|
org_constant_crud,
|
|
data_source_create,
|
|
data_source_delete
|
|
) VALUES (
|
|
'${organizationId}',
|
|
'${groupPermissions.name}',
|
|
'${groupPermissions.type}',
|
|
${groupPermissions.appCreate},
|
|
${groupPermissions.appDelete},
|
|
${groupPermissions.folderCRUD},
|
|
${groupPermissions.orgConstantCRUD},
|
|
${groupPermissions.dataSourceCreate},
|
|
${groupPermissions.dataSourceDelete}
|
|
) RETURNING *;
|
|
`;
|
|
const group: GroupPermissions = (await manager.query(query))[0];
|
|
const groupGranularPermissions: Record<
|
|
ResourceType,
|
|
CreateResourcePermissionObject<any>
|
|
> = DEFAULT_RESOURCE_PERMISSIONS[group.name];
|
|
|
|
for (const resource of Object.keys(groupGranularPermissions)) {
|
|
const dtoObject: CreateGranularPermissionDto = {
|
|
name: DEFAULT_GRANULAR_PERMISSIONS_NAME[resource],
|
|
groupId: group.id,
|
|
type: resource as ResourceType,
|
|
isAll: true,
|
|
createResourcePermissionObject: {},
|
|
};
|
|
if (group.name === USER_ROLE.ADMIN) {
|
|
const createResourcePermissionObj: CreateResourcePermissionObjectGeneric =
|
|
groupGranularPermissions[resource];
|
|
|
|
const granularPermissions = await this.createGranularPermission(manager, dtoObject);
|
|
if (resource === ResourceType.APP) {
|
|
await this.createAppsResourcePermission(
|
|
manager,
|
|
{ granularPermissions, organizationId },
|
|
createResourcePermissionObj as CreateResourcePermissionObject<ResourceType.APP>
|
|
);
|
|
} else if (resource === ResourceType.DATA_SOURCE) {
|
|
await this.createDataSourceResourcePermission(
|
|
manager,
|
|
{ granularPermissions, organizationId },
|
|
createResourcePermissionObj as CreateResourcePermissionObject<ResourceType.DATA_SOURCE>
|
|
);
|
|
}
|
|
}
|
|
}
|
|
//Migrating Admins to new Admins
|
|
if (group.name === USER_ROLE.ADMIN) {
|
|
const adminsUsers = await manager
|
|
.createQueryBuilder(UserGroupPermission, 'usersGroup')
|
|
.innerJoin(
|
|
'usersGroup.groupPermission',
|
|
'groupPermission',
|
|
'groupPermission.organizationId = :organizationId',
|
|
{
|
|
organizationId,
|
|
}
|
|
)
|
|
.where('groupPermission.group = :admin', {
|
|
admin: 'admin',
|
|
})
|
|
.getMany();
|
|
const uniqueUserIds = new Set(adminsUsers.map((userGroup) => userGroup.userId));
|
|
if (uniqueUserIds.size === 0) continue;
|
|
const userIds = [...uniqueUserIds];
|
|
await this.migrateUserGroup(manager, userIds, group.id);
|
|
}
|
|
}
|
|
migrationProgress.show();
|
|
}
|
|
await nestApp.close();
|
|
}
|
|
|
|
async createGranularPermission(
|
|
manager: EntityManager,
|
|
createObject: CreateGranularPermissionDto
|
|
): Promise<GranularPermissions> {
|
|
const query = `
|
|
INSERT INTO granular_permissions (
|
|
group_id,
|
|
name,
|
|
type,
|
|
is_all
|
|
) VALUES (
|
|
'${createObject.groupId}', '${createObject.name}', '${createObject.type}', ${createObject.isAll}
|
|
) RETURNING *;
|
|
`;
|
|
return (await manager.query(query))[0];
|
|
}
|
|
|
|
async createAppsResourcePermission(
|
|
manager: EntityManager,
|
|
createMeta: ResourcePermissionMetaData,
|
|
createObject: CreateResourcePermissionObject<ResourceType.APP>
|
|
): Promise<AppsGroupPermissions> {
|
|
const { granularPermissions } = createMeta;
|
|
const query = `
|
|
INSERT INTO apps_group_permissions (
|
|
granular_permission_id,
|
|
can_edit,
|
|
can_view,
|
|
hide_from_dashboard
|
|
) VALUES (
|
|
'${granularPermissions.id}', ${createObject.canEdit}, ${createObject.canView}, ${createObject.hideFromDashboard}
|
|
) RETURNING *;
|
|
`;
|
|
return (await manager.query(query))[0];
|
|
}
|
|
|
|
async createDataSourceResourcePermission(
|
|
manager: EntityManager,
|
|
createMeta: ResourcePermissionMetaData,
|
|
createObject: CreateResourcePermissionObject<ResourceType.DATA_SOURCE>
|
|
): Promise<AppsGroupPermissions> {
|
|
const { granularPermissions } = createMeta;
|
|
const query = `
|
|
INSERT INTO data_sources_group_permissions (
|
|
granular_permission_id,
|
|
can_configure,
|
|
can_use
|
|
) VALUES (
|
|
'${granularPermissions.id}', ${createObject?.action?.canConfigure || false}, ${
|
|
createObject?.action?.canUse || false
|
|
}
|
|
) RETURNING *;
|
|
`;
|
|
return (await manager.query(query))[0];
|
|
}
|
|
|
|
async migrateUserGroup(manager: EntityManager, userIds: string[], groupId: string) {
|
|
if (userIds.length == 0) return;
|
|
const valuesString = userIds.map((id) => `('${id}', '${groupId}')`).join(',');
|
|
const query = `
|
|
INSERT INTO group_users (user_id, group_id)
|
|
VALUES ${valuesString};
|
|
`;
|
|
return await manager.query(query);
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {}
|
|
}
|