Example #1
0
def update_mailbox(request, mailbox_slug):
    """
    updates a mailbox's info
    """
    ctx = request.context
    couchdb = ctx.get_couchdb_server()
    try:
        dbname = ctx.get_database_name(mailbox_slug)
        mb = couchdb[dbname]
        if not is_mailbox(mb):
            return HttpResponse(status=404)
        if not ctx.user.has_perm(PERM_UPDATE, mb):
            return HttpResponse(status=401)

        info = _mailbox_info_json(request)
        mbinfo = MailboxInfo.get(mb)
        try:
            mbinfo.user_update(info)
        except: 
            return HttpResponse(status=400)
        mbinfo.store(mb)
        
        return HttpResponse()
    except ResourceNotFound:
        return HttpResponse(status=404)
Example #2
0
    def test_mailbox_create(self):
        """
        test creating a mailbox
        """
        try:
            slug = self.TEST_MAILBOX_SLUG + '_test_mailbox_create'
            mb_url = self.url_for('mailbox_rest', mailbox_slug=slug)
            assert get_mailbox(self.config, slug) is None
            
            c = self.get_test_app()
            self.login_as_admin(c)
            
            c.head(mb_url, status=404)
            c.put(mb_url, '{}', content_type="application/json", status=201)
            c.head(mb_url, status=200)

            
            mb = get_mailbox(self.config, slug)
            assert mb is not None
            assert is_mailbox(mb)
        finally:
            dbname = get_database_name(self.config, slug)
            couchdb = get_couchdb_server(self.config)
            if dbname in couchdb: 
                del couchdb[dbname]
Example #3
0
def delete_mailbox(request, mailbox_slug):
    """
    destroys a mailbox.
    """
    ctx = request.context
    couchdb = ctx.get_couchdb_server()
    try:
        dbname = ctx.get_database_name(mailbox_slug)
        mb = couchdb[dbname]
        if not is_mailbox(mb):
            return HttpResponse(status=404)
        if not ctx.user.has_perm(PERM_DELETE, mb):
            return HttpResponse(status=401)
        del couchdb[dbname]
        return HttpResponse()
    except ResourceNotFound:
        return HttpResponse(status=404)