Skip to content

Commit

Permalink
Merge pull request #7316 from Yasasr1/email-domain-migration-fix
Browse files Browse the repository at this point in the history
Allow old console roles to update discovery configurations after migrating to IS 7.1
  • Loading branch information
Yasasr1 authored Jan 25, 2025
2 parents f646ab5 + e164214 commit 271cd66
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .changeset/tricky-socks-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wso2is/admin.organization-discovery.v1": patch
"@wso2is/console": patch
---

Allow old console roles to update discovery configurations after migrating to IS 7.1
1 change: 1 addition & 0 deletions apps/console/src/public/deployment.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@
"internal_organization_view"
],
"update": [
"internal_organization_config_update",
"internal_organization_discovery_update"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {
UpdateGovernanceConnectorConfigPropertyInterface,
useGetGovernanceConnectorById
} from "../../admin.server-configurations.v1";
import addOrganizationDiscoveryConfig from "../api/add-organization-discovery-config";
import deleteOrganizationDiscoveryConfig from "../api/delete-organization-discovery-config";
import updateOrganizationDiscoveryConfig from "../api/update-organization-discovery-config";
import useGetOrganizationDiscovery from "../api/use-get-organization-discovery";
import useGetOrganizationDiscoveryConfig from "../api/use-get-organization-discovery-config";
Expand Down Expand Up @@ -84,7 +86,11 @@ const OrganizationDiscoveryDomainsPage: FunctionComponent<OrganizationDiscoveryD
const isEmailDomainDiscoveryForSelfRegFeatureEnabled: boolean = isFeatureEnabled(
featureConfig?.organizationDiscovery,
OrganizationDiscoveryConstants.FEATURE_DICTIONARY.get("ORGANIZATION_DISCOVERY_EMAIL_DOMAIN_FOR_SELF_REG"));
const isReadOnly: boolean = !useRequiredScopes(featureConfig?.organizationDiscovery?.scopes?.update);
const hasUpdateScopes: boolean = useRequiredScopes(featureConfig?.organizationDiscovery?.scopes?.update);
const hasCreateScopes: boolean = useRequiredScopes(featureConfig?.organizationDiscovery?.scopes?.create);
const hasDeleteScopes: boolean = useRequiredScopes(featureConfig?.organizationDiscovery?.scopes?.delete);
// To preserve backward compatibility with old console roles.
const isReadOnly: boolean = !hasUpdateScopes && !(hasCreateScopes && hasDeleteScopes);

const [ searchQuery, setSearchQuery ] = useState<string>("");
const [ listItemLimit, setListItemLimit ] = useState<number>(UIConstants.DEFAULT_RESOURCE_LIST_ITEM_LIMIT);
Expand Down Expand Up @@ -267,50 +273,123 @@ const OrganizationDiscoveryDomainsPage: FunctionComponent<OrganizationDiscoveryD
});
}

updateOrganizationDiscoveryConfig(updateData)
.then(() => {
dispatch(
addAlert({
description: data.checked ? t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.success.description"
) : t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.success.description"),
level: AlertLevels.SUCCESS,
message: data.checked ? t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.success.message"
) : t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.success.message"
)
// To preserve backward compatibility with old console roles.
if (hasUpdateScopes) {
updateOrganizationDiscoveryConfig(updateData)
.then(() => {
dispatch(
addAlert({
description: data.checked ? t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.success.description"
) : t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.success.description"),
level: AlertLevels.SUCCESS,
message: data.checked ? t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.success.message"
) : t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.success.message"
)
})
);

mutateOrganizationDiscoveryConfigFetchRequest();
})
.catch(() => {
dispatch(
addAlert({
description: data.checked ? t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.error.description"
) : t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.error.description"
),
level: AlertLevels.ERROR,
message: data.checked ? t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.error.message"
) : t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.error.message"
)
})
);
});
} else if (hasCreateScopes && hasDeleteScopes) {
if (data.checked) {
addOrganizationDiscoveryConfig(updateData)
.then(() => {
dispatch(
addAlert({
description: t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.success.description"
),
level: AlertLevels.SUCCESS,
message: t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.success.message"
)
})
);

mutateOrganizationDiscoveryConfigFetchRequest();
})
);

mutateOrganizationDiscoveryConfigFetchRequest();
})
.catch(() => {
dispatch(
addAlert({
description: data.checked ? t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.error.description"
) : t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.error.description"
),
level: AlertLevels.ERROR,
message: data.checked ? t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.error.message"
) : t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.error.message"
)
.catch(() => {
dispatch(
addAlert({
description: t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.error.description"
),
level: AlertLevels.ERROR,
message: t(
"organizationDiscovery:notifications." +
"enableEmailDomainDiscovery.error.message"
)
})
);
});
} else {
deleteOrganizationDiscoveryConfig()
.then(() => {
dispatch(
addAlert({
description: t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.success.description"
),
level: AlertLevels.SUCCESS,
message: t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.success.message"
)
})
);

mutateOrganizationDiscoveryConfigFetchRequest();
})
);
});
.catch(() => {
dispatch(
addAlert({
description: t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.error.description"
),
level: AlertLevels.ERROR,
message: t(
"organizationDiscovery:notifications." +
"disableEmailDomainDiscovery.error.message"
)
})
);
});
}
}
};

/**
Expand Down Expand Up @@ -368,7 +447,7 @@ const OrganizationDiscoveryDomainsPage: FunctionComponent<OrganizationDiscoveryD
label={ t("organizationDiscovery:selfRegistration.label") }
listen={ (value: boolean) => handleEmailDomainBasedSelfRegistration(value) }
checked={ isEmailDomainBasedSelfRegistrationEnabled }
disabled={ !isSelfRegEnabled }
disabled={ !isSelfRegEnabled || !hasUpdateScopes }
width={ 16 }
data-testid={ `${testId}-notify-account-confirmation` }
hint={ isSelfRegEnabled && t("organizationDiscovery:selfRegistration.labelHint") }
Expand Down

0 comments on commit 271cd66

Please sign in to comment.