-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide admin for email view (let's use see email HTML formatting)
- Loading branch information
Showing
8 changed files
with
119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% load user_tags %} | ||
{% load ui_utils %} | ||
{% load js_tags %} | ||
{% if render_mode == "embedded" %} | ||
{% labelled label="Created" %}{% timestamp email.created %}{% endlabelled %} | ||
{% labelled label="Subject" %}{{ email.subject }}{% endlabelled %} | ||
{% else %} | ||
{% admin_link email %}<br/> | ||
{% endif %} | ||
<label class="mb-4 mt-2">Recipients</label>: | ||
<div> | ||
{% for email_address in unrecognised %} | ||
<div class="text-dark" style="font-size:9pt"><i class="fa-regular fa-envelope mx-1"></i> {{ email_address }}</div> | ||
{% endfor %} | ||
{% for email_user in users %} | ||
<div class="mt-1">{% user email_user show_avatar=True show_email=True show_group=True size='tiny' %}</div> | ||
{% endfor %} | ||
</div> | ||
<label class="my-4">Content</label>: | ||
<div class="border rounded p-4" style="background-color:#fdfdfd"> | ||
{{ email.html | safe }} | ||
</div> |
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,9 @@ | ||
{% extends "uicore/page/base.html" %} | ||
{% load ui_menu_bars %} | ||
{% block title %}Email{% endblock title %} | ||
{% block submenu %}{% menu_bar_settings %}{% endblock submenu %} | ||
{% block content %} | ||
<div class="container"> | ||
<table id="email-datatable" class="event-table sticky-header" data-datatable-responsive="true" data-datatable-url="{% url 'email_datatable' %}"></table> | ||
</div> | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from email_manager.views.email_manager_views import email_manager_view, EmailColumns, email_detail | ||
from snpdb.views.datatable_view import DatabaseTableView | ||
from variantgrid.perm_path import perm_path | ||
|
||
urlpatterns = [ | ||
perm_path('', email_manager_view, name='email_log'), | ||
perm_path('detail/<int:email_id>', email_detail, name='email_detail'), | ||
perm_path('datatable', DatabaseTableView.as_view(column_class=EmailColumns), name='email_datatable') | ||
] |
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,69 @@ | ||
from typing import List | ||
from django.contrib.auth.models import User | ||
from django.core.exceptions import PermissionDenied | ||
from django.db.models import QuerySet, Q | ||
from django.http import HttpRequest | ||
from django.shortcuts import render | ||
from email_manager.models import EmailLog | ||
from library.django_utils import require_superuser | ||
from library.utils.django_utils import render_ajax_view | ||
from snpdb.views.datatable_view import DatatableConfig, RichColumn, SortOrder, CellData | ||
|
||
|
||
@require_superuser | ||
def email_manager_view(request): | ||
return render(request, 'email_log.html', context={}) | ||
|
||
|
||
@require_superuser | ||
def email_detail(request, email_id: int): | ||
email_log = EmailLog.objects.get(pk=email_id) | ||
recipients = [address.strip() for address in email_log.recipient_list.split(";")] | ||
recipients = [address for address in recipients if address] | ||
users: List[User] = list(User.objects.filter(email__in=recipients).order_by('email').all()) | ||
unrecognised_emails = set(recipients) | ||
check_user: User | ||
for check_user in users: | ||
unrecognised_emails.discard(check_user.email) | ||
unrecognised_email_list = list(sorted(unrecognised_emails)) | ||
unrecognised_email_list += ["foo@bar", "cat@dog", "what#ddfd"] | ||
|
||
return render_ajax_view( | ||
request, | ||
'email_detail.html', | ||
context={"email": email_log, "users": users, "unrecognised": unrecognised_email_list}, | ||
menubar='settings' | ||
) | ||
|
||
|
||
class EmailColumns(DatatableConfig[EmailLog]): | ||
|
||
def power_search(self, qs: QuerySet[EmailLog], search_string: str) -> QuerySet[EmailLog]: | ||
if search_string: | ||
qs = qs.filter(Q(recipient_list__icontains=search_string) | Q(subject__icontains=search_string)) | ||
return qs | ||
|
||
def recipient_renderer(self, row: CellData): | ||
if filename := row.get('filename'): | ||
return filename | ||
elif detail := row.get('details'): | ||
return detail.split('\n', 1)[0] | ||
|
||
def __init__(self, request: HttpRequest): | ||
super().__init__(request) | ||
if not self.user.is_superuser: | ||
raise PermissionDenied("Email log requires admin privileges") | ||
|
||
self.search_box_enabled = True | ||
|
||
self.expand_client_renderer = DatatableConfig._row_expand_ajax('email_detail', expected_height=300) | ||
self.rich_columns = [ | ||
RichColumn('created', client_renderer='TableFormat.timestamp', orderable=True, default_sort=SortOrder.DESC), | ||
RichColumn('subject', orderable=True), | ||
RichColumn('recipient_list', label='Recipients', orderable=False), | ||
RichColumn('probably_sent', client_renderer='TableFormat.boolean.bind(null, "false_is_error")'), | ||
RichColumn('id', visible=False) | ||
] | ||
|
||
def get_initial_queryset(self) -> QuerySet[EmailLog]: | ||
return EmailLog.objects.all() |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"analysis", | ||
"annotation", | ||
"eventlog", | ||
"email_manager", | ||
"flags", | ||
"genes", | ||
"pathtests", | ||
|