verbose_name=_('Email address'), related_name='ticket_subscriptions' ) can_view = models.BooleanField( _('Can View Ticket?'), blank=True, default=False, help_text=_('Can this person view the ticket details?'), ) can_update = models.BooleanField( _('Can Update Ticket?'), blank=True, default=False, help_text=_('Can this person change/update the ticket?'), ) def __str__(self): return u'%s for %s' % (self.email_address.email_address, self.ticket.title) class Meta: app_label = 'service' # TODO: refine these permissions (e.g. maybe someone with read access to a given ticket can see the subscriber list) rules.add_perm('service.view_ticketsubscriber', is_superuser | is_staff) rules.add_perm('service.add_ticketsubscriber', is_superuser | is_staff & has_django_permission('service.add_ticketsubscriber')) rules.add_perm('service.change_ticketsubscriber', is_superuser | is_staff & has_django_permission('service.change_ticketsubscriber')) rules.add_perm('service.delete_ticketsubscriber', is_superuser | is_staff & has_django_permission('service.delete_ticketsubscriber'))
return _('Action') else: return _('Comment') @property def ticket_changes(self): for ticket_change in self.ticketchange_set.all(): yield { 'field_name': ticket_change.field, 'old_value': ticket_change.old_value, 'new_value': ticket_change.new_value } @property def editable(self): age = timezone.now() - self.created_at return age < timedelta( seconds=settings.TICKET_UPDATE_ALLOW_EDIT_DURATION) rules.add_perm('service.view_update', is_superuser | is_staff) rules.add_perm( 'service.add_update', is_superuser | is_staff & has_django_permission('service.add_update')) rules.add_perm( 'service.change_update', is_superuser | is_staff & has_django_permission('service.change_update')) rules.add_perm( 'service.delete_update', is_superuser | is_staff & has_django_permission('service.delete_update'))
class Meta: ordering = ('slug', ) verbose_name = _('Department') verbose_name_plural = _('Departments') app_label = "service" @property def smtp_from_address(self): """ Short property to provide a sender address in SMTP format, eg 'Name <email>'. We do this so we can put a simple error message in the sender name field, so hopefully the admin can see and fix it. """ if not self.email_address: return u'NO DEPARTMENT EMAIL ADDRESS DEFINED <%s>' % settings.DEFAULT_FROM_EMAIL else: return u'%s <%s>' % (self.name, self.email_address) rules.add_perm('service.view_department', is_superuser | is_staff | is_team_member) rules.add_perm( 'service.add_department', is_superuser | is_staff & has_django_permission('service.add_department')) rules.add_perm( 'service.change_department', is_superuser | is_staff & has_django_permission('service.change_department')) rules.add_perm( 'service.delete_department', is_superuser | is_staff & has_django_permission('service.delete_department'))
class Meta: verbose_name = _('Note') verbose_name_plural = _('Notes') ordering = ('created_at', ) body = models.TextField(_('Body')) person = models.ForeignKey('contacts.Person', editable=False) update = models.ForeignKey('service.Update', related_name='notes') @property def editable(self): age = timezone.now() - self.created_at return age < timedelta( seconds=settings.TICKET_NOTE_ALLOW_EDIT_DURATION) rules.add_perm('service.view_note', is_superuser | is_staff) rules.add_perm( 'service.add_note', is_superuser | is_staff & has_django_permission('service.add_note')) rules.add_perm( 'service.change_note', is_superuser | is_staff & has_django_permission('service.change_note') | is_note_creator) rules.add_perm( 'service.delete_note', is_superuser | is_staff & has_django_permission('service.delete_note') | is_note_creator)
OPEN_STATUSES = ( Ticket.NEW_STATUS, Ticket.IN_PROGRESS_STATUS, Ticket.WAITING_FOR_CUSTOMER_STATUS, Ticket.ON_HOLD_STATUS, Ticket.RESOLVED_STATUS, Ticket.FOLLOW_UP_SENT_STATUS, Ticket.REOPENED_STATUS ) rules.add_perm('service.view_ticket', is_superuser | is_staff | is_ticket_team_member | has_ticket_object_view_rights | has_ticket_view_subscription | is_ticket_signaler) rules.add_perm('service.add_ticket', is_superuser | (is_staff & has_django_permission('service.add_ticket'))) rules.add_perm('service.change_ticket', is_superuser | is_object_organization_admin | is_ticket_team_member | has_ticket_change_subscription | (is_staff & has_django_permission('service.change_ticket'))) rules.add_perm('service.delete_ticket', is_superuser | is_ticket_team_member |
model=self.person._meta.model_name, name='gravatar_url', id=self.person.id )) super().save(*args, **kwargs) def delete(self, *args, **kwargs): if self.person and self.person.user and self.email_address == self.person.user.email: return else: super().delete(*args, **kwargs) rules.add_perm( 'contacts.view_emailaddress', is_superuser & is_verified | is_staff & is_verified | is_object_organization_member | is_email_owner | is_same_organization ) rules.add_perm('contacts.add_emailaddress', is_authenticated) has_change_or_delete_rights = is_superuser | is_object_organization_admin | is_object_person_manager | is_email_owner rules.add_perm( 'contacts.change_emailaddress', has_change_or_delete_rights | is_staff & has_django_permission('contacts.change_emailaddress') ) rules.add_perm( 'contacts.delete_emailaddress', has_change_or_delete_rights | is_staff & has_django_permission('contacts.delete_emailaddress') )
verbose_name=_('managers'), related_name='managed_departments', blank=True ) class Meta: verbose_name = _('department') verbose_name_plural = _('departments') app_label = 'contacts' def __str__(self): return u"%s" % self.name rules.add_perm( 'contacts.view_department', is_superuser | is_staff | is_department_member | is_object_organization_admin ) rules.add_perm( 'contacts.add_department', is_superuser | is_object_organization_admin | is_staff & has_django_permission( 'contacts.add_department' ) ) rules.add_perm( 'contacts.change_department', is_superuser | is_object_organization_admin | is_department_manager | is_staff & has_django_permission( 'contacts.change_department' ) )
class Manufacturer(Organization): class Meta: proxy = True objects = ManufacturerManager() class HardwareSupplier(Organization): class Meta: proxy = True objects = HardwareSupplierManager() class TelecomProvider(Organization): class Meta: proxy = True objects = TelecomProviderManager() rules.add_perm('contacts.view_organization', is_superuser | is_staff | is_organization_member) rules.add_perm('contacts.add_organization', is_superuser | is_staff & has_django_permission('contacts.add_organization')) rules.add_perm('contacts.change_organization', is_superuser | is_staff & has_django_permission('contacts.change_organization')) rules.add_perm('contacts.delete_organization', is_superuser | is_staff & has_django_permission('contacts.delete_organization'))
@property def gravatar_url(self): hash_input = getattr(self.primary_email, 'email_address', self.pk) hashvalue = gravatar_hash(hash_input) return 'https://secure.gravatar.com/avatar/{}'.format(hashvalue) @transaction.atomic def create_login(self, **user_kwargs): if not self.primary_email: email = self.email_addresses.first() if email: self.set_primary_email(email) user_kwargs['email'] = email.email_address self.user = User.objects.create(**user_kwargs) self.save() return self.user rules.add_perm('contacts.view_person', is_superuser | is_staff | is_same_organization) rules.add_perm( 'contacts.add_person', is_superuser | is_object_organization_admin | is_staff & has_django_permission('contacts.add_person')) rules.add_perm( 'contacts.change_person', is_superuser | is_object_organization_admin | is_staff & has_django_permission('contacts.change_person')) rules.add_perm( 'contacts.delete_person', is_superuser | is_object_organization_admin | is_staff & has_django_permission('contacts.delete_person'))