-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14550f9
commit 67b4a47
Showing
5 changed files
with
79 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { useActionSettingsConfig } from "ee/PluginActionEditor/hooks/useActionSettingsConfig"; | ||
export { useHandleDeleteClick } from "ee/PluginActionEditor/hooks/useHandleDeleteClick"; | ||
export { useHandleRunClick } from "ee/PluginActionEditor/hooks/useHandleRunClick"; | ||
export { useBlockExecution } from "ee/PluginActionEditor/hooks/useBlockExecution"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/client/src/ce/PluginActionEditor/hooks/useBlockExecution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { getHasExecuteActionPermission } from "ee/utils/BusinessFeatures/permissionPageHelpers"; | ||
import { FEATURE_FLAG } from "ee/entities/FeatureFlag"; | ||
import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; | ||
import { DEFAULT_DATASOURCE_NAME } from "constants/ApiEditorConstants/ApiEditorConstants"; | ||
import { UIComponentTypes } from "api/PluginApi"; | ||
import { SQL_DATASOURCES } from "constants/QueryEditorConstants"; | ||
import { usePluginActionContext } from "PluginActionEditor/PluginActionContext"; | ||
|
||
const useBlockExecution = () => { | ||
const { action, plugin } = usePluginActionContext(); | ||
const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled); | ||
const isExecutePermitted = getHasExecuteActionPermission( | ||
isFeatureEnabled, | ||
action?.userPermissions, | ||
); | ||
|
||
let actionBody = ""; | ||
let blockExecution = false; | ||
|
||
// API Editor Constants | ||
// this gets the url of the current action's datasource | ||
const actionDatasourceUrl = | ||
action.datasource.datasourceConfiguration?.url || ""; | ||
const actionDatasourceUrlPath = action.actionConfiguration.path || ""; | ||
// this gets the name of the current action's datasource | ||
const actionDatasourceName = action.datasource.name || ""; | ||
|
||
// Query Editor Constants | ||
if (!!action.actionConfiguration) { | ||
if ("formData" in action.actionConfiguration) { | ||
// if the action has a formData (the action is postUQI e.g. Oracle) | ||
actionBody = action.actionConfiguration.formData?.body?.data || ""; | ||
} else { | ||
// if the action is pre UQI, the path is different e.g. mySQL | ||
actionBody = action.actionConfiguration?.body || ""; | ||
} | ||
} | ||
|
||
if ( | ||
[ | ||
UIComponentTypes.ApiEditorForm, | ||
UIComponentTypes.GraphQLEditorForm, | ||
].includes(plugin.uiComponent) | ||
) { | ||
// if the url is empty and the action's datasource name is the default datasource name (this means the api does not have a datasource attached) | ||
// or the user does not have permission, | ||
// we block action execution. | ||
blockExecution = | ||
(!actionDatasourceUrl && | ||
!actionDatasourceUrlPath && | ||
actionDatasourceName === DEFAULT_DATASOURCE_NAME) || | ||
!isExecutePermitted; | ||
} else { | ||
// if (the body is empty and the action is an sql datasource) or the user does not have permission, block action execution. | ||
blockExecution = | ||
(!actionBody && SQL_DATASOURCES.includes(plugin.name)) || | ||
!isExecutePermitted; | ||
} | ||
|
||
return blockExecution; | ||
}; | ||
|
||
export { useBlockExecution }; |
1 change: 1 addition & 0 deletions
1
app/client/src/ee/PluginActionEditor/hooks/useBlockExecution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "ce/PluginActionEditor/hooks/useBlockExecution"; |