aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-30 15:03:09 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-04 16:21:39 +0200
commitbc90883f1a5e9c4ecb76ae358734b85be515af7f (patch)
tree47d578c1d5a3a95e89f2badfade76b125de11084 /server/models
parenta4995eb7ac5745f62604d70f7b2225ff33916d49 (diff)
downloadPeerTube-bc90883f1a5e9c4ecb76ae358734b85be515af7f.tar.gz
PeerTube-bc90883f1a5e9c4ecb76ae358734b85be515af7f.tar.zst
PeerTube-bc90883f1a5e9c4ecb76ae358734b85be515af7f.zip
Handle external login errors
Diffstat (limited to 'server/models')
-rw-r--r--server/models/server/plugin.ts44
1 files changed, 29 insertions, 15 deletions
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts
index 83c873c5b..3f88ac26d 100644
--- a/server/models/server/plugin.ts
+++ b/server/models/server/plugin.ts
@@ -1,5 +1,10 @@
1import * as Bluebird from 'bluebird'
2import { FindAndCountOptions, json } from 'sequelize'
1import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 3import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { getSort, throwIfNotValid } from '../utils' 4import { MPlugin, MPluginFormattable } from '@server/typings/models'
5import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model'
6import { PluginType } from '../../../shared/models/plugins/plugin.type'
7import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model'
3import { 8import {
4 isPluginDescriptionValid, 9 isPluginDescriptionValid,
5 isPluginHomepage, 10 isPluginHomepage,
@@ -7,12 +12,7 @@ import {
7 isPluginTypeValid, 12 isPluginTypeValid,
8 isPluginVersionValid 13 isPluginVersionValid
9} from '../../helpers/custom-validators/plugins' 14} from '../../helpers/custom-validators/plugins'
10import { PluginType } from '../../../shared/models/plugins/plugin.type' 15import { getSort, throwIfNotValid } from '../utils'
11import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model'
12import { FindAndCountOptions, json } from 'sequelize'
13import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model'
14import * as Bluebird from 'bluebird'
15import { MPlugin, MPluginFormattable } from '@server/typings/models'
16 16
17@DefaultScope(() => ({ 17@DefaultScope(() => ({
18 attributes: { 18 attributes: {
@@ -112,7 +112,7 @@ export class PluginModel extends Model<PluginModel> {
112 return PluginModel.findOne(query) 112 return PluginModel.findOne(query)
113 } 113 }
114 114
115 static getSetting (pluginName: string, pluginType: PluginType, settingName: string) { 115 static getSetting (pluginName: string, pluginType: PluginType, settingName: string, registeredSettings: RegisterServerSettingOptions[]) {
116 const query = { 116 const query = {
117 attributes: [ 'settings' ], 117 attributes: [ 'settings' ],
118 where: { 118 where: {
@@ -123,13 +123,23 @@ export class PluginModel extends Model<PluginModel> {
123 123
124 return PluginModel.findOne(query) 124 return PluginModel.findOne(query)
125 .then(p => { 125 .then(p => {
126 if (!p || !p.settings) return undefined 126 if (!p || p.settings === undefined) {
127 const registered = registeredSettings.find(s => s.name === settingName)
128 if (!registered || registered.default === undefined) return undefined
129
130 return registered.default
131 }
127 132
128 return p.settings[settingName] 133 return p.settings[settingName]
129 }) 134 })
130 } 135 }
131 136
132 static getSettings (pluginName: string, pluginType: PluginType, settingNames: string[]) { 137 static getSettings (
138 pluginName: string,
139 pluginType: PluginType,
140 settingNames: string[],
141 registeredSettings: RegisterServerSettingOptions[]
142 ) {
133 const query = { 143 const query = {
134 attributes: [ 'settings' ], 144 attributes: [ 'settings' ],
135 where: { 145 where: {
@@ -140,13 +150,17 @@ export class PluginModel extends Model<PluginModel> {
140 150
141 return PluginModel.findOne(query) 151 return PluginModel.findOne(query)
142 .then(p => { 152 .then(p => {
143 if (!p || !p.settings) return {} 153 const result: { [settingName: string ]: string | boolean } = {}
144 154
145 const result: { [settingName: string ]: string } = {} 155 for (const name of settingNames) {
156 if (!p || p.settings[name] === undefined) {
157 const registered = registeredSettings.find(s => s.name === name)
146 158
147 for (const key of Object.keys(p.settings)) { 159 if (registered?.default !== undefined) {
148 if (settingNames.includes(key)) { 160 result[name] = registered.default
149 result[key] = p.settings[key] 161 }
162 } else {
163 result[name] = p.settings[name]
150 } 164 }
151 } 165 }
152 166