Skip to content

Commit

Permalink
MOSIP-36036: Sonar bugs, security hotspots, duplications for UI code
Browse files Browse the repository at this point in the history
Signed-off-by: Anil_Kumar_Majji <106086523+Anil-kumar-Majji@users.noreply.github.com>
  • Loading branch information
Anil-kumar-Majji committed Jan 2, 2025
1 parent 1975952 commit 5666b0e
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 222 deletions.
19 changes: 9 additions & 10 deletions pmp-revamp-ui/src/nav/HeaderNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { useState, useRef, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { getUserProfile } from '../services/UserProfileService.js';
import { isLangRTL, onPressEnterKey } from '../utils/AppUtils.js';
import { handleMouseClickForDropdown, logout } from '../utils/AppUtils.js';
import { isLangRTL, onPressEnterKey, handleMouseClickForDropdown, logout } from '../utils/AppUtils.js';
import profileIcon from '../profile_icon.png';
import hamburgerIcon from '../svg/hamburger_icon.svg';
import orgIcon from '../svg/org_icon.svg';
Expand Down Expand Up @@ -43,8 +42,8 @@ function HeaderNav({ open, setOpen }) {
{!open && (
<div className={`flex items-center ${isLoginLanguageRTL ? "pr-5" : "pl-6"}`}>
<img src={process.env.PUBLIC_URL + '/mosip_icon.svg'} alt="Mosip Icon" className="w-8 h-8" />
<div id='header_hamburger_open_sidenav' className="p-9 cursor-pointer" onClick={() => setOpen(!open)}>
<img id=' hamburger_icon' className="min-w-5 w-5 h-5" src={hamburgerIcon} alt="" tabIndex="0" onKeyDown={(e) => onPressEnterKey(e, ()=>setOpen(!open))} />
<div id='header_hamburger_open_sidenav' className="p-9 cursor-pointer">
<img id=' hamburger_icon' src={hamburgerIcon} className="min-w-5 w-5 h-5" alt="" onClick={() => setOpen(!open)} tabIndex="0" onKeyDown={(e) => onPressEnterKey(e, () => setOpen(!open))} />
</div>
</div>
)}
Expand All @@ -54,8 +53,8 @@ function HeaderNav({ open, setOpen }) {
<div className={`duration-700`}>
<img src={side_menu_title} alt="" className="w-32 h-10" />
</div>
<div id='header_hamburger_close_sidenav' className="cursor-pointer" onClick={() => setOpen(!open)}>
<img id=' hamburger_icon' className="min-w-5" src={hamburgerIcon} alt="" tabIndex="0" onKeyDown={(e) => onPressEnterKey(e,()=>setOpen(!open))}/>
<div id='header_hamburger_close_sidenav' className="cursor-pointer" >
<img id=' hamburger_icon' src={hamburgerIcon} className="min-w-5" alt="" onClick={() => setOpen(!open)} tabIndex="0" onKeyDown={(e) => onPressEnterKey(e, () => setOpen(!open))} />
</div>
</div>
)}
Expand All @@ -65,15 +64,15 @@ function HeaderNav({ open, setOpen }) {
&nbsp;
</div>
</div>
<div className={`flex items-center relative justify-between gap-x-12 ${isLoginLanguageRTL ?"left-3":"right-3"}`}>
<div className={`flex items-center relative justify-between gap-x-12 ${isLoginLanguageRTL ? "left-3" : "right-3"}`}>
<div className="flex items-center">
<div className="p-2 m-1 bg-blue-50">
<img id='orgIcon' src={orgIcon} alt="" className="w-5 h-5" />
</div>

<h2 className={`text-xs font-bold text-gray-600 ${isLoginLanguageRTL ? "mr-1": "ml-1"}`}>{getUserProfile().orgName}</h2>
</div>
<div onClick={openDropdown} className={`flex items-center ${isLoginLanguageRTL ? "mr-1" : "ml-1"}`} ref={dropdownRef} tabIndex="0" onKeyDown={(e)=>onPressEnterKey(e,openDropdown)}>
<div role='button' onClick={openDropdown} className={`flex items-center ${isLoginLanguageRTL ? "mr-1" : "ml-1"}`} ref={dropdownRef} tabIndex="0" onKeyDown={(e)=>onPressEnterKey(e,openDropdown)}>
<button id='header_user_profile_icon_btn' className="relative flex rounded-full text-sm focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-transparent">
<img id='orgIcon' className="h-9 w-8 rounded-full" src={profileIcon} alt="" />
</button>
Expand All @@ -82,11 +81,11 @@ function HeaderNav({ open, setOpen }) {

{isDropdownOpen && (
<div className={`absolute top-[3.1rem] ${isLoginLanguageRTL ? "origin-top-left" : "origin-top-right"} z-10 w-dynamic rounded-md bg-white py-1 shadow-md ring-1 ring-gray-50 focus:outline-none`}>
<button id='header_user_profile_info_btn' onClick={moveToMyProfile} className={`block w-full px-4 py-2 text-xs text-gray-900 ${isLoginLanguageRTL ? "text-right" : "text-left"} hover:bg-gray-100`} tabIndex="0" onKeyDown={(e)=>onPressEnterKey(e,moveToMyProfile)}>
<button id='header_user_profile_info_btn' onClick={moveToMyProfile} className={`block w-full px-4 py-2 text-xs text-gray-900 ${isLoginLanguageRTL ? "text-right" : "text-left"} hover:bg-gray-100`} tabIndex="0" onKeyDown={(e) => onPressEnterKey(e, moveToMyProfile)}>
{t('header.userProfile')}
</button>
<div className="border-gray-100 border-t mx-2"></div>
<button id='header_user_profile_logout_btn' className={`block w-full px-4 py-2 text-xs text-red-700 ${isLoginLanguageRTL ? "text-right" : "text-left"} hover:bg-gray-100`} onClick={logout} onKeyDown={(e)=>onPressEnterKey(e,logout)}>{t('commons.logout')}</button>
<button id='header_user_profile_logout_btn' className={`block w-full px-4 py-2 text-xs text-red-700 ${isLoginLanguageRTL ? "text-right" : "text-left"} hover:bg-gray-100`} onClick={logout} onKeyDown={(e) => onPressEnterKey(e, logout)}>{t('commons.logout')}</button>
</div>
)}
</div>
Expand Down
5 changes: 2 additions & 3 deletions pmp-revamp-ui/src/nav/MainLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import '../index.css';
import { getUserProfile } from '../services/UserProfileService.js';
import { useTranslation } from 'react-i18next';
import { useState, useEffect, useRef } from 'react';
import { logout } from '../utils/AppUtils.js';
import { logout, getPartnerManagerUrl, createRequest } from "../utils/AppUtils";
import { getAppConfig } from '../services/ConfigService.js';
import { HttpService } from "../services/HttpService";
import { getPartnerManagerUrl, createRequest } from "../utils/AppUtils";

function MainLayout({ children }) {
const { i18n } = useTranslation();
Expand Down Expand Up @@ -122,7 +121,7 @@ function MainLayout({ children }) {
});
const response = await HttpService.put(
getPartnerManagerUrl('/partners/email/verify', process.env.NODE_ENV), verifyEmailRequest);
if (response && response.data && response.data.response) {
if (response?.data?.response) {
const resData = response.data.response;
setPolicyRequiredPartnerTypes(resData.policyRequiredPartnerTypes);
setPartnerType(userProfile.partnerType);
Expand Down
27 changes: 13 additions & 14 deletions pmp-revamp-ui/src/nav/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function SideNav({ open, policyRequiredPartnerTypes, partnerType }) {
const [enablePolicyManagerMenu, setEnablePolicyManagerMenu] = useState(false);

useEffect(() => {
// console.log(selectedPath);
if (selectedPath.includes('dashboard')) {
setActiveIcon("home");
} else if (selectedPath.includes('policy-manager')) {
Expand Down Expand Up @@ -121,57 +120,57 @@ function SideNav({ open, policyRequiredPartnerTypes, partnerType }) {
<div className={`h-full ${open ? "absolute inset-y-14 min-w-[16rem]" : "absolute inset-y-14 w-[4.5rem]"}
flex-col duration-500`}>
<ul className={`pt-3 h-full space-y-5 bg-[#FCFCFC] shadow-[rgba(0,0,0,0.13)_5px_2px_8px_-2px]`}>
<li id='side_nav_home_icon' className="duration-700 cursor-pointer" onClick={() => showHome()} onKeyDown={(e) => { e.key === 'Enter' && showHome() }}>
<li role="button" id='side_nav_home_icon' className="duration-700 cursor-pointer" onClick={() => showHome()} onKeyDown={(e) => { e.key === 'Enter' && showHome() }}>
<SideNavMenuItem title={t('commons.home')} id='home' isExpanded={open} activeIcon={activeIcon} />
</li>
{!enablePartnerAdminMenu &&
<li id='side_nav_partner_certificate_icon' className="duration-700 cursor-pointer" onClick={() => showPartnerCertificatesList()} onKeyDown={(e) => { e.key === 'Enter' && showPartnerCertificatesList() }}>
<li role="button" id='side_nav_partner_certificate_icon' className="duration-700 cursor-pointer" onClick={() => showPartnerCertificatesList()} onKeyDown={(e) => { e.key === 'Enter' && showPartnerCertificatesList() }}>
<SideNavMenuItem title={t('dashboard.partnerCertificate')} id='partnerCertificate' isExpanded={open} activeIcon={activeIcon} />
</li>
}
{!enablePartnerAdminMenu && enablePoliciesMenu &&
<li id='side_nav_policies_icon' className="duration-700 cursor-pointer" onClick={() => showPolicies()} onKeyDown={(e) => { e.key === 'Enter' && showPolicies() }}>
<li role="button" id='side_nav_policies_icon' className="duration-700 cursor-pointer" onClick={() => showPolicies()} onKeyDown={(e) => { e.key === 'Enter' && showPolicies() }}>
<SideNavMenuItem title={t('dashboard.policies')} id='policies' isExpanded={open} activeIcon={activeIcon} />
</li>
}
{!enablePartnerAdminMenu && enableAuthenticationServicesMenu &&
<li id='side_nav_authentication_service_icon' className="duration-700 cursor-pointer" onClick={() => showAuthenticationServices()} onKeyDown={(e) => { e.key === 'Enter' && showAuthenticationServices() }}>
<li role="button" id='side_nav_authentication_service_icon' className="duration-700 cursor-pointer" onClick={() => showAuthenticationServices()} onKeyDown={(e) => { e.key === 'Enter' && showAuthenticationServices() }}>
<SideNavMenuItem title={t('dashboard.authenticationServices')} id='authenticationServices' isExpanded={open} activeIcon={activeIcon} />
</li>
}
{!enablePartnerAdminMenu && enableDeviceProviderServicesMenu &&
<li id='side_nav_device_provider_service_icon' className="duration-700 cursor-pointer" onClick={() => showDeviceProviderServices()} onKeyDown={(e) => { e.key === 'Enter' && showDeviceProviderServices() }}>
<li role="button" id='side_nav_device_provider_service_icon' className="duration-700 cursor-pointer" onClick={() => showDeviceProviderServices()} onKeyDown={(e) => { e.key === 'Enter' && showDeviceProviderServices() }}>
<SideNavMenuItem title={t('dashboard.deviceProviderServices')} id='deviceProviderServices' isExpanded={open} activeIcon={activeIcon} />
</li>
}
{!enablePartnerAdminMenu && enableFtmServicesMenu &&
<li id='side_nav_ftmchip_provider_service_icon' className="duration-700 cursor-pointer" onClick={() => showFtmServices()} onKeyDown={(e) => { e.key === 'Enter' && showFtmServices() }}>
<li role="button" id='side_nav_ftmchip_provider_service_icon' className="duration-700 cursor-pointer" onClick={() => showFtmServices()} onKeyDown={(e) => { e.key === 'Enter' && showFtmServices() }}>
<SideNavMenuItem title={t('dashboard.ftmChipProviderServices')} id='ftmChipProviderServices' isExpanded={open} activeIcon={activeIcon} />
</li>
}
{enablePartnerAdminMenu && (
<>
<li id='side_nav_rootOfTrustCertificate_service_icon' className="duration-700 cursor-pointer" onClick={() => showRootOfTrustCertificate()} onKeyDown={(e) => { e.key === 'Enter' && showRootOfTrustCertificate() }}>
<li role="button" id='side_nav_rootOfTrustCertificate_service_icon' className="duration-700 cursor-pointer" onClick={() => showRootOfTrustCertificate()} onKeyDown={(e) => { e.key === 'Enter' && showRootOfTrustCertificate() }}>
<SideNavMenuItem title={t('dashboard.rootOfTrustCertificate')} id='rootOfTrustCertificate' isExpanded={open} activeIcon={activeIcon} />
</li>
<li id='side_nav_partner_icon' className="duration-700 cursor-pointer" onClick={() => showPartner()} onKeyDown={(e) => { e.key === 'Enter' && showPartner() }}>
<li role="button" id='side_nav_partner_icon' className="duration-700 cursor-pointer" onClick={() => showPartner()} onKeyDown={(e) => { e.key === 'Enter' && showPartner() }}>
<SideNavMenuItem title={t('dashboard.partner')} id='partner' isExpanded={open} activeIcon={activeIcon} />
</li>
{enablePolicyManagerMenu && (
<li id='side_nav_policy_icon' className="duration-700 cursor-pointer" onClick={() => showAdminPolicies() } onKeyDown={(e) => { e.key === 'Enter' && showAdminPolicies() }}>
<li role="button" id='side_nav_policy_icon' className="duration-700 cursor-pointer" onClick={() => showAdminPolicies()} onKeyDown={(e) => { e.key === 'Enter' && showAdminPolicies() }}>
<SideNavMenuItem title={t('dashboard.policies')} id='admin_policies' isExpanded={open} activeIcon={activeIcon} />
</li>
)}
<li id='side_nav_partnerPolicyMapping_icon' className={`duration-700 cursor-pointer ${isLoginLanguageRTL ? 'pl-1' : 'pr-1'}`} onClick={() => showPartnerPolicyMapping()} onKeyDown={(e) => { e.key === 'Enter' && showPartnerPolicyMapping() }}>
<li role="button" id='side_nav_partnerPolicyMapping_icon' className={`duration-700 cursor-pointer ${isLoginLanguageRTL ? 'pl-1' : 'pr-1'}`} onClick={() => showPartnerPolicyMapping()} onKeyDown={(e) => { e.key === 'Enter' && showPartnerPolicyMapping() }}>
<SideNavMenuItem title={t('dashboard.partnerPolicyMapping')} id='partnerPolicyMapping' isExpanded={open} activeIcon={activeIcon} />
</li>
<li id='side_nav_sbiDeviceDetails_icon' className="duration-700 cursor-pointer" onClick={() => showSbiDeviceDetails()} onKeyDown={(e) => { e.key === 'Enter' && showSbiDeviceDetails() }}>
<li role="button" id='side_nav_sbiDeviceDetails_icon' className="duration-700 cursor-pointer" onClick={() => showSbiDeviceDetails()} onKeyDown={(e) => { e.key === 'Enter' && showSbiDeviceDetails() }}>
<SideNavMenuItem title={t('dashboard.sbiDevice')} id='deviceProviderServices' isExpanded={open} activeIcon={activeIcon} />
</li>
<li id='side_nav_ftmDetails_icon' className="duration-700 cursor-pointer" onClick={() => showAdminFtmDetails()} onKeyDown={(e) => { e.key === 'Enter' && showAdminFtmDetails() }}>
<li role="button" id='side_nav_ftmDetails_icon' className="duration-700 cursor-pointer" onClick={() => showAdminFtmDetails()} onKeyDown={(e) => { e.key === 'Enter' && showAdminFtmDetails() }}>
<SideNavMenuItem title={t('dashboard.ftmChip')} id='ftmChipProviderServices' isExpanded={open} activeIcon={activeIcon} />
</li>
<li id='side_nav_authenticationServices_icon' className="duration-700 cursor-pointer" onClick={() => showAdminAuthenticationServices()} onKeyDown={(e) => { e.key === 'Enter' && showAdminAuthenticationServices() }}>
<li role="button" id='side_nav_authenticationServices_icon' className="duration-700 cursor-pointer" onClick={() => showAdminAuthenticationServices()} onKeyDown={(e) => { e.key === 'Enter' && showAdminAuthenticationServices() }}>
<SideNavMenuItem title={t('dashboard.authenticationServices')} id='authenticationServices' isExpanded={open} activeIcon={activeIcon} />
</li>
</>
Expand Down
Loading

0 comments on commit 5666b0e

Please sign in to comment.