1# -*- coding: utf-8 -*-
2# Copyright (C) 1998-2021 by the Free Software Foundation, Inc.
3#
4# This file is part of Postorius.
5#
6# Postorius is free software: you can redistribute it and/or modify it under
7# the terms of the GNU General Public License as published by the Free
8# Software Foundation, either version 3 of the License, or (at your option)
9# any later version.
10#
11# Postorius is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14# more details.
15#
16# You should have received a copy of the GNU General Public License along with
17# Postorius.  If not, see <http://www.gnu.org/licenses/>.
18
19
20from django.conf.urls import include, url
21
22from postorius.views import domain as domain_views
23from postorius.views import list as list_views
24from postorius.views import rest as rest_views
25from postorius.views import system as system_views
26from postorius.views import template as template_views
27from postorius.views import user as user_views
28
29
30list_patterns = [
31    url(r'^csv_view/$', list_views.csv_view, name='csv_view'),
32    url(r'^members/options/(?P<email>.+)$', list_views.list_member_options,
33        name='list_member_options'),
34    url(r'^members/(?P<role>\w+)/$', list_views.ListMembersViews.as_view(),
35        name='list_members'),
36    url(r'^$', list_views.ListSummaryView.as_view(),
37        name='list_summary'),
38    url(r'^subscribe$', list_views.ListSubscribeView.as_view(),
39        name='list_subscribe'),
40    url(r'^anonymous_subscribe$',
41        list_views.ListAnonymousSubscribeView.as_view(),
42        name='list_anonymous_subscribe'),
43    url(r'^change_subscription$', list_views.ChangeSubscriptionView.as_view(),
44        name='change_subscription'),
45    url(r'^unsubscribe/$', list_views.ListUnsubscribeView.as_view(),
46        name='list_unsubscribe'),
47    url(r'^subscription_requests$', list_views.list_subscription_requests,
48        name='list_subscription_requests'),
49    url(r'^pending_confirmation$', list_views.list_pending_confirmations,
50        name='list_pending_confirmation'),
51    url(r'^handle_subscription_request/(?P<request_id>[^/]+)/'
52        '(?P<action>[accept|reject|discard|defer]+)$',
53        list_views.handle_subscription_request,
54        name='handle_subscription_request'),
55    url(r'^mass_subscribe/$', list_views.list_mass_subscribe,
56        name='mass_subscribe'),
57    url(r'^mass_removal/$', list_views.ListMassRemovalView.as_view(),
58        name='mass_removal'),
59    url(r'^delete$', list_views.list_delete, name='list_delete'),
60    url(r'^held_messages$', list_views.list_moderation,
61        name='list_held_messages'),
62    url(r'^held_messages/moderate$', list_views.moderate_held_message,
63        name='moderate_held_message'),
64    url(r'^bans/$', list_views.list_bans, name='list_bans'),
65    url(r'^header-matches/$', list_views.list_header_matches,
66        name='list_header_matches'),
67    url(r'^remove/(?P<role>[^/]+)/(?P<address>.+)$', list_views.remove_role,
68        name='remove_role'),
69    url(r'^settings/(?P<visible_section>[^/]+)?$', list_views.list_settings,
70        name='list_settings'),
71    url(r'^unsubscribe_all$', list_views.remove_all_subscribers,
72        name='unsubscribe_all'),
73    url(r'^confirm/$', list_views.confirm_token,
74        name='confirm_token'),
75    url(r'^templates$',
76        template_views.ListTemplateIndexView.as_view(),
77        name='list_template_list'),
78    url(r'^templates/new$',
79        template_views.ListTemplateCreateView.as_view(),
80        name='list_template_new'),
81    url(r'^templates/(?P<pk>[^/]+)?/update$',
82        template_views.ListTemplateUpdateView.as_view(),
83        name='list_template_update'),
84    url(r'^templates/(?P<pk>[^/]+)?/delete$',
85        template_views.ListTemplateDeleteView.as_view(),
86        name='list_template_delete')
87]
88
89urlpatterns = [
90    url(r'^$', list_views.list_index),                   # noqa: W605 (bogus)
91    url(r'^accounts/subscriptions/$', user_views.user_subscriptions,
92        name='ps_user_profile'),
93    url(r'^accounts/per-address-preferences/$',
94        user_views.UserAddressPreferencesView.as_view(),
95        name='user_address_preferences'),
96    # if this URL changes, update Mailman's Member.options_url
97    url(r'^accounts/per-subscription-preferences/$',
98        user_views.UserSubscriptionPreferencesView.as_view(),
99        name='user_subscription_preferences'),
100    url(r'^accounts/mailmansettings/$',
101        user_views.UserMailmanSettingsView.as_view(),
102        name='user_mailmansettings'),
103    url(r'^accounts/list-options/(?P<list_id>[^/]+)/$',
104        user_views.UserListOptionsView.as_view(),
105        name='user_list_options'),
106    # /domains/
107    url(r'^domains/$', domain_views.domain_index, name='domain_index'),
108    url(r'^domains/new/$', domain_views.domain_new, name='domain_new'),
109    url(r'^domains/(?P<domain>[^/]+)/$', domain_views.domain_edit,
110        name='domain_edit'),
111    url(r'^domains/(?P<domain>[^/]+)/delete$', domain_views.domain_delete,
112        name='domain_delete'),
113    url(r'^domains/(?P<domain>[^/]+)/owners$', domain_views.domain_owners,
114        name='domain_owners'),
115    url(r'^domains/(?P<domain>[^/]+)/owners/(?P<user_id>.+)/remove$',
116        domain_views.remove_owners,
117        name='remove_domain_owner'),
118    # Ideally, these paths should be accessible by domain_owners, however,
119    # we don't have good ways to check that, so for now, this views are
120    # protected by superuser privileges.
121    # I know it is bad, but this will be fixed soon. See postorius#
122    url(r'^domains/(?P<domain>[^/]+)/templates$',
123        template_views.DomainTemplateIndexView.as_view(),
124        name='domain_template_list'),
125    url(r'^domains/(?P<domain>[^/]+)/templates/new$',
126        template_views.DomainTemplateCreateView.as_view(),
127        name='domain_template_new'),
128    url(r'^domains/(?P<domain>[^/]+)/templates/(?P<pk>[^/]+)/update$',
129        template_views.DomainTemplateUpdateView.as_view(),
130        name='domain_template_update'),
131    url(r'^domains/(?P<domain>[^/]+)/templates/(?P<pk>[^/]+)/delete$',
132        template_views.DomainTemplateDeleteView.as_view(),
133        name='domain_template_delete'),
134    # /lists/
135    url(r'^lists/$', list_views.list_index, name='list_index'),
136    url(r'^lists/new/$', list_views.list_new, name='list_new'),
137    url(r'^lists/(?P<list_id>[^/]+)/', include(list_patterns)),
138
139    # /system/
140    url(r'^system/$', system_views.system_information,
141        name='system_information'),
142
143    # /bans/
144    url(r'^bans/$', system_views.bans, name='global_bans'),
145
146    # /api/
147    url(r'^api/list/(?P<list_id>[^/]+)/held_message/(?P<held_id>\d+)/$',
148        rest_views.get_held_message, name='rest_held_message'),
149    url(r'^api/list/(?P<list_id>[^/]+)/held_message/(?P<held_id>\d+)/'
150        r'attachment/(?P<attachment_id>\d+)/$',
151        rest_views.get_attachment_for_held_message,
152        name='rest_attachment_for_held_message'),
153    # URL configuration for templates.
154    url(r'^api/templates/(?P<context>[^/]+)/(?P<identifier>[^/]+)/(?P<name>[^/]+)',  # noqa: E501
155        template_views.get_template_data,
156        name='rest_template'),
157]
158