Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.188.195.90
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/modoboa/env/lib64/python3.5/site-packages/modoboa_contacts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/modoboa/env/lib64/python3.5/site-packages/modoboa_contacts/handlers.py
"""Webmail handlers."""

from django.db.models import signals
from django.urls import reverse
from django.dispatch import receiver
from django.utils.translation import ugettext as _

from modoboa.admin import models as admin_models
from modoboa.core import signals as core_signals
from modoboa.lib import signals as lib_signals

from . import models


@receiver(core_signals.extra_user_menu_entries)
def menu(sender, location, user, **kwargs):
    """Return extra menu entry."""
    if location != "top_menu" or not hasattr(user, "mailbox"):
        return []
    return [
        {"name": "contacts",
         "label": _("Contacts"),
         "url": reverse("modoboa_contacts:index")},
    ]


@receiver(core_signals.get_top_notifications)
def check_addressbook_first_sync(sender, include_all, **kwargs):
    """Check if address book first sync has been made."""
    request = lib_signals.get_request()
    qset = (
        request.user.addressbook_set.filter(last_sync__isnull=True)
    )
    condition = (
        not request.user.parameters.get_value("enable_carddav_sync") or
        not qset.exists()
    )
    if condition:
        return []
    return [{
        "id": "abook_sync_required",
        "url": reverse("modoboa_contacts:index"),
        "text": _("Your address book must be synced"),
        "level": "warning"
    }]


@receiver(signals.post_save, sender=admin_models.Mailbox)
def create_addressbook(sender, instance, created, **kwargs):
    """Create default address book for new mailbox."""
    if not created:
        return
    models.AddressBook.objects.create(
        user=instance.user, name="Contacts", _path="contacts")


@receiver(core_signals.extra_static_content)
def inject_sync_poller(sender, caller, st_type, user, **kwargs):
    """Inject javascript code."""
    condition = (
        caller != "top" or
        st_type != "js" or
        not hasattr(user, "mailbox") or
        not user.parameters.get_value("enable_carddav_sync")
    )
    if condition:
        return ""
    return """<script>
$(document).ready(function () {
    new Poller('%s', {
        interval: %d * 1000
    });
});
</script>
""" % (reverse("api:addressbook-sync-from-cdav"),
       user.parameters.get_value("sync_frequency"))

Anon7 - 2022
AnonSec Team