Move mailing list admin to com

This commit is contained in:
Antoine Bartuccio 2017-08-19 16:13:53 +02:00
parent 69e997d587
commit 76efb91e40
10 changed files with 38 additions and 33 deletions

View File

@ -237,7 +237,7 @@ class Mailing(models.Model):
super(Mailing, self).clean()
def is_owned_by(self, user):
return user.is_in_group(self) or user.is_root or user.is_board_member
return user.is_in_group(self) or user.is_root or user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
def can_view(self, user):
return self.club.has_rights_in_club(user)
@ -281,10 +281,10 @@ class MailingSubscription(models.Model):
super(MailingSubscription, self).clean()
def is_owned_by(self, user):
return self.mailing.club.has_rights_in_club(user) or user.is_root
return self.mailing.club.has_rights_in_club(user) or user.is_root or self.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
def can_be_edited_by(self, user):
return self.is_owned_by(user) or (user is not None and user.id == self.user.id)
return (user is not None and user.id == self.user.id)
def fetch_format(self):
return self.email + ' '

View File

@ -7,6 +7,8 @@
{% block content %}
{% if has_objects %}
{% trans %}Remember : mailing lists need to be validated by the school to work, please inform us about any new mailing list created{% endtrans %}
{% for mailing in object_list %}
<h2>{% trans %}Mailing{% endtrans %} {{ mailing.email }}
{%- if user.is_owner(mailing) -%}

View File

@ -24,9 +24,8 @@
#
from django import forms
from enum import Enum
from django.views.generic import ListView, DetailView, TemplateView
from django.views.generic.edit import DeleteView, FormView
from django.views.generic.edit import DeleteView
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import UpdateView, CreateView
from django.http import HttpResponseRedirect, HttpResponse
@ -38,7 +37,7 @@ from ajax_select.fields import AutoCompleteSelectField
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
from core.views.forms import SelectDate, SelectDateTime
from club.models import Club, Membership, Mailing, MailingSubscription
from sith.settings import SITH_MAXIMUM_FREE_ROLE
@ -394,7 +393,7 @@ class ClubMailingView(ClubTabsMixin, ListView):
current_tab = 'mailing'
def authorized(self):
return self.club.has_rights_in_club(self.user) or self.user.is_root or self.user.is_board_member
return self.club.has_rights_in_club(self.user) or self.user.is_root or self.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
def dispatch(self, request, *args, **kwargs):
self.club = get_object_or_404(Club, pk=kwargs['club_id'])

View File

@ -15,13 +15,13 @@
{% for mailing in object_list %}
<tr>
<td>{{ mailing.email }}</td>
<td>{{ mailing.club }} <a href="{{ url('club:mailing_delete', mailing_id=mailing.id) }}">{% trans %}Delete{% endtrans %}</a></td>
<td><a href="{{ url('club:mailing', club_id=mailing.club.id) }}">{{ mailing.club }}</a> <a href="{{ url('club:mailing_delete', mailing_id=mailing.id) }}">{% trans %}Delete{% endtrans %}</a></td>
</tr>
{% endfor %}
</table>
{% else %}
<p>{% trans %}No mailing existing{% endtrans %}</p>
<p>{% trans %}No mailing list existing{% endtrans %}</p>
{% endif %}
{% endblock %}

View File

@ -42,5 +42,6 @@ urlpatterns = [
url(r'^news/(?P<news_id>[0-9]+)/moderate$', NewsModerateView.as_view(), name='news_moderate'),
url(r'^news/(?P<news_id>[0-9]+)/edit$', NewsEditView.as_view(), name='news_edit'),
url(r'^news/(?P<news_id>[0-9]+)$', NewsDetailView.as_view(), name='news_detail'),
url(r'^mailings$', MailingListAdminView.as_view(), name='mailing_admin'),
]

View File

