+++ /dev/null
-import * as Sequelize from 'sequelize'
-
-async function up (utils: {
- transaction: Sequelize.Transaction
- queryInterface: Sequelize.QueryInterface
- sequelize: Sequelize.Sequelize
-}): Promise<void> {
-
- const metadata = {
- type: Sequelize.JSONB,
- allowNull: true
- }
- await utils.queryInterface.addColumn('videoFile', 'metadata', metadata)
-
- const metadataUrl = {
- type: Sequelize.STRING,
- allowNull: true
- }
- await utils.queryInterface.addColumn('videoFile', 'metadataUrl', metadataUrl)
-
-}
-
-function down (options) {
- throw new Error('Not implemented.')
-}
-
-export {
- up,
- down
-}
--- /dev/null
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+ transaction: Sequelize.Transaction
+ queryInterface: Sequelize.QueryInterface
+ sequelize: Sequelize.Sequelize
+}): Promise<void> {
+
+ {
+ const password = {
+ type: Sequelize.STRING,
+ allowNull: true
+ }
+ await utils.queryInterface.changeColumn('user', 'password', password)
+ }
+
+ {
+ const pluginAuth = {
+ type: Sequelize.STRING,
+ allowNull: true
+ }
+ await utils.queryInterface.addColumn('user', 'pluginAuth', pluginAuth)
+ }
+
+ {
+ const authName = {
+ type: Sequelize.STRING,
+ allowNull: true
+ }
+ await utils.queryInterface.addColumn('oAuthToken', 'authName', authName)
+ }
+
+}
+
+function down (options) {
+ throw new Error('Not implemented.')
+}
+
+export {
+ up,
+ down
+}
authOptions.authName, pluginAuth.npmName, loginOptions.id, authOptions.getWeight()
)
- const loginResult = await authOptions.login(loginOptions)
- if (loginResult) {
- logger.info(
- 'Login success with auth method %s of plugin %s for %s.',
- authOptions.authName, pluginAuth.npmName, loginOptions.id
- )
-
- res.locals.bypassLogin = {
- bypass: true,
- pluginName: pluginAuth.npmName,
- authName: authOptions.authName,
- user: {
- username: loginResult.username,
- email: loginResult.email,
- role: loginResult.role || UserRole.USER,
- displayName: loginResult.displayName || loginResult.username
+ try {
+ const loginResult = await authOptions.login(loginOptions)
+ if (loginResult) {
+ logger.info(
+ 'Login success with auth method %s of plugin %s for %s.',
+ authOptions.authName, pluginAuth.npmName, loginOptions.id
+ )
+
+ res.locals.bypassLogin = {
+ bypass: true,
+ pluginName: pluginAuth.npmName,
+ authName: authOptions.authName,
+ user: {
+ username: loginResult.username,
+ email: loginResult.email,
+ role: loginResult.role || UserRole.USER,
+ displayName: loginResult.displayName || loginResult.username
+ }
}
- }
- return
+ return
+ }
+ } catch (err) {
+ logger.error('Error in auth method %s of plugin %s', authOptions.authName, pluginAuth.npmName, { err })
}
}
}
return {
getSetting: (name: string) => PluginModel.getSetting(this.plugin.name, this.plugin.type, name),
+ getSettings: (names: string[]) => PluginModel.getSettings(this.plugin.name, this.plugin.type, names),
+
setSetting: (name: string, value: string) => PluginModel.setSetting(this.plugin.name, this.plugin.type, name, value)
}
}
})
}
+ static getSettings (pluginName: string, pluginType: PluginType, settingNames: string[]) {
+ const query = {
+ attributes: [ 'settings' ],
+ where: {
+ name: pluginName,
+ type: pluginType
+ }
+ }
+
+ return PluginModel.findOne(query)
+ .then(p => {
+ if (!p || !p.settings) return {}
+
+ const result: { [settingName: string ]: string } = {}
+
+ for (const key of Object.keys(p.settings)) {
+ if (settingNames.includes(key)) {
+ result[key] = p.settings[key]
+ }
+ }
+
+ return result
+ })
+ }
+
static setSetting (pluginName: string, pluginType: PluginType, settingName: string, settingValue: string) {
const query = {
where: {
expect(body.role).to.equal(UserRole.MODERATOR)
})
- it('Should correctly auth token of laguna', async function () {
+ it('Should reject token of laguna by the plugin hook', async function () {
this.timeout(10000)
await wait(5000)
import * as Bluebird from 'bluebird'
export interface PluginSettingsManager {
- getSetting: (name: string) => Bluebird<string>
+ getSetting: (name: string) => Bluebird<string | boolean>
+
+ getSettings: (names: string[]) => Bluebird<{ [settingName: string]: string | boolean }>
setSetting: (name: string, value: string) => Bluebird<any>
}