def test_vhosts_for_user(): assert vhosts_for_user('staff') == { MailVirtualHost('staff', 'dev-vhost.ocf.berkeley.edu'), MailVirtualHost('staff', 'dev-dev-vhost.ocf.berkeley.edu'), } assert vhosts_for_user('ckuehl') == { MailVirtualHost('ckuehl', 'ckuehl.berkeley.edu'), } assert vhosts_for_user('jvperrin') == set()
def vhost_mail(request): user = logged_in_user(request) vhosts = [] with _txn() as c: for vhost in sorted(vhosts_for_user(user)): addresses = sorted(vhost.get_forwarding_addresses(c)) vhosts.append({ 'domain': vhost.domain, 'addresses': addresses, 'has_wildcard': any(address.is_wildcard for address in addresses), }) return render( request, 'account/vhost_mail/index.html', { 'title': 'Mail Virtual Hosting', 'vhosts': vhosts, 'example_csv': EXAMPLE_CSV, }, )
def test_mail_vhosts(): mail_vhosts = get_mail_vhosts() # Make sure we're actually getting some app vhosts back assert(any(mail_vhosts)) # Check that the ggroup user has some mail vhosts (these are used for # testing by OCF staff so they're likely to stick around) assert(any(vhosts_for_user('ggroup'))) # Check that dev-vhost.o.b.e exists as an mail vhost (this is used for # testing by OCF staff, so it's likely to stick around) assert( 'dev-vhost.ocf.berkeley.edu' in {vhost.domain for vhost in mail_vhosts} )
def api_vhost_mail(request): user = logged_in_user(request) vhosts = [] with _txn() as c: for vhost in sorted(vhosts_for_user(user)): addresses = {} for forwarding_addr in sorted(vhost.get_forwarding_addresses(c)): addresses[forwarding_addr.address] = list( forwarding_addr.forward_to) vhosts.append({ 'domain': vhost.domain, 'addresses': addresses, }) return JsonResponse(vhosts, safe=False)
def vhost_mail(request): user = logged_in_user(request) vhosts = [] with _txn() as c: for vhost in sorted(vhosts_for_user(user)): addresses = sorted(vhost.get_forwarding_addresses(c)) vhosts.append({ 'domain': vhost.domain, 'addresses': addresses, 'has_wildcard': any(address.is_wildcard for address in addresses), }) return render( request, 'account/vhost_mail/index.html', { 'title': 'Mail Virtual Hosting', 'vhosts': vhosts, }, )
def _get_vhost(user, domain): vhosts = vhosts_for_user(user) for vhost in vhosts: if vhost.domain == domain: return vhost
def _get_vhost(user: Any, domain: str) -> Any: vhosts = vhosts_for_user(user) for vhost in vhosts: if vhost.domain == domain: return vhost