From 0c87168ee41a329feccdd4fd343cb1589fa9f95b Mon Sep 17 00:00:00 2001 From: Shreeyash Shrestha Date: Fri, 31 Oct 2025 16:15:39 +0545 Subject: [PATCH 1/3] feat(local-unit): add new fields in local unit form --- .../LocalUnitsFormModal/LocalUnitsForm/index.tsx | 8 +++----- .../LocalUnitsFormModal/LocalUnitsForm/schema.ts | 1 - go-api | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx index 255ff4caa..771a42a19 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx @@ -383,7 +383,8 @@ function LocalUnitsForm(props: Props) { }); const hasValidatePermission = isAuthenticated && ( - isSuperUser + !isExternallyManaged + || isSuperUser || isLocalUnitGlobalValidatorByType(value.type) || isLocalUnitCountryValidatorByType(countryResponse?.id, value.type) || isLocalUnitRegionValidatorByType(countryResponse?.region, value.type) @@ -393,9 +394,6 @@ function LocalUnitsForm(props: Props) { || isRegionAdmin(countryResponse?.region) || hasValidatePermission; - const hasDeletePermission = isCountryAdmin(countryResponse?.id) - || hasValidatePermission; - const handleFormSubmit = useCallback( () => { const result = validate(); @@ -543,7 +541,7 @@ function LocalUnitsForm(props: Props) { {isDefined(localUnitDetailsResponse) && ( <> - {hasDeletePermission && ( + {hasValidatePermission && ( ); } diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx index 771a42a19..095067c27 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx @@ -382,13 +382,13 @@ function LocalUnitsForm(props: Props) { }, }); - const hasValidatePermission = isAuthenticated && ( - !isExternallyManaged - || isSuperUser - || isLocalUnitGlobalValidatorByType(value.type) - || isLocalUnitCountryValidatorByType(countryResponse?.id, value.type) - || isLocalUnitRegionValidatorByType(countryResponse?.region, value.type) - ); + const hasValidatePermission = isAuthenticated + && !isExternallyManaged + && (isSuperUser + || isLocalUnitGlobalValidatorByType(value.type) + || isLocalUnitCountryValidatorByType(countryResponse?.id, value.type) + || isLocalUnitRegionValidatorByType(countryResponse?.region, value.type) + ); const hasUpdatePermission = isCountryAdmin(countryResponse?.id) || isRegionAdmin(countryResponse?.region) @@ -542,20 +542,20 @@ function LocalUnitsForm(props: Props) { {isDefined(localUnitDetailsResponse) && ( <> {hasValidatePermission && ( - - )} - {hasValidatePermission && ( - + <> + + + )} {readOnlyFromProps && isEditable diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts index cdc9619eb..439af3599 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/schema.ts @@ -1,3 +1,4 @@ +import { isNotDefined } from '@togglecorp/fujs'; import { addCondition, emailCondition, diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/LocalUnitTableActions/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/LocalUnitTableActions/index.tsx index 120311e70..5f92c5fbd 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/LocalUnitTableActions/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/LocalUnitTableActions/index.tsx @@ -168,7 +168,7 @@ function LocalUnitsTableActions(props: Props) { > {strings.localUnitActionsView} - {((hasValidatePermission || countryAdmin) + {(hasValidatePermission && !isBulkUploadLocalUnit) && ( item.type_details.name, { columnClassName: styles.type }, ), - createStringColumn( - 'focal', - strings.localUnitsTableFocal, - (item) => getFirstTruthyString(item.focal_person_loc, item.focal_person_en), - ), - createStringColumn( - 'phone', - strings.localUnitsTablePhoneNumber, - (item) => item.phone, - ), - createStringColumn( - 'email', - strings.localUnitsTableEmail, - (item) => item.email, - ), createElementColumn( 'status', strings.localUnitsTableStatus, @@ -227,9 +212,6 @@ function LocalUnitsTable(props: Props) { strings.localUnitsTableAddress, strings.localUnitsTableName, strings.localUnitsTableType, - strings.localUnitsTableFocal, - strings.localUnitsTablePhoneNumber, - strings.localUnitsTableEmail, strings.localUnitsTableStatus, refetchLocalUnits, ]); diff --git a/go-api b/go-api index 12c8869d6..86ea0fa6a 160000 --- a/go-api +++ b/go-api @@ -1 +1 @@ -Subproject commit 12c8869d60e85882b6380d102f0fb2278bb28ffc +Subproject commit 86ea0fa6a114094b7766cc23f446de5d1ea136d3 From b65273e69d627bbd25e88088de4a1eef499f94e7 Mon Sep 17 00:00:00 2001 From: Shreeyash Shrestha Date: Fri, 28 Nov 2025 15:20:17 +0545 Subject: [PATCH 3/3] feat(local-unit): add local unit edit permission for selected organization --- app/src/hooks/domain/usePermissions.ts | 24 ++++++++++++++++++- .../LocalUnitsForm/index.tsx | 5 +++- .../LocalUnitTableActions/index.tsx | 5 ++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/hooks/domain/usePermissions.ts b/app/src/hooks/domain/usePermissions.ts index 9c0e19523..c1cd95fcd 100644 --- a/app/src/hooks/domain/usePermissions.ts +++ b/app/src/hooks/domain/usePermissions.ts @@ -1,8 +1,16 @@ import { useMemo } from 'react'; -import { isDefined } from '@togglecorp/fujs'; +import { + isDefined, + isNotDefined, +} from '@togglecorp/fujs'; +import { type GlobalEnums } from '#contexts/domain'; import useUserMe from '#hooks/domain/useUserMe'; +type OrganizationType = NonNullable[number]['key']; + +const canEditLocalUnitOrganization: OrganizationType[] = ['NTLS', 'DLGN', 'SCRT']; + function usePermissions() { const userMe = useUserMe(); @@ -96,6 +104,19 @@ function usePermissions() { ) ); + const canEditLocalUnit = ( + countryId: number | undefined, + ) => { + if (isGuestUser + || isNotDefined(countryId) + || isNotDefined(userMe?.profile.org_type)) return false; + + return ( + userMe?.profile.country?.id === countryId + && canEditLocalUnitOrganization.includes(userMe?.profile.org_type) + ); + }; + const isPerAdmin = !isGuestUser && ((userMe?.is_per_admin_for_countries.length ?? 0) > 0 || (userMe?.is_per_admin_for_regions.length ?? 0) > 0); @@ -126,6 +147,7 @@ function usePermissions() { isSuperUser, isGuestUser, isRegionalOrCountryAdmin, + canEditLocalUnit, }; }, [userMe], diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx index 095067c27..661d9eaec 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx @@ -159,6 +159,7 @@ function LocalUnitsForm(props: Props) { isLocalUnitGlobalValidatorByType, isLocalUnitRegionValidatorByType, isLocalUnitCountryValidatorByType, + canEditLocalUnit, } = usePermissions(); const { api_visibility_choices: visibilityOptions } = useGlobalEnums(); @@ -392,7 +393,8 @@ function LocalUnitsForm(props: Props) { const hasUpdatePermission = isCountryAdmin(countryResponse?.id) || isRegionAdmin(countryResponse?.region) - || hasValidatePermission; + || hasValidatePermission + || canEditLocalUnit(countryResponse?.id); const handleFormSubmit = useCallback( () => { @@ -1437,6 +1439,7 @@ function LocalUnitsForm(props: Props) { className={styles.diffContainer} > )} - {hasAddEditLocalUnitPermission && ( + {(hasAddEditLocalUnitPermission) && (