Revision c72a830d ui/userdata/models.py
b/ui/userdata/models.py | ||
---|---|---|
1 | 1 |
from django.db import models |
2 |
from django.conf import settings |
|
3 |
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS |
|
4 |
|
|
2 | 5 |
from synnefo.db import models as synnefo_models |
3 | 6 |
|
4 | 7 |
User = synnefo_models.SynnefoUser |
... | ... | |
25 | 28 |
|
26 | 29 |
class Meta: |
27 | 30 |
app_label = 'userdata' |
31 |
|
|
32 |
def clean(self): |
|
33 |
if PublicKeyPair.user_limit_exceeded(self.user): |
|
34 |
raise ValidationError("SSH keys limit exceeded.") |
|
35 |
|
|
36 |
@classmethod |
|
37 |
def user_limit_exceeded(cls, user): |
|
38 |
return PublicKeyPair.objects.filter(user=user).count() >= settings.MAX_SSH_KEYS_PER_USER |
Also available in: Unified diff