Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add mechanism of hiding letter - close #392 #414

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion feder/cases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def with_milestone(self):

def with_letter(self):
from feder.letters.models import Letter
queryset = Letter.objects.with_author().all()
queryset = Letter.objects.with_author().filter(mark_hidden_by=None).all()
return self.prefetch_related(Prefetch(lookup='letter_set',
queryset=queryset))

Expand Down
7 changes: 6 additions & 1 deletion feder/cases/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from feder.cases.models import Case
from feder.institutions.factories import InstitutionFactory
from feder.letters.factories import IncomingLetterFactory
from feder.letters.factories import IncomingLetterFactory, HiddenLetterFactory
from feder.letters.models import Letter
from feder.main.mixins import PermissionStatusMixin
from feder.users.factories import UserFactory
Expand Down Expand Up @@ -60,6 +60,11 @@ def test_not_contains_spam_letter(self):
response = self.client.get(self.get_url())
self.assertNotContains(response, letter.body)

def test_hide_content_of_hidden_letter(self):
letter = HiddenLetterFactory(case=self.case)
response = self.client.get(self.get_url())
self.assertNotContains(response, letter.body)

def test_contains_letter(self):
letter = IncomingLetterFactory(case=self.case)
response = self.client.get(self.get_url())
Expand Down
5 changes: 4 additions & 1 deletion feder/letters/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class DraftLetterFactory(OutgoingLetterFactory):
is_draft = True


class HiddenLetterFactory(IncomingLetterFactory):
mark_hidden_by = factory.SubFactory(UserFactory)


class SendOutgoingLetterFactory(LetterFactory):
author_user = factory.SubFactory(UserFactory)

is_send_yes = factory.PostGenerationMethodCall('send')
Binary file modified feder/letters/locale/pl/LC_MESSAGES/django.mo
Binary file not shown.
92 changes: 63 additions & 29 deletions feder/letters/locale/pl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: letters 0.1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-19 00:56+0000\n"
"PO-Revision-Date: 2018-02-19 01:56+0100\n"
"POT-Creation-Date: 2018-02-19 22:48+0000\n"
"PO-Revision-Date: 2018-02-19 23:49+0100\n"
"Last-Translator: Adam Dobrawy <[email protected]>\n"
"Language-Team: Adam Dobrawy <[email protected]>\n"
"Language: pl_PL\n"
Expand All @@ -19,7 +19,7 @@ msgstr ""
"|| n%100>=20) ? 1 : 2);\n"
"X-Generator: Poedit 1.8.7.1\n"

#: apps.py:8 models.py:100
#: apps.py:8 models.py:106
msgid "Letter"
msgstr "List"

Expand Down Expand Up @@ -47,36 +47,44 @@ msgstr "Data utworzenia (rosnąco)"
msgid "Creation date (descending)"
msgstr "Data utworzenia (malejąco)"

#: forms.py:53 forms.py:56
#: forms.py:22 models.py:65
msgid "Case"
msgstr "Sprawa"

#: forms.py:56 forms.py:59
msgid "Save draft"
msgstr "Zapisz szkic"

#: forms.py:54 forms.py:58
#: forms.py:57 forms.py:61
msgid "Send reply"
msgstr "Wyślij odpowiedź"

#: forms.py:63
#: forms.py:66
msgid ""
"Nothing to do. You do not have permission to save draft or send replies."
msgstr ""
"Nic do zrobienia. Nie masz uprawnień, aby zapisać szkic lub wysłać odpowiedź."

#: forms.py:67
#: forms.py:70
msgid "You do not have permission to send replies."
msgstr "Nie masz uprawnień, aby wysłać odpowiedzi."

#: forms.py:71
#: forms.py:74
msgid "You do not have permission to save draft."
msgstr "Nie masz odpowiedzi, aby wysłać odpowiedź."

#: forms.py:91
#: forms.py:94
msgid "Assign"
msgstr "Przypisz"

#: forms.py:92
#: forms.py:95 forms.py:109
msgid "Case number"
msgstr "Numer sprawy"

#: forms.py:107
msgid "Reassign"
msgstr "Ponownie przypisz"

#: models.py:62
msgid "Unknown"
msgstr "Nieznane"
Expand All @@ -89,10 +97,6 @@ msgstr "Spam"
msgid "Non-spam"
msgstr "Nie-spam"

#: models.py:65
msgid "Case"
msgstr "Sprawa"

#: models.py:66
msgid "Author (if user)"
msgstr "Autor (jeżeli użytkownik)"
Expand All @@ -118,47 +122,59 @@ msgid "Comments from editor"
msgstr "Komentarz od redakcji"

#: models.py:76
msgid "Is draft?"
msgstr "Czy szkic?"
msgid "Spam marker"
msgstr "Oznaczający spam"

#: models.py:78
#: models.py:77
msgid "The person who marked it as spam"
msgstr "Osoba, która oznaczyła jako spam"

