-
Notifications
You must be signed in to change notification settings - Fork 539
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
Restricted custom fields #3495
Restricted custom fields #3495
Conversation
def _user_can_manage_customfield(self, user, custom_field): | ||
return ( | ||
custom_field.managing_group is None or | ||
custom_field.managing_group in user.groups.all() |
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.
Did you try user.groups.filter(pk=custom_field.managing_group.pk).exists()
?
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.
Looks more efficient. Thanks!
src/ralph/lib/custom_fields/forms.py
Outdated
def __init__( | ||
self, data=None, files=None, instance=None, save_as_new=None, | ||
prefix=None, queryset=None, request=None, **kwargs | ||
): |
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.
You can write def __init__(self, request=None, *args, **kwargs):
if you only need request
. Also super
clause should simplify to super().__init__(request=request, queryset=queryset, *args, **kwargs)
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.
+1
src/ralph/lib/custom_fields/forms.py
Outdated
) | ||
|
||
super().__init__( | ||
data=data, files=files, instance=instance, save_as_new=save_as_new, |
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.
Where is request
?
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.
It is not expected there.
@@ -135,3 +135,42 @@ def changeform_view( | |||
return super().changeform_view( | |||
request, object_id, form_url, extra_context | |||
) | |||
|
|||
def _create_formsets(self, request, obj, change): |
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.
Where did you use this function?
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.
It it used internally by the ModelAdmin class
Add an optional managing group property to custom fields. If set, adding, changing or deleting values of those custom fields will be restricted to mebmerb of a specified groups only. Custom field form will not show such custom field values to unauthorized users.
8e57a4d
to
e930064
Compare
The commits have been squashed. Since no other changes have been made, I'm going to merge this with a single approve. |
Add an optional managing group property to custom fields. If set,
adding, changing or deleting values of those custom fields will
be restricted to mebmerb of a specified groups only.
Custom field form will not show such custom field values to
unauthorized users.