<commit_before># Generated by Django 3.0.5 on 2020-04-15 09:43

from django.db import migrations


def change_extension_permission_to_plugin_permission(apps, schema_editor):
    permission = apps.get_model("auth", "Permission")
    users = apps.get_model("account", "User")

    plugin_permission = permission.objects.filter(
        codename="manage_plugins", content_type__app_label="plugins"
    ).first()
    extension_permission = permission.objects.filter(
        codename="manage_plugins", content_type__app_label="extensions"
    ).first()
    users = users.objects.filter(
        user_permissions__content_type__app_label="extensions",
        user_permissions__codename="manage_plugins",
    )

    if not plugin_permission or not extension_permission:
        return

    for user in users:
        user.user_permissions.remove(extension_permission)
        user.user_permissions.add(plugin_permission)

    if extension_permission:
        extension_permission.delete()


class Migration(migrations.Migration):
<commit_msg>Fix plugin permission data migration<commit_after># Generated by Django 3.0.5 on 2020-04-15 09:43

from django.db import migrations


def change_extension_permission_to_plugin_permission(apps, schema_editor):
    permission = apps.get_model("auth", "Permission")
    users = apps.get_model("account", "User")
    service_account = apps.get_model("account", "ServiceAccount")

    plugin_permission = permission.objects.filter(
        codename="manage_plugins", content_type__app_label="plugins"
    ).first()
    extension_permission = permission.objects.filter(
        codename="manage_plugins", content_type__app_label="extensions"
    ).first()
    users = users.objects.filter(
        user_permissions__content_type__app_label="extensions",
        user_permissions__codename="manage_plugins",
    )
    service_accounts = service_account.objects.filter(
        permissions__content_type__app_label="extensions",
        permissions__codename="manage_plugins",
    )

    if not plugin_permission or not extension_permission:
        return

    for user in users:
        user.user_permissions.remove(extension_permission)
        user.user_permissions.add(plugin_permission)

    for service_account in service_accounts:
        service_account.permissions.remove(extension_permission)
        service_account.permissions.add(plugin_permission)

    if extension_permission:
        extension_permission.delete()


class Migration(migrations.Migration):

{'fraction_non_alphanumeric': 0.08676529388244703, 'fraction_numerical': 0.011995201919232307, 'mean_word_length': 4.312101910828026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3866363', 'n_tokens_mistral': 714, 'n_tokens_neox': 675, 'n_words': 123}