#: models.py:81
#: models.py:80
msgid "Time when letter was marked as spam"
msgstr "Czas kiedy list został oznaczony jako spam"

#: models.py:83
#: models.py:82
msgid "Is draft?"
msgstr "Czy szkic?"

#: models.py:84
msgid "Hiding person"
msgstr "Osoba ukrywająca"

#: models.py:85
msgid "The person who hid the letter"
msgstr "Osoba, która ukryła list"

#: models.py:89
msgid "ID of sent email message \"Message-ID\""
msgstr "ID wysłanej wiadomości e-mail \"Message-ID\""

#: models.py:86
#: models.py:92
msgid "File"
msgstr "Plik"

#: models.py:91
#: models.py:97
msgid "Message"
msgstr "Wiadomość"

#: models.py:92
#: models.py:98
msgid "Message registerd by django-mailbox"
msgstr "Wiadomość zarejestrowanaa przez django-maiblxo"

#: models.py:101 templates/letters/base.html:5
#: models.py:107 templates/letters/base.html:5
#: templates/letters/letter_detail.html:3
msgid "Letters"
msgstr "Listy"

#: models.py:104
#: models.py:110
msgid "Can filter eml"
msgstr "Może filtrować po eml"

#: models.py:105
#: models.py:111
msgid "Can recognize letter"
msgstr "Może rozpoznawać listy"

#: models.py:119
#: models.py:129
msgid "(no subject)"
msgstr "(bez tematu)"

Expand All @@ -179,12 +195,16 @@ msgstr "Odpowiedź"
msgid "Send draft"
msgstr "Wyślij ten szkic"

#: templates/letters/_btn.html:31 templates/letters/letter_spam.html:15
#: templates/letters/_btn.html:30 tests/test_views.py:76
msgid "Mark hidden"
msgstr "Oznacz jako ukrytę"

#: templates/letters/_btn.html:36 templates/letters/letter_spam.html:15
#: tests/test_views.py:69
msgid "Report spam"
msgstr "Zgłoś spam"

#: templates/letters/_btn.html:36
#: templates/letters/_btn.html:41
msgid "Mark spam"
msgstr "Oznacz spam"

Expand Down Expand Up @@ -387,6 +407,10 @@ msgid "^(?P<pk>[\\d-]+)/~mark-spam"
msgstr "^(?P<pk>[\\d-]+)/~oznacz-spam"

#: urls.py:46
msgid "^(?P<pk>[\\d-]+)/~mark-hidden"
msgstr "^(?P<pk>[\\d-]+)/~oznacz-ukryte"

#: urls.py:49
msgid "^messages/logs/"
msgstr "^wiadomosci/dziennik/"

Expand Down Expand Up @@ -460,7 +484,17 @@ msgstr "List {object} został oznaczony jako spam i ukryty."
msgid "The message {object} has been marked as spam and hidden."
msgstr "List {object} został oznaczony jako spam i ukryty."

#: views.py:308
#: views.py:301
#, python-brace-format
msgid "The letter {object} has been marked as non-hidden."
msgstr "List {object} został oznaczony jako nie-ukryty."

#: views.py:302
#, python-brace-format
msgid "The message {object} has been marked as hidden."
msgstr "List {object} został oznaczony jako ukryty."

#: views.py:341
#, python-format
msgid "Assigned message to case '%(case)s'"
msgstr "Przypisano wiadomość do sprawy '%(case)s'"
Expand Down
Binary file modified feder/letters/logs/locale/pl/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion feder/letters/logs/locale/pl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-19 00:56+0000\n"
"POT-Creation-Date: 2018-02-19 22:48+0000\n"
"PO-Revision-Date: 2017-09-20 20:27+0200\n"
"Last-Translator: Adam Dobrawy <[email protected]>\n"
"Language-Team: \n"
Expand Down
23 changes: 23 additions & 0 deletions feder/letters/migrations/0014_letter_mark_hidden_by.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-02-19 18:42
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('letters', '0013_letter_mark_spam_at'),
]

operations = [
migrations.AddField(
model_name='letter',
name='mark_hidden_by',
field=models.ForeignKey(blank=True, help_text='The person who hid the letter', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='letter_mark_hidden_by', to=settings.AUTH_USER_MODEL, verbose_name='Hiding person'),
),
]
14 changes: 12 additions & 2 deletions feder/letters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ class Letter(TimeStampedModel):
email = models.EmailField(verbose_name=_("E-mail"), max_length=100, blank=True)
note = models.TextField(verbose_name=_("Comments from editor"), blank=True)
is_spam = models.IntegerField(choices=SPAM, default=SPAM.unknown, db_index=True)
is_draft = models.BooleanField(verbose_name=_("Is draft?"), default=True)
mark_spam_by = models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True, blank=True, verbose_name="Spam marker",
mark_spam_by = models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True, blank=True, verbose_name=_("Spam marker"),
help_text=_("The person who marked it as spam"),
related_name="letter_mark_spam_by")
mark_spam_at = models.DateTimeField(null=True, verbose_name="Time of mark as spam",
help_text=_("Time when letter was marked as spam"))

