-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1420 from liqd/mn-2019-03-delete-projects
Mn 2019 03 delete projects
- Loading branch information
Showing
11 changed files
with
218 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.db.models.signals import post_delete | ||
from django.dispatch import receiver | ||
|
||
from adhocracy4.projects.models import Project | ||
|
||
from .emails import DeleteProjectEmail | ||
|
||
|
||
@receiver(post_delete, sender=Project) | ||
def send_delete_project_notification(sender, instance, **kwargs): | ||
DeleteProjectEmail.send_no_object(instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import importlib | ||
|
||
from background_task import background | ||
|
||
|
||
@background(schedule=1) | ||
def send_async_no_object(email_module_name, | ||
email_class_name, | ||
object, args, kwargs): | ||
mod = importlib.import_module(email_module_name) | ||
cls = getattr(mod, email_class_name) | ||
return cls().dispatch(object, *args, **kwargs) |
10 changes: 10 additions & 0 deletions
10
euth/projects/templates/euth_projects/emails/delete_project.en.email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends 'email_base.'|add:part_type %} | ||
{% load verbose_name %} | ||
|
||
{% block subject %}Deletion of project{% endblock %} | ||
|
||
{% block headline %}The project {{ name }} was deleted.{% endblock %} | ||
|
||
{% block content %}The project "{{ name }}" on the participation platform {{ site.name }} was deleted.{% endblock %} | ||
|
||
{% block reason %}This email was sent to {{ receiver }}. This email was sent to you because you are an initiator of the organisation '{{ organisation }}', in wich a project was deleted.{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import pytest | ||
from django.core.urlresolvers import reverse | ||
|
||
from adhocracy4.projects import models | ||
from adhocracy4.test.helpers import redirect_target | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_anonymous_cannot_delete(client, project_factory): | ||
project = project_factory() | ||
count = models.Project.objects.all().count() | ||
assert count == 1 | ||
url = reverse( | ||
'project-delete', | ||
kwargs={ | ||
'pk': project.pk | ||
}) | ||
response = client.post(url) | ||
assert response.status_code == 302 | ||
assert redirect_target(response) == 'account_login' | ||
count = models.Project.objects.all().count() | ||
assert count == 1 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_user_cannot_delete(client, project_factory, user): | ||
project = project_factory() | ||
count = models.Project.objects.all().count() | ||
assert count == 1 | ||
client.login(username=user.email, password='password') | ||
url = reverse( | ||
'project-delete', | ||
kwargs={ | ||
'pk': project.pk | ||
}) | ||
response = client.post(url) | ||
assert response.status_code == 302 | ||
count = models.Project.objects.all().count() | ||
assert count == 1 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_moderator_cannot_delete(client, project_factory, user): | ||
project = project_factory() | ||
count = models.Project.objects.all().count() | ||
assert count == 1 | ||
moderator = project.moderators.first() | ||
client.login(username=moderator.email, password='password') | ||
url = reverse( | ||
'project-delete', | ||
kwargs={ | ||
'pk': project.pk | ||
}) | ||
response = client.post(url) | ||
assert response.status_code == 302 | ||
count = models.Project.objects.all().count() | ||
assert count == 1 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_initator_can_delete(client, project_factory): | ||
project = project_factory() | ||
count = models.Project.objects.all().count() | ||
assert count == 1 | ||
initiator = project.organisation.initiators.first() | ||
client.login(username=initiator.email, password='password') | ||
url = reverse( | ||
'project-delete', | ||
kwargs={ | ||
'pk': project.pk | ||
}) | ||
response = client.get(url) | ||
assert response.status_code == 405 | ||
response = client.post(url) | ||
assert response.status_code == 302 | ||
count = models.Project.objects.all().count() | ||
assert count == 0 |