Skip to content

Commit

Permalink
[#1050] Implemented basic zaakinformationobject notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van der Schoor committed Feb 7, 2023
1 parent 74be124 commit 1a6cdf4
Show file tree
Hide file tree
Showing 13 changed files with 1,391 additions and 819 deletions.
10 changes: 5 additions & 5 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,15 @@
],
},
"case_notification": {
"name": _("Case status update notification"),
"name": _("Case update notification"),
"description": _(
"This email is used to notify people a status update happened to their case"
"This email is used to notify people an update happened to their case"
),
"subject_default": "Status update to your case at {{ site_name }}",
"subject_default": "Update to your case at {{ site_name }}",
"body_default": """
<p>Beste</p>
<p>You are receiving this email because one of your cases received a status update.</p>
<p>You are receiving this email because one of your cases received a new status update or document attachment.</p>
<table>
<tr>
Expand Down Expand Up @@ -962,7 +962,7 @@
},
{
"name": "case_link",
"description": _("The link to your case details."),
"description": _("The link to the case details."),
},
{
"name": "site_name",
Expand Down
23 changes: 23 additions & 0 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .models import (
CatalogusConfig,
OpenZaakConfig,
UserCaseInfoObjectNotification,
UserCaseStatusNotification,
ZaakTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
Expand Down Expand Up @@ -211,3 +212,25 @@ class UserCaseStatusNotificationAdmin(admin.ModelAdmin):

def has_change_permission(self, request, obj=None):
return False


@admin.register(UserCaseInfoObjectNotification)
class UserCaseInfoObjectNotificationAdmin(admin.ModelAdmin):
raw_id_fields = ["user"]
search_fields = [
"user__first_name",
"user__last_name",
"user__email",
"user__id",
"case_uuid",
"zaak_info_object_uuid",
]
list_display = [
"user",
"case_uuid",
"zaak_info_object_uuid",
"created",
]

def has_change_permission(self, request, obj=None):
return False
23 changes: 23 additions & 0 deletions src/open_inwoner/openzaak/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ def fetch_single_case(case_uuid: str) -> Optional[Zaak]:
return case


@cache_result(
"single_case_information_object:{url}", timeout=settings.CACHE_ZGW_ZAKEN_TIMEOUT
)
def fetch_single_case_information_object(url: str) -> Optional[ZaakInformatieObject]:
client = build_client("zaak")

if client is None:
return

try:
response = client.retrieve("zaakinformatieobject", url=url)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
logger.exception("exception while making request", exc_info=e)
return

case = factory(ZaakInformatieObject, response)

return case


def fetch_case_by_url_no_cache(case_url: str) -> Optional[Zaak]:
client = build_client("zaak")
try:
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/openzaak/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def upload_document(
"inhoud": base64.b64encode(file.read()).decode("utf-8"),
"bestandsomvang": file.size,
"bestandsnaam": file.name,
"status": "definitief",
# "status": "definitief",
"taal": "nld",
"informatieobjecttype": ZaakTypeInformatieObjectTypeConfig.objects.get(
id=user_choice
Expand Down
42 changes: 28 additions & 14 deletions src/open_inwoner/openzaak/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@
from open_inwoner.accounts.models import User

if TYPE_CHECKING:
from open_inwoner.openzaak.models import UserCaseStatusNotification
from open_inwoner.openzaak.models import (
UserCaseInfoObjectNotification,
UserCaseStatusNotification,
)


class UserCaseStatusNotificationQueryset(models.QuerySet):
def get_user_case_notifications(self, user, case_uuid):
return self.filter(user=user, case_uuid=case_uuid)

def has_notification(self, user, case_uuid, status_uuid):
return self.filter(
user=user, case_uuid=case_uuid, status_uuid=status_uuid
).exists()


class UserCaseStatusNotificationManager(
models.Manager.from_queryset(UserCaseStatusNotificationQueryset)
):
class UserCaseStatusNotificationManager(models.Manager):
def record_if_unique_notification(
self,
user: User,
Expand All @@ -44,6 +35,29 @@ def record_if_unique_notification(
return None


class UserCaseInfoObjectNotificationManager(models.Manager):
def record_if_unique_notification(
self,
user: User,
case_uuid: UUID,
zaak_info_object_uuid: UUID,
) -> Optional["UserCaseInfoObjectNotification"]:
"""
assume this is the first delivery but depend on the unique constraint
"""
kwargs = {
"user": user,
"case_uuid": case_uuid,
"zaak_info_object_uuid": zaak_info_object_uuid,
}
try:
with transaction.atomic():
note = self.create(**kwargs)
return note
except IntegrityError:
return None


class ZaakTypeInformatieObjectTypeConfigQueryset(models.QuerySet):
def get_visible_ztiot_configs_for_case(self, case):
"""
Expand Down
63 changes: 63 additions & 0 deletions src/open_inwoner/openzaak/migrations/0011_auto_20230207_1030.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generated by Django 3.2.15 on 2023-02-07 09:30

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


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("openzaak", "0010_openzaakconfig_reformat_esuite_zaak_identificatie"),
]

operations = [
migrations.AlterModelOptions(
name="usercasestatusnotification",
options={"verbose_name": "Open Zaak status notification record"},
),
migrations.CreateModel(
name="UserCaseInfoObjectNotification",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("case_uuid", models.UUIDField(verbose_name="Zaak UUID")),
(
"zaak_info_object_uuid",
models.UUIDField(verbose_name="InformatieObject UUID"),
),
(
"created",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="Created"
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "Open Zaak info object notification record",
},
),
migrations.AddConstraint(
model_name="usercaseinfoobjectnotification",
constraint=models.UniqueConstraint(
fields=("user", "case_uuid", "zaak_info_object_uuid"),
name="unique_user_case_info_object",
),
),
]
29 changes: 28 additions & 1 deletion src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from zgw_consumers.constants import APITypes

from open_inwoner.openzaak.managers import (
UserCaseInfoObjectNotificationManager,
UserCaseStatusNotificationManager,
ZaakTypeConfigQueryset,
ZaakTypeInformatieObjectTypeConfigQueryset,
Expand Down Expand Up @@ -258,11 +259,37 @@ class UserCaseStatusNotification(models.Model):
objects = UserCaseStatusNotificationManager()

class Meta:
verbose_name = _("Open Zaak notification user inform record")
verbose_name = _("Open Zaak status notification record")

constraints = [
UniqueConstraint(
name="unique_user_case_status",
fields=["user", "case_uuid", "status_uuid"],
)
]


class UserCaseInfoObjectNotification(models.Model):
user = models.ForeignKey(
"accounts.User",
on_delete=models.CASCADE,
)
case_uuid = models.UUIDField(
verbose_name=_("Zaak UUID"),
)
zaak_info_object_uuid = models.UUIDField(
verbose_name=_("InformatieObject UUID"),
)
created = models.DateTimeField(verbose_name=_("Created"), default=timezone.now)

objects = UserCaseInfoObjectNotificationManager()

class Meta:
verbose_name = _("Open Zaak info object notification record")

constraints = [
UniqueConstraint(
name="unique_user_case_info_object",
fields=["user", "case_uuid", "zaak_info_object_uuid"],
)
]
Loading

0 comments on commit 1a6cdf4

Please sign in to comment.