-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix: update taxonomies permission rules #33413
fix: update taxonomies permission rules #33413
Conversation
Thanks for the pull request, @rpenido! 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. |
# Only taxonomy admins can view disabled all org taxonomies | ||
if is_all_org and not taxonomy.enabled: | ||
return 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.
I'm not sure how we're supposed to handle a Taxonomy that's linked to "all orgs" and linked to one or more specific orgs -- which takes precedence, the "all orgs" row, or the specific org rows?
I would guess that "all orgs" takes precedence.
So I'd expect this check to look like this, and is_all_org
to not be referenced again in this function:
# Only taxonomy admins can view disabled all org taxonomies | |
if is_all_org and not taxonomy.enabled: | |
return False | |
# Only taxonomy admins can view disabled all org taxonomies | |
if is_all_org: | |
return taxonomy.enabled |
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 agree that "all orgs" should take precedence.
We can't change the check that way because we would enable an ordinary user (without org) to see this taxonomy. We can short circuit a False
here (denying permission) but to return a True
we need additional checks.
But reviewing the code, I think we don't need to check is_all_org
after:
# Org-level staff can view any taxonomy that is associated with one of their orgs.
if is_org_admin(taxonomy_orgs, user):
return True
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.
@rpenido I don't think your conclusion ^ is correct?
We can't change the check that way because we would enable an ordinary user (without org) to see this taxonomy.
This comment says:
- Enabled Taxonomy linked to all orgs - any registered user can view the taxonomy and its tags (3)
- Disabled Taxonomy linked to all orgs - only global staff can view the taxonomy and its tags (5)
So my original suggestion stands:
# Only taxonomy admins can view disabled all org taxonomies | |
if is_all_org and not taxonomy.enabled: | |
return False | |
# Enabled all-org taxonomies can be viewed by any registered user. | |
if is_all_org: | |
return taxonomy.enabled |
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.
You're right @pomegranited !
Done: dd4696a110c9d22baa1780fc8fcf6d63438cef01
I'll check/fix the related test tomorrow
@@ -62,7 +196,7 @@ def can_change_object_tag_taxonomy(user: UserType, taxonomy: oel_tagging.Taxonom | |||
Taxonomy users can tag objects using tags from any taxonomy that they have permission to view. Only taxonomy admins | |||
can tag objects using tags from disabled taxonomies. |
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.
"Only taxonomy admins can tag objects using tags from disabled taxonomies."
I'm not sure about this.. I think "disabled" means it can't be used to tag objects, even if you're an admin.
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 that it could make sense to let an admin clean tags from a disabled taxonomy. But we can simplify and let only enabled taxonomies be used.
What do 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.
"Only taxonomy admins can tag objects using tags from disabled taxonomies."
Yeah I agree with @pomegranited. I don't think we have any need for this. In fact for the MVP we won't really be using disabled taxonomies at all.
Either of these options is fine with me:
- If the taxonomy is disabled, nobody can modify its tags on an object.
- If the taxonomy is disabled, admins can remove tags from objects, but not add new ones.
This only affects the API. In the UI, we will never display tags from disabled taxonomies, even to admins. (I 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.
Agreed!
I went to: "If the taxonomy is disabled, nobody can modify its tags on an object."
@@ -22,7 +22,7 @@ def setUp(self): | |||
name="Learning Objectives", | |||
enabled=False, | |||
) | |||
api.set_taxonomy_orgs(self.taxonomy_disabled, all_orgs=True) | |||
api.set_taxonomy_orgs(self.taxonomy_disabled, orgs=[self.org1, self.org2]) |
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.
Why did this have to change? I think it's still useful to include a taxonomy in the tests which is disabled + all_orgs.
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 changed it to fix the following test:
We have disabled + all_orgs test here:
https://github.com/open-craft/edx-platform/blob/aeeebf948941ed37c9cc8b28e15315e1d8d4f62a/openedx/core/djangoapps/content_tagging/tests/test_rules.py#L375C1-L392C57
13da9ee
to
62e6984
Compare
openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py
Outdated
Show resolved
Hide resolved
c29f48f
to
db0229f
Compare
851bb83
to
2a419d0
Compare
a055fac
to
ec80122
Compare
ec80122
to
9594728
Compare
Hi @pomegranited ! We have a Lint error:
I needed to create a ContentLibrary for the tests (to check our condition no. 8). Should we ignore this lint or is there a better way to handle this in the tests?
Also, after implementing condition 8, I saw a potential problem. If an Org has a ContentLibrary with I also noted that we are not preventing a user with access to more than one org from "cross tag" objects. |
You need to use the public |
I think that's actually fine. Taxonomies aren't super private. |
7b12224
to
999fe76
Compare
@@ -735,61 +1164,66 @@ def test_tag_course(self, user_attr, taxonomy_attr, tag_values, expected_status) | |||
assert set(t["value"] for t in response.data) == set(tag_values) | |||
|
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.
Subjective comment: you could split test_tag_course
into two test methods, one for the successful staffA
and staff
users, and one for the forbidden user
attempts. That would reduce the number of ddt parameters required, and negate the need for this if status.is_success
clause.
But objectively: I still don't see any tests for the GET
ObjectTag endpoint in this file? You could add get
view tests after these successful PUT
s like this:
# Check that re-fetching the tags returns what we set | |
response = self.client.get(url, format="json") | |
assert status.is_success(response.status_code) | |
assert set(t["value"] for t in response.data) == set(tag_values) |
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.
Done 9695d67
@rpenido One comment about missing tests, but this still looks good 👍 . FYI, while a PR is actively being reviewed, if you |
2510a48
to
381f4df
Compare
@bradenmacdonald Package updated and tests green. |
Sorry for that @pomegranited! |
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.
Looks great! Just one minor thing and question, then I'll approve.
) | ||
def test_detail_taxonomy_staff_see_all(self, taxonomy_attr: str) -> None: | ||
""" | ||
Tests that org users can't see taxonomies from other orgs |
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.
This docstring is wrong.
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.
Done 66158a7!
""" | ||
Test cases for TaxonomyViewSet when ENABLE_CREATOR_GROUP is True | ||
Test cases for TestTaxonomyReadViewSet when ENABLE_CREATOR_GROUP is True |
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.
Does ENABLE_CREATOR_GROUP
have any effect at all on the taxonomy code/permissions? I'm unclear why we have different tests based on that.
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.
After we stopped using the is_content_creator
check, the FLAG didn't impact our code anymore.
If any, these tests tell us that the FLAG is not affecting our permissions.
I think we can safely clear this. What do 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.
I think it's confusing to mention that flag if it has no effect. Maybe just add one little test case that ensures things work the same way with or without that flag, but even that is probably not necessary.
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.
Yeah I agree -- we used to care about this flag, but we don't anymore with the new permissions, so these extra tests can be removed.
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.
Great! I will fix this tomorrow ping you 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.
4d5c569
to
98064bc
Compare
98064bc
to
217cedb
Compare
@rpenido 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production. |
2U Release Notice: This PR has been deployed to the edX production environment. |
1 similar comment
2U Release Notice: This PR has been deployed to the edX production environment. |
Description
Updates the content tagging rest API permissions according to spec.
Supporting Information
Testing instructions
Before Merge
openedx-learning
versionPrivate-ref: FAL-3518