Closed jchate6 closed 3 months ago
See these threads in #snex2 slack channel: https://lcogt.slack.com/archives/CFJ0D9PNH/p1722467894595529 https://lcogt.slack.com/archives/CFJ0D9PNH/p1722467180327669
A snippit for checking content Types and Permissions
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from tom_targets.models import Target
tct = ContentType.objects.get_for_model(Target)
pt_target = Permission.objects.filter(content_type=tct)
for pt in pt_target:
print(pt.codename,"|", pt.name)
Update target permissions if the user has extended a target model.
from tom_targets.models import Target
from guardian.models import GroupObjectPermission, UserObjectPermission
for target in Target.objects.all():
group_set = set([gop.group for gop in GroupObjectPermission.objects.filter(object_pk=target.pk)])
for group in group_set:
target.give_user_access(group)
user_set = set([uop.user for uop in UserObjectPermission.objects.filter(object_pk=target.pk)])
for user in user_set:
target.give_user_access(user)
This was caused by pointing to the same DB from multiple versions of the Tom Toolkit
There are, however some actual concerns about how the extended Target Model interacts with Permissions: Once
Target
has been renamed toBaseTarget
we seem to then have 2 sets of permissions forview_targets
. This does not seem to cause any problems, but could cause confusion in the admin interface.Also, If an extended user Target is actually made, then the old Targets that are upgraded through the management command would not be automatically connected to the users and groups they had before. Permissions need to be manually updated during this process.