-
Notifications
You must be signed in to change notification settings - Fork 87
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
Conversation
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:
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. |
917874e
to
9deffad
Compare
to determine which actions/menu items to offer the user
9deffad
to
18a2aa3
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
…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.
76277e6
to
93b0ad0
Compare
There was a problem hiding this 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/TaxonomyListPage.jsx
Outdated
@@ -157,6 +158,7 @@ const TaxonomyListPage = () => { | |||
return { taxonomyListData, isLoaded }; | |||
}; | |||
const { taxonomyListData, isLoaded } = useTaxonomyListData(); | |||
const canAdd = isLoaded ? taxonomyListData.canAdd : false; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
d5456b1
to
3b97b18
Compare
There was a problem hiding this 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.
Permissions are included in the response; no need to request them.
to avoid duplication.
There was a problem hiding this 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?
<TagBubbleComponent | ||
value={tagBubbleData.value} | ||
lineage={data.lineage} | ||
implicit={tagBubbleData.implicit} | ||
removeTagHandler={tagBubbleData.removeTagHandler} | ||
/>, |
There was a problem hiding this comment.
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.
// 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(); |
There was a problem hiding this comment.
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.
value: PropTypes.string, | ||
lineage: PropTypes.arrayOf(PropTypes.string), | ||
})), | ||
canTagObject: PropTypes.bool.isRequired, | ||
}).isRequired, | ||
editable: PropTypes.bool.isRequired, | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
172add8
to
0eb4661
Compare
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. |
@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. |
@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. |
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:
Testing Tag Drawer:
Testing Taxonomy Manager:
(Superusers have permission to do anything, and so aren't a good test of this change.)
Deadline
None
Private ref: FAL-3577