Commit 461da84e authored by Robert's avatar Robert

Add membership deletion views

parent ff29796e
......@@ -18,3 +18,7 @@ class Apply(forms.ModelForm):
if commit:
self.contribution.save()
return application
class ResignRequest(forms.Form):
member = forms.EmailField(label='E-Mail-Adresse')
from core import notifications
from core.notifications import Notification
class MembershipCreated(notifications.Notification):
subject = 'Stadtgestalten: In Gruppe aufgenommen'
class Member(Notification):
subject = 'Mitgliedschaft'
def get_context_data(self, **kwargs):
kwargs['token'] = self.token
return super().get_context_data(**kwargs)
class MembershipCreated(Notification):
subject = 'Mitgliedschaft'
class NoMember(Notification):
subject = 'Mitgliedschaft'
def get_formatted_recipient(self):
return '<{}>'.format(self.recipient)
......@@ -4,7 +4,7 @@ from rules import add_perm, is_authenticated
from features.groups import rules as groups
from features.groups.rules import is_closed
from features.memberships.predicates import is_member_of
from features.memberships.predicates import is_member, is_member_of
from . import predicates as memberships
......@@ -24,10 +24,9 @@ rules.add_perm(
& groups.is_closed
& memberships.is_member_of)
rules.add_perm(
'memberships.delete_membership',
rules.is_authenticated
& memberships.is_member)
add_perm('memberships.delete', is_authenticated & is_member_of)
add_perm('memberships.delete_request', ~is_authenticated)
rules.add_perm(
'memberships.view_list',
......
{% extends 'stadt/stadt.html' %}
{% block title %}Mitgliedschaft - {{ block.super }}{% endblock %}
{% block menu %}{% menu 'group' view.group %}{% endblock %}
{% block breadcrumb %}{% breadcrumb view.group 'Mitgliedschaft' %}{% endblock %}
{% block heading_title_text %}Mitgliedschaft{% endblock %}
{% block sidebar %}
{% include 'associations/_sidebar_entity.html' with entity=view.group %}
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
<p>Möchtest Du Deine Mitgliedschaft in der Gruppe <em>{{ view.group }}</em> beenden?</p>
<button class="btn btn-primary">Mitgliedschaft beenden</button>
</form>
{% endblock %}
{% extends 'stadt/stadt.html' %}
{% block title %}Mitgliedschaft - {{ block.super }}{% endblock %}
{% block menu %}{% menu 'group' view.group %}{% endblock %}
{% block breadcrumb %}{% breadcrumb view.group 'Mitgliedschaft' %}{% endblock %}
{% block heading_title_text %}Mitgliedschaft{% endblock %}
{% block sidebar %}
{% include 'associations/_sidebar_entity.html' with entity=view.group %}
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{% include 'core/_field.html' with field=form.member %}
<button class="btn btn-primary">Mitgliedschaft beenden</button>
</form>
{% endblock %}
Jemand hat Deine E-Mail-Adresse auf {{ site.name }} angegeben. Wenn Du es nicht warst, kannst Du diese Nachricht gefahrlos ignorieren.
Wenn Du Deine Mitgliedschaft in der Gruppe '{{ object }}' beenden möchtest, bestätige dies bitte, indem Du diesem Verweis folgst:
{% url 'resign-confirm' token.secret_key as url %}{{ url|full_url }}
Jemand hat Deine E-Mail-Adresse auf {{ site.name }} angegeben.
Für Deine E-Mail-Adresse existiert keine Mitgliedschaft in der Gruppe '{{ object }}'.
import django
from django import db, http, shortcuts
from django import db, http, shortcuts, urls
from django.contrib import messages
from django import urls
from django.contrib.messages import info, success
from django.shortcuts import get_object_or_404
from django.views.generic import DeleteView, FormView
import core
from core import fields, views
from core import fields, views, views as utils_views
from core.models import PermissionToken
from core.views import PermissionMixin
from features.associations import models as associations
from features.contributions import models as contributions
from features.gestalten import models as gestalten_models, views as gestalten_views
from features.gestalten.models import Gestalt
from features.groups import models as groups_models, views as groups_views
from core import views as utils_views
from . import forms, models
from features.groups.models import Group
from . import forms, models, notifications
class Apply(core.views.PermissionMixin, django.views.generic.CreateView):
......@@ -127,13 +132,62 @@ class MemberAdd(MembershipMixin, views.Create):
return urls.reverse('members', args=(self.related_object.pk,))
class Resign(MembershipMixin, utils_views.Delete):
action = 'Austreten'
description = 'Aus der Gruppe <em>{{ group }}</em> austreten'
permission_required = 'memberships.delete_membership'
class Resign(PermissionMixin, DeleteView):
permission_required = 'memberships.delete'
template_name = 'memberships/delete.html'
def delete(self, *args, **kwargs):
success(self.request, 'Du bist nicht mehr Mitglied dieser Gruppe.')
return super().delete(*args, **kwargs)
def get_object(self):
return models.Membership.objects.filter(
group=self.related_object,
member=self.request.user.gestalt
).first()
return self.gestalt.memberships.filter(group=self.group)
def get_permission_object(self):
self.gestalt = self.request.user.gestalt if self.request.user.is_authenticated else None
self.group = get_object_or_404(Group, pk=self.kwargs.get('group_pk'))
return self.group
def get_success_url(self):
return self.group.get_absolute_url()
class ResignConfirm(Resign):
def get_permission_object(self):
token = get_object_or_404(
PermissionToken, feature_key='group-resign',
secret_key=self.kwargs.get('secret_key'))
self.gestalt = token.gestalt
self.group = token.target
return self.group
def has_permission(self):
obj = self.get_permission_object()
perms = self.get_permission_required()
return self.gestalt.user.has_perms(perms, obj)
class ResignRequest(PermissionMixin, FormView):
permission_required = 'memberships.delete_request'
form_class = forms.ResignRequest
template_name = 'memberships/delete_request.html'
def form_valid(self, form):
email = form.cleaned_data['member']
try:
member = self.group.members.get_by_email(email)
notification = notifications.Member(self.group)
notification.token = PermissionToken.objects.create(
gestalt=member, target=self.group, feature_key='group-resign')
notification.send(member)
except Gestalt.DoesNotExist:
notifications.NoMember(self.group).send(email)
info(self.request, 'Es wurde eine E-Mail an die angebene Adresse versendet.')
return super().form_valid(form)
def get_permission_object(self):
self.group = get_object_or_404(Group, pk=self.kwargs.get('group_pk'))
return self.group
def get_success_url(self):
return self.group.get_absolute_url()
Jemand hat Deine E-Mail-Adresse auf {{ site.name }} angegeben.
Für Deine E-Mail-Adresse existiert kein Abonnenment der Gruppe {{ object }}.
Für Deine E-Mail-Adresse existiert kein Abonnenment der Gruppe '{{ object }}'.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment