Commit 64245999 authored by alexAubin's avatar alexAubin

Remove 'activated' field for all configuration classes ... now replaced by...

Remove 'activated' field for all configuration classes ... now replaced by provisioning mechanism. Also remove the LDAP stuff for VPN which imho should be replaced by a custom hook by Illyse
parent 0a96a365
......@@ -19,46 +19,17 @@ class HousingConfigurationInline(admin.StackedInline):
class HousingConfigurationAdmin(ConfigurationAdminFormMixin, PolymorphicChildModelAdmin):
base_model = HousingConfiguration
list_display = ('offersubscription', 'activated',
list_display = ('offersubscription',
'ipv4_endpoint', 'ipv6_endpoint', 'comment')
list_filter = ('activated',)
search_fields = ('comment',
# TODO: searching on member directly doesn't work
'offersubscription__member__first_name',
'offersubscription__member__last_name',
'offersubscription__member__email')
actions = (delete_selected, "generate_endpoints", "generate_endpoints_v4",
"generate_endpoints_v6", "activate", "deactivate")
"generate_endpoints_v6")
inline = HousingConfigurationInline
def get_readonly_fields(self, request, obj=None):
if obj:
return []
else:
return []
def set_activation(self, request, queryset, value):
count = 0
# We must update each object individually, because we want to run
# the save() method to update the backend.
for housing in queryset:
if housing.activated != value:
housing.activated = value
housing.full_clean()
housing.save()
count += 1
action = "activated" if value else "deactivated"
msg = "{} Housing subscription(s) {}.".format(count, action)
self.message_user(request, msg)
def activate(self, request, queryset):
self.set_activation(request, queryset, True)
activate.short_description = "Activate selected Housings"
def deactivate(self, request, queryset):
self.set_activation(request, queryset, False)
deactivate.short_description = "Deactivate selected Housings"
def generate_endpoints_generic(self, request, queryset, v4=True, v6=True):
count = 0
for housing in queryset:
......
......@@ -20,7 +20,6 @@ Ce code requiert une sévère factorisation avec vpn/models.py et vps/models.py
class HousingConfiguration(Configuration):
url_namespace = "housing"
activated = models.BooleanField(default=False, verbose_name='activé')
ipv4_endpoint = InetAddressField(validators=[validation.validate_v4],
verbose_name="IPv4", blank=True, null=True,
help_text="Adresse IPv4 utilisée par "
......
......@@ -19,46 +19,24 @@ class VPNConfigurationInline(admin.StackedInline):
class VPNConfigurationAdmin(ConfigurationAdminFormMixin, PolymorphicChildModelAdmin):
base_model = VPNConfiguration
list_display = ('offersubscription', 'activated', 'login',
list_display = ('offersubscription', 'login',
'ipv4_endpoint', 'ipv6_endpoint', 'comment')
list_filter = ('activated',)
search_fields = ('login', 'comment',
# TODO: searching on member directly doesn't work
'offersubscription__member__first_name',
'offersubscription__member__last_name',
'offersubscription__member__email')
actions = (delete_selected, "generate_endpoints", "generate_endpoints_v4",
"generate_endpoints_v6", "activate", "deactivate")
"generate_endpoints_v6")
exclude = ("password",)
inline = VPNConfigurationInline
def get_readonly_fields(self, request, obj=None):
readonly_fields = super(VPNConfigurationAdmin, self).get_readonly_fields(request, obj)
if obj:
return ['login',]
else:
return []
def set_activation(self, request, queryset, value):
count = 0
# We must update each object individually, because we want to run
# the save() method to update the backend.
for vpn in queryset:
if vpn.activated != value:
vpn.activated = value
vpn.full_clean()
vpn.save()
count += 1
action = "activated" if value else "deactivated"
msg = "{} VPN subscription(s) {}.".format(count, action)
self.message_user(request, msg)
def activate(self, request, queryset):
self.set_activation(request, queryset, True)
activate.short_description = "Activer les VPN sélectionnés"
def deactivate(self, request, queryset):
self.set_activation(request, queryset, False)
deactivate.short_description = "Désactiver les VPN sélectionnés"
readonly_fields = list(readonly_fields)
readonly_fields.append('login')
return readonly_fields
def generate_endpoints_generic(self, request, queryset, v4=True, v6=True):
count = 0
......
......@@ -6,10 +6,7 @@ from django.core.exceptions import ValidationError
from django.conf import settings
from django.core.urlresolvers import reverse
from netfields import InetAddressField, NetManager
import ldapdb.models
from ldapdb.models.fields import CharField, ListField
from coin.mixins import CoinLdapSyncMixin
from coin.configuration.models import Configuration
# from coin.offers.backends import ValidateBackendType
from coin import utils
......@@ -23,14 +20,12 @@ vps/models.py
"""
class VPNConfiguration(CoinLdapSyncMixin, Configuration):
class VPNConfiguration(Configuration):
url_namespace = "vpn"
# backend_name = "openvpn_ldap"
# administrative_subscription = models.OneToOneField(
# 'offers.OfferSubscription',
# related_name=backend_name,
# validators=[ValidateBackendType(backend_name)])
activated = models.BooleanField(default=False, verbose_name='activé')
login = models.CharField(max_length=50, unique=True, blank=True,
verbose_name="identifiant",
help_text="Laisser vide pour une génération automatique")
......@@ -63,23 +58,6 @@ class VPNConfiguration(CoinLdapSyncMixin, Configuration):
subnets = self.ip_subnet.all()
return [subnet for subnet in subnets if subnet.inet.version == version]
def sync_to_ldap(self, creation, *args, **kwargs):
if creation:
config = LdapVPNConfig()
else:
config = LdapVPNConfig.objects.get(pk=self.login)
config.login = config.sn = self.login
config.password = self.password
config.active = 'yes' if self.activated else 'no'
config.ipv4_endpoint = utils.str_or_none(self.ipv4_endpoint)
config.ipv6_endpoint = utils.str_or_none(self.ipv6_endpoint)
config.ranges_v4 = [str(s) for s in self.get_subnets(4)]
config.ranges_v6 = [str(s) for s in self.get_subnets(6)]
config.save()
def delete_from_ldap(self):
LdapVPNConfig.objects.get(pk=self.login).delete()
def generate_endpoints(self, v4=True, v6=True):
"""Generate IP endpoints in one of the attributed IP subnets. If there is
no available subnet for a given address family, then no endpoint
......@@ -160,24 +138,3 @@ class VPNConfiguration(CoinLdapSyncMixin, Configuration):
class Meta:
verbose_name = 'VPN'
verbose_name_plural = 'VPN'
class LdapVPNConfig(ldapdb.models.Model):
base_dn = settings.VPN_CONF_BASE_DN
object_classes = [b'person', b'organizationalPerson', b'inetOrgPerson',
b'top', b'radiusprofile']
login = CharField(db_column=b'cn', primary_key=True, max_length=255)
sn = CharField(db_column=b'sn', max_length=255)
password = CharField(db_column=b'userPassword', max_length=255)
active = CharField(db_column=b'dialupAccess', max_length=3)
ipv4_endpoint = CharField(db_column=b'radiusFramedIPAddress', max_length=16)
ipv6_endpoint = CharField(db_column=b'postalAddress', max_length=40)
ranges_v4 = ListField(db_column=b'radiusFramedRoute')
ranges_v6 = ListField(db_column=b'registeredAddress')
def __unicode__(self):
return self.login
class Meta:
managed = False # Indique à South de ne pas gérer le model LdapUser
......@@ -56,14 +56,6 @@
{% endif %}
</tr>
<tr>
<td class="center boolviewer" colspan="2">
{% if form %}
<input type="checkbox" disabled="disabled"{% if object.activated %} checked="checked"{% endif %} />
{% endif %}
<span>Ce VPN est {{ object.activated|yesno:"activé,désactivé" }}</span>
</td>
</tr>
</table>
</div>
</div>
......
......@@ -28,46 +28,17 @@ class VPSConfigurationInline(admin.StackedInline):
class VPSConfigurationAdmin(ConfigurationAdminFormMixin, PolymorphicChildModelAdmin):
base_model = VPSConfiguration
list_display = ('offersubscription', 'activated',
list_display = ('offersubscription',
'ipv4_endpoint', 'ipv6_endpoint', 'comment')
list_filter = ('activated',)
search_fields = ('comment',
# TODO: searching on member directly doesn't work
'offersubscription__member__first_name',
'offersubscription__member__last_name',
'offersubscription__member__email')
actions = (delete_selected, "generate_endpoints", "generate_endpoints_v4",
"generate_endpoints_v6", "activate", "deactivate")
"generate_endpoints_v6")
inline = VPSConfigurationInline
def get_readonly_fields(self, request, obj=None):
if obj:
return []
else:
return []
def set_activation(self, request, queryset, value):
count = 0
# We must update each object individually, because we want to run
# the save() method to update the backend.
for vps in queryset:
if vps.activated != value:
vps.activated = value
vps.full_clean()
vps.save()
count += 1
action = "activated" if value else "deactivated"
msg = "{} VPS subscription(s) {}.".format(count, action)
self.message_user(request, msg)
def activate(self, request, queryset):
self.set_activation(request, queryset, True)
activate.short_description = "Activate selected VPSs"
def deactivate(self, request, queryset):
self.set_activation(request, queryset, False)
deactivate.short_description = "Deactivate selected VPSs"
def generate_endpoints_generic(self, request, queryset, v4=True, v6=True):
count = 0
for vps in queryset:
......
......@@ -32,7 +32,6 @@ PROTOCOLE_TYPES = (
class VPSConfiguration(Configuration):
url_namespace = "vps"
activated = models.BooleanField(default=False, verbose_name='activé')
ipv4_endpoint = InetAddressField(validators=[validation.validate_v4],
verbose_name="IPv4", blank=True, null=True,
help_text="Adresse IPv4 utilisée par "
......
......@@ -56,14 +56,6 @@
{% endif %}
</tr>
<tr>
<td class="center boolviewer" colspan="2">
{% if form %}
<input type="checkbox" disabled="disabled"{% if object.activated %} checked="checked"{% endif %} />
{% endif %}
<span>Ce VPS est {{ object.activated|yesno:"activé,désactivé" }}</span>
</td>
</tr>
</table>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment