# Path: ssheepdog/utils.py
# def add_permission(orm, codename, name, app_label='ssheepdog', model='login'):
#     ct, created = orm['contenttypes.ContentType'].objects.get_or_create(
#         model=model, app_label=app_label)
#     orm['auth.permission'].objects.get_or_create(
#         content_type=ct, codename=codename, defaults=dict(name=name))


import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from ssheepdog.utils import add_permission
# encoding: utf-8

NEW_PERMISSIONS = ( # Managed by South so added by data migration!
    ("can_view_all_users", "Can view other users"),
    ("can_view_all_logins", "Can view other's logins"),
    )

class Migration(SchemaMigration):

    def forwards(self, orm):
        # Adding field 'Login.additional_public_keys'
        db.add_column('ssheepdog_login', 'additional_public_keys', self.gf('ssheepdog.fields.PublicKeyField')(default='', blank=True), keep_default=False)

        # Changing field 'UserProfile.ssh_key'
        db.alter_column('ssheepdog_userprofile', 'ssh_key', self.gf('ssheepdog.fields.PublicKeyField')(blank=True))

        # Delete permission which was unintionally injected by previous migration
        orm['auth.Permission'].objects.filter(name='Verbose Name').delete()

        ct, created = orm['contenttypes.ContentType'].objects.get_or_create(
            model='login', app_label='ssheepdog')
        for codename, name in NEW_PERMISSIONS:

# Path: ssheepdog/utils.py
# def add_permission(orm, codename, name, app_label='ssheepdog', model='login'):
#     ct, created = orm['contenttypes.ContentType'].objects.get_or_create(
#         model=model, app_label=app_label)
#     orm['auth.permission'].objects.get_or_create(
#         content_type=ct, codename=codename, defaults=dict(name=name))


# Path: ssheepdog/migrations/0009_auto__add_field_login_additional_public_keys__chg_field_userprofile_ss.py
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from ssheepdog.utils import add_permission

# encoding: utf-8

NEW_PERMISSIONS = ( # Managed by South so added by data migration!
    ("can_view_all_users", "Can view other users"),
    ("can_view_all_logins", "Can view other's logins"),
    )

class Migration(SchemaMigration):

    def forwards(self, orm):
        # Adding field 'Login.additional_public_keys'
        db.add_column('ssheepdog_login', 'additional_public_keys', self.gf('ssheepdog.fields.PublicKeyField')(default='', blank=True), keep_default=False)

        # Changing field 'UserProfile.ssh_key'
        db.alter_column('ssheepdog_userprofile', 'ssh_key', self.gf('ssheepdog.fields.PublicKeyField')(blank=True))

        # Delete permission which was unintionally injected by previous migration
        orm['auth.Permission'].objects.filter(name='Verbose Name').delete()

        ct, created = orm['contenttypes.ContentType'].objects.get_or_create(
            model='login', app_label='ssheepdog')
        for codename, name in NEW_PERMISSIONS:

            add_permission(orm, codename, name)