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

Use object permissions in Tagging frontend [FC-0036] #787

Merged
merged 9 commits into from
Jan 29, 2024

Conversation

pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Jan 10, 2024

Description

Uses the permissions added to the Tagging REST API by openedx/openedx-learning#138 to decide what actions (e.g. import, export, edit, delete) to present to the current user when viewing Tagging-related content.

Supporting information

Part of openedx/modular-learning#160

This PR is dependent on these PRs:

Testing instructions

Setup:

  1. Run edx-platform from the branch on Tagging: serialize object permissions to REST API [FC-0036] edx-platform#34004
  2. Install the updated requirements from ^.
  3. Create test taxonomies, tags, orgs, and courses with https://github.com/open-craft/taxonomy-sample-data/
  4. Run this PR's branch for course authoring.

Testing Tag Drawer:

  1. Login to Studio as a non-superuser with course authoring permissions.
  2. Visit the Sample Taxonomy Course course-v1:SampleTaxonomyOrg1+STC1+2023_1
  3. Navigate to a Unit
  4. Click "Manage Tags", either from the sidebar or the unit's menu
  5. Ensure that the tag drawer opens with:
    • All the taxonomies the user is allowed to view
    • "Add tags" buttons for the listed taxonomies
    • Any selected object tags shown.
  6. Add a bunch of tags at various hierarchy levels, and ensure they add as expected.
  7. Delete some tags and ensure they delete as expected.

Testing Taxonomy Manager:

  1. Login to Studio as a non-superuser with course authoring permissions.
    (Superusers have permission to do anything, and so aren't a good test of this change.)
  2. Visit the Taxonomies list (http://localhost:2001/taxonomies)
  3. Check that the "Import" button is enabled (new taxonomies can be added)
  4. For each taxonomy listed, check that:
    • All taxonomies show "Export" as a menu option
    • Non-system taxonomies show "Re-import", "Manage organizations", and "Delete" as menu options
    • System taxonomies do not show "Re-import" or "Delete" as menu options

Deadline

None

Private ref: FAL-3577

@openedx-webhooks
Copy link

openedx-webhooks commented Jan 10, 2024

Thanks for the pull request, @pomegranited! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jan 10, 2024
@pomegranited pomegranited marked this pull request as draft January 10, 2024 06:27
@pomegranited pomegranited force-pushed the jill/tagging-rest-perms branch from 917874e to 9deffad Compare January 10, 2024 06:32
to determine which actions/menu items to offer the user
@pomegranited pomegranited force-pushed the jill/tagging-rest-perms branch from 9deffad to 18a2aa3 Compare January 10, 2024 06:47
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bdb4ffe) 89.95% compared to head (0eb4661) 90.30%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #787      +/-   ##
==========================================
+ Coverage   89.95%   90.30%   +0.35%     
==========================================
  Files         506      506              
  Lines        8450     8477      +27     
  Branches     1779     1784       +5     
==========================================
+ Hits         7601     7655      +54     
+ Misses        819      794      -25     
+ Partials       30       28       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…gging REST API

to decide what actions to offer the user.

These object-specific permissions replace the global "editable" field,
which has been removed from the REST API.
to alleviate confusion about what permissions they reflect.

Also fixes some properties and wraps menu clicks in act() to remove errors from the tests.
Copy link
Contributor

@rpenido rpenido left a comment

Choose a reason for hiding this comment

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

Hi @pomegranited!
I think we mixed the Tag with ObjectTag permissions here. Instead of using the Tag canAdd and canDelete, we should use the Taxonomy canTagObject you created.

We will use the Tag permissions to manage the Tags of a Taxonomy (not to tag objects). Does this make sense?

src/taxonomy/taxonomy-menu/TaxonomyMenu.jsx Outdated Show resolved Hide resolved
src/content-tags-drawer/ContentTagsTree.jsx Outdated Show resolved Hide resolved
src/content-tags-drawer/data/api.js Outdated Show resolved Hide resolved
@@ -157,6 +158,7 @@ const TaxonomyListPage = () => {
return { taxonomyListData, isLoaded };
};
const { taxonomyListData, isLoaded } = useTaxonomyListData();
const canAdd = isLoaded ? taxonomyListData.canAdd : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same. I think we need the canTagObject flag here

Copy link
Contributor Author

@pomegranited pomegranited Jan 15, 2024

Choose a reason for hiding this comment

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

I disagree -- this is taxonomy.canAdd , which indicates whether the user can create a new taxonomy.

But clearly these permissions are confusing, so I can rename them to include the model name:

  • objecttag.canAdd -> canTagObjects (already done)
  • objecttag.canDelete -> canDeleteObjectTag
  • taxonomy.canAdd -> canAddTaxonomy
  • tag.canChange -> canChangeTag
  • tag.canDelete -> canDeleteTag

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad here @pomegranited! You're right. I meant to mark the canAdd from ObjectTag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries at all @rpenido ! It really helped me to hear your perspective reviewing these PRs, and I hope the code is now more legible to everyone.

@pomegranited pomegranited force-pushed the jill/tagging-rest-perms branch from d5456b1 to 3b97b18 Compare January 16, 2024 02:46
@rpenido rpenido self-requested a review January 17, 2024 13:51
Copy link
Contributor

@rpenido rpenido left a comment

Choose a reason for hiding this comment

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

Good work @pomegranited! 👍

  • I tested this using the Testing Instructions from Use object permissions in Tagging frontend [FC-0036] #787
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation
  • I made sure any change in configuration variables is reflected in the corresponding client's configuration-secure repository.

src/taxonomy/taxonomy-menu/TaxonomyMenu.test.jsx Outdated Show resolved Hide resolved
Permissions are included in the response; no need to request them.
Copy link
Contributor

@xitij2000 xitij2000 left a comment

Choose a reason for hiding this comment

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

Just minor suggestions, but looks good otherwise.

I think this will require the other PRs to merge first otherwise the UI might break. Is that correct?

Comment on lines 106 to 111
<TagBubbleComponent
value={tagBubbleData.value}
lineage={data.lineage}
implicit={tagBubbleData.implicit}
removeTagHandler={tagBubbleData.removeTagHandler}
/>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for symmetry with the previous test, canRemove should be passed here as well.

Comment on lines 110 to 119
// Click on button again to close the menu
fireEvent.click(getByTestId('taxonomy-menu-button'));

// Menu closed
// Jest bug: toBeVisible() isn't checking opacity correctly
// expect(getByTestId('taxonomy-menu')).not.toBeVisible();
expect(getByTestId('taxonomy-menu').style.opacity).toEqual('0');

// Menu button still visible
expect(getByTestId('taxonomy-menu-button')).toBeVisible();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this part of the test can just be skipped. It's not testing functionality of this app, but testing that the dropdown component functions properly, which is (or should be) covered by paragon tests.

Comment on lines 215 to 220
value: PropTypes.string,
lineage: PropTypes.arrayOf(PropTypes.string),
})),
canTagObject: PropTypes.bool.isRequired,
}).isRequired,
editable: PropTypes.bool.isRequired,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these type definition are repeated in multiple places, it might be worth defining them once and them reusing them.

i.e. you could do put into a data/proptypes.js the following:

import PropTypes from 'prop-types';

const tag = PropTypes.shape({
  value: PropTypes.string,
  lineage: PropTypes.arrayOf(PropTypes.string),
});

const taxonomy = PropTypes.shape({
  id: PropTypes.number,
  name: PropTypes.string,
  contentTags: PropTypes.arrayOf(tag),
  canTagObject: PropTypes.bool.isRequired,
});

export default {
  tag,
  taxonomy,
};

Then they can be used anywhere as:

import TaxonomyProps from './data/proptypes';

ContentTagsCollapsible.propTypes = {
  contentId: PropTypes.string.isRequired,
  taxonomyAndTagsData: TaxonomyProps.taxonomy.isRequired,
};

This will avoid needing to update all places when the structure changes, and also will also make it easier to discover all the places that rely on this data structure.

Copy link
Contributor Author

@pomegranited pomegranited Jan 24, 2024

Choose a reason for hiding this comment

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

Thank you for your review @xitij2000 ! And yep, we have to wait for openedx/edx-platform#34004 to merge before merging here.

Some of these type definition are repeated in multiple places, it might be worth defining them once and them reusing them.

Unfortunately, it looks like the components in src/taxonomy and src/content-tags-drawer don't share enough propTypes to warrant creating a prototypes.js file for them to use.

However, I do think it's silly that our test modules don't just re-use the propTypes of the components they're testing, so I've fixed that: 0eb4661
Let me know what you think?

Copy link
Contributor

@xitij2000 xitij2000 Jan 24, 2024

Choose a reason for hiding this comment

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

Sure, I think that makes sense. I don't see any benefit in duplicating this, since it's already a development/testing tool more than a production tool.

@pomegranited pomegranited force-pushed the jill/tagging-rest-perms branch from 172add8 to 0eb4661 Compare January 24, 2024 01:24
@pomegranited
Copy link
Contributor Author

FYI @xitij2000 openedx/edx-platform#34004 (review) should merge tomorrow -- are you ok with merging this in the next couple days?

@xitij2000
Copy link
Contributor

FYI @xitij2000 openedx/edx-platform#34004 (review) should merge tomorrow -- are you ok with merging this in the next couple days?

I'm on leave tomorrow, and then it's the weekend. Since merging is the only thing left, I can do that via my phone though.

@pomegranited
Copy link
Contributor Author

@xitij2000 If you feel comfortable with merging on your day off, then that's fine. but there's no all-fired rush :) OK to wait until you're back at work next week.
Thank you!

@xitij2000 xitij2000 merged commit b56b5d9 into openedx:master Jan 29, 2024
6 checks passed
@openedx-webhooks
Copy link

@pomegranited 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants