Skip to content

Commit

Permalink
Merge pull request #523 from AI4Bharat/CL-594
Browse files Browse the repository at this point in the history
fixed org owner permission issues
  • Loading branch information
harsh12-99 authored Dec 18, 2023
2 parents a4a79d3 + c0d28fc commit 4a8917b
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 31 deletions.
21 changes: 15 additions & 6 deletions src/containers/Organization/MyOrganization.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const MyOrganization = () => {
const [alertData, setAlertData] = useState([]);
const [alertMessage, setAlertMessage] = useState("");
const [alertColumn, setAlertColumn] = useState([]);
const [orgOwnerId, setOrgOwnerId] = useState("");

const organizationDetails = useSelector(
(state) => state.getOrganizationDetails.data
Expand Down Expand Up @@ -124,6 +125,16 @@ const MyOrganization = () => {

useEffect(() => {
userData?.organization?.id && getProjectList(userData?.organization?.id);

if (userData && userData.id) {
const {
organization: { organization_owner },
} = userData;

console.log(organization_owner,'organization_owner tetete');

setOrgOwnerId(organization_owner.id);
}
// eslint-disable-next-line
}, [userData]);

Expand Down Expand Up @@ -179,13 +190,11 @@ const MyOrganization = () => {
<Tab label={"Members"} sx={{ fontSize: 16, fontWeight: "700" }} />
)}

{roles.filter((role) => role.value === userData?.role)[0]
?.orgSettingVisible && (
{userData?.id === orgOwnerId && (
<Tab label={"Reports"} sx={{ fontSize: 16, fontWeight: "700" }} />
)}

{roles.filter((role) => role.value === userData?.role)[0]
?.orgSettingVisible && (
{userData?.id === orgOwnerId && (
<Tab
label={"Settings"}
sx={{ fontSize: 16, fontWeight: "700" }}
Expand All @@ -206,7 +215,7 @@ const MyOrganization = () => {
alignItems="center"
>
<Box display={"flex"} width={"100%"}>
{userData?.role === "ORG_OWNER" && (
{userData?.id === orgOwnerId && (
<Fragment>
<Button
style={{ marginRight: "10px" }}
Expand Down Expand Up @@ -277,7 +286,7 @@ const MyOrganization = () => {
justifyContent="center"
alignItems="center"
>
{userData.role === "ORG_OWNER" && (
{userData?.id === orgOwnerId && (
<Button
className={classes.projectButton}
onClick={() => setAddUserDialog(true)}
Expand Down
43 changes: 31 additions & 12 deletions src/containers/Organization/Project/EditProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ const EditProject = () => {
});
const [taskDescription, setTaskDescription] = useState("");
const [integrateVideo, setIntegrateVideo] = useState(false);
const [orgOwnerId, setOrgOwnerId] = useState("");

useEffect(() => {
if (userData && userData.id) {
const {
organization: { organization_owner },
} = userData;

setOrgOwnerId(organization_owner.id);
}
}, [userData]);

useEffect(() => {
const apiObj = new FetchProjectDetailsAPI(projectId);
Expand Down Expand Up @@ -312,7 +323,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
/>
Expand All @@ -333,7 +344,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
renderValue={(selected) => {
Expand Down Expand Up @@ -381,7 +392,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
>
Expand Down Expand Up @@ -412,7 +423,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
>
Expand Down Expand Up @@ -443,7 +454,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
>
Expand All @@ -470,7 +481,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
MenuProps={MenuProps}
Expand Down Expand Up @@ -557,7 +568,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
renderInput={(params) => <TextField {...params} />}
Expand All @@ -582,7 +593,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
renderValue={(selected) => {
Expand All @@ -604,9 +615,10 @@ const EditProject = () => {
</FormControl>
</Grid>

{projectDetails?.managers?.some(
{(projectDetails?.managers?.some(
(item) => item.id === userData.id
) && (
) ||
userData?.id === orgOwnerId) && (
<Grid item xs={12} sm={12} md={6} lg={6} xl={6}>
<Button
fullWidth
Expand Down Expand Up @@ -643,6 +655,13 @@ const EditProject = () => {
onChange={() =>
setIntegrateVideo((prevState) => !prevState)
}
disabled={
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData?.id === orgOwnerId
)
}
/>
</FormControl>
</Box>
Expand All @@ -663,7 +682,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
/>
Expand All @@ -684,7 +703,7 @@ const EditProject = () => {
!(
projectDetails?.managers?.some(
(item) => item.id === userData.id
) || userData.role === "ORG_OWNER"
) || userData?.id === orgOwnerId
)
}
/>
Expand Down
13 changes: 12 additions & 1 deletion src/containers/Organization/Project/Project.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const Project = () => {
const [speakerType, setSpeakerType] = useState("individual");
const [alertMessage, setAlertMessage] = useState("");
const [alertColumn, setAlertColumn] = useState("");
const [orgOwnerId, setOrgOwnerId] = useState("");

const projectInfo = useSelector((state) => state.getProjectDetails.data);
const projectvideoList = useSelector(
Expand All @@ -110,6 +111,16 @@ const Project = () => {
const userList = useSelector((state) => state.getOrganizatioUsers.data);
const apiStatus = useSelector((state) => state.apiStatus);

useEffect(() => {
if (userData && userData.id) {
const {
organization: { organization_owner },
} = userData;

setOrgOwnerId(organization_owner.id);
}
}, [userData]);

useEffect(() => {
const { progress, success, apiType, data } = apiStatus;

Expand Down Expand Up @@ -448,7 +459,7 @@ const Project = () => {
alignItems="center"
>
{(projectInfo?.managers?.some((item) => item.id === userData.id) ||
userData.role === "ORG_OWNER") && (
userData?.id === orgOwnerId) && (
<Button
className={classes.projectButton}
onClick={() => setAddUserDialog(true)}
Expand Down
13 changes: 12 additions & 1 deletion src/containers/Organization/Project/ProjectMemberDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const ProjectMemberDetails = () => {
const [openMemberErrorDialog, setOpenMemberErrorDialog] = useState(false);
const [errorMessage, setErrorMessage] = useState("");
const [errorResponse, setErrorResponse] = useState("");
const [orgOwnerId, setOrgOwnerId] = useState("");

const projectMembersList = useSelector(
(state) => state.getProjectMembers.data
Expand All @@ -40,6 +41,16 @@ const ProjectMemberDetails = () => {
const userData = useSelector((state) => state.getLoggedInUserDetails.data);
const projectDetails = useSelector((state) => state.getProjectDetails.data);

useEffect(() => {
if (userData && userData.id) {
const {
organization: { organization_owner },
} = userData;

setOrgOwnerId(organization_owner.id);
}
}, [userData]);

useEffect(() => {
const { progress, success, apiType, data } = apiStatus;

Expand Down Expand Up @@ -104,7 +115,7 @@ const ProjectMemberDetails = () => {
{(projectDetails?.managers?.some(
(item) => item.id === userData.id
) ||
userData.role === "ORG_OWNER") && (
userData?.id === orgOwnerId) && (
<Tooltip title="Delete">
<IconButton
onClick={() => {
Expand Down
15 changes: 13 additions & 2 deletions src/containers/Organization/Project/VideoList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const VideoList = ({ data, removeVideo }) => {
const [exportType, setExportType] = useState("srt");
const [videoIdForDowload, setVideoIdForDowload] = useState("");
const [videoName, setVideoName] = useState("");
const [orgOwnerId, setOrgOwnerId] = useState("");

const userData = useSelector((state) => state.getLoggedInUserDetails.data);
const apiStatus = useSelector((state) => state.apiStatus);
Expand All @@ -68,6 +69,16 @@ const VideoList = ({ data, removeVideo }) => {
(state) => state.getTranslationExportTypes.data.export_types
);

useEffect(() => {
if (userData && userData.id) {
const {
organization: { organization_owner },
} = userData;

setOrgOwnerId(organization_owner.id);
}
}, [userData]);

useEffect(() => {
const { progress, success, apiType, data } = apiStatus;

Expand Down Expand Up @@ -160,7 +171,7 @@ const VideoList = ({ data, removeVideo }) => {
</Tooltip>

{(projectInfo?.managers?.some((item) => item.id === userData.id) ||
userData.role === "ORG_OWNER") && (
userData?.id === orgOwnerId) && (
<Tooltip title="Create Task">
<IconButton
onClick={() => {
Expand All @@ -175,7 +186,7 @@ const VideoList = ({ data, removeVideo }) => {
)}

{(projectInfo.managers?.some((item) => item.id === userData.id) ||
userData.role === "ORG_OWNER") && (
userData?.id === orgOwnerId) && (
<Tooltip title="Delete">
<IconButton onClick={() => handleDeleteVideo(item.id)}>
<DeleteIcon color="error" />
Expand Down
19 changes: 16 additions & 3 deletions src/containers/Organization/ProjectList.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { getColumns, getOptions, roles } from "utils";
import { getColumns, getOptions } from "utils";
import { Link, useParams } from "react-router-dom";
import { projectColumns } from "config";

Expand All @@ -26,10 +26,24 @@ const ProjectList = ({ data, removeProjectList }) => {

const [projectid, setprojectid] = useState([]);
const [open, setOpen] = useState(false);
const [orgOwnerId, setOrgOwnerId] = useState("");

const apiStatus = useSelector((state) => state.apiStatus);
const userData = useSelector((state) => state.getLoggedInUserDetails.data);

useEffect(() => {
if (userData && userData.id) {
const {
organization: { organization_owner },
} = userData;

console.log(organization_owner,'organization_owner tetete');

setOrgOwnerId(organization_owner.id);
}
// eslint-disable-next-line
}, [userData]);

useEffect(() => {
const { progress, success, apiType } = apiStatus;

Expand Down Expand Up @@ -83,8 +97,7 @@ const ProjectList = ({ data, removeProjectList }) => {
</Tooltip>
</Link>

{roles.filter((role) => role.value === userData?.role)[0]
?.canDeleteProject && (
{userData?.id === orgOwnerId && (
<Tooltip title="Delete">
<IconButton onClick={() => handleDeleteProject(selectedRow.id)}>
<DeleteIcon color="error" />
Expand Down
Loading

0 comments on commit 4a8917b

Please sign in to comment.