-
Notifications
You must be signed in to change notification settings - Fork 136
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
Add new can view and can view minor roles #2791
Conversation
beaa829
to
1364ff8
Compare
1364ff8
to
c6fc9b5
Compare
ed09fb5
to
53b4c03
Compare
c6fc9b5
to
c942615
Compare
aae378b
to
a57ceba
Compare
a57ceba
to
97aa6a7
Compare
onadata/apps/logger/models/xform.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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.
onadata/apps/logger/models/xform.py
Outdated
if instance.deleted_by is None and metadata is None: | ||
from onadata.libs.serializers.metadata_serializer import MetaDataSerializer | ||
|
||
serializer = MetaDataSerializer( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
onadata/libs/permissions.py
Outdated
@@ -251,6 +261,33 @@ class DataEntryRole(Role): | |||
} | |||
|
|||
|
|||
class EditorNoDownload(Role): | |||
""" | |||
Editor-Minor Role class - user can submit data, read and edit only the data |
There was a problem hiding this comment.
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}") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved!
62e9830
to
0a9edc6
Compare
0a9edc6
to
769aee2
Compare
9eafbf3
to
965c0f2
Compare
769aee2
to
f78d5eb
Compare
e726383
to
919d5af
Compare
f78d5eb
to
5a303f9
Compare
Changes / Features implemented
Steps taken to verify this change does what is intended
Added test cases
Before submitting this PR for review, please make sure you have:
Todo