Skip to content

Commit fd81c3c

Browse files
fix: deny "modify tag" permission when tag.taxonomy is None
1 parent 558b92f commit fd81c3c

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎openedx/core/djangoapps/content_tagging/rules.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,10 @@ def can_change_taxonomy_tag(user: UserType, tag: oel_tagging.Tag | None = None)
355355
return False # Cannot edit tags in read-only taxonomies.
356356
if taxonomy.allow_free_text:
357357
return False # Cannot edit tags in free-text taxonomies.
358-
# FIXME: properly block adding new tags in this case. (when tag=None, we don't have access to 'taxonomy', so the
359-
# permissions check needs to pass a dummy tag object.)
360-
# Also, for superusers, this permissions check is bypassed: https://github.com/openedx/openedx-core/issues/635
358+
if taxonomy is None:
359+
# Taxonomy shouldn't be None if we're editing any real tag.
360+
# And for testing "add", we should always be passed a dummy Tag() object with a valid taxonomy.
361+
return False
361362
return oel_tagging.is_taxonomy_admin(user)
362363

363364
# Taxonomy

‎openedx/core/djangoapps/content_tagging/tests/test_rules.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,15 @@ def test_view_taxonomy_disabled_no_org(self):
365365
)
366366
def test_tag_base_edit_permissions(self, perm):
367367
"""
368-
Test that only Staff & Superuser can call add/edit/delete tags.
368+
Test that only Staff & Superuser can call add/edit/delete tags in an
369+
"all orgs" taxonomy.
369370
"""
370-
assert self.superuser.has_perm(perm)
371-
assert self.staff.has_perm(perm)
372-
assert not self.user_both_orgs.has_perm(perm)
373-
assert not self.user_org2.has_perm(perm)
374-
assert not self.learner.has_perm(perm)
371+
tag = Tag(taxonomy=self.taxonomy_all_orgs)
372+
assert self.superuser.has_perm(perm, tag)
373+
assert self.staff.has_perm(perm, tag)
374+
assert not self.user_both_orgs.has_perm(perm, tag)
375+
assert not self.user_org2.has_perm(perm, tag)
376+
assert not self.learner.has_perm(perm, tag)
375377

376378
def test_tag_base_view_permissions(self):
377379
"""
@@ -459,14 +461,14 @@ def test_free_text_taxonomy_tag(self, perm):
459461
"oel_tagging.delete_tag",
460462
)
461463
def test_tag_no_taxonomy(self, perm):
462-
"""Taxonomy administrators can modify any Tag, even those with no Taxonnmy."""
464+
"""A "floating" tag with no taxonomy cannot be edited. This shouldn't really happen"""
463465
tag = Tag()
464466

465-
# Global Taxonomy Admins can do pretty much anything
467+
# superusers cannot be prevented from doing anything - their permissions check short-circuits our logic.
466468
assert self.superuser.has_perm(perm, tag)
467-
assert self.staff.has_perm(perm, tag)
468469

469470
# Everyone else can't do anything
471+
assert not self.staff.has_perm(perm, tag)
470472
assert not self.user_both_orgs.has_perm(perm, tag)
471473
assert not self.user_org2.has_perm(perm, tag)
472474
assert not self.learner.has_perm(perm, tag)

0 commit comments

Comments
 (0)