示例#1
0
    def list_delete(self, listid):
        "Delete a list item"
        item = get_listitem(listid)
        if not item:
            abort(404)

        if c.user.account_type != 1 and c.user.id != item.user_id:
            abort(403)

        c.form = list_forms[c.user.account_type](request.POST,
                                                 item,
                                                 csrf_context=session)
        if not c.user.is_superadmin:
            del c.form.add_to_alias
        if c.user.is_domain_admin:
            orgs = [group.id for group in c.user.organizations]
            query = Session.query(Domain.name).join(domain_owners)\
                    .filter(domain_owners.c.organization_id.in_(orgs))
            options = [(domain.name, domain.name) for domain in query]
            # options.insert(0, ('any', _('All domains')))
            c.form.to_domain.choices = options
        if c.user.is_peleb:
            query = self._user_addresses()
            options = [(addr.email, addr.email) for addr in query]
            c.form.to_address.choices = options
        c.id = item.id
        if request.method == 'POST' and c.form.validate():
            if item.list_type == 1:
                listname = _('Approved senders')
            else:
                listname = _('Banned senders')
            name = item.from_address
            list_type = item.list_type
            Session.delete(item)
            Session.commit()
            update_lists_backend(list_type)
            info = auditmsgs.LISTDEL_MSG % dict(s=name, l=listname)
            audit_log(c.user.username, 4, unicode(info), request.host,
                      request.remote_addr,
                      arrow.utcnow().datetime)
            flash(_('The item has been deleted'))
            if not request.is_xhr:
                redirect(url(controller='lists'))
            else:
                c.delflag = True
        return self.render('/lists/delete.html')
示例#2
0
    def list_delete(self, listid):
        "Delete a list item"
        item = get_listitem(listid)
        if not item:
            abort(404)

        if c.user.account_type != 1 and c.user.id != item.user_id:
            abort(403)

        c.form = list_forms[c.user.account_type](request.POST,
                                                item,
                                                csrf_context=session)
        if not c.user.is_superadmin:
            del c.form.add_to_alias
        if c.user.is_domain_admin:
            orgs = [group.id for group in c.user.organizations]
            query = Session.query(Domain.name).join(domain_owners)\
                    .filter(domain_owners.c.organization_id.in_(orgs))
            options = [(domain.name, domain.name) for domain in query]
            # options.insert(0, ('any', _('All domains')))
            c.form.to_domain.choices = options
        if c.user.is_peleb:
            query = self._user_addresses()
            options = [(addr.email, addr.email) for addr in query]
            c.form.to_address.choices = options
        c.id = item.id
        if request.method == 'POST' and c.form.validate():
            if item.list_type == 1:
                listname = _('Approved senders')
            else:
                listname = _('Banned senders')
            name = item.from_address
            list_type = item.list_type
            Session.delete(item)
            Session.commit()
            update_lists_backend(list_type)
            info = auditmsgs.LISTDEL_MSG % dict(s=name, l=listname)
            audit_log(c.user.username,
                    4, unicode(info), request.host,
                    request.remote_addr, arrow.utcnow().datetime)
            flash(_('The item has been deleted'))
            if not request.is_xhr:
                redirect(url(controller='lists'))
            else:
                c.delflag = True
        return self.render('/lists/delete.html')
