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: Adding permission check for the view tab on datasource editor #37308

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
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
54 changes: 34 additions & 20 deletions app/client/src/pages/Editor/DatasourceInfo/DatasorceTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
} from "utils/editorContextUtils";
import { getPlugin } from "ee/selectors/entitiesSelector";
import GoogleSheetSchema from "./GoogleSheetSchema";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "ee/entities/FeatureFlag";
import { getHasCreateDatasourceActionPermission } from "ee/utils/BusinessFeatures/permissionPageHelpers";

const TabsContainer = styled(Tabs)`
height: 100%;
Expand Down Expand Up @@ -72,38 +75,49 @@ const DatasourceTabs = (props: DatasourceTabProps) => {
)
: false;

const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);

const canCreateDatasourceActions = getHasCreateDatasourceActionPermission(
isFeatureEnabled,
props.datasource?.userPermissions ?? [],
);

return (
<TabsContainer
defaultValue={
isDatasourceValid || isPluginAuthorized
(isDatasourceValid || isPluginAuthorized) && canCreateDatasourceActions
? VIEW_MODE_TABS.VIEW_DATA
: VIEW_MODE_TABS.CONFIGURATIONS
}
>
<TabListWrapper className="t--datasource-tab-list">
<Tab value={VIEW_MODE_TABS.VIEW_DATA}>
{createMessage(DATASOURCE_VIEW_DATA_TAB)}
</Tab>
{canCreateDatasourceActions && (
<Tab value={VIEW_MODE_TABS.VIEW_DATA}>
{createMessage(DATASOURCE_VIEW_DATA_TAB)}
</Tab>
)}
<Tab value={VIEW_MODE_TABS.CONFIGURATIONS}>
{createMessage(DATASOURCE_CONFIGURATIONS_TAB)}
</Tab>
</TabListWrapper>
<TabPanelContainer
className="t--datasource-tab-container"
value={VIEW_MODE_TABS.VIEW_DATA}
>
{isGoogleSheetPlugin ? (
<GoogleSheetSchema
datasourceId={props.datasource.id}
pluginId={props.datasource?.pluginId}
/>
) : (
<DatasourceViewModeSchema
datasource={props.datasource}
setDatasourceViewModeFlag={setDatasourceViewModeFlagClick}
/>
)}
</TabPanelContainer>
{canCreateDatasourceActions && (
<TabPanelContainer
className="t--datasource-tab-container"
value={VIEW_MODE_TABS.VIEW_DATA}
>
{isGoogleSheetPlugin ? (
<GoogleSheetSchema
datasourceId={props.datasource.id}
pluginId={props.datasource?.pluginId}
/>
) : (
<DatasourceViewModeSchema
datasource={props.datasource}
setDatasourceViewModeFlag={setDatasourceViewModeFlagClick}
/>
)}
</TabPanelContainer>
)}
<ConfigurationsTabPanelContainer
className="t--datasource-tab-container"
value={VIEW_MODE_TABS.CONFIGURATIONS}
Expand Down
Loading