本文整理汇总了Python中modoboa.lib.events.raiseEvent函数的典型用法代码示例。如果您正苦于以下问题:Python raiseEvent函数的具体用法?Python raiseEvent怎么用?Python raiseEvent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raiseEvent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
def edit(request, rdom_id, tplname='common/tabforms.html'):
rdom = RelayDomain.objects.get(pk=rdom_id)
if not request.user.can_access(rdom):
raise PermDeniedException
instances = {'general': rdom}
events.raiseEvent("FillRelayDomainInstances", request.user, rdom, instances)
if request.method == 'POST':
rdom.oldname = rdom.name
form = RelayDomainForm(request.user, request.POST, instances=instances)
if form.is_valid():
form.save(request.user)
events.raiseEvent('RelayDomainModified', rdom)
return render_to_json_response(_('Relay domain modified'))
return render_to_json_response(
{'form_errors': form.errors}, status=400
)
ctx = {
'action': reverse(edit, args=[rdom.id]),
'formid': 'rdomform',
'title': rdom.name,
'action_label': _("Update"),
'action_classes': "submit",
'tabs': RelayDomainForm(request.user, instances=instances)
}
return render(request, tplname, ctx)
示例2: save
def save(self, user, account):
"""Save or update account mailbox."""
if self.cleaned_data["email"] == "":
return None
if self.cleaned_data["quota_act"]:
self.cleaned_data["quota"] = None
if not hasattr(self, "mb") or self.mb is None:
self.create_mailbox(user, account)
else:
self.cleaned_data["use_domain_quota"] = (
self.cleaned_data["quota_act"])
self.mb.update_from_dict(user, self.cleaned_data)
events.raiseEvent(
'SaveExtraFormFields', 'mailform', self.mb, self.cleaned_data
)
account.email = self.cleaned_data["email"]
account.save()
self._update_aliases(user, account)
self._update_sender_addresses()
return self.mb
示例3: handle
def handle(self, *args, **options):
"""Command entry point."""
load_core_settings()
if not User.objects.filter(is_superuser=True).count():
admin = User(username="admin", is_superuser=True)
admin.set_password("password")
admin.save()
ObjectAccess.objects.create(
user=admin, content_object=admin, is_owner=True)
exts_pool.load_all()
superadmin = User.objects.filter(is_superuser=True).first()
groups = PERMISSIONS.keys() + [
role[0] for role
in events.raiseQueryEvent("GetExtraRoles", superadmin, None)
]
for groupname in groups:
group, created = Group.objects.get_or_create(name=groupname)
permissions = (
PERMISSIONS.get(groupname, []) +
events.raiseQueryEvent("GetExtraRolePermissions", groupname)
)
if not permissions:
continue
add_permissions_to_group(group, permissions)
for extname in exts_pool.extensions.keys():
extension = exts_pool.get_extension(extname)
extension.load_initial_data()
events.raiseEvent("InitialDataLoaded", extname)
示例4: edit
def edit(request, rdom_id, tplname='common/tabforms.html'):
rdom = RelayDomain.objects.get(pk=rdom_id)
if not request.user.can_access(rdom):
raise PermDeniedException
instances = {'general': rdom}
events.raiseEvent("FillRelayDomainInstances", request.user, rdom, instances)
return RelayDomainForm(request, instances=instances).process()
示例5: post_create
def post_create(self, creator):
from modoboa.lib.permissions import grant_access_to_object
grant_access_to_object(creator, self, is_owner=True)
events.raiseEvent("MailboxAliasCreated", creator, self)
if creator.is_superuser:
for admin in self.domain.admins:
grant_access_to_object(admin, self)
示例6: update_mailbox
def update_mailbox(self, user, account):
newaddress = None
if self.cleaned_data["email"] != self.mb.full_address:
newaddress = self.cleaned_data["email"]
elif (account.group == "SimpleUsers" and
account.username != self.mb.full_address):
newaddress = account.username
if newaddress is not None:
self.mb.old_full_address = self.mb.full_address
local_part, domname = split_mailbox(newaddress)
try:
domain = Domain.objects.get(name=domname)
except Domain.DoesNotExist:
raise NotFound(_("Domain does not exist"))
if not user.can_access(domain):
raise PermDeniedException
self.mb.rename(local_part, domain)
self.mb.use_domain_quota = self.cleaned_data["quota_act"]
override_rules = True \
if not self.mb.quota or user.has_perm("admin.add_domain") \
else False
self.mb.set_quota(self.cleaned_data["quota"], override_rules)
self.mb.save()
events.raiseEvent('MailboxModified', self.mb)
示例7: _update_aliases
def _update_aliases(self, user, account):
"""Update mailbox aliases."""
aliases = []
for name, value in self.cleaned_data.iteritems():
if not name.startswith("aliases"):
continue
if value == "":
continue
aliases.append(value.lower())
for alias in self.mb.alias_set.all():
if alias.full_address not in aliases:
if len(alias.get_recipients()) >= 2:
continue
alias.delete()
else:
aliases.remove(alias.full_address)
if not aliases:
return
events.raiseEvent(
"CanCreate", user, "mailbox_aliases", len(aliases)
)
for alias in aliases:
local_part, domname = split_mailbox(alias)
try:
self.mb.alias_set.get(address=local_part, domain__name=domname)
except Alias.DoesNotExist:
pass
else:
continue
al = Alias(address=local_part, enabled=account.is_active)
al.domain = Domain.objects.get(name=domname)
al.save(int_rcpts=[self.mb])
al.post_create(user)
示例8: delete
def delete(self, fromuser, *args, **kwargs):
"""Custom delete method
To check permissions properly, we need to make a distinction
between 2 cases:
* If the user owns a mailbox, the check is made on that object
(useful for domain admins)
* Otherwise, the check is made on the user
"""
from modoboa.lib.permissions import \
get_object_owner, grant_access_to_object, ungrant_access_to_object
if fromuser == self:
raise PermDeniedException(
_("You can't delete your own account")
)
if not fromuser.can_access(self):
raise PermDeniedException
owner = get_object_owner(self)
for ooentry in self.objectaccess_set.filter(is_owner=True):
if ooentry.content_object is not None:
grant_access_to_object(owner, ooentry.content_object, True)
events.raiseEvent("AccountDeleted", self, fromuser, **kwargs)
ungrant_access_to_object(self)
super(User, self).delete()
示例9: save
def save(self, user, domain):
if not self.fields:
return
if self.cleaned_data["create_dom_admin"] == "no":
return
username = "%[email protected]%s" % (
self.cleaned_data["dom_admin_username"], domain.name)
try:
da = User.objects.get(username=username)
except User.DoesNotExist:
pass
else:
raise Conflict(_("User '%s' already exists" % username))
events.raiseEvent("CanCreate", user, "mailboxes")
da = User(username=username, email=username, is_active=True)
da.set_password("password")
da.save()
da.set_role("DomainAdmins")
da.post_create(user)
mb = Mailbox(
address=self.cleaned_data["dom_admin_username"], domain=domain,
user=da, use_domain_quota=True
)
mb.set_quota(
override_rules=user.has_perm("modoboa_admin.change_domain"))
mb.save(creator=user)
if self.cleaned_data["create_aliases"] == "yes":
events.raiseEvent("CanCreate", user, "mailbox_aliases")
alias = Alias(address="postmaster", domain=domain, enabled=True)
alias.save(int_rcpts=[mb])
alias.post_create(user)
domain.add_admin(da)
示例10: save
def save(self, user, commit=True):
d = super(DomainFormGeneral, self).save(commit=False)
if commit:
old_mail_homes = None
hm = parameters.get_admin("HANDLE_MAILBOXES", raise_error=False)
if hm == "yes":
if self.oldname is not None and d.name != self.oldname:
for q in Quota.objects.filter(username__contains="@%s" % self.oldname):
q.username = q.username.replace("@%s" % self.oldname, "@%s" % d.name)
q.save()
old_mail_homes = dict((mb.id, mb.mail_home) for mb in d.mailbox_set.all())
d.save()
Mailbox.objects.filter(domain=d, use_domain_quota=True).update(quota=d.quota)
if old_mail_homes is not None:
for mb in d.mailbox_set.all():
mb.rename_dir(old_mail_homes[mb.id])
for k, v in self.cleaned_data.iteritems():
if not k.startswith("aliases"):
continue
if v in ["", None]:
continue
try:
d.domainalias_set.get(name=v)
except DomainAlias.DoesNotExist:
pass
else:
continue
events.raiseEvent("CanCreate", user, "domain_aliases")
al = DomainAlias(name=v, target=d, enabled=d.enabled)
al.save(creator=user)
for dalias in d.domainalias_set.all():
if not len(filter(lambda name: self.cleaned_data[name] == dalias.name, self.cleaned_data.keys())):
dalias.delete()
return d
示例11: update_from_dict
def update_from_dict(self, user, values):
"""Update mailbox from a dictionary."""
newaddress = None
if values["email"] != self.full_address:
newaddress = values["email"]
elif (self.user.group == "SimpleUsers" and
self.user.username != self.full_address):
newaddress = self.user.username
if newaddress is not None:
local_part, domname = split_mailbox(newaddress)
domain = Domain.objects.filter(name=domname).first()
if domain is None:
raise lib_exceptions.NotFound(_("Domain does not exist"))
if not user.can_access(domain):
raise lib_exceptions.PermDeniedException
if "use_domain_quota" in values:
self.use_domain_quota = values["use_domain_quota"]
override_rules = True \
if not self.quota or user.has_perm("admin.add_domain") \
else False
self.set_quota(values["quota"], override_rules)
if newaddress:
self.rename(local_part, domain)
self.save()
events.raiseEvent("MailboxModified", self)
示例12: editdomain
def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
domain = Domain.objects.get(pk=dom_id)
if not request.user.can_access(domain):
raise PermDeniedException
instances = dict(general=domain)
events.raiseEvent("FillDomainInstances", request.user, domain, instances)
if request.method == "POST":
domain.oldname = domain.name
form = DomainForm(request.user, request.POST, instances=instances)
if form.is_valid():
form.save(request.user)
events.raiseEvent("DomainModified", domain)
return render_to_json_response(_("Domain modified"))
return render_to_json_response({
'form_errors': form.errors
}, status=400)
domadmins = [u for u in domain.admins
if request.user.can_access(u) and not u.is_superuser]
if not request.user.is_superuser:
domadmins = [u for u in domadmins if u.group == "DomainAdmins"]
ctx = {"title": domain.name,
"action_label": _("Update"),
"action_classes": "submit",
"action": reverse(editdomain, args=[dom_id]),
"formid": "domform",
"domain": domain,
"tabs": DomainForm(request.user, instances=instances),
"domadmins": domadmins}
return render(request, tplname, ctx)
示例13: save
def save(self, user, commit=True, rdomalias_post_create=False):
"""Custom save method.
As relay domain aliases are defined using the same form as
relay domains, we need to save them manually.
:param ``User`` user: connected user
"""
rd = super(RelayDomainFormGeneral, self).save(commit=False)
if commit:
rd.save()
aliases = []
for k, v in self.cleaned_data.iteritems():
if not k.startswith("aliases"):
continue
if v in ["", None]:
continue
aliases.append(v)
for rdalias in rd.relaydomainalias_set.all():
if not rdalias.name in aliases:
rdalias.delete()
else:
aliases.remove(rdalias.name)
if aliases:
events.raiseEvent("CanCreate", user, "relay_domain_aliases", len(aliases))
for alias in aliases:
try:
rd.relaydomainalias_set.get(name=alias)
except RelayDomainAlias.DoesNotExist:
pass
else:
continue
al = RelayDomainAlias(name=alias, target=rd, enabled=rd.enabled)
al.save(creator=user) if rdomalias_post_create else al.save()
return rd
示例14: editdomain
def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
domain = Domain.objects.get(pk=dom_id)
if not request.user.can_access(domain):
raise PermDeniedException
instances = dict(general=domain)
events.raiseEvent("FillDomainInstances", request.user, domain, instances)
return DomainForm(request, instances=instances).process()
示例15: editaccount
def editaccount(request, accountid, tplname="common/tabforms.html"):
account = User.objects.get(pk=accountid)
if not request.user.can_access(account):
raise PermDeniedException
mb = account.mailbox if hasattr(account, "mailbox") else None
instances = dict(general=account, mail=mb, perms=account)
events.raiseEvent("FillAccountInstances", request.user, account, instances)
return AccountForm(request, instances=instances).process()