@ -2,6 +2,7 @@
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
# - Sli <antoine@bartuccio.fr>
#
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
# http://ae.utbm.fr.
@ -34,6 +35,7 @@ from django.utils import timezone
from django.conf import settings
from django.db.models import Max
from django.forms.models import modelform_factory
from django.core.exceptions import PermissionDenied
from django import forms
from datetime import timedelta
@ -42,7 +44,7 @@ from com.models import Sith, News, NewsDate, Weekmail, WeekmailArticle
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin, QuickNotifMixin
from core.views.forms import SelectDateTime
from core.models import Notification, RealGroup
from club.models import Club
from club.models import Club, Mailing
# Sith object
@ -81,6 +83,11 @@ class ComTabsMixin(TabedViewMixin):
'slug': 'alert',
'name': _("Alert message"),
})
tab_list.append({
'url': reverse('com:mailing_admin'),
'slug': 'mailings',
'name': _("Mailing lists administration"),
})
return tab_list
@ -414,3 +421,19 @@ class WeekmailArticleDeleteView(CanEditPropMixin, DeleteView):
template_name = 'core/delete_confirm.jinja'
success_url = reverse_lazy('com:weekmail')
pk_url_kwarg = "article_id"
class MailingListAdminView(ComTabsMixin, ListView):
template_name = "com/mailing_admin.jinja"
model = Mailing
current_tab = "mailings"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID):
raise PermissionDenied
return super(MailingListAdminView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
kwargs = super(MailingListAdminView, self).get_context_data(**kwargs)
kwargs['has_objects'] = len(kwargs['object_list']) > 0
return kwargs

View File

@ -59,10 +59,10 @@
</tbody>
</table>
{% if profile.mailing_subscriptions.exists() and (profile.id == user.id or user.is_root) %}
{% if profile.mailing_subscriptions.exists() and (profile.id == user.id or user.is_root or self.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)) %}
<h4>{% trans %}Subscribed mailing lists{% endtrans %}</h4>
{% for sub in profile.mailing_subscriptions.all() %}
<p>{{ sub }} <a href="{{ url('club:mailing_subscription_delete', mailing_subscription_id=sub.id) }}">{% trans %}Unsuscribe{% endtrans %}</a></p>
<p>{{ sub.mailing.email }} <a href="{{ url('club:mailing_subscription_delete', mailing_subscription_id=sub.id) }}">{% trans %}Unsuscribe{% endtrans %}</a></p>
{% endfor %}
{% endif %}
{% endblock %}

View File

@ -13,7 +13,6 @@
{% if user.is_root %}
<li><a href="{{ url('core:group_list') }}">{% trans %}Groups{% endtrans %}</a></li>
<li><a href="{{ url('rootplace:merge') }}">{% trans %}Merge users{% endtrans %}</a></li>
<li><a href="{{ url('rootplace:mailings') }}">{% trans %}Mailing lists administration{% endtrans %}</a></li>
{% endif %}
{% if user.can_create_subscription or user.is_root %}
<li><a href="{{ url('subscription:subscription') }}">{% trans %}Subscriptions{% endtrans %}</a></li>
@ -88,6 +87,7 @@
<li><a href="{{ url('com:alert_edit') }}">{% trans %}Edit alert message{% endtrans %}</a></li>
<li><a href="{{ url('com:info_edit') }}">{% trans %}Edit information message{% endtrans %}</a></li>
<li><a href="{{ url('core:file_moderation') }}">{% trans %}Moderate files{% endtrans %}</a></li>
<li><a href="{{ url('com:mailing_admin') }}">{% trans %}Mailing lists administration{% endtrans %}</a></li>
{% endif %}
{% if user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) %}
<li><a href="{{ url('sas:moderation') }}">{% trans %}Moderate pictures{% endtrans %}</a></li>

View File

@ -28,5 +28,4 @@ from rootplace.views import *
urlpatterns = [
url(r'^merge$', MergeUsersView.as_view(), name='merge'),
url(r'^mailings$', MailingListAdminView.as_view(), name='mailings')
]

View File

@ -23,20 +23,16 @@
#
#
from django.shortcuts import render
from django.utils.translation import ugettext as _
from django.views.generic.edit import FormView
from django.core.urlresolvers import reverse
from django import forms
from django.views.generic import ListView
from django.core.exceptions import PermissionDenied
from ajax_select.fields import AutoCompleteSelectField
from core.views import CanViewMixin
from core.models import User
from counter.models import Customer
from club.models import Mailing
def merge_users(u1, u2):
@ -112,18 +108,3 @@ class MergeUsersView(FormView):
def get_success_url(self):
return reverse('core:user_profile', kwargs={'user_id': self.final_user.id})
class MailingListAdminView(ListView):
template_name = "rootplace/mailing_lists.jinja"
model = Mailing
def dispatch(self, request, *args, **kwargs):
if not request.user.is_root:
raise PermissionDenied
return super(MailingListAdminView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
kwargs = super(MailingListAdminView, self).get_context_data(**kwargs)
kwargs['has_objects'] = len(kwargs['object_list']) > 0
return kwargs