Ejemplo n.º 1
0
def user_delete(request, user_id,
                template='postorius/users/user_confirm_delete.html'):
    """ Deletes a user upon confirmation.
    """
    try:
        mm_user = MailmanUser.objects.get_or_404(address=user_id)
        email_id = mm_user.addresses[0]
    except MailmanApiError:
        return utils.render_api_error(request)
    except IndexError:
        email_id = ''
    if request.method == 'POST':
        try:
            mm_user.delete()
        except MailmanApiError:
            return utils.render_api_error(request)
        except HTTPError as e:
            messages.error(request, _('The user could not be deleted:'
                                      ' %s' % e.msg))
            return redirect("user_index")
        messages.success(request,
                         _('The user %s has been deleted.' % email_id))
        return redirect("user_index")
    return render_to_response(template,
                              {'user_id': user_id, 'email_id': email_id},
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def user_profile(request):
    utils.set_other_emails(request.user)
    try:
        mm_user = MailmanUser.objects.get_or_create_from_django(request.user)
    except MailmanApiError:
        return utils.render_api_error(request)
    if request.method == 'POST':
        if request.POST.get('formname') == 'displayname':
            display_name_form = ChangeDisplayNameForm(request.POST)
            form = AddressActivationForm(
                initial={'user_email': request.user.email})
            if display_name_form.is_valid():
                name = display_name_form.cleaned_data['display_name']
                try:
                    mm_user.display_name = name
                    mm_user.save()
                except MailmanApiError:
                    return utils.render_api_error(request)
                except HTTPError as e:
                    messages.error(request, e)
                else:
                    messages.success(request, _('Display name changed'))
                return redirect('user_profile')
        else:
            display_name_form = ChangeDisplayNameForm(
                initial={'display_name': mm_user.display_name})
            form = AddressActivationForm(request.POST)
            if form.is_valid():
                profile, c = (
                    AddressConfirmationProfile.objects.update_or_create(
                        email=form.cleaned_data['email'],
                        user=request.user,
                        defaults={'activation_key': uuid.uuid4().hex}))
                try:
                    profile.send_confirmation_link(request)
                    messages.success(
                        request,
                        _('Please follow the instructions sent via'
                          ' email to confirm the address'))
                    return redirect('user_profile')
                except (SMTPException, socket_error) as e:
                    if (not isinstance(e, SMTPException)
                            and e.errno != errno.ECONNREFUSED):
                        raise e
                    profile.delete()
                    messages.error(
                        request,
                        _('Currently emails can not be added,'
                          ' please try again later'))
    else:
        form = AddressActivationForm(
            initial={'user_email': request.user.email})
        display_name_form = ChangeDisplayNameForm(
            initial={'display_name': mm_user.display_name})
    return render(request, 'postorius/user/profile.html', {
        'mm_user': mm_user,
        'form': form,
        'name_form': display_name_form
    })
Ejemplo n.º 3
0
def user_profile(request):
    utils.set_other_emails(request.user)
    try:
        mm_user = MailmanUser.objects.get_or_create_from_django(request.user)
    except MailmanApiError:
        return utils.render_api_error(request)
    if request.method == 'POST':
        if request.POST.get('formname') == 'displayname':
            display_name_form = ChangeDisplayNameForm(request.POST)
            form = AddressActivationForm(
                initial={'user_email': request.user.email})
            if display_name_form.is_valid():
                name = display_name_form.cleaned_data['display_name']
                try:
                    mm_user.display_name = name
                    mm_user.save()
                except MailmanApiError:
                    return utils.render_api_error(request)
                except HTTPError as e:
                    messages.error(request, e)
                else:
                    messages.success(request, _('Display name changed'))
                return redirect('user_profile')
        else:
            display_name_form = ChangeDisplayNameForm(
                initial={'display_name': mm_user.display_name})
            form = AddressActivationForm(request.POST)
            if form.is_valid():
                profile, c = (
                    AddressConfirmationProfile.objects.update_or_create(
                        email=form.cleaned_data['email'], user=request.user,
                        defaults={'activation_key': uuid.uuid4().hex}))
                try:
                    profile.send_confirmation_link(request)
                    messages.success(request, _(
                                     'Please follow the instructions sent via'
                                     ' email to confirm the address'))
                    return redirect('user_profile')
                except (SMTPException, socket_error) as e:
                    if (not isinstance(e, SMTPException) and
                            e.errno != errno.ECONNREFUSED):
                        raise e
                    profile.delete()
                    messages.error(request,
                                   _('Currently emails can not be added,'
                                     ' please try again later'))
    else:
        form = AddressActivationForm(
            initial={'user_email': request.user.email})
        display_name_form = ChangeDisplayNameForm(
            initial={'display_name': mm_user.display_name})
    return render(request, 'postorius/user/profile.html',
                  {'mm_user': mm_user, 'form': form,
                   'name_form': display_name_form})
Ejemplo n.º 4
0
def domain_new(request):
    form_initial = {'site': Site.objects.get_current(request)}
    if request.method == 'POST':
        form = DomainForm(request.POST, initial=form_initial)
        if form.is_valid():
            domain = Domain(mail_host=form.cleaned_data['mail_host'],
                            description=form.cleaned_data['description'],
                            owner=request.user.email)
            try:
                domain.save()
            except MailmanApiError:
                return utils.render_api_error(request)
            except HTTPError as e:
                messages.error(request, e)
            else:
                messages.success(request, _("New Domain registered"))
            MailDomain.objects.get_or_create(
                site=form.cleaned_data['site'],
                mail_domain=form.cleaned_data['mail_host'])
            return redirect("domain_index")
        else:
            messages.error(request, _('Please check the errors below'))
    else:
        form = DomainForm(initial=form_initial)
    return render(request, 'postorius/domain/new.html', {'form': form})
Ejemplo n.º 5
0
def reorder_tasks_by(request, reorder_param):
    """Reorder Dashboard Tasks according to specified
    parameter.
    """
    try:
        lists = List.objects.all()
        tasks = filter_tasks_by_role(request.user, AdminTasks.objects.all(), lists)
        order_tasks = []
        for idx in xrange(0, len(tasks)):
            max_ob = max(tasks, key=operator.attrgetter(reorder_param))
            order_tasks.append(max_ob)
            tasks.remove(max_ob)
        tasks = order_tasks
        email = request.user.email
        global_search = GlobalSearchForm()
        search_form = TaskSearchForm()
        search_li = ListIndexSearchForm()
        mtask_form = NewManualTaskForm()
        events = events_allowed(request.user, EventTracker.objects.all())

        sub_objects, mod_objects = generate_graph_object([each_list.list_id for each_list in lists])
        stats = {'subs': sub_objects, 'mods': mod_objects}

        lists = allowed_lists(request.user, lists)
        for each in events:
            each.made_on = get_rel_timediff(each)
        for each in tasks:
            each.made_on = get_rel_timediff(each)
    except MailmanApiError:
        return utils.render_api_error(request)
    return render_to_response('postorius/user_dashboard.html',
                              {'tasks': tasks, 'lists': lists, 'li_res': lists, 'mtask_form': mtask_form,
                               'search_li': search_li, 'search_form': search_form, 'global_search': global_search,
                               'events': events, 'stats': stats}, context_instance=RequestContext(request))
Ejemplo n.º 6
0
    def post(self, request, list_id, email):
        try:
            client = utils.get_client()
            mm_member = client.get_member(list_id, email)
            mm_list = client.get_list(list_id)
            preferences_form = UserPreferences(request.POST)
            if preferences_form.is_valid():
                preferences = mm_member.preferences
                for key in preferences_form.fields.keys():
                    preferences[key] = preferences_form.cleaned_data[key]
                preferences.save()
                messages.success(
                    request, 'The member\'s preferences have been updated.')
            else:
                messages.error(request, 'Something went wrong.')

            # this is a bit silly, since we already have the preferences,
            # but I want to be sure we don't show stale data.
            settingsform = UserPreferences(initial=mm_member.preferences)
        except MailmanApiError:
            return utils.render_api_error(request)
        except HTTPError as e:
            messages.error(request, e.msg)
        return render_to_response(
            'postorius/lists/memberoptions.html',
            {'mm_member': mm_member,
             'list': mm_list,
             'settingsform': settingsform,
             },
            context_instance=RequestContext(request))
Ejemplo n.º 7
0
 def process_exception(self, request, exception):
     if isinstance(exception, (MailmanApiError, MailmanConnectionError)):
         logger.exception('Mailman REST API not available')
         return utils.render_api_error(request)
     elif isinstance(exception, HTTPError):
         logger.exception('Un-handled exception: %s', str(exception))
         return utils.render_client_error(request, exception)
Ejemplo n.º 8
0
 def post(self, request, list_id):
     try:
         mm_user = MailmanUser.objects.get(address=request.user.email)
         user_emails = [str(address) for address in mm_user.addresses]
         form = ListSubscribe(user_emails, request.POST)
         for address in user_emails:
             try:
                 userMember = self.mailing_list.get_member(address)
             except ValueError:
                 pass
             else:
                 userSubscribed = True
                 old_email = address
         if form.is_valid():
             email = form.cleaned_data['email']
             if old_email == email:
                 messages.error(request, 'You are already subscribed')
             else:
                 self.mailing_list.unsubscribe(old_email)
                 self.mailing_list.subscribe(email)
                 messages.success(request,
                     'Subscription changed to {} address'.format(email))
         else:
             messages.error(request, 'Something went wrong. '
                            'Please try again.')
     except MailmanApiError:
         return utils.render_api_error(request)
     except HTTPError, e:
         messages.error(request, e.msg)
Ejemplo n.º 9
0
 def post(self, request, list_id):
     """
     Subscribes an email address to a mailing list via POST and 
     redirects to the `list_summary` view.
     """
     try:
         try:
             mm_user = MailmanUser.objects.get(address=request.user.email)
             user_addresses = [str(address) for address in mm_user.addresses]
         except Mailman404Error:
             mm_user = None
             user_addresses = (request.POST.get('email'),)
         form = ListSubscribe(user_addresses, request.POST)
         if form.is_valid():
             email = request.POST.get('email')
             response = self.mailing_list.subscribe(
                 email, pre_verified=True, pre_confirmed=True)
             if type(response) == dict and response.get('token_owner') == \
                     'moderator':
                 messages.success(
                     request,
                     'Your subscription request has been submitted and is '
                     'waiting for moderator approval.')
             else:
                 messages.success(
                     request, 'You are subscribed to %s.' %
                     self.mailing_list.fqdn_listname)
         else:
             messages.error(request, 'Something went wrong. '
                            'Please try again.')
     except MailmanApiError:
         return utils.render_api_error(request)
     except HTTPError, e:
         messages.error(request, e.msg)
Ejemplo n.º 10
0
def domain_index(request):
    try:
        existing_domains = Domain.objects.all()
    except MailmanApiError:
        return utils.render_api_error(request)
    return render(request, 'postorius/domain/index.html',
                  {'domains': existing_domains})
Ejemplo n.º 11
0
 def get(self, request):
     try:
         helperform = UserPreferences()
         mm_user = MailmanUser.objects.get(address=request.user.email)
         addresses = mm_user.addresses
         i = 0
         for address in addresses:
             i = i + 1
         AFormset = formset_factory(UserPreferences, extra=i)
         formset = AFormset()
         zipped_data = zip(formset.forms, addresses)
         for form, address in zipped_data:
             form.initial = address.preferences
     except MailmanApiError:
         return utils.render_api_error(request)
     except Mailman404Error:
         return render_to_response(
             'postorius/user_address_preferences.html',
             {'nolists': 'true'},
             context_instance=RequestContext(request))
     return render_to_response('postorius/user_address_preferences.html',
                               {'mm_user': mm_user,
                                'addresses': addresses,
                                'helperform': helperform,
                                'formset': formset,
                                'zipped_data': zipped_data},
                               context_instance=RequestContext(request))
Ejemplo n.º 12
0
def handle_subscription_request(request, list_id, request_id, action):
    """
    Handle a subscription request. Possible actions:
        - accept
        - defer
        - reject
        - discard
    """
    confirmation_messages = {
        'accept': _('The request has been accepted.'),
        'reject': _('The request has been rejected.'),
        'discard': _('The request has been discarded.'),
        'defer': _('The request has been defered.'),
    }
    try:
        m_list = utils.get_client().get_list(list_id)
        # Moderate request and add feedback message to session.
        m_list.moderate_request(request_id, action)
        messages.success(request, confirmation_messages[action])
    except MailmanApiError:
        return utils.render_api_error(request)
    except HTTPError as e:
        messages.error(request, '{0}: {1}'.format(
            _('The request could not be moderated'), e.reason))
    return redirect('list_subscription_requests', m_list.list_id)
Ejemplo n.º 13
0
 def get(self, request):
     try:
         mm_user = MailmanUser.objects.get(address=request.user.email)
         subscriptions = mm_user.subscriptions
         i = len(subscriptions)
         member_subscriptions = []
         for subscription in subscriptions:
             if subscription.role == "member":
                 member_subscriptions.append(subscription)
         Mformset = formset_factory(UserPreferences, extra=i)
         formset = Mformset()
         zipped_data = zip(formset.forms, member_subscriptions)
         for form, subscription in zipped_data:
             form.initial = subscription.preferences
     except MailmanApiError:
         return utils.render_api_error(request)
     except Mailman404Error:
         return render_to_response(
             'postorius/user_subscription_preferences.html',
             {'nolists': 'true'},
             context_instance=RequestContext(request))
     return render_to_response(
         'postorius/user_subscription_preferences.html',
         {'mm_user': mm_user,
          'subscriptions': subscriptions,
          'zipped_data': zipped_data,
          'formset': formset},
         context_instance=RequestContext(request))
Ejemplo n.º 14
0
 def post(self, request):
     try:
         mm_user = MailmanUser.objects.get(address=request.user.email)
         formset_class = formset_factory(UserPreferences)
         formset = formset_class(request.POST)
         if formset.is_valid():
             for form, address in zip(formset.forms, mm_user.addresses):
                 preferences = address.preferences
                 for key in form.fields.keys():
                     if (key in form.cleaned_data
                             and form.cleaned_data[key] is not None):
                         # None: nothing set yet. Remember to remove this
                         # test when Mailman accepts None as a
                         # "reset to default" value.
                         preferences[key] = form.cleaned_data[key]
                 preferences.save()
             messages.success(request,
                              _('Your preferences have been updated.'))
         else:
             messages.error(request, _('Something went wrong.'))
     except MailmanApiError:
         return utils.render_api_error(request)
     except HTTPError as e:
         messages.error(request, e.msg)
     return redirect("user_address_preferences")
Ejemplo n.º 15
0
def domain_index(request):
    try:
        existing_domains = Domain.objects.all()
    except MailmanApiError:
        return utils.render_api_error(request)
    return render_to_response('postorius/domain_index.html',
                              {'domains': existing_domains},
                              context_instance=RequestContext(request))
Ejemplo n.º 16
0
def domain_index(request):
    try:
        existing_domains = Domain.objects.all()
    except MailmanApiError:
        return utils.render_api_error(request)
    return render_to_response('postorius/domain_index.html',
                              {'domains': existing_domains},
                              context_instance=RequestContext(request))
Ejemplo n.º 17
0
def user_subscriptions(request):
    """Shows the subscriptions of a user."""
    try:
        mm_user = MailmanUser.objects.get_or_create_from_django(request.user)
    except MailmanApiError:
        return utils.render_api_error(request)
    memberships = [m for m in mm_user.subscriptions if m.role == 'member']
    return render(request, 'postorius/user/subscriptions.html',
                  {'memberships': memberships})
Ejemplo n.º 18
0
 def get(self, request):
     try:
         mm_user = MailmanUser.objects.get_or_create_from_django(
             request.user)
     except MailmanApiError:
         return utils.render_api_error(request)
     settingsform = UserPreferences(initial=mm_user.preferences)
     return render(request, 'postorius/user/mailman_settings.html',
                   {'mm_user': mm_user, 'settingsform': settingsform})
Ejemplo n.º 19
0
def _get_choosable_domains(request):
    try:
        domains = Domain.objects.all()
    except MailmanApiError:
        return utils.render_api_error(request)
    choosable_domains = [("", _("Choose a Domain"))]
    for domain in domains:
        choosable_domains.append((domain.mail_host,
                                  domain.mail_host))
    return choosable_domains
Ejemplo n.º 20
0
def _get_choosable_domains(request):
    try:
        domains = Domain.objects.all()
    except MailmanApiError:
        return utils.render_api_error(request)
    choosable_domains = [("", _("Choose a Domain"))]
    for domain in domains:
        choosable_domains.append((domain.mail_host,
                                  domain.mail_host))
    return choosable_domains
Ejemplo n.º 21
0
def list_held_messages(request, fqdn_listname):
    """Shows a list of held messages.
    """
    try:
        the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
    except MailmanApiError:
        return utils.render_api_error(request)
    return render_to_response('postorius/lists/held_messages.html',
                              {'list': the_list},
                              context_instance=RequestContext(request))
Ejemplo n.º 22
0
def list_subscription_requests(request, list_id):
    """Shows a list of held messages.
    """
    try:
        m_list = utils.get_client().get_list(list_id)
    except MailmanApiError:
        return utils.render_api_error(request)
    return render_to_response('postorius/lists/subscription_requests.html',
                              {'list': m_list},
                              context_instance=RequestContext(request))
Ejemplo n.º 23
0
def list_held_messages(request, list_id):
    """Shows a list of held messages.
    """
    try:
        the_list = List.objects.get_or_404(fqdn_listname=list_id)
    except MailmanApiError:
        return utils.render_api_error(request)
    return render_to_response('postorius/lists/held_messages.html',
                              {'list': the_list},
                              context_instance=RequestContext(request))
Ejemplo n.º 24
0
def user_subscriptions(request):
    """Shows the subscriptions of a user."""
    utils.set_other_emails(request.user)
    try:
        mm_user = MailmanUser.objects.get_or_create_from_django(request.user)
    except MailmanApiError:
        return utils.render_api_error(request)
    memberships = [m for m in mm_user.subscriptions if m.role == 'member']
    return render(request, 'postorius/user/subscriptions.html',
                  {'memberships': memberships})
Ejemplo n.º 25
0
def reject_held_message(request, list_id, msg_id):
    """Rejects a held message.
    """
    try:
        the_list = List.objects.get_or_404(fqdn_listname=list_id)
        the_list.reject_message(msg_id)
    except MailmanApiError:
        return utils.render_api_error(request)
    except HTTPError, e:
        messages.error(request, e.msg)
        return redirect('list_held_messages', the_list.list_id)
Ejemplo n.º 26
0
 def get(self, request, *args, **kwargs):
     email = kwargs['email']
     try:
         self.mailing_list.unsubscribe(email)
         messages.success(request,
                          '%s has been unsubscribed from this list.' %
                          email)
     except MailmanApiError:
         return utils.render_api_error(request)
     except ValueError, e:
         messages.error(request, e)
Ejemplo n.º 27
0
def user_mailmansettings(request):
    try:
        the_user = MailmanUser.objects.get(address=request.user.email)
    except MailmanApiError:
        return utils.render_api_error(request)

    settingsform = MembershipSettings()
    return render_to_response('postorius/user_mailmansettings.html',
                              {'mm_user': the_user,
                               'settingsform': settingsform},
                              context_instance=RequestContext(request))
Ejemplo n.º 28
0
def defer_held_message(request, list_id, msg_id):
    """Defers a held message for a later decision.
    """
    try:
        the_list = List.objects.get_or_404(fqdn_listname=list_id)
        the_list.defer_message(msg_id)
    except MailmanApiError:
        return utils.render_api_error(request)
    except HTTPError, e:
        messages.error(request, e.msg)
        return redirect('list_held_messages', the_list.list_id)
Ejemplo n.º 29
0
 def get(self, request):
     try:
         mm_user = MailmanUser.objects.get_or_create_from_django(
             request.user)
     except MailmanApiError:
         return utils.render_api_error(request)
     settingsform = UserPreferences(initial=mm_user.preferences)
     return render(request, 'postorius/user/mailman_settings.html', {
         'mm_user': mm_user,
         'settingsform': settingsform
     })
Ejemplo n.º 30
0
def reject_held_message(request, fqdn_listname, msg_id):
    """Accepts a held message.
    """
    try:
        the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
        the_list.reject_message(msg_id)
    except MailmanApiError:
        return utils.render_api_error(request)
    except HTTPError, e:
        messages.error(request, e.msg)
        return redirect('list_held_messages', the_list.fqdn_listname)
Ejemplo n.º 31
0
 def get(self, request, *args, **kwargs):
     email = kwargs['email']
     try:
         self.mailing_list.unsubscribe(email)
         messages.success(request,
                          '%s has been unsubscribed from this list.' %
                          email)
     except MailmanApiError:
         return utils.render_api_error(request)
     except ValueError, e:
         messages.error(request, e)
Ejemplo n.º 32
0
def user_index(request, template='postorius/users/index.html'):
    """Show a table of all users.
    """
    error = None
    try:
        mm_users = MailmanUser.objects.all()
    except MailmanApiError:
        return utils.render_api_error(request)
    return render_to_response(template,
                              {'error': error,
                               'mm_users': mm_users},
                              context_instance=RequestContext(request))
Ejemplo n.º 33
0
 def get(self, request):
     try:
         mm_user = MailmanUser.objects.get(address=request.user.email)
         settingsform = UserPreferences(initial=mm_user.preferences)
     except MailmanApiError:
         return utils.render_api_error(request)
     except Mailman404Error:
         mm_user = None
         settingsform = None
     return render_to_response('postorius/user_mailmansettings.html',
                               {'mm_user': mm_user,
                                'settingsform': settingsform},
                               context_instance=RequestContext(request))
Ejemplo n.º 34
0
def remove_role(request, list_id=None, role=None, address=None,
                template='postorius/lists/confirm_remove_role.html'):
    """Removes a list moderator or owner.
    """
    try:
        the_list = List.objects.get_or_404(fqdn_listname=list_id)
    except MailmanApiError:
        return utils.render_api_error(request)

    if role == 'owner':
        if address not in the_list.owners:
            messages.error(request,
                           _('The user {} is not an owner'.format(address)))
            return redirect("list_members", the_list.list_id)
    elif role == 'moderator':
        if address not in the_list.moderators:
            messages.error(request,
                           _('The user {} is not a moderator'.format(address)))
            return redirect("list_members", the_list.list_id)

    if request.method == 'POST':
        try:
            the_list.remove_role(role, address)
        except MailmanApiError:
            return utils.render_api_error(request)
        except HTTPError as e:
            messages.error(request, _('The {0} could not be removed:'
                                      ' {1}'.format(role, e.msg)))
            return redirect("list_members", the_list.list_id)
        messages.success(request,
                         _('The user {0} has been removed as {1}.'
                           .format(address, role)))
        return redirect("list_members", the_list.list_id)

    return render_to_response(template,
                              {'role': role, 'address': address,
                               'list_id': the_list.list_id},
                              context_instance=RequestContext(request))
Ejemplo n.º 35
0
def remove_role(request, fqdn_listname=None, role=None, address=None,
                template='postorius/lists/confirm_remove_role.html'):
    """Removes a list moderator or owner.
    """
    try:
        the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
    except MailmanApiError:
        return utils.render_api_error(request)

    if role == 'owner':
        if address not in the_list.owners:
            messages.error(request,
                           _('The user {} is not an owner'.format(address)))
            return redirect("list_members", the_list.fqdn_listname)
    elif role == 'moderator':
        if address not in the_list.moderators:
            messages.error(request,
                           _('The user {} is not a moderator'.format(address)))
            return redirect("list_members", the_list.fqdn_listname)

    if request.method == 'POST':
        try:
            the_list.remove_role(role, address)
        except MailmanApiError:
            return utils.render_api_error(request)
        except HTTPError as e:
            messages.error(request, _('The {0} could not be removed:'
                                      ' {1}'.format(role, e.msg)))
            return redirect("list_members", the_list.fqdn_listname)
        messages.success(request,
                         _('The user {0} has been removed as {1}.'
                           .format(address, role)))
        return redirect("list_members", the_list.fqdn_listname)

    return render_to_response(template,
                              {'role': role, 'address': address,
                               'fqdn_listname': the_list.fqdn_listname},
                              context_instance=RequestContext(request))
Ejemplo n.º 36
0
def reject_held_message(request, list_id, msg_id):
    """Rejects a held message.
    """
    try:
        the_list = List.objects.get_or_404(fqdn_listname=list_id)
        add_mod_event(request, msg_id, list_id, 'reject')
        the_list.reject_message(msg_id)
    except MailmanApiError:
        return utils.render_api_error(request)
    except HTTPError as e:
        messages.error(request, e.msg)
        return redirect('list_held_messages', the_list.list_id)
    messages.success(request, 'The message has been rejected.')
    return redirect('list_held_messages', the_list.list_id)
Ejemplo n.º 37
0
 def dispatch(self, request, *args, **kwargs):
     # get the list object.
     if 'fqdn_listname' in kwargs:
         try:
             self.mailing_list = self._get_list(kwargs['fqdn_listname'])
         except MailmanApiError:
             return utils.render_api_error(request)
         request.user.is_list_owner = self._is_list_owner(
             request.user, self.mailing_list)
         request.user.is_list_moderator = self._is_list_moderator(
             request.user, self.mailing_list)
     # set the template
     if 'template' in kwargs:
         self.template = kwargs['template']
     return super(MailingListView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 38
0
def set_task_priority(request, task_id, priority):
    """Set Priority for a Task."""
    try:
        the_task = AdminTasks.objects.get(task_id=task_id)
        if the_task.priority == int(priority):
            the_task.priority = -2
        else:
            the_task.priority = priority
        the_task.save()
        return redirect('user_dashboard')
    except ObjectDoesNotExist:
        messages.error(request, "An unexpected Error occured! The Task couldn't be found")
    except MailmanApiError:
        return utils.render_api_error(request)
    return redirect('user_dashboard')
Ejemplo n.º 39
0
def domain_index(request):
    try:
        existing_domains = Domain.objects.all()
    except MailmanApiError:
        return utils.render_api_error(request)
    for domain in existing_domains:
        try:
            web_host = MailDomain.objects.get(mail_domain=domain.mail_host)
        except MailDomain.DoesNotExist:
            site = Site.objects.get_current(request)
            web_host = MailDomain.objects.create(site=site,
                                                 mail_domain=domain.mail_host)
        domain.site = web_host.site
    return render(request, 'postorius/domain/index.html', {
        'domains': existing_domains,
    })
Ejemplo n.º 40
0
 def post(self, request, fqdn_listname):
     try:
         form = ListSubscribe(request.POST)
         if form.is_valid():
             email = request.POST.get('email')
             self.mailing_list.subscribe(email)
             messages.success(
                 request, 'You are subscribed to %s.' %
                 self.mailing_list.fqdn_listname)
         else:
             messages.error(request, 'Something went wrong. '
                            'Please try again.')
     except MailmanApiError:
         return utils.render_api_error(request)
     except HTTPError, e:
         messages.error(request, e.msg)
Ejemplo n.º 41
0
 def dispatch(self, request, *args, **kwargs):
     # get the list object.
     if 'list_id' in kwargs:
         try:
             self.mailing_list = self._get_list(kwargs['list_id'],
                                                int(kwargs.get('page', 1)))
         except MailmanApiError:
             return utils.render_api_error(request)
         request.user.is_list_owner = self._is_list_owner(
             request.user, self.mailing_list)
         request.user.is_list_moderator = self._is_list_moderator(
             request.user, self.mailing_list)
     # set the template
     if 'template' in kwargs:
         self.template = kwargs['template']
     return super(MailingListView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 42
0
def user_new(request):
    message = None
    if request.method == 'POST':
        form = UserNew(request.POST)
        if form.is_valid():
            user = MailmanUser(display_name=form.cleaned_data['display_name'],
                               email=form.cleaned_data['email'],
                               password=form.cleaned_data['password'])
            try:
                user.save()
            except MailmanApiError:
                return utils.render_api_error(request)
            except HTTPError, e:
                messages.error(request, e)
            else:
                messages.success(request, _("New User registered"))
            return redirect("user_index")
Ejemplo n.º 43
0
    def dispatch(self, request, *args, **kwargs):
        # get the user object.
        user_id = None
        if 'user_id' in kwargs:
            user_id = kwargs['user_id']
        elif request.user.is_authenticated():
            user_id = request.user.email
        if user_id is not None:
            try:
                self.mm_user = self._get_user(user_id)
            except MailmanApiError:
                return utils.render_api_error(request)

        # set the template
        if 'template' in kwargs:
            self.template = kwargs['template']
        return super(MailmanUserView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 44
0
def domain_new(request):
    message = None
    if request.method == 'POST':
        form = DomainNew(request.POST)
        if form.is_valid():
            domain = Domain(mail_host=form.cleaned_data['mail_host'],
                            base_url=form.cleaned_data['web_host'],
                            description=form.cleaned_data['description'])
            try:
                domain.save()
            except MailmanApiError:
                return utils.render_api_error(request)
            except HTTPError, e:
                messages.error(request, e)
            else:
                messages.success(request, _("New Domain registered"))
            return redirect("domain_index")
Ejemplo n.º 45
0
    def dispatch(self, request, *args, **kwargs):
        # get the user object.
        user_id = None
        if 'user_id' in kwargs:
            user_id = kwargs['user_id']
        elif request.user.is_authenticated():
            user_id = request.user.email
        if user_id is not None:
            try:
                self.mm_user = self._get_user(user_id)
            except MailmanApiError:
                return utils.render_api_error(request)

        # set the template
        if 'template' in kwargs:
            self.template = kwargs['template']
        return super(MailmanUserView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 46
0
def user_index(request, page=1, template='postorius/users/index.html'):
    """Show a table of all users.
    """
    page = int(page)
    error = None
    try:
        mm_user_page = utils.get_client().get_user_page(25, page)
    except MailmanApiError:
        return utils.render_api_error(request)
    return render_to_response(
        template,
        {'error': error,
         'mm_user_page': mm_user_page,
         'mm_user_page_nr': page,
         'mm_user_page_previous_nr': page - 1,
         'mm_user_page_next_nr': page + 1,
         'mm_user_page_show_next': len(mm_user_page) >= 25},
        context_instance=RequestContext(request))
Ejemplo n.º 47
0
def domain_new(request):
    message = None
    if request.method == 'POST':
        form = DomainNew(request.POST)
        if form.is_valid():
            domain = Domain(mail_host=form.cleaned_data['mail_host'],
                            base_url=form.cleaned_data['web_host'],
                            description=form.cleaned_data['description'],
                            owner=request.user.email)
            try:
                domain.save()
            except MailmanApiError:
                return utils.render_api_error(request)
            except HTTPError, e:
                messages.error(request, e)
            else:
                messages.success(request, _("New Domain registered"))
            return redirect("domain_index")
Ejemplo n.º 48
0
 def post(self, request):
     try:
         mm_user = MailmanUser.objects.get(address=request.user.email)
         global_preferences_form = UserPreferences(request.POST)
         if global_preferences_form.is_valid():
             preferences = mm_user.preferences
             for key in global_preferences_form.fields.keys():
                 preferences[
                     key] = global_preferences_form.cleaned_data[key]
                 preferences.save()
             messages.success(
                 request, 'Your preferences have been updated.')
         else:
             messages.error(request, 'Something went wrong.')
     except MailmanApiError:
         return utils.render_api_error(request)
     except Mailman404Error as e:
         messages.error(request, e.msg)
     return redirect("user_mailmansettings")