1 from django.conf import settings
2 from django.contrib.auth.models import User
3 from django.db import models
4 from django.utils.translation import ugettext_lazy as _
7 class Service(models.Model):
8 name = models.CharField(_('name'), max_length=255)
9 url = models.URLField(_('URL'), blank=True)
10 key = models.CharField(_('key'), max_length=255, blank=True)
11 uses_ssh = models.BooleanField(_('uses SSH'), default=False)
12 groups = models.ManyToManyField('auth.Group', verbose_name=_('groups'), blank=True)
13 users = models.ManyToManyField(settings.AUTH_USER_MODEL, verbose_name=_('users'), blank=True)
17 verbose_name = _('service')
18 verbose_name_plural = _('services')
24 return User.objects.filter(
25 models.Q(service=self) |
26 models.Q(groups__service=self)
30 def for_user(cls, user):
31 return cls.objects.filter(models.Q(users=user) | models.Q(groups__user=user))
34 class Hook(models.Model):
35 service = models.ForeignKey(Service, on_delete=models.CASCADE)
36 email = models.CharField(max_length=255)