fnp
/
cas.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
deployment stuff
[cas.git]
/
src
/
services
/
models.py
diff --git
a/src/services/models.py
b/src/services/models.py
index
593eff2
..
fc40bf8
100644
(file)
--- a/
src/services/models.py
+++ b/
src/services/models.py
@@
-1,7
+1,9
@@
+import secrets
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
-from django.utils.translation import ugettext_lazy as _
+from django.urls import reverse
+from django.utils.translation import gettext_lazy as _
class Service(models.Model):
class Service(models.Model):
@@
-9,6
+11,11
@@
class Service(models.Model):
url = models.URLField(_('URL'), blank=True)
key = models.CharField(_('key'), max_length=255, blank=True)
uses_ssh = models.BooleanField(_('uses SSH'), default=False)
url = models.URLField(_('URL'), blank=True)
key = models.CharField(_('key'), max_length=255, blank=True)
uses_ssh = models.BooleanField(_('uses SSH'), default=False)
+
+ for_all = models.BooleanField(_('for all'), default=False)
+ description = models.TextField(_('description'), blank=True)
+ icon = models.FileField(_('icon'), blank=True, upload_to='service/icon')
+
groups = models.ManyToManyField('auth.Group', verbose_name=_('groups'), blank=True)
users = models.ManyToManyField(settings.AUTH_USER_MODEL, verbose_name=_('users'), blank=True)
groups = models.ManyToManyField('auth.Group', verbose_name=_('groups'), blank=True)
users = models.ManyToManyField(settings.AUTH_USER_MODEL, verbose_name=_('users'), blank=True)
@@
-20,6
+27,14
@@
class Service(models.Model):
def __str__(self):
return self.name
def __str__(self):
return self.name
+ def get_absolute_url(self):
+ return reverse('service_detail', args=[self.pk])
+
+ def save(self, *args, **kwargs):
+ if not self.key:
+ self.key = secrets.token_urlsafe()
+ return super().save(*args, **kwargs)
+
def all_users(self):
return User.objects.filter(
models.Q(service=self) |
def all_users(self):
return User.objects.filter(
models.Q(service=self) |
@@
-28,7
+43,9
@@
class Service(models.Model):
@classmethod
def for_user(cls, user):
@classmethod
def for_user(cls, user):
- return cls.objects.filter(models.Q(users=user) | models.Q(groups__user=user))
+ return cls.objects.filter(
+ models.Q(for_all=True) | models.Q(users=user) | models.Q(groups__user=user)
+ )
class Hook(models.Model):
class Hook(models.Model):