fix: Adding permission check for the view tab on datasource editor (#37308)

## Description

Adding permission check for the view tab on datasource editor

Fixes [#37317](https://github.com/appsmithorg/appsmith/issues/37317)

## Automation

/ok-to-test tags="@tag.Sanity, @tag.Datasource"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11766974110>
> Commit: bd2ecfe1a834869a99962116e2d45512e6dfc54a
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11766974110&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity, @tag.Datasource`
> Spec:
> <hr>Sun, 10 Nov 2024 18:51:27 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced feature flag checks for tab rendering based on user
permissions.
- Conditional display of the "View Data" tab, ensuring only authorized
users can access it.

- **Bug Fixes**
- Improved control flow for tab activation based on datasource validity
and user permissions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Ankita Kinger 2024-11-11 14:28:18 +05:30 committed by GitHub
parent 99841a34c6
commit 5c075e89de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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%;
@ -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}