mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 17:08:34 +00:00
Revert masked constants (#9824)
* revert masked constants * update * update * update * update * update * removed validation * bump version --------- Co-authored-by: gsmithun4 <gsmithun4@gmail.com>
This commit is contained in:
parent
3974b00087
commit
7c35c5fea0
11 changed files with 30 additions and 83 deletions
2
.version
2
.version
|
|
@ -1 +1 @@
|
|||
2.43.0
|
||||
2.44.0
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
2.43.0
|
||||
2.44.0
|
||||
|
|
|
|||
|
|
@ -103,8 +103,6 @@ export function CodeHinter({
|
|||
}) {
|
||||
const context = useContext(CodeHinterContext);
|
||||
|
||||
const hiddenWorkspaceConstantText = 'Workspace constant values are hidden';
|
||||
|
||||
const darkMode = localStorage.getItem('darkMode') === 'true';
|
||||
const options = {
|
||||
lineNumbers: lineNumbers ?? false,
|
||||
|
|
@ -137,8 +135,6 @@ export function CodeHinter({
|
|||
const isWorkspaceVariable =
|
||||
typeof currentValue === 'string' && (currentValue.includes('%%client') || currentValue.includes('%%server'));
|
||||
|
||||
const isWorkspaceConstant = typeof currentValue === 'string' && currentValue.includes('constants.');
|
||||
|
||||
const constantRegex = /{{constants\.([a-zA-Z0-9_]+)}}/g;
|
||||
|
||||
const slideInStyles = useSpring({
|
||||
|
|
@ -269,7 +265,7 @@ export function CodeHinter({
|
|||
globalPreviewCopy = preview;
|
||||
globalErrorCopy = null;
|
||||
setResolvingError(null);
|
||||
setResolvedValue(isWorkspaceConstant ? hiddenWorkspaceConstantText : preview);
|
||||
setResolvedValue(preview);
|
||||
}
|
||||
|
||||
return [globalPreviewCopy, globalErrorCopy];
|
||||
|
|
@ -281,7 +277,7 @@ export function CodeHinter({
|
|||
return () => {
|
||||
if (enablePreview) {
|
||||
setPrevCurrentValue(null);
|
||||
setResolvedValue(isWorkspaceConstant ? hiddenWorkspaceConstantText : globalPreviewCopy);
|
||||
setResolvedValue(globalPreviewCopy);
|
||||
setResolvingError(globalErrorCopy);
|
||||
}
|
||||
};
|
||||
|
|
@ -377,9 +373,9 @@ export function CodeHinter({
|
|||
<div>
|
||||
<div className="d-flex my-1">
|
||||
<div className="flex-grow-1" style={{ fontWeight: 700, textTransform: 'capitalize' }}>
|
||||
{!isWorkspaceConstant && previewType}
|
||||
{previewType}
|
||||
</div>
|
||||
{isFocused && !isWorkspaceConstant && (
|
||||
{isFocused && (
|
||||
<div className="preview-icons position-relative">
|
||||
<CodeHinter.PopupIcon callback={() => copyToClipboard(content)} icon="copy" tip="Copy to clipboard" />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -77,8 +77,6 @@ enablePatches();
|
|||
|
||||
const decimalToHex = (alpha) => (alpha === 0 ? '00' : Math.round(255 * alpha).toString(16));
|
||||
|
||||
const maskedWorkspaceConstantStr = '**************';
|
||||
|
||||
const EditorComponent = (props) => {
|
||||
const { socket } = createWebsocketConnection(props?.params?.id);
|
||||
const mounted = useMounted();
|
||||
|
|
@ -374,7 +372,8 @@ const EditorComponent = (props) => {
|
|||
orgEnvironmentConstantService.getAll().then(({ constants }) => {
|
||||
const orgConstants = {};
|
||||
constants.map((constant) => {
|
||||
orgConstants[constant.name] = maskedWorkspaceConstantStr;
|
||||
const constantValue = constant.values.find((value) => value.environmentName === 'production')['value'];
|
||||
orgConstants[constant.name] = constantValue;
|
||||
});
|
||||
|
||||
useCurrentStateStore.getState().actions.setCurrentState({
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ import DesktopHeader from './Viewer/DesktopHeader';
|
|||
import './Viewer/viewer.scss';
|
||||
import useAppDarkMode from '@/_hooks/useAppDarkMode';
|
||||
|
||||
const maskedWorkspaceConstantStr = '**************';
|
||||
class ViewerComponent extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
@ -246,7 +245,7 @@ class ViewerComponent extends React.Component {
|
|||
if (variablesResult && Array.isArray(variablesResult)) {
|
||||
variablesResult.map((constant) => {
|
||||
const constantValue = constant.values.find((value) => value.environmentName === 'production')['value'];
|
||||
orgConstants[constant.name] = maskedWorkspaceConstantStr;
|
||||
orgConstants[constant.name] = constantValue;
|
||||
});
|
||||
return {
|
||||
constants: orgConstants,
|
||||
|
|
|
|||
|
|
@ -61,19 +61,7 @@ const verifyConstant = (value, definedConstants) => {
|
|||
};
|
||||
|
||||
const ResolvedValue = ({ value, isFocused, state = {}, type }) => {
|
||||
const isConstant = type === 'Workspace Constant';
|
||||
const hiddenWorkspaceConstantText = 'Workspace constant values are hidden';
|
||||
const invalidConstants = verifyConstant(value, state.constants);
|
||||
let preview;
|
||||
let error;
|
||||
if (invalidConstants?.length) {
|
||||
[preview, error] = [value, `Undefined constants: ${invalidConstants}`];
|
||||
} else {
|
||||
[preview, error] = resolveReferences(value, state, null, {}, true, true);
|
||||
if (isConstant) {
|
||||
preview = hiddenWorkspaceConstantText;
|
||||
}
|
||||
}
|
||||
const [preview, error] = resolveReferences(value, state, null, {}, true, true);
|
||||
|
||||
const previewType = typeof preview;
|
||||
|
||||
|
|
@ -84,7 +72,7 @@ const ResolvedValue = ({ value, isFocused, state = {}, type }) => {
|
|||
: error?.toString();
|
||||
const isValidError = error && errorMessage !== 'HiddenEnvironmentVariable';
|
||||
|
||||
if (error && (!isValidError || error?.toString().includes('Undefined constants:'))) {
|
||||
if (error && !isValidError) {
|
||||
resolvedValue = errorMessage;
|
||||
}
|
||||
|
||||
|
|
@ -109,6 +97,8 @@ const ResolvedValue = ({ value, isFocused, state = {}, type }) => {
|
|||
}
|
||||
};
|
||||
|
||||
const isConstant = type === 'Workspace Constant';
|
||||
|
||||
const [heightRef, currentHeight] = useHeight();
|
||||
|
||||
const slideInStyles = useSpring({
|
||||
|
|
@ -130,7 +120,7 @@ const ResolvedValue = ({ value, isFocused, state = {}, type }) => {
|
|||
<div className="alert-banner-type-text">
|
||||
<div className="d-flex my-1">
|
||||
<div className="flex-grow-1" style={{ fontWeight: 800, textTransform: 'capitalize' }}>
|
||||
{isValidError ? 'Error' : isConstant ? null : ` ${type} - ${previewType}`}
|
||||
{isValidError ? 'Error' : ` ${type} - ${previewType}`}
|
||||
</div>
|
||||
</div>
|
||||
{getPreviewContent(resolvedValue, previewType)}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ const initialState = {
|
|||
variables: {},
|
||||
},
|
||||
succededQuery: {},
|
||||
constants: {},
|
||||
};
|
||||
|
||||
export const useCurrentStateStore = create(
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
2.43.0
|
||||
2.44.0
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import { OrganizationConstantsAbilityFactory } from 'src/modules/casl/abilities/
|
|||
import { AppDecorator as App } from 'src/decorators/app.decorator';
|
||||
import { OrgEnvironmentVariablesAbilityFactory } from 'src/modules/casl/abilities/org-environment-variables-ability.factory';
|
||||
import { OrgEnvironmentVariable } from 'src/entities/org_envirnoment_variable.entity';
|
||||
import { OrganizationConstant } from 'src/entities/organization_constants.entity';
|
||||
|
||||
@Controller('organization-constants')
|
||||
export class OrganizationConstantController {
|
||||
|
|
@ -32,39 +31,24 @@ export class OrganizationConstantController {
|
|||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
async get(@User() user, @Query('decryptValue') decryptValue) {
|
||||
const ability = await this.organizationConstantsAbilityFactory.organizationConstantActions(user, null);
|
||||
const decrypt =
|
||||
decryptValue === 'true' &&
|
||||
(ability.can('createOrganizationConstant', OrganizationConstant) ||
|
||||
ability.can('deleteOrganizationConstant', OrganizationConstant));
|
||||
const result = await this.organizationConstantsService.allEnvironmentConstants(user.organizationId, decrypt);
|
||||
async get(@User() user) {
|
||||
const result = await this.organizationConstantsService.allEnvironmentConstants(user.organizationId);
|
||||
return { constants: result };
|
||||
}
|
||||
|
||||
@UseGuards(IsPublicGuard)
|
||||
@Get(':app_slug')
|
||||
async getConstantsFromApp(@App() app, @User() user) {
|
||||
const result = await this.organizationConstantsService.allEnvironmentConstants(app.organizationId, false);
|
||||
const result = await this.organizationConstantsService.allEnvironmentConstants(app.organizationId);
|
||||
return { constants: result };
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/environment/:environmentId')
|
||||
async getConstantsFromEnvironment(
|
||||
@User() user,
|
||||
@Param('environmentId') environmentId,
|
||||
@Query('decryptValue') decryptValue
|
||||
) {
|
||||
const ability = await this.organizationConstantsAbilityFactory.organizationConstantActions(user, null);
|
||||
const decrypt =
|
||||
decryptValue === 'true' &&
|
||||
(ability.can('createOrganizationConstant', OrganizationConstant) ||
|
||||
ability.can('deleteOrganizationConstant', OrganizationConstant));
|
||||
async getConstantsFromEnvironment(@User() user, @Param('environmentId') environmentId) {
|
||||
const result = await this.organizationConstantsService.getConstantsForEnvironment(
|
||||
user.organizationId,
|
||||
environmentId,
|
||||
decrypt
|
||||
environmentId
|
||||
);
|
||||
return { constants: result };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -605,7 +605,7 @@ export class DataQueriesService {
|
|||
|
||||
if (variables?.length > 0) {
|
||||
for (const variable of variables) {
|
||||
object = object.replace(variable, await this.resolveConstants(variable, organization_id, environmentId));
|
||||
object = object.replace(variable, options[variable]);
|
||||
}
|
||||
}
|
||||
return object;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export class OrganizationConstantsService {
|
|||
private appEnvironmentService: AppEnvironmentService
|
||||
) {}
|
||||
|
||||
async allEnvironmentConstants(organizationId: string, decryptValue: boolean): Promise<OrganizationConstant[]> {
|
||||
async allEnvironmentConstants(organizationId: string): Promise<OrganizationConstant[]> {
|
||||
return await dbTransactionWrap(async (manager: EntityManager) => {
|
||||
const query = manager
|
||||
.createQueryBuilder(OrganizationConstant, 'organization_constants')
|
||||
|
|
@ -33,21 +33,11 @@ export class OrganizationConstantsService {
|
|||
appEnvironments.map(async (env) => {
|
||||
const value = constant.orgEnvironmentConstantValues.find((value) => value.environmentId === env.id);
|
||||
|
||||
const valueResult = {
|
||||
return {
|
||||
environmentName: env.name,
|
||||
id: value ? value.environmentId : undefined, // Safeguard for undefined 'value'
|
||||
value: value && value.value.length > 0 ? await this.decryptSecret(organizationId, value.value) : '',
|
||||
id: value.environmentId,
|
||||
};
|
||||
|
||||
if (value && value.value.length > 0) {
|
||||
const decryptedOrRawValue = decryptValue
|
||||
? await this.decryptSecret(organizationId, value.value)
|
||||
: value.value;
|
||||
|
||||
if (decryptValue) {
|
||||
valueResult['value'] = decryptedOrRawValue;
|
||||
}
|
||||
}
|
||||
return valueResult;
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -64,11 +54,7 @@ export class OrganizationConstantsService {
|
|||
});
|
||||
}
|
||||
|
||||
async getConstantsForEnvironment(
|
||||
organizationId: string,
|
||||
environmentId: string,
|
||||
decryptValue: boolean
|
||||
): Promise<OrganizationConstant[]> {
|
||||
async getConstantsForEnvironment(organizationId: string, environmentId: string): Promise<OrganizationConstant[]> {
|
||||
return await dbTransactionWrap(async (manager: EntityManager) => {
|
||||
const query = manager
|
||||
.createQueryBuilder(OrganizationConstant, 'organization_constants')
|
||||
|
|
@ -78,20 +64,12 @@ export class OrganizationConstantsService {
|
|||
const result = await query.getMany();
|
||||
|
||||
const constantsWithValues = result.map(async (constant) => {
|
||||
const constantResult = {
|
||||
const decryptedValue = await this.decryptSecret(organizationId, constant.orgEnvironmentConstantValues[0].value);
|
||||
return {
|
||||
id: constant.id,
|
||||
name: constant.constantName,
|
||||
value: decryptedValue,
|
||||
};
|
||||
|
||||
if (decryptValue && constant.orgEnvironmentConstantValues.length > 0) {
|
||||
const decryptedValue = await this.decryptSecret(
|
||||
organizationId,
|
||||
constant.orgEnvironmentConstantValues[0].value
|
||||
);
|
||||
constantResult['value'] = decryptedValue;
|
||||
}
|
||||
|
||||
return constantResult;
|
||||
});
|
||||
|
||||
return Promise.all(constantsWithValues);
|
||||
|
|
|
|||
Loading…
Reference in a new issue