Skip to content

Commit

Permalink
Merge pull request #1547 from laws-africa/report-issue
Browse files Browse the repository at this point in the history
Add functionality for reporting a document with an issue
  • Loading branch information
longhotsummer authored Sep 28, 2023
2 parents 595a0ac + 1e00330 commit 1b31217
Show file tree
Hide file tree
Showing 23 changed files with 5,261 additions and 631 deletions.
2 changes: 2 additions & 0 deletions africanlii/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@

# add middleware to redirect from agp.africanlii.org to africanlii.org
MIDDLEWARE.insert(1, "africanlii.middleware.RedirectAGPMiddleware") # noqa

ADMINS = [("AfricanLII", "[email protected]")]
2 changes: 2 additions & 0 deletions liiweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
# Court codes mappings for legacy lii urls
# Override this in the lii settings.py
COURT_CODE_MAPPINGS = {}

ADMINS = [("Laws.Africa", "[email protected]")]
41 changes: 41 additions & 0 deletions peachjam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
from os.path import splitext

from django import forms
from django.conf import settings
from django.core.files import File
from django.core.mail import mail_admins
from django.http import QueryDict
from django.template.loader import render_to_string
from django.utils.text import slugify
from django.utils.translation import gettext as _

from peachjam.models import AttachedFiles, CoreDocument, Ingestor, SourceFile
from peachjam.plugins import plugins
Expand Down Expand Up @@ -197,3 +201,40 @@ class AttachedFilesForm(AttachmentFormMixin, forms.ModelForm):
class Meta:
model = AttachedFiles
fields = "__all__"


class DocumentProblemForm(forms.Form):
document_link = forms.CharField(max_length=255, required=True)
problem_description = forms.CharField(widget=forms.Textarea, required=True)
email_address = forms.EmailField(required=False)

def send_email(self):
document_link = self.cleaned_data["document_link"]
problem_description = self.cleaned_data["problem_description"]
email_address = self.cleaned_data["email_address"]

context = {
"document_link": document_link,
"problem_description": problem_description,
}
if email_address:
context["email_address"] = email_address

html = render_to_string(
"peachjam/emails/document_problem_email.html", context=context
)
plain_txt_msg = render_to_string(
"peachjam/emails/document_problem_email.txt",
context=context,
)

subject = _("Document problem reported on %(app_name)s") % {
"app_name": settings.PEACHJAM["APP_NAME"]
}

mail_admins(
subject=subject,
message=plain_txt_msg,
html_message=html,
fail_silently=False,
)
118 changes: 118 additions & 0 deletions peachjam/js/components/DocumentProblemModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<template>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 id="documentProblemModalTitle" class="modal-title">
{{ $t('Is there something wrong with this document?') }}
</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"/>
</div>
<div class="modal-body">
<form
v-if="!submitted"
id="document-problem-form"
ref="form"
method="post"
@submit.prevent="onSubmit"
>
<input
type="hidden"
name="document_link"
:value="url"
>
<div class="form-group mb-2">
<label for="problem_description">
{{ $t("What's the problem?") }}
<span class="text-danger">*</span>
</label>
<textarea
id="problem_description"
v-model="problem"
class="form-control"
name="problem_description"
rows="4"
required
/>
</div>
<div class="form-group">
<label for="email_address">{{ $t('Your email address (optional)') }}</label>
<input
id="email_address"
v-model="email"
type="email"
class="form-control"
name="email_address"
placeholder="[email protected]"
>
</div>
</form>
<div v-else>
{{ success ? $t('Thank you for your feedback.') : $t('Something went wrong.') }}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
{{ submitted ? $t('Close') : $t('Cancel') }}
</button>
<button
v-if="!submitted"
type="submit"
class="btn btn-success"
form="document-problem-form"
>
{{ $t('Report problem') }}
</button>
</div>
</div>
</div>
</template>

<script>
import { authHeaders } from '../api';
export default {
name: 'DocumentProblemModal',
data () {
return {
email: '',
message: '',
problem: '',
submitted: false,
success: true,
url: window.location.toString()
};
},
mounted () {
// attach a listener to the bootstrap modal events
this.$el.parentElement.addEventListener('show.bs.modal', this.onShow);
},
methods: {
onShow () {
this.email = '';
this.message = '';
this.problem = '';
this.submitted = false;
this.success = true;
},
onSubmit () {
const form = new FormData(this.$refs.form);
fetch('/document-problem/', {
method: 'post',
body: form,
headers: authHeaders()
}).then(response => {
this.submitted = true;
this.success = response.ok;
}).catch(error => {
console.log(error);
});
}
}
};
</script>
2 changes: 2 additions & 0 deletions peachjam/js/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ToggleTab } from './tabs';
import TaxonomyTree from './taxonomy-tree';
import TermsOfUse from './terms-of-use';