is_draft = models.BooleanField(verbose_name=_("Is draft?"), default=True)

mark_hidden_by = models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True, blank=True, verbose_name=_("Hiding person"),
help_text=_("The person who hid the letter"),
related_name="letter_mark_hidden_by")

message_id_header = models.CharField(blank=True,
verbose_name=_('ID of sent email message "Message-ID"'),
max_length=500)
Expand Down Expand Up @@ -113,6 +119,10 @@ def is_incoming(self):
def is_outgoing(self):
return bool(self.author_user_id)

@property
def is_hidden(self):
return bool(self.mark_hidden_by_id)

def get_title(self):
if self.title and self.title.strip():
return self.title
Expand Down
7 changes: 6 additions & 1 deletion feder/letters/templates/letters/_btn.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
</a>
{% endif %}
{% endif %}

{% if 'hide_letter' in monitoring_perms %}
<a class="btn btn-primary" href="{% url 'letters:mark_hidden' pk=object.pk %}">
<i class="fa fa-pen"></i>
{% trans 'Mark hidden' %}
</a>
{% endif %}
{% if not object.is_spam_validated %}
<a class="btn btn-primary" href="{% url 'letters:spam' pk=object.pk %}">
<i class="fa fa-bullhorn"></i>
Expand Down
17 changes: 10 additions & 7 deletions feder/letters/templates/letters/_milestone.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<li>
<i class="milestone-default fa {% if object.author_institution %}fa-home{% elif object.author_user %}fa-user{% else %}fa-envelope{% endif %}"></i>
<div class="gray">
{% include 'letters/_header.html' with object=object %}
{% include 'letters/_object.html' with object=object %}
</div>
</li>
{% if not object.is_hidden %}
{# TODO: Style display of hidden letter #}
<li>
<i class="milestone-default fa {% if object.author_institution %}fa-home{% elif object.author_user %}fa-user{% else %}fa-envelope{% endif %}"></i>
<div class="gray">
{% include 'letters/_header.html' with object=object %}
{% include 'letters/_object.html' with object=object %}
</div>
</li>
{% endif %}
5 changes: 4 additions & 1 deletion feder/letters/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from feder.monitorings.factories import MonitoringFactory
from feder.users.factories import UserFactory
from ..factories import (IncomingLetterFactory, LetterFactory,
OutgoingLetterFactory, SendOutgoingLetterFactory)
OutgoingLetterFactory, SendOutgoingLetterFactory, HiddenLetterFactory)
from ..models import Letter
from feder.letters.signals import MessageParser

Expand Down Expand Up @@ -114,6 +114,9 @@ def test_send_new_case_adds_footer_from_monitoring(self):
self.assertIn(footer_text, mail.outbox[0].body,
"Email for a new case should contain footer text from monitoring")

def test_is_hidden(self):
self.assertEqual(HiddenLetterFactory().is_hidden, True)


class IncomingEmailTestCase(MessageMixin, TestCase):
def test_case_identification(self):
Expand Down
14 changes: 13 additions & 1 deletion feder/letters/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from feder.main.mixins import PermissionStatusMixin
from feder.monitorings.factories import MonitoringFactory
from feder.users.factories import UserFactory
from ..factories import IncomingLetterFactory, OutgoingLetterFactory
from ..factories import IncomingLetterFactory, OutgoingLetterFactory, HiddenLetterFactory
from django.utils.translation import ugettext_lazy as _


Expand Down Expand Up @@ -69,6 +69,18 @@ def test_contains_link_to_report_spam(self):
self.assertContains(response, _("Report spam"))
self.assertContains(response, reverse('letters:spam', kwargs={'pk': self.letter.pk}))

def test_contains_link_to_hide_link(self):
self.permission = ['monitorings.hide_letter']
self.login_permitted_user()
response = self.client.get(self.get_url())
self.assertContains(response, _("Mark hidden"))
self.assertContains(response, reverse('letters:mark_hidden', kwargs={'pk': self.letter.pk}))

def test_show_content_of_hidden_letter(self):
letter = HiddenLetterFactory(case=self.case)
response = self.client.get(self.get_url())
self.assertNotContains(response, letter.body)


class LetterCreateViewTestCase(ObjectMixin, PermissionStatusMixin, TestCase):
permission = ['monitorings.add_letter', ]
Expand Down
3 changes: 3 additions & 0 deletions feder/letters/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
name="spam"),
url(_(r'^(?P<pk>[\d-]+)/~mark-spam'), views.LetterMarkSpamView.as_view(),
name="mark_spam"),
url(_(r'^(?P<pk>[\d-]+)/~mark-hidden'), views.LetterMarkHiddenView.as_view(),
name="mark_hidden"),

url(_(r'^messages/logs/'), include(messages_urlpatterns, namespace="messages")),
]
Loading