mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
* add: columns and migrations for data queries and sources * add: migrations for app environments * fix: datasources and queries api * fix: import apis * add: radixui colors * create: global datasource page * fix: version creation not including global datasources queries * fix: version deletion failure * fix: ui and other bugs * add: check for abilities on global ds * fix: bugs * fix: existing test cases * fix: migration and bugs * fix: rest api oauthorize bugs * hide: add button for local ds * fix: query bugs * fix: new organization environment creation * fix: local ds label showing for new apps * fix: on page load queries for preview app and published app * fix: import bugs from v1 * fix: merge conflicts * fix: import apis * fix: apss with mulit envs * fix: ui bugs * fix: environments not being created on db:seed * fix: ui bugs * fix: route settings for global datasources * fix: customer dashboard template * fix: local ds queries not being saved * fix: runpy issues * changes: ui * fix: migration issues * fix: ui * hide datasources when no local datasources * fix: test cases * fix: unit test cases and global queries on app import/export * cleanup * add: package-lock file * undo: migration rename * cleanup * fix: ui bugs * migration fixes * fix: dark mode issues * fix: change datasource failing on query create mode * fix: workspace selector issues * fix: clickoutside for change scope option * migration changes * fix: open api issue * reverting configs changes * [Fix] Global datasources & Environment Id issue (#5830) * fix: oauth env id issue * code changes --------- Co-authored-by: gsmithun4 <gsmithun4@gmail.com> Co-authored-by: Muhsin Shah <muhsinshah21@gmail.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { User } from 'src/entities/user.entity';
|
|
import { InferSubjects, AbilityBuilder, Ability, AbilityClass, ExtractSubjectType } from '@casl/ability';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { UsersService } from 'src/services/users.service';
|
|
import { DataSource } from 'src/entities/data_source.entity';
|
|
|
|
type Actions =
|
|
| 'createGlobalDataSource'
|
|
| 'updateGlobalDataSource'
|
|
| 'deleteGlobalDataSource'
|
|
| 'authorizeOauthForSource';
|
|
|
|
type Subjects = InferSubjects<typeof User | typeof DataSource> | 'all';
|
|
|
|
export type GlobalDataSourcesAbility = Ability<[Actions, Subjects]>;
|
|
|
|
@Injectable()
|
|
export class GlobalDataSourceAbilityFactory {
|
|
constructor(private usersService: UsersService) {}
|
|
|
|
async globalDataSourceActions(user: User) {
|
|
const { can, build } = new AbilityBuilder<Ability<[Actions, Subjects]>>(
|
|
Ability as AbilityClass<GlobalDataSourcesAbility>
|
|
);
|
|
|
|
if (await this.usersService.userCan(user, 'create', 'GlobalDataSource')) {
|
|
can('createGlobalDataSource', DataSource);
|
|
}
|
|
|
|
if (await this.usersService.userCan(user, 'update', 'GlobalDataSource')) {
|
|
can('updateGlobalDataSource', DataSource);
|
|
}
|
|
|
|
if (await this.usersService.userCan(user, 'delete', 'GlobalDataSource')) {
|
|
can('deleteGlobalDataSource', DataSource);
|
|
}
|
|
|
|
if (await this.usersService.userCan(user, 'create', 'GlobalDataSource')) {
|
|
can('authorizeOauthForSource', DataSource);
|
|
}
|
|
|
|
return build({
|
|
detectSubjectType: (item) => item.constructor as ExtractSubjectType<Subjects>,
|
|
});
|
|
}
|
|
}
|