Skip to content
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

[FC-0049] feat: Update permissions to remove object tags #188

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this down below can_change_object_tag_objectid ? Also the default value shouldn't be True - the default value should be the same as can_change_object_tag_objectid, so just call that function and return the same value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradenmacdonald Updated here bf49f69



@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)
Loading