Skip to content

Commit

Permalink
Merge pull request #213 from maykinmedia/revert-212-revert-211-issues…
Browse files Browse the repository at this point in the history
…#2022-05-09

✨ #481 - Handle situation where the user has been made inact…"
  • Loading branch information
alextreme authored Jun 2, 2022
2 parents db912a9 + 30971ab commit 2b30068
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/open_inwoner/accounts/templates/accounts/inbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ <h1 class="h1">{% trans 'Mijn berichten' %}</h1>

{% block content %}
{% if conversation_messages or other_user %}
{% messages conversation_messages request.user form other_user.get_full_name status %}
{% messages message_list=conversation_messages me=request.user form=form other_user=other_user status=status %}
{% endif %}
{% endblock %}
1 change: 0 additions & 1 deletion src/open_inwoner/accounts/views/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def get_initial(self):
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["user"] = self.request.user

return kwargs

def form_valid(self, form):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load button_tags form_tags messages_tags %}
{% load i18n button_tags form_tags messages_tags %}

<section class="messages">
<header class="messages__header">
Expand Down Expand Up @@ -37,18 +37,21 @@ <h4 class="p p--muted">{{ day.text }}</h4>
{% endfor %}
</ol>

{% render_form id="message-form" form=form method="POST" enctype="multipart/form-data" %}
{% csrf_token %}
{% hidden form.receiver %}
<div class="group-input">
{% textarea form.content %}
<div class="group-input__toolbar">
{% input form.file icon="attach_file" no_label=True no_help=True extra_classes="message-file" %}
{% button class="emoji-button" icon="tag_faces" text=_('Selecteer emoji') hide_text=True type="button" %}
{% if other_user.is_active %}
{% render_form id="message-form" form=form method="POST" enctype="multipart/form-data" %}
{% csrf_token %}
{% hidden form.receiver %}
<div class="group-input">
{% textarea form.content %}
<div class="group-input__toolbar">
{% input form.file icon="attach_file" no_label=True no_help=True extra_classes="message-file" %}
{% button class="emoji-button" icon="tag_faces" text=_('Selecteer emoji') hide_text=True type="button" %}
</div>
</div>
</div>
{% form_actions primary_text=_("Verzenden") primary_icon='arrow_forward' %}
{% endrender_form %}

{% form_actions primary_text=_("Verzenden") primary_icon='arrow_forward' %}
{% endrender_form %}
{% else %}
<p class="p p--muted">{% trans "De gebruiker is inactief. Het is niet mogelijk een bericht te sturen." %}</p>
{% endif %}
</div>
</section>
10 changes: 6 additions & 4 deletions src/open_inwoner/components/templatetags/messages_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ def messages(
message_list: MessageQuerySet,
me: User,
form: Form,
subject: str,
other_user: str,
status: str,
):
"""
Generate all messages in a conversation and shows the form to add a new message
Usage:
{% messages message_list=messages me=request.user form=message_form subject="this is the subject" status="open" %}
{% messages message_list=messages me=request.user form=message_form other_user=other_user status="open" %}
Variables:
+ message_list: Message[] | a list of messages that needs to be displayed.
+ me: User | currently loggedin user.
+ form: Form | a django form.
+ subject: string | The title that will be displayed above the messages.
+ other_user: User | The user that we will be messaging.
+ status: string | The status below the subject.
Extra context:
- days: set | the message_list grouped by date.
- subject: string | The title that will be displayed above the messages.
"""

def get_dates(message_list: MessageQuerySet) -> List[datetime.date]:
Expand Down Expand Up @@ -80,7 +81,8 @@ def get_messages_by_date(message_list: MessageQuerySet) -> List[dict]:
"form": form,
"me": me,
"status": status,
"subject": subject,
"other_user": other_user,
"subject": other_user.get_full_name(),
}


Expand Down
18 changes: 10 additions & 8 deletions src/open_inwoner/components/tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ def setUp(self) -> None:
self.me = UserFactory.create(
first_name="My", last_name="User", email="myuser@example.com"
)
other_user = UserFactory.create(
self.other_user = UserFactory.create(
first_name="Other", last_name="User", email="otheruser@example.com"
)

self.message_1 = MessageFactory.create(
sender=self.me,
receiver=other_user,
receiver=self.other_user,
created_on=timezone.now() - datetime.timedelta(days=2),
content="Lorem ipsum.",
)
self.message_2 = MessageFactory.create(
sender=self.me,
receiver=other_user,
receiver=self.other_user,
created_on=timezone.now() - datetime.timedelta(days=1),
content="Dolor sit amet.",
)
self.message_3 = MessageFactory.create(
sender=other_user,
sender=self.other_user,
receiver=self.me,
created_on=timezone.now(),
content="Consectetur adipiscing elit.",
)
self.message_4 = MessageFactory.create(
sender=self.me,
receiver=other_user,
receiver=self.other_user,
created_on=timezone.now() - datetime.timedelta(hours=2),
content="Maecenas dignissim felis nec purus viverra.",
)
Expand All @@ -54,7 +54,7 @@ def setUp(self) -> None:
"message_list": message_queryset,
"me": self.me,
"form": InboxForm(user=self.me),
"subject": "Lorem ipsum.",
"other_user": self.other_user,
"status": "Dolor sit amet.",
}

Expand All @@ -64,7 +64,7 @@ def test_render(self):
"message_list": [],
"me": self.me,
"form": InboxForm(user=self.me),
"subject": "Lorem ipsum.",
"other_user": self.other_user,
"status": "Dolor sit amet.",
}
)
Expand Down Expand Up @@ -133,7 +133,9 @@ def test_subject(self):
Tests that:
- Header renders the correct subject.
"""
self.assertTextContent(".messages__header .h4", "Lorem ipsum.", self.config)
self.assertTextContent(
".messages__header .h4", self.other_user.get_full_name(), self.config
)

def test_status(self):
"""
Expand Down
22 changes: 22 additions & 0 deletions src/open_inwoner/pdc/migrations/0038_alter_category_highlighted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.13 on 2022-06-01 08:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("pdc", "0037_category_highlighted"),
]

operations = [
migrations.AlterField(
model_name="category",
name="highlighted",
field=models.BooleanField(
default=False,
help_text="Wether the category should be highlighted or not.",
verbose_name="Highlighted",
),
),
]
2 changes: 2 additions & 0 deletions src/open_inwoner/scss/components/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
}

&--disabled {
background-color: var(--color-gray) !important;
border-color: var(--color-gray) !important;
color: var(--color-gray-light);
pointer-events: none;
cursor: default;
Expand Down

0 comments on commit 2b30068

Please sign in to comment.