8000 Add new can view and can view minor roles by FrankApiyo · Pull Request #2791 · onaio/onadata · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add new can view and can view minor roles #2791

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

Merged

Conversation

FrankApiyo
Copy link
Contributor
@FrankApiyo FrankApiyo commented Apr 7, 2025

Changes / Features implemented

  • Add new can view and can view minor roles

Steps taken to verify this change does what is intended

Added test cases

Before submitting this PR for review, please make sure you have:

  • Included tests
  • Updated documentation

Todo

  • Add test cases for new meta permissions

@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch 6 times, most recently from beaa829 to 1364ff8 Compare April 9, 2025 12:57
@FrankApiyo FrankApiyo marked this pull request as ready for review April 9, 2025 14:45
@FrankApiyo FrankApiyo requested review from ukanga and kelvin-muchiri and removed request for ukanga April 9, 2025 14:45
@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch from 1364ff8 to c6fc9b5 Compare April 14, 2025 06:50
@FrankApiyo FrankApiyo changed the base branch from main to < 8000 span class="css-overflow-wrap-anywhere">valigetta-integration April 14, 2025 06:51
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from ed09fb5 to 53b4c03 Compare April 15, 2025 09:43
@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch from c6fc9b5 to c942615 Compare April 24, 2025 14:13
@FrankApiyo FrankApiyo changed the base branch from valigetta-integration to main April 24, 2025 14:13
@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch from aae378b to a57ceba Compare April 25, 2025 06:31
@FrankApiyo FrankApiyo changed the base branch from main to valigetta-integration April 25, 2025 06:31
@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch from a57ceba to 97aa6a7 Compare April 25, 2025 08:58
@@ -1415,6 +1415,27 @@ def save_project(sender, instance=None, created=False, **kwargs):
pre_save.connect(save_project, sender=XForm, dispatch_uid="save_project_xform")


def _create_meta_perms(sender, instance, created, **kwargs):
metadata = instance.metadata_set.all().filter(data_type="xform_meta_perms").first()
if instance.deleted_by is None and metadata is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we care whether the object is deleted or not? I think we can omit the check.

if instance.deleted_by is None and metadata is None:
from onadata.libs.serializers.metadata_serializer import MetaDataSerializer

serializer = MetaDataSerializer(
Copy link
Contributor
@kelvin-muchiri kelvin-muchiri Apr 28, 2025

Choose a reason for hiding this comment

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

In the past, how have we created xform_meta_perms,or rather when is the record created? It's best to use the MetaData model here to created the object directly instead of using the serializer

Copy link
Contributor Author
@FrankApiyo FrankApiyo Apr 29, 2025

Choose a reason for hiding this comment

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

The xform_meta_perms , in the past, has been created by making API requests from the front-end. So this record is normally not created on the back-end service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could use the MetaData.objects.create method directly. I think if we use the serializer this way, we will benefit from some validation and logic already in the create method of the serializer

Copy link
Contributor

Choose a reason for hiding this comment

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

@FrankApiyo Noted, though since it's being created directly and not a request from a client, we are assured the values are always correct. But if there is some essential checks that we think applies, it should be moved to a some utiility module accessible by the serializer module and model module

Copy link
Contributor Author
@FrankApiyo FrankApiyo May 5, 2025

Choose a reason for hiding this comment

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

I've refactored the MetaData creation signal to use the model directly

@@ -251,6 +261,33 @@ class DataEntryRole(Role):
}


class EditorNoDownload(Role):
"""
Editor-Minor Role class - user can submit data, read and edit only the data
Copy link
Contributor

Choose a reason for hiding this comment

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

Editor-Minor Role class does not match the class name, either way, I think we can omit it the Editor-Minor Role class - prefix altogether

update_role_by_meta_xform_perms(instance.content_object)
xform = instance.content_object
update_role_by_meta_xform_perms(xform)
safe_delete(f"{PROJ_OWNER_CACHE}{xform.project.pk}")
Copy link
Contributor
@kelvin-muchiri kelvin-muchiri Apr 28, 2025

Choose a reason for hiding this comment

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

Is it preferrable if the cache invalidations be inside update_role_by_meta_xform_perms method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved!

@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch from 62e9830 to 0a9edc6 Compare April 29, 2025 18:13
@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch from 0a9edc6 to 769aee2 Compare April 29, 2025 18:18
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from 9eafbf3 to 965c0f2 Compare May 2, 2025 07:32
@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch from 769aee2 to f78d5eb Compare May 2, 2025 07:44
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from e726383 to 919d5af Compare May 5, 2025 08:47
@FrankApiyo FrankApiyo force-pushed the add-new-can-view-and-can-view-minor-roles branch from f78d5eb to 5a303f9 Compare May 5, 2025 11:55
@FrankApiyo FrankApiyo merged commit f3fbdc1 into valigetta-integration May 6, 2025
1 check passed
@FrankApiyo FrankApiyo deleted the add-new-can-view-and-can-view-minor-roles branch May 6, 2025 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0