Skip to content

Commit

Permalink
Added support to django-netjsonconfig 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Nov 3, 2017
1 parent 140db7f commit 2304479
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
7 changes: 7 additions & 0 deletions openwisp_controller/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ def clean(self):
self._validate_org_relation('ca')
self._validate_org_relation('cert')

def _auto_create_cert_extra(self, cert):
"""
sets the organization on the created certificate
"""
cert.organization = self.organization
return cert


class VpnClient(AbstractVpnClient):
"""
Expand Down
2 changes: 2 additions & 0 deletions openwisp_controller/pki/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CaAdmin(MultitenantAdminMixin, VersionAdmin, BaseCaAdmin):
'country_code',
'state',
'city',
'organization_name',
'email',
'common_name',
'extensions',
Expand Down Expand Up @@ -49,6 +50,7 @@ class CertAdmin(MultitenantAdminMixin, VersionAdmin, BaseCertAdmin):
'country_code',
'state',
'city',
'organization_name',
'email',
'common_name',
'extensions',
Expand Down
25 changes: 25 additions & 0 deletions openwisp_controller/pki/migrations/0002_add_organization_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-03 15:47
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pki', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='ca',
name='organization_name',
field=models.CharField(blank=True, max_length=64, verbose_name='organization'),
),
migrations.AddField(
model_name='cert',
name='organization_name',
field=models.CharField(blank=True, max_length=64, verbose_name='organization'),
),
]
30 changes: 30 additions & 0 deletions openwisp_controller/pki/migrations/0003_fill_organization_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


def forward(apps, schema_editor):
"""
Fills the organization_name field of the following models:
* ``openwisp_controller.pki.Ca``
* ``openwisp_controller.pki.Cert``
"""
if not schema_editor.connection.alias == 'default':
return
from ..models import Ca, Cert

for model in [Ca, Cert]:
for obj in model.objects.all():
obj.organization_name = obj.x509.get_subject().organizationName or ''
obj.save()


class Migration(migrations.Migration):
dependencies = [
('pki', '0002_add_organization_name'),
]

operations = [
migrations.RunPython(forward, reverse_code=migrations.RunPython.noop),
]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
django-netjsonconfig>=0.6.4,<0.7.0
django-netjsonconfig>=0.7.0,<0.8.0
openwisp-utils[users]<0.2

0 comments on commit 2304479

Please sign in to comment.