Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update permissions #926

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@
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
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
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 🤔

Copy link
Contributor

@rpenido rpenido Apr 4, 2024

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 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 @@ -123,13 +132,26 @@
const contentTaxonomy = taxonomiesList.find((taxonomy) => taxonomy.id === contentTaxonomyTags.taxonomyId);
if (contentTaxonomy) {
contentTaxonomy.contentTags = contentTaxonomyTags.tags;
}

Check failure on line 135 in src/content-tags-drawer/ContentTagsDrawer.jsx

View workflow job for this annotation

GitHub Actions / tests

Closing curly brace does not appear on the same line as the subsequent block
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);;

Check failure on line 139 in src/content-tags-drawer/ContentTagsDrawer.jsx

View workflow job for this annotation

GitHub Actions / tests

'contentTaxonomy' is already declared in the upper scope on line 132 column 15

Check failure on line 139 in src/content-tags-drawer/ContentTagsDrawer.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing whitespace after semicolon

Check failure on line 139 in src/content-tags-drawer/ContentTagsDrawer.jsx

View workflow job for this annotation

GitHub Actions / tests

Unnecessary semicolon
if (contentTaxonomy) {
contentTaxonomy.contentTags = contentTaxonomyTags.tags;
taxonomiesList.push(contentTaxonomy)

Check failure on line 142 in src/content-tags-drawer/ContentTagsDrawer.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
}
}
});

return taxonomiesList;
}
return [];
}, [taxonomyListData, contentTaxonomyTagsData]);
}, [
taxonomyListData,
contentTaxonomyTagsData,
allTaxonomyListData,
]);

return (

Expand All @@ -151,7 +173,7 @@

<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 @@
/**
* 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 @@
params.org = org;
}
}
if (contentId !== undefined) {
params.content_id = contentId

Check failure on line 40 in src/taxonomy/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
}
return makeUrl('.', { enabled: 'true', ...params });
},
/**
Expand Down Expand Up @@ -88,10 +92,11 @@
/**
* 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
Loading