aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-09 15:14:29 +0100
committerChocobozzz <me@florianbigard.com>2019-01-10 11:32:37 +0100
commita4101923e699e49ceb9ff36e971c75417fafc9f0 (patch)
treec098a87ac5a85e1bc7454facbb59ecbd6c7dac82 /shared
parent8d00889b6038c38d9c86cbeca88a9f3c23962c48 (diff)
downloadPeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.tar.gz
PeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.tar.zst
PeerTube-a4101923e699e49ceb9ff36e971c75417fafc9f0.zip
Implement contact form on server side
Diffstat (limited to 'shared')
-rw-r--r--shared/models/server/contact-form.model.ts5
-rw-r--r--shared/models/server/custom-config.model.ts4
-rw-r--r--shared/models/server/index.ts6
-rw-r--r--shared/models/server/server-config.model.ts4
-rw-r--r--shared/utils/miscs/email.ts4
-rw-r--r--shared/utils/server/config.ts3
-rw-r--r--shared/utils/server/contact-form.ts28
7 files changed, 54 insertions, 0 deletions
diff --git a/shared/models/server/contact-form.model.ts b/shared/models/server/contact-form.model.ts
new file mode 100644
index 000000000..0696be8b4
--- /dev/null
+++ b/shared/models/server/contact-form.model.ts
@@ -0,0 +1,5 @@
1export interface ContactForm {
2 fromEmail: string
3 fromName: string
4 body: string
5}
diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts
index 028aafa1a..7a3eaa33f 100644
--- a/shared/models/server/custom-config.model.ts
+++ b/shared/models/server/custom-config.model.ts
@@ -41,6 +41,10 @@ export interface CustomConfig {
41 email: string 41 email: string
42 } 42 }
43 43
44 contactForm: {
45 enabled: boolean
46 }
47
44 user: { 48 user: {
45 videoQuota: number 49 videoQuota: number
46 videoQuotaDaily: number 50 videoQuotaDaily: number
diff --git a/shared/models/server/index.ts b/shared/models/server/index.ts
new file mode 100644
index 000000000..c42f6f67f
--- /dev/null
+++ b/shared/models/server/index.ts
@@ -0,0 +1,6 @@
1export * from './about.model'
2export * from './contact-form.model'
3export * from './custom-config.model'
4export * from './job.model'
5export * from './server-config.model'
6export * from './server-stats.model'
diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts
index a6d28e05e..7031009d9 100644
--- a/shared/models/server/server-config.model.ts
+++ b/shared/models/server/server-config.model.ts
@@ -19,6 +19,10 @@ export interface ServerConfig {
19 enabled: boolean 19 enabled: boolean
20 } 20 }
21 21
22 contactForm: {
23 enabled: boolean
24 }
25
22 signup: { 26 signup: {
23 allowed: boolean, 27 allowed: boolean,
24 allowedForCurrentIP: boolean, 28 allowedForCurrentIP: boolean,
diff --git a/shared/utils/miscs/email.ts b/shared/utils/miscs/email.ts
index 6fac7621f..f9f1bd95b 100644
--- a/shared/utils/miscs/email.ts
+++ b/shared/utils/miscs/email.ts
@@ -15,6 +15,8 @@ class MockSmtpServer {
15 return this.emails.push(msg.email) 15 return this.emails.push(msg.email)
16 } 16 }
17 }) 17 })
18
19 process.on('exit', () => this.kill())
18 } 20 }
19 21
20 collectEmails (emailsCollection: object[]) { 22 collectEmails (emailsCollection: object[]) {
@@ -42,6 +44,8 @@ class MockSmtpServer {
42 } 44 }
43 45
44 kill () { 46 kill () {
47 if (!this.emailChildProcess) return
48
45 process.kill(this.emailChildProcess.pid) 49 process.kill(this.emailChildProcess.pid)
46 50
47 this.emailChildProcess = null 51 this.emailChildProcess = null
diff --git a/shared/utils/server/config.ts b/shared/utils/server/config.ts
index ff5288c82..0c5512bab 100644
--- a/shared/utils/server/config.ts
+++ b/shared/utils/server/config.ts
@@ -80,6 +80,9 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) {
80 admin: { 80 admin: {
81 email: 'superadmin1@example.com' 81 email: 'superadmin1@example.com'
82 }, 82 },
83 contactForm: {
84 enabled: true
85 },
83 user: { 86 user: {
84 videoQuota: 5242881, 87 videoQuota: 5242881,
85 videoQuotaDaily: 318742 88 videoQuotaDaily: 318742
diff --git a/shared/utils/server/contact-form.ts b/shared/utils/server/contact-form.ts
new file mode 100644
index 000000000..80394cf99
--- /dev/null
+++ b/shared/utils/server/contact-form.ts
@@ -0,0 +1,28 @@
1import * as request from 'supertest'
2import { ContactForm } from '../../models/server'
3
4function sendContactForm (options: {
5 url: string,
6 fromEmail: string,
7 fromName: string,
8 body: string,
9 expectedStatus?: number
10}) {
11 const path = '/api/v1/server/contact'
12
13 const body: ContactForm = {
14 fromEmail: options.fromEmail,
15 fromName: options.fromName,
16 body: options.body
17 }
18 return request(options.url)
19 .post(path)
20 .send(body)
21 .expect(options.expectedStatus || 204)
22}
23
24// ---------------------------------------------------------------------------
25
26export {
27 sendContactForm
28}