Skip to content
Closed
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
30 changes: 26 additions & 4 deletions src/content-tags-drawer/ContentTagsDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +81 to +82

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ChrisChV !
This call (even if we don't explicitly include an Org) will filter out the taxonomies on which the user has no permission (i.e. taxonomies from other/no orgs).

I'm getting it wrong here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the testing I have done, the Test taxonomy does not belong to any organization. So currently it doesn't filter those permissions 🤔

@rpenido rpenido Apr 4, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have two different cases:
1 - In the one you show, the user have permission to access the taxonomy (because he is the staff?).
2 - Another case is when the user is not staff (so he can't see no-org taxonomies or taxonomies from org that he doesn't have permission)

We have 1 covered. Do we need to worry about 2?


let contentName = '';
if (isContentDataLoaded) {
Expand Down Expand Up @@ -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;

Expand All @@ -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 (

Expand All @@ -151,7 +173,7 @@ const ContentTagsDrawer = ({ id, onClose }) => {

<hr />

{ isTaxonomyListLoaded && isContentTaxonomyTagsLoaded
{ isTaxonomyListLoaded && isAllTaxonomyListLoaded && isContentTaxonomyTagsLoaded
? taxonomies.map((data) => (
<div key={`taxonomy-tags-collapsible-${data.id}`}>
<ContentTagsCollapsible
Expand Down
11 changes: 8 additions & 3 deletions src/taxonomy/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export const apiUrls = {
/**
* Get the URL of the "list all taxonomies" endpoint
* @param {string} [org] Optionally, 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
*/
taxonomyList(org) {
taxonomyList(org, contentId = undefined) {
const params = {};
if (org !== undefined) {
if (org === UNASSIGNED) {
Expand All @@ -35,6 +36,9 @@ export const apiUrls = {
params.org = org;
}
}
if (contentId !== undefined) {
params.content_id = contentId
}
return makeUrl('.', { enabled: 'true', ...params });
},
/**
Expand Down Expand Up @@ -88,10 +92,11 @@ export const apiUrls = {
/**
* Get list of taxonomies.
* @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
* @returns {Promise<import("./types.mjs").TaxonomyListData>}
*/
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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/taxonomy/data/apiHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
);

Expand Down