Skip to content

Commit

Permalink
feat: Update permissions to remove object tags
Browse files Browse the repository at this point in the history
* chore: Bump version

* fix: Issue with remove object tag permission
  • Loading branch information
ChrisChV committed May 7, 2024
1 parent be4b8e3 commit c791682
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion openedx_learning/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Open edX Learning ("Learning Core").
"""
__version__ = "0.9.2"
__version__ = "0.9.3"
9 changes: 8 additions & 1 deletion openedx_tagging/core/tagging/rest_api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ class Meta:
fields = ["value", "lineage", "can_delete_objecttag"]

lineage = serializers.ListField(child=serializers.CharField(), source="get_lineage", read_only=True)
can_delete_objecttag = serializers.SerializerMethodField(method_name='get_can_delete')
can_delete_objecttag = serializers.SerializerMethodField()

def get_can_delete_objecttag(self, instance) -> bool | None:
"""
Returns True if the current request user may delete object tags on this taxonomy
"""
perm_name = f'{self.app_label}.remove_objecttag_objectid'
return self._can(perm_name, instance.object_id)


class ObjectTagSerializer(ObjectTagMinimalSerializer):
Expand Down
11 changes: 11 additions & 0 deletions openedx_tagging/core/tagging/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ def can_view_object_tag_objectid(_user: UserType, _object_id: str) -> bool:
return True


@rules.predicate
def can_remove_object_tag_objectid(_user: UserType, _object_id: str) -> bool:
"""
Everybody can remove object tags from any objects.
This rule could be defined in other apps for proper permission checking.
"""
return True


@rules.predicate
def can_view_object_tag(
user: UserType, perm_obj: ObjectTagPermissionItem | None = None
Expand Down Expand Up @@ -194,3 +204,4 @@ def can_change_object_tag(
rules.add_perm("oel_tagging.view_objecttag_taxonomy", can_view_object_tag_taxonomy)
rules.add_perm("oel_tagging.change_objecttag_taxonomy", can_view_object_tag_taxonomy)
rules.add_perm("oel_tagging.change_objecttag_objectid", can_change_object_tag_objectid)
rules.add_perm("oel_tagging.remove_objecttag_objectid", can_remove_object_tag_objectid)

0 comments on commit c791682

Please sign in to comment.