Skip to content

Commit

Permalink
fix: Adding permission check for the view tab on datasource editor (a…
Browse files Browse the repository at this point in the history
…ppsmithorg#37308)

## Description

Adding permission check for the view tab on datasource editor

Fixes [appsmithorg#37317](appsmithorg#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: bd2ecfe
> <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 -->
  • Loading branch information
ankitakinger authored Nov 11, 2024
1 parent 0429f67 commit aeb891f
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions 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

0 comments on commit aeb891f

Please sign in to comment.