Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge beta to main #674

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion migrations/20200422165711-apiv3-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ module.exports = {
console.log('- Changing the name of the new UUID field to "id" and make it the primary key')
await migration.renameColumn('Groups', 'id2', 'id', { transaction })

await migration.addConstraint('Groups', ['id'], {
await migration.addConstraint('Groups', {
fields: ['id'],
type: 'primary key',
transaction,
})
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@log4js-node/gelf": "^1.0.2",
"@log4js-node/slack": "^1.0.0",
"@log4js-node/smtp": "^1.1.0",
"apn": "^2.2.0",
"axios": "^0.21.1",
"bcrypt": "^3.0.7",
"date-fns": "^2.8.1",
Expand All @@ -30,7 +31,7 @@
"gulp-cli": "^2.2.0",
"i18next": "^19.0.1",
"join-js": "xlexi/joinjs",
"knex": "^0.20.4",
"knex": "~2.4.2",
"koa": "^2.11.0",
"koa-body": "^4.1.1",
"koa-conditional-get": "^2.0.0",
Expand All @@ -42,16 +43,17 @@
"maxmind": "3.1.2",
"mysql": "^2.17.1",
"nanoid": "^3.1.3",
"nodemailer": "^6.4.2",
"nodemailer": "^6.9.3",
"npid": "^0.4.0",
"otplib": "^12.0.1",
"pg": "^8.5.1",
"pure-uuid": "^1.5.7",
"sequelize": "^5.21.2",
"sequelize": "^6.32.1",
"sharp": "^0.28.3",
"sinon": "^7.5.0",
"twitter": "^1.7.1",
"ua-parser-js": "^0.7.20",
"ua-parser-js": "^1.0.35",
"web-push": "^3.5.0",
"workerpool": "^5.0.2",
"ws": "^7.2.0",
"yayson": "^2.0.8"
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import babel from '@rollup/plugin-babel'
import { babel } from '@rollup/plugin-babel'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import fs from 'fs'
Expand Down
4 changes: 2 additions & 2 deletions src/classes/Anope.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class Anope {

account.user = await User.findOne({
where: {
email: { iLike: account.email },
email: { iLike: account.email, status: 'active' },
},
})
return account
Expand Down Expand Up @@ -265,7 +265,7 @@ class Anope {

account.user = await User.findOne({
where: {
email: { iLike: account.email },
email: { iLike: account.email, status: 'active' },
},
})
return account
Expand Down
24 changes: 21 additions & 3 deletions src/classes/Authentication.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class Authentication {

// const user = await User.findByEmail(email)

const user = await User.findOne({ where: { email: { ilike: email } } })
const user = await User.findOne({
where: {
email: { ilike: email },
suspended: null,
status: 'active',
},
})
if (!user) {
return undefined
}
Expand Down Expand Up @@ -70,7 +76,13 @@ class Authentication {
where: { id: user.id },
})
}
return User.findOne({ where: { email: { ilike: email } } })
return User.findOne({
where: {
email: { ilike: email },
suspended: null,
status: 'active',
},
})
}

/**
Expand All @@ -92,7 +104,13 @@ class Authentication {
throw new GoneAPIError({})
}

const user = await User.findOne({ where: { id: token.userId } })
const user = await User.findOne({
where: {
id: token.userId,
suspended: null,
status: 'active',
},
})
return {
user,
scope: token.scope,
Expand Down
11 changes: 11 additions & 0 deletions src/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ const config = {
token: optional('FRAPI_TWITTER_TOKEN', [], undefined),
tokenSecret: optional('FRAPI_TWITTER_TOKEN_SECRET', [], undefined),
},
webpush: {
privateKey: recommended('FRAPI_WEBPUSH_PRIVATE_KEY', [], undefined),
publicKey: recommended('FRAPI_WEBPUSH_PUBLIC_KEY', [], undefined),
},
apn: {
token: {
key: recommended('FRAPI_APN_PATH', [], undefined),
keyId: recommended('FRAPI_APN_ID', [], undefined),
teamId: recommended('FRAPI_APN_TEAM', [], undefined),
},
},
}

ensureValidConfig()
Expand Down
49 changes: 49 additions & 0 deletions src/db/ApplePushSubscription.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Model, { column, table, validate, type } from './Model'

/**
* Model class for user sessions
*/
@table({
indexes: [{
fields: ['deviceToken', 'userId'],
}],
})
export default class ApplePushSubscription extends Model {
@validate({ isUUID: 4 })
@column(type.UUID, { primaryKey: true })
static id = type.UUIDV4

@column(type.STRING, { unique: true })
static deviceToken = undefined

@validate({ isUUID: 4 })
@column(type.UUID)
static userId = undefined

/**
* @inheritdoc
*/
static getScopes (models) {
return {
defaultScope: [{
include: [
{
model: models.User,
as: 'user',
required: true,
},
],
}, {
override: true,
}],
}
}

/**
* @inheritdoc
*/
static associate (models) {
super.associate(models)
models.ApplePushSubscription.belongsTo(models.User, { as: 'user' })
}
}
73 changes: 73 additions & 0 deletions src/db/WebPushSubscription.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import Model, { column, table, validate, type } from './Model'

/**
* Model class for user sessions
*/
@table({
indexes: [{
fields: ['endpoint', 'userId'],
}],
})
export default class WebPushSubscription extends Model {
@validate({ isUUID: 4 })
@column(type.UUID, { primaryKey: true })
static id = type.UUIDV4

@column(type.STRING, { unique: true })
static endpoint = undefined

@column(type.INTEGER, { allowNull: true })
static expirationTime = undefined

@column(type.STRING)
static auth = undefined

@column(type.STRING)
static p256dh = undefined

@column(type.BOOLEAN)
static alertsOnly = true

@column(type.BOOLEAN)
static pc = true

@column(type.BOOLEAN)
static xb = true

@column(type.BOOLEAN)
static ps = true

@column(type.BOOLEAN)
static odyssey = true

@validate({ isUUID: 4 })
@column(type.UUID)
static userId = undefined

/**
* @inheritdoc
*/
static getScopes (models) {
return {
defaultScope: [{
include: [
{
model: models.User,
as: 'user',
required: true,
},
],
}, {
override: true,
}],
}
}

/**
* @inheritdoc
*/
static associate (models) {
super.associate(models)
models.WebPushSubscription.belongsTo(models.User, { as: 'user' })
}
}
6 changes: 6 additions & 0 deletions src/db/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Sequelize from 'sequelize'
import config from '../config'
import logger from '../logging'

import ApplePushSubscription from './ApplePushSubscription'
import Authenticator from './Authenticator'
import Avatar from './Avatar'
import Client from './Client'
Expand All @@ -22,8 +23,10 @@ import Token from './Token'
import User from './User'
import UserGroups from './UserGroups'
import VerificationToken from './VerificationToken'
import WebPushSubscription from './WebPushSubscription'

const models = {
ApplePushSubscription,
User,
Authenticator,
Avatar,
Expand All @@ -42,6 +45,7 @@ const models = {
UserGroups,
VerificationToken,
Session,
WebPushSubscription,
}

const {
Expand Down Expand Up @@ -137,6 +141,7 @@ export {
db as sequelize,
Sequelize,
Op,
ApplePushSubscription,
Authenticator,
Avatar,
Client,
Expand All @@ -157,4 +162,5 @@ export {
User,
UserGroups,
VerificationToken,
WebPushSubscription,
}
Loading