Skip to content

Commit

Permalink
fix: Bug DRF UI when creating tag + failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-musleh committed Oct 17, 2023
1 parent f09f75d commit f9e28da
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 0 additions & 1 deletion openedx_tagging/core/tagging/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ def add_tag(
tag_value: str,
parent_tag_id: int | None = None,
external_id: str | None = None

) -> Tag:
"""
Add new Tag to Taxonomy. If an existing Tag with the `tag_value` already
Expand Down
3 changes: 3 additions & 0 deletions openedx_tagging/core/tagging/rest_api/v1/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import rules # type: ignore[import]
from rest_framework.permissions import DjangoObjectPermissions

from ...models import Tag


class TaxonomyObjectPermissions(DjangoObjectPermissions):
"""
Expand Down Expand Up @@ -54,4 +56,5 @@ def has_object_permission(self, request, view, obj):
"""
Returns True if the user on the given request is allowed the given view for the given object.
"""
obj = obj.taxonomy if isinstance(obj, Tag) else obj
return rules.has_perm("oel_tagging.list_tag", request.user, obj)
3 changes: 1 addition & 2 deletions openedx_tagging/core/tagging/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ def can_view_tag(user: UserType, tag: Tag | None = None) -> bool:
User can view tags for any taxonomy they can view.
"""
taxonomy = tag.taxonomy.cast() if (tag and tag.taxonomy) else None
has_perm_thing = user.has_perm(
return user.has_perm(
"oel_tagging.view_taxonomy",
taxonomy,
)
return has_perm_thing


@rules.predicate
Expand Down
4 changes: 2 additions & 2 deletions tests/openedx_tagging/core/tagging/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def test_add_change_tag(self, perm):
)
def test_tag_free_text_taxonomy(self, perm):
"""
Taxonomy administrators cannot modify tags on a free-text Taxonomy
Taxonomy administrators can modify any Tag, even those associated with a free-text Taxonomy
"""
self.taxonomy.allow_free_text = True
self.taxonomy.save()
assert self.superuser.has_perm(perm, self.bacteria)
assert not self.staff.has_perm(perm, self.bacteria)
assert self.staff.has_perm(perm, self.bacteria)
assert not self.learner.has_perm(perm, self.bacteria)

@ddt.data(
Expand Down

0 comments on commit f9e28da

Please sign in to comment.