Added forwards on mailboxes.display_addresses

This commit is contained in:
Marc Aymerich 2016-05-13 08:42:58 +00:00
parent 3e1d9f7d22
commit 8a44b99377
8 changed files with 41 additions and 7 deletions

View file

@ -463,4 +463,6 @@ with open(file) as handler:
# Mark transaction process as executed should not override higher transaction states # Mark transaction process as executed should not override higher transaction states
# Show password and set password management commands -sam -A|--all --systemuser --account --mailbox vs raw passwords on forms # mailbox.addresses get_Queryset SQL contact @ with mailboxes and forwards
# Remove membership fee when changing account.type

View file

@ -285,8 +285,7 @@ class ChangePasswordAdminMixin(object):
form = self.change_password_form(obj, request.POST, related=related, raw=raw) form = self.change_password_form(obj, request.POST, related=related, raw=raw)
if form.is_valid(): if form.is_valid():
form.save() form.save()
change_message = self.construct_change_message(request, form, None) self.log_change(request, obj, _("Password changed."))
self.log_change(request, obj, change_message)
msg = _('Password changed successfully.') msg = _('Password changed successfully.')
messages.success(request, msg) messages.success(request, msg)
update_session_auth_hash(request, form.user) # This is safe update_session_auth_hash(request, form.user) # This is safe

View file

@ -15,6 +15,7 @@ class LogEntryAdmin(admin.ModelAdmin):
) )
list_filter = ( list_filter = (
'action_flag', 'action_flag',
('user', admin.RelatedOnlyFieldListFilter),
('content_type', admin.RelatedOnlyFieldListFilter), ('content_type', admin.RelatedOnlyFieldListFilter),
) )
date_hierarchy = 'action_time' date_hierarchy = 'action_time'

View file

@ -15,6 +15,7 @@ from orchestra.admin.utils import admin_link, change_url
from orchestra.contrib.accounts.actions import list_accounts from orchestra.contrib.accounts.actions import list_accounts
from orchestra.contrib.accounts.admin import SelectAccountAdminMixin from orchestra.contrib.accounts.admin import SelectAccountAdminMixin
from orchestra.contrib.accounts.filters import IsActiveListFilter from orchestra.contrib.accounts.filters import IsActiveListFilter
from orchestra.core import caches
from . import settings from . import settings
from .actions import SendMailboxEmail, SendAddressEmail from .actions import SendMailboxEmail, SendAddressEmail
@ -82,11 +83,33 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo
type(self).actions = self.actions + (SendMailboxEmail(),) type(self).actions = self.actions + (SendMailboxEmail(),)
def display_addresses(self, mailbox): def display_addresses(self, mailbox):
# Get from forwards
cache = caches.get_request_cache()
cached_forwards = cache.get('forwards')
if cached_forwards is None:
cached_forwards = {}
qs = Address.objects.filter(forward__regex=r'(^|.*\s)[^@]+(\s.*|$)')
qs = qs.select_related('domain')
qs = qs.annotate(email=Concat('name', V('@'), 'domain__name'))
qs = qs.values_list('id', 'email', 'forward')
for addr_id, email, mbox in qs:
url = reverse('admin:mailboxes_address_change', args=(addr_id,))
link = '<a href="%s">%s</a>' % (url, email)
try:
cached_forwards[mbox].append(link)
except KeyError:
cached_forwards[mbox] = [link]
cache.set('forwards', cached_forwards)
try:
forwards = cached_forwards[mailbox.name]
except KeyError:
forwards = []
# Get from mailboxes
addresses = [] addresses = []
for addr in mailbox.addresses.all(): for addr in mailbox.addresses.all():
url = change_url(addr) url = change_url(addr)
addresses.append('<a href="%s">%s</a>' % (url, addr.email)) addresses.append('<a href="%s">%s</a>' % (url, addr.email))
return '<br>'.join(addresses) return '<br>'.join(addresses+forwards)
display_addresses.short_description = _("Addresses") display_addresses.short_description = _("Addresses")
display_addresses.allow_tags = True display_addresses.allow_tags = True

View file

@ -70,7 +70,7 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController):
# Update/create %(user)s user state # Update/create %(user)s user state
if id %(user)s ; then if id %(user)s ; then
old_password=$(getent shadow %(user)s | cut -d':' -f2) old_password=$(getent shadow %(user)s | cut -d':' -f2)
usermod %(user)s \\ usermod %(user)s \\
--shell %(initial_shell)s \\ --shell %(initial_shell)s \\
--password '%(password)s' --password '%(password)s'
if [[ "$old_password" != '%(password)s' ]]; then if [[ "$old_password" != '%(password)s' ]]; then

View file

@ -35,6 +35,14 @@ def m2m_collector(sender, *args, **kwargs):
class orchestrate(ContextDecorator): class orchestrate(ContextDecorator):
"""
Context manager for triggering backend operations out of request-response cycle, e.g. shell
with orchestrate():
user = SystemUser.objects.get(username='rata')
user.shell = '/dev/null'
user.save(update_fields=('shell',))
"""
thread_locals = local() thread_locals = local()
thread_locals.pending_operations = None thread_locals.pending_operations = None
thread_locals.route_cache = None thread_locals.route_cache = None

View file

@ -56,7 +56,8 @@ class OrderAdmin(AccountAdminMixin, ExtendedModelAdmin):
'display_metric' 'display_metric'
) )
list_filter = ( list_filter = (
ActiveOrderListFilter, IgnoreOrderListFilter, BilledOrderListFilter, 'service' ActiveOrderListFilter, IgnoreOrderListFilter, BilledOrderListFilter, 'account__type',
'service',
) )
default_changelist_filters = ( default_changelist_filters = (
('ignore', '0'), ('ignore', '0'),

View file

@ -47,7 +47,7 @@ def set_permission(modeladmin, request, queryset):
user.set_perm_perms) user.set_perm_perms)
context = { context = {
'action': verbose_action, 'action': verbose_action,
'perms': verbose_permissions, 'perms': verbose_permissions.lower(),
'to': os.path.join(user.set_perm_base_home, user.set_perm_home_extension), 'to': os.path.join(user.set_perm_base_home, user.set_perm_home_extension),
} }
msg = _("%(action)s %(perms)s permission to %(to)s") % context msg = _("%(action)s %(perms)s permission to %(to)s") % context