def default_permissions_post_save(sender, instance, created, raw, **kwargs):
    """
    Users must have both model-level and object-level permissions to satisfy
    DRF, so assign the newly-created user all available collection and asset
    permissions at the model level
    """
    if raw:
        # `raw` means we can't touch (so make sure your fixtures include
        # all necessary permissions!)
        return
    if not created:
        # We should only grant default permissions when the user is first
        # created
        return
    grant_default_model_level_perms(instance)
Exemple #2
0
 def handle(self, *args, **options):
     existing_users = User.objects.all()
     existing_users_count = existing_users.count()
     counter = 0
     last_progress_message_length = 0
     for user in existing_users:
         grant_default_model_level_perms(user)
         grant_kc_model_level_perms(user)
         counter += 1
         sys.stdout.write('\b' * last_progress_message_length)
         progress_message = ' {}/{} users...'.format(
             counter, existing_users_count)
         last_progress_message_length = len(progress_message)
         sys.stdout.write(progress_message)
         sys.stdout.flush()
     print(" done!")