You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a ValidationError in the BaseObjectPermission class that prevents assigning of permissions to an object that does not match the content type of the given permission.
defsave(self, *args, **kwargs):
content_type=get_content_type(self.content_object)
ifcontent_type!=self.permission.content_type:
raiseValidationError("Cannot persist permission not designed for ""this class (permission's type is %r and object's type is %r)"% (self.permission.content_type, content_type))
Also, there is an exception in the ObjectPermissionBackend class that checks the mentioned criteria.
ifapp_label!=ctype.app_label:
raiseWrongAppError("Passed perm has app label of '%s' while ""given obj has app label '%s' and given obj""content_type has app label '%s'"%
(app_label, obj._meta.app_label, ctype.app_label))
I know that it sounds awkward to assign the view_groups permission (which has the group content type ) to an instance of the School model to a user. But consider the following scenario:
I have an Education Academy that has some teachers and students and these teachers and students are members of some other Education Academies too. (M2M relation). I have other entities like Homework and Notification too.
So How can I say Teacher-A has permission to add Homework in School-A and Teacher-A can only Add Notifications in School-B? (we have the same thing for students too).
The Djagno/guardian of what I said is below:
fromguardian.shortcutsimportassign_permschool_a=School.objects.create(name='School-A')
school_b=School.objects.create(name='School-B')
user_a=get_user_model().object.create(username='user_a')
school_a.teachers.add(user_a)
school_b.teachers.add(user_a)
assign_perm( 'add_homework',user_a, school_a)
assign_perm( 'add_notification', user_a, school_b)
# There we go, user_a can call the API to add homework in School-A but can not add homework in School-B
What I am proposing is that the user is an entity that login to the system but that user can become a member of some other thing (like a teacher/student is a member of a school) and because of that membership has some permissions in that place(object).
Thank you in advance for any time and effort that you are putting into this issue.
The text was updated successfully, but these errors were encountered:
There is a ValidationError in the BaseObjectPermission class that prevents assigning of permissions to an object that does not match the content type of the given permission.
Also, there is an exception in the ObjectPermissionBackend class that checks the mentioned criteria.
I know that it sounds awkward to assign the
view_groups
permission (which has the group content type ) to an instance of the School model to a user. But consider the following scenario:I have an Education Academy that has some teachers and students and these teachers and students are members of some other Education Academies too. (M2M relation). I have other entities like Homework and Notification too.
So How can I say Teacher-A has permission to add Homework in School-A and Teacher-A can only Add Notifications in School-B? (we have the same thing for students too).
The Djagno/guardian of what I said is below:
What I am proposing is that the user is an entity that login to the system but that user can become a member of some other thing (like a teacher/student is a member of a school) and because of that membership has some permissions in that place(object).
Thank you in advance for any time and effort that you are putting into this issue.
The text was updated successfully, but these errors were encountered: