old_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.13 on 2018-07-10 17:34
  from __future__ import unicode_literals
  
  from django.db import migrations
  from django.contrib.auth.models import Group
  from django.contrib.auth.models import Permission
  
  
  def get_new_permissions(read_only=False):
      if not read_only:
          return Permission.objects.filter(codename__endswith='_registrationprovider').exclude(codename='add_registrationprovider')
      return Permission.objects.filter(codename='view_registrationprovider')
  
  def add_registrationprovider_perms(*args):
  
      # Add permissions for the read only group
      read_only_group = Group.objects.get(name='read_only')
      [read_only_group.permissions.add(perm) for perm in get_new_permissions(read_only=True)]
      read_only_group.save()
  
      # Add permissions for new OSF Admin group - can perform actions
      admin_group = Group.objects.get(name='osf_admin')
      [admin_group.permissions.add(perm) for perm in get_new_permissions()]
      admin_group.save()
  
  def remove_registrationprovider_perms(*args):
      # remove the read only group
      read_only_group = Group.objects.get(name='read_only')
      [read_only_group.permissions.remove(perm) for perm in get_new_permissions(read_only=True)]
      read_only_group.save()
  
      # remove the osf admin group
      admin_group = Group.objects.get(name='osf_admin')
      [admin_group.permissions.remove(perm) for perm in get_new_permissions()]
      admin_group.save()
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('osf', '0118_auto_20180706_1127'),
      ]
  
      operations = [
          migrations.RunPython(add_registrationprovider_perms, remove_registrationprovider_perms),
      ]
  
new_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.13 on 2018-07-10 17:34
  from __future__ import unicode_literals
  
  from django.db import migrations
  from django.contrib.auth.models import Group
  from django.contrib.auth.models import Permission
  from django.core.management.sql import emit_post_migrate_signal
  
  
  def get_new_permissions(read_only=False):
      if not read_only:
          return Permission.objects.filter(codename__endswith='_registrationprovider').exclude(codename='add_registrationprovider')
      return Permission.objects.filter(codename='view_registrationprovider')
  
  def add_registrationprovider_perms(*args):
      # this is to make sure that the permissions created in an earlier migration exist!
      emit_post_migrate_signal(2, False, 'default')
  
      # Add permissions for the read only group
      read_only_group = Group.objects.get(name='read_only')
      [read_only_group.permissions.add(perm) for perm in get_new_permissions(read_only=True)]
      read_only_group.save()
  
      # Add permissions for new OSF Admin group - can perform actions
      admin_group = Group.objects.get(name='osf_admin')
      [admin_group.permissions.add(perm) for perm in get_new_permissions()]
      admin_group.save()
  
  def remove_registrationprovider_perms(*args):
      # remove the read only group
      read_only_group = Group.objects.get(name='read_only')
      [read_only_group.permissions.remove(perm) for perm in get_new_permissions(read_only=True)]
      read_only_group.save()
  
      # remove the osf admin group
      admin_group = Group.objects.get(name='osf_admin')
      [admin_group.permissions.remove(perm) for perm in get_new_permissions()]
      admin_group.save()
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('osf', '0118_auto_20180706_1127'),
      ]
  
      operations = [
          migrations.RunPython(add_registrationprovider_perms, remove_registrationprovider_perms),
      ]
  
subject: Fix migration