import DocumentProblemModal from './DocumentProblemModal.vue';
import FindDocuments from './FindDocuments/index.vue';
import LegislationTable from './LegislationTable/index.vue';
import PocketLawDownload from './PocketLawDownload.vue';
Expand All @@ -23,6 +24,7 @@ const components: Record<string, any> = {
TermsOfUse,

// Vue components
DocumentProblemModal,
FindDocuments,
LegislationTable,
PocketLawDownload
Expand Down
13 changes: 11 additions & 2 deletions peachjam/js/locale/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"{document_count} documents found.": "{document_count} documents found.",
"{document_count} documents found": "{document_count} documents found.",
"{reverse_verb} this provision": "{reverse_verb} this provision",
"Advanced search": "Advanced search",
"All these words": "All these words",
Expand All @@ -9,6 +9,7 @@
"Attorneys": "Attorneys",
"Author": "Author",
"Between {prev_expression_date} and {new_expression_date}": "Between {prev_expression_date} and {new_expression_date}",
"Cancel": "Cancel",
"Clear": "Clear",
"Clear all": "Clear all",
"Close": "Close",
Expand All @@ -30,13 +31,15 @@
"Expand all": "Expand all",
"Filters": "Filters",
"Help": "Help",
"Is there something wrong with this document?": "Is there something wrong with this document?",
"Judges": "Judges",
"Jurisdiction": "Jurisdiction",
"Language": "Language",
"Link citation": "Link citation",
"Loading": "Loading",
"Locality": "Locality",
"Matter type": "Matter type",
"More than 10,000 documents found": "More than 10,000 documents found.",
"Multiple languages available": "Multiple languages available",
"Nature": "Nature",
"No documents match your search": "No documents match your search.",
Expand All @@ -49,6 +52,8 @@
"Page": "Page",
"Regional body": "Regional body",
"Relevance": "Relevance",
"Remove": "Remove",
"Report problem": "Report problem",
"Search": "Search",
"Search {{appName}}": {
"": "Search {{appName}}..."
Expand All @@ -58,8 +63,10 @@
"Search table of contents": "Search table of contents",
"Share": "Share",
"Show changes side-by-side": "Show changes side-by-side",
"Something went wrong": "Something went wrong.",
"Sort by": "Sort by",
"Taxonomies": "Taxonomies",
"Thank you for your feedback": "Thank you for your feedback.",
"The date range is invalid": "The date range is invalid",
"This exact word or phrase": "This exact word or phrase",
"This provision": "This provision",
Expand All @@ -68,6 +75,8 @@
"To the top": "To the top",
"Try searching instead": "Try searching instead",
"What changed?": "What changed?",
"What's the problem?": "What's the problem?",
"Year": "Year",
"Years": "Years"
"Years": "Years",
"Your email address (optional)": "Your email address (optional)"
}
15 changes: 12 additions & 3 deletions peachjam/js/locale/fr/translation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"{document_count} documents found.": "{document_count} documents trouvés.",
"{document_count} documents found": "{document_count} documents trouvés.",
"{reverse_verb} this provision": "{reverse_verb} cette disposition",
"Advanced search": "Recherche avancée",
"All these words": "Tous ces mots",
Expand All @@ -9,6 +9,7 @@
"Attorneys": "Avocats",
"Author": "Auteur",
"Between {prev_expression_date} and {new_expression_date}": "Entre {prev_expression_date} et {new_expression_date}",
"Cancel": "Annuler",
"Clear": "Nettoyer",
"Clear all": "Effacer tout",
"Close": "Fermer",
Expand All @@ -30,13 +31,15 @@
"Expand all": "Développer tout",
"Filters": "Filtres",
"Help": "Aide",
"Is there something wrong with this document?": "Y a-t-il quelque chose qui ne va pas avec ce document?",
"Judges": "Juges",
"Jurisdiction": "Juridiction",
"Language": "Langue",
"Link citation": "Citation de lien",
"Loading": "En cours de chargement",
"Locality": "Localité",
"Matter type": "Type de matière",
"More than 10,000 documents found": "Plus de 10 000 documents trouvés.",
"Multiple languages available": "Plusieurs langues disponibles",
"Nature": "Nature",
"No documents match your search": "Aucun document ne correspond à votre recherche.",
Expand All @@ -49,6 +52,8 @@
"Page": "Page",
"Regional body": "Corps régional",
"Relevance": "Pertinence",
"Remove": "Retirer",
"Report problem": "Signaler un problème",
"Search": "Recherche",
"Search {{appName}}": {
"": "Rechercher dans {{appName}}..."
Expand All @@ -58,16 +63,20 @@
"Search table of contents": "Rechercher la table des matières",
"Share": "Partager",
"Show changes side-by-side": "Afficher les modifications côte à côte",
"Something went wrong": "Quelque chose s'est mal passé",
"Sort by": "Trier par",
"Taxonomies": "Taxonomies",
"Thank you for your feedback": "Merci pour votre commentaire.",
"The date range is invalid": "La plage de dates n'est pas valide",
"This exact word or phrase": "Cette phrase ou ce mot exact",
"This provision": "Cette disposition",
"This provision has been amended": "Cette disposition a été modifiée",
"Title": "Titre",
"To the top": "En haut",
"Try searching instead": "Essayez plutôt de faire une recherche",
"What changed?": "Quels sont les changements ?",
"What changed?": "Quels sont les changements?",
"What's the problem?": "Quel est le problème?",
"Year": "Année",
"Years": "Années"
"Years": "Années",
"Your email address (optional)": "Votre adresse e-mail (facultatif)"
}
15 changes: 12 additions & 3 deletions peachjam/js/locale/pt/translation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"{document_count} documents found.": "{document_count} documentos encontrados.",
"{document_count} documents found": "{document_count} documentos encontrados.",
"{reverse_verb} this provision": "{reverse_verb} esta disposição",
"Advanced search": "Pesquisa avançada",
"All these words": "Todas essas palavras",
Expand All @@ -9,6 +9,7 @@
"Attorneys": "Advogados",
"Author": "Autor",
"Between {prev_expression_date} and {new_expression_date}": "Entre {prev_expression_date} e {new_expression_date}",
"Cancel": "Cancelar",
"Clear": "Limpar",
"Clear all": "Limpar tudo",
"Close": "FECHAR",
Expand All @@ -30,13 +31,15 @@
"Expand all": "Expandir tudo",
"Filters": "Filtros",
"Help": "Socorro",
"Is there something wrong with this document?": "Há algo errado com este documento?",
"Judges": "Juízes",
"Jurisdiction": "Jurisdição",
"Language": "Idioma",
"Link citation": "Citação de link",
"Loading": "Carregando...",
"Locality": "Localidade",
"Matter type": "Tipo de matéria",
"More than 10,000 documents found": "Mais de 10.000 documentos encontrados.",
"Multiple languages available": "Vários idiomas disponíveis",
"Nature": "Natureza",
"No documents match your search": "Nenhum documento corresponde à sua pesquisa.",
Expand All @@ -49,6 +52,8 @@
"Page": "Página",
"Regional body": "Corpo regional",
"Relevance": "Relevância",
"Remove": "Remover",
"Report problem": "Reportar problema",
"Search": "Pesquisa",
"Search {{appName}}": {
"": "Pesquisar {{appName}}..."
Expand All @@ -58,8 +63,10 @@
"Search table of contents": "Pesquisar na tabela de conteúdos",
"Share": "Compartilhar",
"Show changes side-by-side": "Mostrar mudanças lado a lado",
"Something went wrong": "Algo deu errado",
"Sort by": "Classificar por",
"Taxonomies": "Taxonomies",
"Taxonomies": "Taxonomias",
"Thank you for your feedback": "Obrigado pelo seu feedback.",
"The date range is invalid": "O intervalo de datas é inválido",
"This exact word or phrase": "Esta palavra ou frase exata",
"This provision": "Esta disposição",
Expand All @@ -68,6 +75,8 @@
"To the top": "Para o topo",
"Try searching instead": "Tente pesquisar no lugar",
"What changed?": "O que mudou?",
"What's the problem?": "Qual é o problema?",
"Year": "Ano",
"Years": "anos"
"Years": "anos",
"Your email address (optional)": "Seu endereço de e-mail (opcional)"
}
Loading

0 comments on commit 1b31217

Please sign in to comment.