diff options
author | Chocobozzz <me@florianbigard.com> | 2020-02-17 10:27:00 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-02-17 10:27:00 +0100 |
commit | 4c1c17093461b58d3ee3f23f239e340d8dac1149 (patch) | |
tree | 236b724f1415a812a4274fd63b519124cba2e42f | |
parent | 45f1bd72a08998c60a9dd68ff069cea9de39161c (diff) | |
download | PeerTube-4c1c17093461b58d3ee3f23f239e340d8dac1149.tar.gz PeerTube-4c1c17093461b58d3ee3f23f239e340d8dac1149.tar.zst PeerTube-4c1c17093461b58d3ee3f23f239e340d8dac1149.zip |
Refactor email enabled function
-rw-r--r-- | client/src/app/+video-channels/video-channels.component.scss | 8 | ||||
-rw-r--r-- | client/src/app/header/search-typeahead.component.ts | 22 | ||||
-rw-r--r-- | client/src/sass/include/_variables.scss | 4 | ||||
-rw-r--r-- | server/controllers/api/config.ts | 5 | ||||
-rw-r--r-- | server/controllers/static.ts | 11 | ||||
-rw-r--r-- | server/helpers/custom-validators/users.ts | 7 | ||||
-rw-r--r-- | server/initializers/checker-after-init.ts | 5 | ||||
-rw-r--r-- | server/initializers/config.ts | 7 | ||||
-rw-r--r-- | server/lib/emailer.ts | 6 | ||||
-rw-r--r-- | server/middlewares/validators/config.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/server.ts | 5 |
11 files changed, 37 insertions, 47 deletions
diff --git a/client/src/app/+video-channels/video-channels.component.scss b/client/src/app/+video-channels/video-channels.component.scss index aa26a7e7b..6470629f8 100644 --- a/client/src/app/+video-channels/video-channels.component.scss +++ b/client/src/app/+video-channels/video-channels.component.scss | |||
@@ -12,12 +12,10 @@ | |||
12 | display: grid !important; | 12 | display: grid !important; |
13 | grid-template-columns: 1fr auto; | 13 | grid-template-columns: 1fr auto; |
14 | grid-template-rows: 1fr auto / 1fr auto; | 14 | grid-template-rows: 1fr auto / 1fr auto; |
15 | grid-template-areas: "name buttons" | 15 | grid-template-areas: "name buttons" "lower buttons"; |
16 | "lower buttons"; | ||
17 | 16 | ||
18 | @media screen and (max-width: #{map-get($grid-breakpoints, lg)}) { | 17 | @media screen and (max-width: #{map-get($grid-breakpoints, lg)}) { |
19 | grid-template-areas: "name name" | 18 | grid-template-areas: "name name" "lower buttons"; |
20 | "lower buttons"; | ||
21 | } | 19 | } |
22 | } | 20 | } |
23 | 21 | ||
@@ -53,4 +51,4 @@ | |||
53 | my-subscribe-button { | 51 | my-subscribe-button { |
54 | height: min-content; | 52 | height: min-content; |
55 | } | 53 | } |
56 | } \ No newline at end of file | 54 | } |
diff --git a/client/src/app/header/search-typeahead.component.ts b/client/src/app/header/search-typeahead.component.ts index 210a1474c..372601fa8 100644 --- a/client/src/app/header/search-typeahead.component.ts +++ b/client/src/app/header/search-typeahead.component.ts | |||
@@ -1,17 +1,9 @@ | |||
1 | import { | 1 | import { Component, ElementRef, OnDestroy, OnInit, QueryList, ViewChild } from '@angular/core' |
2 | Component, | 2 | import { ActivatedRoute, Params, Router } from '@angular/router' |
3 | OnInit, | ||
4 | OnDestroy, | ||
5 | QueryList, | ||
6 | ViewChild, | ||
7 | ElementRef | ||
8 | } from '@angular/core' | ||
9 | import { Router, Params, ActivatedRoute } from '@angular/router' | ||
10 | import { AuthService, ServerService } from '@app/core' | 3 | import { AuthService, ServerService } from '@app/core' |
11 | import { first, tap } from 'rxjs/operators' | 4 | import { first, tap } from 'rxjs/operators' |
12 | import { ListKeyManager } from '@angular/cdk/a11y' | 5 | import { ListKeyManager } from '@angular/cdk/a11y' |
13 | import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes' | 6 | import { Result, SuggestionComponent } from './suggestion.component' |
14 | import { SuggestionComponent, Result } from './suggestion.component' | ||
15 | import { of } from 'rxjs' | 7 | import { of } from 'rxjs' |
16 | import { ServerConfig } from '@shared/models' | 8 | import { ServerConfig } from '@shared/models' |
17 | 9 | ||
@@ -145,13 +137,13 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy { | |||
145 | handleKeyUp (event: KeyboardEvent) { | 137 | handleKeyUp (event: KeyboardEvent) { |
146 | event.stopImmediatePropagation() | 138 | event.stopImmediatePropagation() |
147 | if (!this.keyboardEventsManager) return | 139 | if (!this.keyboardEventsManager) return |
148 | 140 | ||
149 | switch (event.key) { | 141 | switch (event.key) { |
150 | case "ArrowDown": | 142 | case 'ArrowDown': |
151 | case "ArrowUp": | 143 | case 'ArrowUp': |
152 | this.keyboardEventsManager.onKeydown(event) | 144 | this.keyboardEventsManager.onKeydown(event) |
153 | break | 145 | break |
154 | case "Enter": | 146 | case 'Enter': |
155 | this.newSearch = false | 147 | this.newSearch = false |
156 | this.doSearch() | 148 | this.doSearch() |
157 | break | 149 | break |
diff --git a/client/src/sass/include/_variables.scss b/client/src/sass/include/_variables.scss index d8db3f3f8..3fb8bb625 100644 --- a/client/src/sass/include/_variables.scss +++ b/client/src/sass/include/_variables.scss | |||
@@ -103,8 +103,8 @@ $variables: ( | |||
103 | 103 | ||
104 | $zindex: ( | 104 | $zindex: ( |
105 | header : 1000, | 105 | header : 1000, |
106 | /* header context */ | 106 | /* header context */ |
107 | headerLeft : 10, | 107 | headerLeft : 10, |
108 | menu : 11000, | 108 | menu : 11000, |
109 | dropdown : 12000, | 109 | dropdown : 12000, |
110 | loadbar : 13000, | 110 | loadbar : 13000, |
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index a383a723f..06fe30371 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -11,10 +11,9 @@ import { ClientHtml } from '../../lib/client-html' | |||
11 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' | 11 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' |
12 | import { remove, writeJSON } from 'fs-extra' | 12 | import { remove, writeJSON } from 'fs-extra' |
13 | import { getServerCommit } from '../../helpers/utils' | 13 | import { getServerCommit } from '../../helpers/utils' |
14 | import { Emailer } from '../../lib/emailer' | ||
15 | import validator from 'validator' | 14 | import validator from 'validator' |
16 | import { objectConverter } from '../../helpers/core-utils' | 15 | import { objectConverter } from '../../helpers/core-utils' |
17 | import { CONFIG, reloadConfig } from '../../initializers/config' | 16 | import { CONFIG, isEmailEnabled, reloadConfig } from '../../initializers/config' |
18 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 17 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
19 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' | 18 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' |
20 | import { Hooks } from '@server/lib/plugins/hooks' | 19 | import { Hooks } from '@server/lib/plugins/hooks' |
@@ -87,7 +86,7 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
87 | default: defaultTheme | 86 | default: defaultTheme |
88 | }, | 87 | }, |
89 | email: { | 88 | email: { |
90 | enabled: Emailer.isEnabled() | 89 | enabled: isEmailEnabled() |
91 | }, | 90 | }, |
92 | contactForm: { | 91 | contactForm: { |
93 | enabled: CONFIG.CONTACT_FORM.ENABLED | 92 | enabled: CONFIG.CONTACT_FORM.ENABLED |
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 75d1a816b..271b788f6 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -1,15 +1,15 @@ | |||
1 | import * as cors from 'cors' | 1 | import * as cors from 'cors' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { | 3 | import { |
4 | CONSTRAINTS_FIELDS, | ||
5 | DEFAULT_THEME_NAME, | ||
4 | HLS_STREAMING_PLAYLIST_DIRECTORY, | 6 | HLS_STREAMING_PLAYLIST_DIRECTORY, |
5 | PEERTUBE_VERSION, | 7 | PEERTUBE_VERSION, |
6 | ROUTE_CACHE_LIFETIME, | 8 | ROUTE_CACHE_LIFETIME, |
7 | STATIC_DOWNLOAD_PATHS, | 9 | STATIC_DOWNLOAD_PATHS, |
8 | STATIC_MAX_AGE, | 10 | STATIC_MAX_AGE, |
9 | STATIC_PATHS, | 11 | STATIC_PATHS, |
10 | WEBSERVER, | 12 | WEBSERVER |
11 | CONSTRAINTS_FIELDS, | ||
12 | DEFAULT_THEME_NAME | ||
13 | } from '../initializers/constants' | 13 | } from '../initializers/constants' |
14 | import { cacheRoute } from '../middlewares/cache' | 14 | import { cacheRoute } from '../middlewares/cache' |
15 | import { asyncMiddleware, videosDownloadValidator } from '../middlewares' | 15 | import { asyncMiddleware, videosDownloadValidator } from '../middlewares' |
@@ -19,8 +19,7 @@ import { VideoCommentModel } from '../models/video/video-comment' | |||
19 | import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' | 19 | import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' |
20 | import { join } from 'path' | 20 | import { join } from 'path' |
21 | import { root } from '../helpers/core-utils' | 21 | import { root } from '../helpers/core-utils' |
22 | import { CONFIG } from '../initializers/config' | 22 | import { CONFIG, isEmailEnabled } from '../initializers/config' |
23 | import { Emailer } from '../lib/emailer' | ||
24 | import { getPreview, getVideoCaption } from './lazy-static' | 23 | import { getPreview, getVideoCaption } from './lazy-static' |
25 | import { VideoStreamingPlaylistType } from '@shared/models/videos/video-streaming-playlist.type' | 24 | import { VideoStreamingPlaylistType } from '@shared/models/videos/video-streaming-playlist.type' |
26 | import { MVideoFile, MVideoFullLight } from '@server/typings/models' | 25 | import { MVideoFile, MVideoFullLight } from '@server/typings/models' |
@@ -249,7 +248,7 @@ async function generateNodeinfo (req: express.Request, res: express.Response) { | |||
249 | default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) | 248 | default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) |
250 | }, | 249 | }, |
251 | email: { | 250 | email: { |
252 | enabled: Emailer.isEnabled() | 251 | enabled: isEmailEnabled() |
253 | }, | 252 | }, |
254 | contactForm: { | 253 | contactForm: { |
255 | enabled: CONFIG.CONTACT_FORM.ENABLED | 254 | enabled: CONFIG.CONTACT_FORM.ENABLED |
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 63673bee2..1ddbe0815 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -3,7 +3,7 @@ import { UserRole } from '../../../shared' | |||
3 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' | 3 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' |
4 | import { exists, isArray, isBooleanValid, isFileValid } from './misc' | 4 | import { exists, isArray, isBooleanValid, isFileValid } from './misc' |
5 | import { values } from 'lodash' | 5 | import { values } from 'lodash' |
6 | import { CONFIG } from '../../initializers/config' | 6 | import { isEmailEnabled } from '../../initializers/config' |
7 | 7 | ||
8 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS | 8 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS |
9 | 9 | ||
@@ -13,9 +13,8 @@ function isUserPasswordValid (value: string) { | |||
13 | 13 | ||
14 | function isUserPasswordValidOrEmpty (value: string) { | 14 | function isUserPasswordValidOrEmpty (value: string) { |
15 | // Empty password is only possible if emailing is enabled. | 15 | // Empty password is only possible if emailing is enabled. |
16 | if (value === '') { | 16 | if (value === '') return isEmailEnabled() |
17 | return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT | 17 | |
18 | } | ||
19 | return isUserPasswordValid(value) | 18 | return isUserPasswordValid(value) |
20 | } | 19 | } |
21 | 20 | ||
diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts index 978023129..e01609eef 100644 --- a/server/initializers/checker-after-init.ts +++ b/server/initializers/checker-after-init.ts | |||
@@ -4,13 +4,12 @@ import { UserModel } from '../models/account/user' | |||
4 | import { ApplicationModel } from '../models/application/application' | 4 | import { ApplicationModel } from '../models/application/application' |
5 | import { OAuthClientModel } from '../models/oauth/oauth-client' | 5 | import { OAuthClientModel } from '../models/oauth/oauth-client' |
6 | import { URL } from 'url' | 6 | import { URL } from 'url' |
7 | import { CONFIG } from './config' | 7 | import { CONFIG, isEmailEnabled } from './config' |
8 | import { logger } from '../helpers/logger' | 8 | import { logger } from '../helpers/logger' |
9 | import { getServerActor } from '../helpers/utils' | 9 | import { getServerActor } from '../helpers/utils' |
10 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' | 10 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' |
11 | import { isArray } from '../helpers/custom-validators/misc' | 11 | import { isArray } from '../helpers/custom-validators/misc' |
12 | import { uniq } from 'lodash' | 12 | import { uniq } from 'lodash' |
13 | import { Emailer } from '../lib/emailer' | ||
14 | import { WEBSERVER } from './constants' | 13 | import { WEBSERVER } from './constants' |
15 | 14 | ||
16 | async function checkActivityPubUrls () { | 15 | async function checkActivityPubUrls () { |
@@ -41,7 +40,7 @@ function checkConfig () { | |||
41 | } | 40 | } |
42 | 41 | ||
43 | // Email verification | 42 | // Email verification |
44 | if (!Emailer.isEnabled()) { | 43 | if (!isEmailEnabled()) { |
45 | if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { | 44 | if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { |
46 | return 'Emailer is disabled but you require signup email verification.' | 45 | return 'Emailer is disabled but you require signup email verification.' |
47 | } | 46 | } |
diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 75372fa4e..950ca61bd 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts | |||
@@ -284,11 +284,16 @@ function registerConfigChangedHandler (fun: Function) { | |||
284 | configChangedHandlers.push(fun) | 284 | configChangedHandlers.push(fun) |
285 | } | 285 | } |
286 | 286 | ||
287 | function isEmailEnabled () { | ||
288 | return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT | ||
289 | } | ||
290 | |||
287 | // --------------------------------------------------------------------------- | 291 | // --------------------------------------------------------------------------- |
288 | 292 | ||
289 | export { | 293 | export { |
290 | CONFIG, | 294 | CONFIG, |
291 | registerConfigChangedHandler | 295 | registerConfigChangedHandler, |
296 | isEmailEnabled | ||
292 | } | 297 | } |
293 | 298 | ||
294 | // --------------------------------------------------------------------------- | 299 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 0f74d2a8c..d0874ab20 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { createTransport, Transporter } from 'nodemailer' | 1 | import { createTransport, Transporter } from 'nodemailer' |
2 | import { isTestInstance } from '../helpers/core-utils' | 2 | import { isTestInstance } from '../helpers/core-utils' |
3 | import { bunyanLogger, logger } from '../helpers/logger' | 3 | import { bunyanLogger, logger } from '../helpers/logger' |
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG, isEmailEnabled } from '../initializers/config' |
5 | import { JobQueue } from './job-queue' | 5 | import { JobQueue } from './job-queue' |
6 | import { EmailPayload } from './job-queue/handlers/email' | 6 | import { EmailPayload } from './job-queue/handlers/email' |
7 | import { readFileSync } from 'fs-extra' | 7 | import { readFileSync } from 'fs-extra' |
@@ -40,7 +40,7 @@ class Emailer { | |||
40 | if (this.initialized === true) return | 40 | if (this.initialized === true) return |
41 | this.initialized = true | 41 | this.initialized = true |
42 | 42 | ||
43 | if (Emailer.isEnabled()) { | 43 | if (isEmailEnabled) { |
44 | logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) | 44 | logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) |
45 | 45 | ||
46 | let tls | 46 | let tls |
@@ -459,7 +459,7 @@ class Emailer { | |||
459 | } | 459 | } |
460 | 460 | ||
461 | async sendMail (options: EmailPayload) { | 461 | async sendMail (options: EmailPayload) { |
462 | if (!Emailer.isEnabled()) { | 462 | if (!isEmailEnabled()) { |
463 | throw new Error('Cannot send mail because SMTP is not configured.') | 463 | throw new Error('Cannot send mail because SMTP is not configured.') |
464 | } | 464 | } |
465 | 465 | ||
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index ceab646c0..dfa549e76 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts | |||
@@ -3,10 +3,10 @@ import { body } from 'express-validator' | |||
3 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' | 3 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
6 | import { Emailer } from '../../lib/emailer' | ||
7 | import { areValidationErrors } from './utils' | 6 | import { areValidationErrors } from './utils' |
8 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | 7 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | 8 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' |
9 | import { isEmailEnabled } from '@server/initializers/config' | ||
10 | 10 | ||
11 | const customConfigUpdateValidator = [ | 11 | const customConfigUpdateValidator = [ |
12 | body('instance.name').exists().withMessage('Should have a valid instance name'), | 12 | body('instance.name').exists().withMessage('Should have a valid instance name'), |
@@ -73,7 +73,7 @@ export { | |||
73 | } | 73 | } |
74 | 74 | ||
75 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { | 75 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { |
76 | if (Emailer.isEnabled()) return true | 76 | if (isEmailEnabled()) return true |
77 | 77 | ||
78 | if (customConfig.signup.requiresEmailVerification === true) { | 78 | if (customConfig.signup.requiresEmailVerification === true) { |
79 | res.status(400) | 79 | res.status(400) |
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts index f6812647b..6158c3363 100644 --- a/server/middlewares/validators/server.ts +++ b/server/middlewares/validators/server.ts | |||
@@ -5,9 +5,8 @@ import { isHostValid, isValidContactBody } from '../../helpers/custom-validators | |||
5 | import { ServerModel } from '../../models/server/server' | 5 | import { ServerModel } from '../../models/server/server' |
6 | import { body } from 'express-validator' | 6 | import { body } from 'express-validator' |
7 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' | 7 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' |
8 | import { Emailer } from '../../lib/emailer' | ||
9 | import { Redis } from '../../lib/redis' | 8 | import { Redis } from '../../lib/redis' |
10 | import { CONFIG } from '../../initializers/config' | 9 | import { CONFIG, isEmailEnabled } from '../../initializers/config' |
11 | 10 | ||
12 | const serverGetValidator = [ | 11 | const serverGetValidator = [ |
13 | body('host').custom(isHostValid).withMessage('Should have a valid host'), | 12 | body('host').custom(isHostValid).withMessage('Should have a valid host'), |
@@ -50,7 +49,7 @@ const contactAdministratorValidator = [ | |||
50 | .end() | 49 | .end() |
51 | } | 50 | } |
52 | 51 | ||
53 | if (Emailer.isEnabled() === false) { | 52 | if (isEmailEnabled() === false) { |
54 | return res | 53 | return res |
55 | .status(409) | 54 | .status(409) |
56 | .send({ error: 'Emailer is not enabled on this instance.' }) | 55 | .send({ error: 'Emailer is not enabled on this instance.' }) |