ActivityPub-federated video streaming platform using P2P directly in your web browser
Feature/subject in contact form (#1926)
Nassim Bounouas4e9fa5b7e9ca
diff --git a/client/src/app/+about/about-instance/contact-admin-modal.component.html b/client/src/app/+about/about-instance/contact-admin-modal.component.htmlindex b2cbd08738..c3c71bdeeb 100644--- a/client/src/app/+about/about-instance/contact-admin-modal.component.html+++ b/client/src/app/+about/about-instance/contact-admin-modal.component.html@@ -25,6 +25,15 @@<div *ngIf="formErrors.fromEmail" class="form-error">{{ formErrors.fromEmail }}</div></div>+ <div class="form-group">+ <label i18n for="subject">Subject</label>+ <input+ type="text" id="subject"+ formControlName="subject" [ngClass]="{ 'input-error': formErrors['subject'] }"+ >+ <div *ngIf="formErrors.subject" class="form-error">{{ formErrors.subject }}</div>+ </div>+<div class="form-group"><label i18n for="body">Your message</label><textarea id="body" formControlName="body" [ngClass]="{ 'input-error': formErrors['body'] }">diff --git a/client/src/app/+about/about-instance/contact-admin-modal.component.ts b/client/src/app/+about/about-instance/contact-admin-modal.component.tsindex 7d79c2215e..c609c98c3a 100644--- a/client/src/app/+about/about-instance/contact-admin-modal.component.ts+++ b/client/src/app/+about/about-instance/contact-admin-modal.component.ts@@ -39,6 +39,7 @@ export class ContactAdminModalComponent extends FormReactive implements OnInit {this.buildForm({fromName: this.instanceValidatorsService.FROM_NAME,fromEmail: this.instanceValidatorsService.FROM_EMAIL,+ subject: this.instanceValidatorsService.SUBJECT,body: this.instanceValidatorsService.BODY})}@@ -58,9 +59,10 @@ export class ContactAdminModalComponent extends FormReactive implements OnInit {sendForm () {const fromName = this.form.value['fromName']const fromEmail = this.form.value[ 'fromEmail' ]+ const subject = this.form.value[ 'subject' ]const body = this.form.value[ 'body' ]- this.instanceService.contactAdministrator(fromEmail, fromName, body)+ this.instanceService.contactAdministrator(fromEmail, fromName, subject, body).subscribe(() => {this.notifier.success(this.i18n('Your message has been sent.'))diff --git a/client/src/app/shared/forms/form-validators/instance-validators.service.ts b/client/src/app/shared/forms/form-validators/instance-validators.service.tsindex 5bb852858f..cc5f3c5a12 100644--- a/client/src/app/shared/forms/form-validators/instance-validators.service.ts+++ b/client/src/app/shared/forms/form-validators/instance-validators.service.ts@@ -7,6 +7,7 @@ import { Injectable } from '@angular/core'export class InstanceValidatorsService {readonly FROM_EMAIL: BuildFormValidatorreadonly FROM_NAME: BuildFormValidator+ readonly SUBJECT: BuildFormValidatorreadonly BODY: BuildFormValidatorconstructor (private i18n: I18n) {@@ -32,6 +33,19 @@ export class InstanceValidatorsService {}}+ this.SUBJECT = {+ VALIDATORS: [+ Validators.required,+ Validators.minLength(1),+ Validators.maxLength(120)+ ],+ MESSAGES: {+ 'required': this.i18n('A subject is required.'),+ 'minlength': this.i18n('The subject must be at least 1 character long.'),+ 'maxlength': this.i18n('The subject cannot be more than 120 characters long.')+ }+ }+this.BODY = {VALIDATORS: [Validators.required,diff --git a/client/src/app/shared/instance/instance.service.ts b/client/src/app/shared/instance/instance.service.tsindex 61321ecce4..d0c96941d1 100644--- a/client/src/app/shared/instance/instance.service.ts+++ b/client/src/app/shared/instance/instance.service.ts@@ -22,10 +22,11 @@ export class InstanceService {.pipe(catchError(res => this.restExtractor.handleError(res)))}- contactAdministrator (fromEmail: string, fromName: string, message: string) {+ contactAdministrator (fromEmail: string, fromName: string, subject: string, message: string) {const body = {fromEmail,fromName,+ subject,body: message}diff --git a/server/controllers/api/server/contact.ts b/server/controllers/api/server/contact.tsindex b1144c94e3..de02ffc0ba 100644--- a/server/controllers/api/server/contact.ts+++ b/server/controllers/api/server/contact.ts@@ -14,7 +14,7 @@ contactRouter.post('/contact',async function contactAdministrator (req: express.Request, res: express.Response) {const data = req.body as ContactForm- await Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.body)+ await Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.subject, data.body)await Redis.Instance.setContactFormIp(req.ip)diff --git a/server/lib/emailer.ts b/server/lib/emailer.tsindex c4a5a5853f..73c2bcb1b5 100644--- a/server/lib/emailer.ts+++ b/server/lib/emailer.ts@@ -402,7 +402,7 @@ class Emailer {return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })}- addContactFormJob (fromEmail: string, fromName: string, body: string) {+ addContactFormJob (fromEmail: string, fromName: string, subject: string, body: string) {const text = 'Hello dear admin,\n\n' +fromName + ' sent you a message' +'\n\n---------------------------------------\n\n' +@@ -415,7 +415,7 @@ class Emailer {fromDisplayName: fromEmail,replyTo: fromEmail,to: [ CONFIG.ADMIN.EMAIL ],- subject: CONFIG.EMAIL.OBJECT.PREFIX + 'Contact form submitted',+ subject: CONFIG.EMAIL.OBJECT.PREFIX + subject,text}diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.tsindex dbdd3a8a68..b3051945ed 100644--- a/server/tests/api/check-params/contact-form.ts+++ b/server/tests/api/check-params/contact-form.ts@@ -26,6 +26,7 @@ describe('Test contact form API validators', function () {const defaultBody = {fromName: 'super name',fromEmail: '[email protected]',+ subject: 'my subject',body: 'Hello, how are you?'}let emailPort: numberdiff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.tsindex 87e55060ca..e4e895acb3 100644--- a/server/tests/api/server/contact-form.ts+++ b/server/tests/api/server/contact-form.ts@@ -43,6 +43,7 @@ describe('Test contact form', function () {url: server.url,fromEmail: '[email protected]',body: 'my super message',+ subject: 'my subject',fromName: 'Super toto'})@@ -55,7 +56,7 @@ describe('Test contact form', function () {expect(email['from'][0]['address']).equal('test-admin@localhost')expect(email['from'][0]['name']).equal('[email protected]')expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')- expect(email['subject']).contains('Contact form')+ expect(email['subject']).contains('my subject')expect(email['text']).contains('my super message')})@@ -64,6 +65,7 @@ describe('Test contact form', function () {url: server.url,fromEmail: '[email protected]',body: 'my super message',+ subject: 'my subject',fromName: 'Super toto'})@@ -72,6 +74,7 @@ describe('Test contact form', function () {fromEmail: '[email protected]',body: 'my super message',fromName: 'Super toto',+ subject: 'my subject',expectedStatus: 403})})@@ -82,8 +85,9 @@ describe('Test contact form', function () {await sendContactForm({url: server.url,fromEmail: '[email protected]',- body: 'my super message',- fromName: 'Super toto'+ fromName: 'Super toto',+ subject: 'my subject',+ body: 'my super message'})})diff --git a/shared/extra-utils/server/contact-form.ts b/shared/extra-utils/server/contact-form.tsindex 80394cf994..e002e03dd7 100644--- a/shared/extra-utils/server/contact-form.ts+++ b/shared/extra-utils/server/contact-form.ts@@ -5,6 +5,7 @@ function sendContactForm (options: {url: string,fromEmail: string,fromName: string,+ subject: string,body: string,expectedStatus?: number}) {@@ -13,6 +14,7 @@ function sendContactForm (options: {const body: ContactForm = {fromEmail: options.fromEmail,fromName: options.fromName,+ subject: options.subject,body: options.body}return request(options.url)diff --git a/shared/models/server/contact-form.model.ts b/shared/models/server/contact-form.model.tsindex 0696be8b4f..c23e6d1bac 100644--- a/shared/models/server/contact-form.model.ts+++ b/shared/models/server/contact-form.model.ts@@ -1,5 +1,6 @@export interface ContactForm {fromEmail: stringfromName: string+ subject: stringbody: string}