From 25f461d577675343ea4a5266285ba1facaed291e Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Thu, 28 Mar 2024 14:12:30 -0500 Subject: [PATCH] feat: Update permissions Update permissions on taxonomies view to allow to show taxonomies outside course organization. --- src/content-tags-drawer/ContentTagsDrawer.jsx | 30 ++++++++++++++++--- src/taxonomy/data/api.js | 11 +++++-- src/taxonomy/data/apiHooks.js | 5 ++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/content-tags-drawer/ContentTagsDrawer.jsx b/src/content-tags-drawer/ContentTagsDrawer.jsx index a72f6a839d..10c597be93 100644 --- a/src/content-tags-drawer/ContentTagsDrawer.jsx +++ b/src/content-tags-drawer/ContentTagsDrawer.jsx @@ -74,7 +74,12 @@ const ContentTagsDrawer = ({ id, onClose }) => { data: contentTaxonomyTagsData, isSuccess: isContentTaxonomyTagsLoaded, } = useContentTaxonomyTagsData(contentId); - const { data: taxonomyListData, isSuccess: isTaxonomyListLoaded } = useTaxonomyList(org); + + // Taxonomies by Organization + const { data: taxonomyListData, isSuccess: isTaxonomyListLoaded } = useTaxonomyList(org, contentId); + + // All taxonomies to verify if exists object tags in other taxonomy that does not belong to the organization. + const { data: allTaxonomyListData, isSuccess: isAllTaxonomyListLoaded } = useTaxonomyList(undefined, contentId); let contentName = ''; if (isContentDataLoaded) { @@ -109,12 +114,16 @@ const ContentTagsDrawer = ({ id, onClose }) => { }, []); const taxonomies = useMemo(() => { - if (taxonomyListData && contentTaxonomyTagsData) { + if (taxonomyListData && contentTaxonomyTagsData && allTaxonomyListData) { // Initialize list of content tags in taxonomies to populate const taxonomiesList = taxonomyListData.results.map((taxonomy) => ({ ...taxonomy, contentTags: /** @type {ContentTagData[]} */([]), })); + const allTaxonomiesList = allTaxonomyListData.results.map((taxonomy) => ({ + ...taxonomy, + contentTags: /** @type {ContentTagData[]} */([]), + })); const contentTaxonomies = contentTaxonomyTagsData.taxonomies; @@ -124,12 +133,25 @@ const ContentTagsDrawer = ({ id, onClose }) => { if (contentTaxonomy) { contentTaxonomy.contentTags = contentTaxonomyTags.tags; } + else { + // In some cases, there are object tags in taxonomies that are not part of the course organization + // It is necessary to show these tags, but without being able to add or delete tags (managed by permissions) + const contentTaxonomy = allTaxonomiesList.find((taxonomy) => taxonomy.id === contentTaxonomyTags.taxonomyId);; + if (contentTaxonomy) { + contentTaxonomy.contentTags = contentTaxonomyTags.tags; + taxonomiesList.push(contentTaxonomy) + } + } }); return taxonomiesList; } return []; - }, [taxonomyListData, contentTaxonomyTagsData]); + }, [ + taxonomyListData, + contentTaxonomyTagsData, + allTaxonomyListData, + ]); return ( @@ -151,7 +173,7 @@ const ContentTagsDrawer = ({ id, onClose }) => {
- { isTaxonomyListLoaded && isContentTaxonomyTagsLoaded + { isTaxonomyListLoaded && isAllTaxonomyListLoaded && isContentTaxonomyTagsLoaded ? taxonomies.map((data) => (
} */ -export async function getTaxonomyListData(org) { - const { data } = await getAuthenticatedHttpClient().get(apiUrls.taxonomyList(org)); +export async function getTaxonomyListData(org, contentId = undefined) { + const { data } = await getAuthenticatedHttpClient().get(apiUrls.taxonomyList(org, contentId)); return camelCaseObject(data); } diff --git a/src/taxonomy/data/apiHooks.js b/src/taxonomy/data/apiHooks.js index a3d241e862..750b561187 100644 --- a/src/taxonomy/data/apiHooks.js +++ b/src/taxonomy/data/apiHooks.js @@ -68,11 +68,12 @@ export const taxonomyQueryKeys = { /** * Builds the query to get the taxonomy list * @param {string} [org] Filter the list to only show taxonomies assigned to this org + * @param {string} [contentId] Optionally, To verify the perms of each taxonomy to manage tags in a content */ -export const useTaxonomyList = (org) => ( +export const useTaxonomyList = (org, contentId = undefined) => ( useQuery({ queryKey: taxonomyQueryKeys.taxonomyList(org), - queryFn: () => api.getTaxonomyListData(org), + queryFn: () => api.getTaxonomyListData(org, contentId), }) );