Skip to content

Commit

Permalink
Check isAdmin for Feed in Dashboards and Pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpzx committed Nov 26, 2024
1 parent 05bc85a commit b2ad9b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
22 changes: 12 additions & 10 deletions frontend/src/modules/Dashboards/views/DashboardView.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,18 @@ const DashboardView = () => {
onClick={() => upVoteDashboard(dashboard.dashboardUri)}
upVotes={upVotes || 0}
/>
<Button
color="primary"
startIcon={<ForumOutlined fontSize="small" />}
sx={{ mt: 1, mr: 1 }}
onClick={() => setOpenFeed(true)}
type="button"
variant="outlined"
>
Chat
</Button>
{isAdmin && (
<Button
color="primary"
startIcon={<ForumOutlined fontSize="small" />}
sx={{ mt: 1, mr: 1 }}
onClick={() => setOpenFeed(true)}
type="button"
variant="outlined"
>
Chat
</Button>
)}
<Button
color="primary"
component={RouterLink}
Expand Down
34 changes: 22 additions & 12 deletions frontend/src/modules/Pipelines/views/PipelineView.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { deleteDataPipeline, getDataPipeline } from '../services';
import { FeedComments, KeyValueTagList, Stack } from 'modules/Shared';
import { PipelineOverview } from '../components';

function PipelineViewPageHeader({ pipeline, deletePipeline }) {
function PipelineViewPageHeader({ pipeline, deletePipeline, isAdmin }) {
const [openFeed, setOpenFeed] = useState(false);
return (
<Grid container justifyContent="space-between" spacing={3}>
Expand Down Expand Up @@ -69,16 +69,18 @@ function PipelineViewPageHeader({ pipeline, deletePipeline }) {
</Grid>
<Grid item>
<Box sx={{ m: -1 }}>
<Button
color="primary"
startIcon={<ForumOutlined fontSize="small" />}
sx={{ mt: 1, mr: 1 }}
onClick={() => setOpenFeed(true)}
type="button"
variant="outlined"
>
Chat
</Button>
{isAdmin && (
<Button
color="primary"
startIcon={<ForumOutlined fontSize="small" />}
sx={{ mt: 1, mr: 1 }}
onClick={() => setOpenFeed(true)}
type="button"
variant="outlined"
>
Chat
</Button>
)}
<Button
color="primary"
component={RouterLink}
Expand Down Expand Up @@ -116,7 +118,8 @@ function PipelineViewPageHeader({ pipeline, deletePipeline }) {

PipelineViewPageHeader.propTypes = {
pipeline: PropTypes.object.isRequired,
deletePipeline: PropTypes.func.isRequired
deletePipeline: PropTypes.func.isRequired,
isAdmin: PropTypes.bool.isRequired
};
const PipelineView = () => {
const dispatch = useDispatch();
Expand All @@ -134,6 +137,7 @@ const PipelineView = () => {
{ label: 'Tags', value: 'tags', icon: <LocalOffer fontSize="small" /> },
{ label: 'Stack', value: 'stack', icon: <FaAws size={20} /> }
];
const [isAdmin, setIsAdmin] = useState(false);

const handleDeleteObjectModalOpen = () => {
setIsDeleteObjectModalOpen(true);
Expand All @@ -148,6 +152,11 @@ const PipelineView = () => {
const response = await client.query(getDataPipeline(params.uri));
if (!response.errors && response.data.getDataPipeline !== null) {
setPipeline(response.data.getDataPipeline);
setIsAdmin(
['Creator', 'Admin', 'Owner'].indexOf(
response.data.getDataPipeline.userRoleForPipeline
) !== -1
);
} else {
const error = response.errors
? response.errors[0].message
Expand Down Expand Up @@ -212,6 +221,7 @@ const PipelineView = () => {
<PipelineViewPageHeader
pipeline={pipeline}
deletePipeline={handleDeleteObjectModalOpen}
isAdmin={isAdmin}
/>
<Box sx={{ mt: 3 }}>
<Tabs
Expand Down

0 comments on commit b2ad9b2

Please sign in to comment.