示例#3
0
 def new(self):
     "Add a new list item"
     c.form = list_forms[c.user.account_type](request.POST,
                                              csrf_context=session)
     if c.user.is_domain_admin:
         orgs = [group.id for group in c.user.organizations]
         query = Session.query(Domain.name).join(domain_owners)\
                 .filter(domain_owners.c.organization_id.in_(orgs))
         options = [(domain.name, domain.name) for domain in query]
         # options.insert(0, ('any', _('All domains')))
         c.form.to_domain.choices = options
     if c.user.is_peleb:
         query = self._user_addresses()
         options = [(item.email, item.email) for item in query]
         c.form.to_address.choices = options
     if request.method == 'POST' and c.form.validate():
         item = make_item(c.form)
         _set_type(item)
         aliases = []
         if c.user.is_superadmin or c.user.is_peleb:
             if c.form.to_address.data != '':
                 item.to_address = c.form.to_address.data
                 if ('add_to_alias' in c.form and c.form.add_to_alias.data
                         and c.user.is_peleb):
                     for new_addr in options:
                         if new_addr[0] == item.to_address:
                             continue
                         newitem = make_item(c.form)
                         _set_type(newitem)
                         newitem.to_address = new_addr[0]
                         aliases.append(newitem)
             else:
                 item.to_address = 'any'
         if c.user.is_domain_admin:
             if c.form.to_address.data in ['', 'any']:
                 item.to_address = c.form.to_domain.data
                 if c.form.add_to_alias.data:
                     for dom in options:
                         if dom[0] == item.to_address:
                             continue
                         newitem = make_item(c.form)
                         _set_type(newitem)
                         newitem.to_address = dom[0]
                         aliases.append(newitem)
             else:
                 item.to_address = "%s@%s" % (c.form.to_address.data,
                                              c.form.to_domain.data)
                 if c.form.add_to_alias.data:
                     for dom in options:
                         newitem = make_item(c.form)
                         _set_type(newitem)
                         newitem.to_address = "%s@%s" % \
                                     (c.form.to_address.data, dom[0])
                         if newitem.to_address == item.to_address:
                             continue
                         aliases.append(newitem)
         try:
             Session.add(item)
             Session.commit()
             for alias in aliases:
                 try:
                     Session.add(alias)
                     Session.commit()
                 except IntegrityError:
                     pass
             update_lists_backend(item.list_type)
             if item.list_type == 1:
                 listname = _('Approved senders')
             else:
                 listname = _('Banned senders')
             info = auditmsgs.LISTADD_MSG % dict(s=item.from_address,
                                                 l=listname)
             audit_log(c.user.username, 3, unicode(info), request.host,
                       request.remote_addr,
                       arrow.utcnow().datetime)
             flash(_('The item has been added to the list'))
             if not request.is_xhr:
                 redirect(
                     url('lists-index', list_type=c.form.list_type.data))
         except IntegrityError:
             Session.rollback()
             flash_alert(_('The list item already exists'))
     return self.render('/lists/add.html')
示例#4
0
 def new(self):
     "Add a new list item"
     c.form = list_forms[c.user.account_type](request.POST,
                                         csrf_context=session)
     if c.user.is_domain_admin:
         orgs = [group.id for group in c.user.organizations]
         query = Session.query(Domain.name).join(domain_owners)\
                 .filter(domain_owners.c.organization_id.in_(orgs))
         options = [(domain.name, domain.name) for domain in query]
         # options.insert(0, ('any', _('All domains')))
         c.form.to_domain.choices = options
     if c.user.is_peleb:
         query = self._user_addresses()
         options = [(item.email, item.email) for item in query]
         c.form.to_address.choices = options
     if request.method == 'POST' and c.form.validate():
         item = make_item(c.form)
         _set_type(item)
         aliases = []
         if c.user.is_superadmin or c.user.is_peleb:
             if c.form.to_address.data != '':
                 item.to_address = c.form.to_address.data
                 if ('add_to_alias' in c.form and c.form.add_to_alias.data
                     and c.user.is_peleb):
                     for new_addr in options:
                         if new_addr[0] == item.to_address:
                             continue
                         newitem = make_item(c.form)
                         _set_type(newitem)
                         newitem.to_address = new_addr[0]
                         aliases.append(newitem)
             else:
                 item.to_address = 'any'
         if c.user.is_domain_admin:
             if c.form.to_address.data in ['', 'any']:
                 item.to_address = c.form.to_domain.data
                 if c.form.add_to_alias.data:
                     for dom in options:
                         if dom[0] == item.to_address:
                             continue
                         newitem = make_item(c.form)
                         _set_type(newitem)
                         newitem.to_address = dom[0]
                         aliases.append(newitem)
             else:
                 item.to_address = "%s@%s" % (c.form.to_address.data,
                 c.form.to_domain.data)
                 if c.form.add_to_alias.data:
                     for dom in options:
                         newitem = make_item(c.form)
                         _set_type(newitem)
                         newitem.to_address = "%s@%s" % \
                                     (c.form.to_address.data, dom[0])
                         if newitem.to_address == item.to_address:
                             continue
                         aliases.append(newitem)
         try:
             Session.add(item)
             Session.commit()
             for alias in aliases:
                 try:
                     Session.add(alias)
                     Session.commit()
                 except IntegrityError:
                     pass
             update_lists_backend(item.list_type)
             if item.list_type == 1:
                 listname = _('Approved senders')
             else:
                 listname = _('Banned senders')
             info = auditmsgs.LISTADD_MSG % dict(s=item.from_address,
                                                 l=listname)
             audit_log(c.user.username,
                     3, unicode(info), request.host,
                     request.remote_addr, arrow.utcnow().datetime)
             flash(_('The item has been added to the list'))
             if not request.is_xhr:
                 redirect(url('lists-index',
                         list_type=c.form.list_type.data))
         except IntegrityError:
             Session.rollback()
             flash_alert(_('The list item already exists'))
     return self.render('/lists/add.html')