1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Fix tests and user quota

This commit is contained in:
Chocobozzz 2017-09-06 16:35:40 +02:00
parent 5c98d3bf07
commit 77a5501f64
9 changed files with 222 additions and 75 deletions

View file

@ -8,6 +8,7 @@ import {
ensureIsAdmin,
ensureUserRegistrationAllowed,
usersAddValidator,
usersRegisterValidator,
usersUpdateValidator,
usersUpdateMeValidator,
usersRemoveValidator,
@ -25,6 +26,7 @@ import {
UserUpdate,
UserUpdateMe
} from '../../../shared'
import { UserInstance } from '../../models'
const usersRouter = express.Router()
@ -61,8 +63,8 @@ usersRouter.post('/',
usersRouter.post('/register',
ensureUserRegistrationAllowed,
usersAddValidator,
createUser
usersRegisterValidator,
registerUser
)
usersRouter.put('/me',
@ -99,11 +101,6 @@ export {
function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
const body: UserCreate = req.body
// On registration, we set the user video quota
if (body.videoQuota === undefined) {
body.videoQuota = CONFIG.USER.VIDEO_QUOTA
}
const user = db.User.build({
username: body.username,
password: body.password,
@ -118,6 +115,23 @@ function createUser (req: express.Request, res: express.Response, next: express.
.catch(err => next(err))
}
function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) {
const body: UserCreate = req.body
const user = db.User.build({
username: body.username,
password: body.password,
email: body.email,
displayNSFW: false,
role: USER_ROLES.USER,
videoQuota: CONFIG.USER.VIDEO_QUOTA
})
user.save()
.then(() => res.type('json').status(204).end())
.catch(err => next(err))
}
function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
db.User.loadByUsername(res.locals.oauth.token.user.username)
.then(user => res.json(user.toFormattedJSON()))
@ -180,7 +194,7 @@ function updateMe (req: express.Request, res: express.Response, next: express.Ne
function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) {
const body: UserUpdate = req.body
const user = res.locals.user
const user: UserInstance = res.locals.user
if (body.email !== undefined) user.email = body.email
if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota