8000 fix: role wise access to delete invitation, create ecosystem and written common function for org roles by 16-karan · Pull Request #561 · credebl/studio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: role wise access to delete invitation, create ecosystem and written common function for org roles #561

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? < 8000 a data-hydro-click="{"event_type":"authentication.click","payload":{"location_in_page":"new issue modal","repository_id":null,"auth_type":"LOG_IN","originating_url":"https://github.com/credebl/studio/pull/561/files","user_id":null}}" data-hydro-click-hmac="c4b6b173e0a6676316f2206c402dc4ebbab96bd1fe9600e88b06dcd62ec47982" class="Link--inTextBlock" href="/login?return_to=%2Fcredebl%2Fstudio%2Fissues%2Fnew%2Fchoose">Sign in to your account

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/commonComponents/EcosystemProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const EcosystemProfileCard = ({getEndorsementListData}:IEndorsement) => {
await getEndorsementListData()
}


useEffect(() => {
fetchEcosystemDetails();
}, []);
Expand Down
3 changes: 2 additions & 1 deletion src/components/Authentication/KeyCloakResetPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { passwordEncryption, resetPasswordKeyCloak } from '../../api/Auth';
import { PassInvisible, PassVisible } from './Svg.js';
import { pathRoutes } from '../../config/pathRoutes';
import type { IPassword, IProps, IValues } from './interfaces';
import React from 'react';

const KeyClockResetPassword = (props: IProps) => {
const [loading, setLoading] = useState(false);
Expand All @@ -34,7 +35,7 @@ const KeyClockResetPassword = (props: IProps) => {
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
setSuccess(data.message);
setLoading(false);
window.location.href = pathRoutes.landingPage.landingPage;
window.location.href= pathRoutes.auth.sinIn
} else {
setError(response as string);
setLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Ecosystem/EcosystemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const EcosystemList = () => {
{showCreateButton && (
<RoleViewButton
buttonTitle="Create"
feature={Features.CRETAE_ORG}
feature={Features.CREATE_ECOSYSTEMS}
svgComponent={
<div className="pr-3">
<svg
Expand Down
19 changes: 9 additions & 10 deletions src/components/Resources/Schema/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,18 @@ const CreateSchema = () => {
},
],
};
const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
setIsEcosystemData(data);
};

const [formData, setFormData] = useState(initFormData);

useEffect(() => {
const fetchData = async () => {
(async () => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
setOrgId(orgId);
};

fetchData();

const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
setIsEcosystemData(data);
};
})();

checkEcosystemData();
}, []);
Expand Down Expand Up @@ -283,7 +282,7 @@ const CreateSchema = () => {
</div>
{isEcosystemData?.isEnabledEcosystem && (
<div className="mx-6 mb-4">
<EcosystemProfileCard />
<EcosystemProfileCard getEndorsementListData={checkEcosystemData} />
</div>
)}

Expand Down
9 changes: 4 additions & 5 deletions src/components/Resources/Schema/ViewSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { EmptyListMessage } from '../../EmptyListComponent';
import { Roles } from '../../../utils/enums/roles';
import { nanoid } from 'nanoid';
import { pathRoutes } from '../../../config/pathRoutes';
import { ICheckEcosystem, checkEcosystem, getEcosystemId } from '../../../config/ecosystem';
import { ICheckEcosystem, checkEcosystem, getEcosystemId, getUserRoles } from '../../../config/ecosystem';
import { createCredDefRequest } from '../../../api/ecosystem';
import EcosystemProfileCard from '../../../commonComponents/EcosystemProfileCard';
import { getLedgersPlatformUrl } from '../../../api/Agent';
Expand Down Expand Up @@ -127,14 +127,13 @@ const ViewSchemas = () => {
fetchData();
}, []);

const getUserRoles = async () => {
const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES)
const roles = orgRoles.split(',')
const getUserOrgRoles = async () => {
const roles = await getUserRoles()
setUserRoles(roles)
}

useEffect(() => {
getUserRoles()
getUserOrgRoles()
const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
setIsEcosystemData(data)
Expand Down
15 changes: 11 additions & 4 deletions src/components/RoleViewButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Features } from '../../utils/enums/features';
import { Roles } from '../../utils/enums/roles';
import { getFromLocalStorage } from '../../api/Auth';
import { storageKeys } from '../../config/CommonConstant';
import { getUserRoles } from '../../config/ecosystem'

interface RoleViewButtonProps {
buttonTitle?: string,
Expand All @@ -20,14 +21,13 @@ const RoleViewButton = ({ buttonTitle, svgComponent, onClickEvent, feature, isOu

const [userRoles, setUserRoles] = useState& 6D47 lt;string[]>([])

const getUserRoles = async () => {
const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES)
const roles = orgRoles.split(',')
const getUserOrgRoles = async () => {
const roles = await getUserRoles()
setUserRoles(roles)
}

useEffect(() => {
getUserRoles()
getUserOrgRoles()
}, [])

const isRoleAccess = (): boolean => {
Expand All @@ -49,6 +49,13 @@ const RoleViewButton = ({ buttonTitle, svgComponent, onClickEvent, feature, isOu
) {
return true
}
return false
} else if (feature === Features.CREATE_ECOSYSTEMS) {
if (userRoles.includes(Roles.OWNER)
|| userRoles.includes(Roles.ADMIN)
) {
return true
}
return false
} else if (userRoles.includes(Roles.OWNER) || userRoles.includes(Roles.ADMIN)) {
return true
Expand Down
15 changes: 10 additions & 5 deletions src/components/organization/invitations/Invitations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import DateTooltip from '../../Tooltip';
import { deleteOrganizationInvitation } from '../../../api/organization';
import { getFromLocalStorage } from '../../../api/Auth';
import ConfirmationModal from '../../../commonComponents/ConfirmationModal';
import { Roles } from '../../../utils/enums/roles';
import { getUserRoles } from '../../../config/ecosystem';

const initialPageState = {
pageNumber: 1,
Expand All @@ -36,20 +38,22 @@ const Invitations = () => {
const [message, setMessage] = useState<string | null>(null)
const [showPopup, setShowPopup] = useState<boolean>(false)
const [error, setError] = useState<string | null>(null)
const [currentPage, setCurrentPage] = useState(initialPageState);

const [roles, setRoles] = useState<string[]>([]);
const [currentPage, setCurrentPage] = useState(initialPageState);

const number) => {
setCurrentPage({
...currentPage,
pageNumber: page
})
};
const [searchText, setSearchText] = useState("");

const [invitationsList, setInvitationsList] = useState<Array<Invitation> | null>(null)
const props = { openModal, setOpenModal };

const getAllInvitations = async () => {
const roles = await getUserRoles()
setRoles(roles)
setLoading(true)
const response = await getOrganizationInvitations(currentPage.pageNumber, currentPage.pageSize, searchText);
const { data } = response as AxiosResponse
Expand Down Expand Up @@ -242,7 +246,8 @@ const Invitations = () => {
}}
color="bg-white"
className="ml-5 p-0 font-normal items-center mt-5 text-sm text-primary-700 border border-blue-700 text-center hover:!bg-primary-800 hover:text-white rounded-lg focus:ring-4 focus:ring-primary-300 sm:w-auto dark:hover:bg-primary-700 dark:text-white dark:bg-primary-700 dark:focus:ring-blue-800"
>
disabled={!roles?.includes(Roles.ADMIN) && !roles?.includes(Roles.OWNER)}
>
<svg
className="w-5 h-5"
aria-hidden="true"
Expand Down
8 changes: 7 additions & 1 deletion src/config/ecosystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ const getEcosystemId = async (): Promise<string> => {
return ecoId;
};

const getUserRoles = async () => {
const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES)
const roles = orgRoles.split(',')
return roles
}

const getOrgDetails = async (): Promise<IOrgDetails> => {
const orgId = await getOrgId();
const org = await getOrgData();
Expand Down Expand Up @@ -131,4 +137,4 @@ const getOrgDetails = async (): Promise<IOrgDetails> => {
return orgData;
};

export { checkEcosystem, getEcosystemId, getOrgDetails };
export { checkEcosystem, getEcosystemId, getOrgDetails, getUserRoles };
0