import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators'
import { AccountVideoRateModel } from '../../models/account/account-video-rate'
import { UserModel } from '../../models/account/user'
+import { OAuthTokenModel } from '../../models/oauth/oauth-token'
import { VideoModel } from '../../models/video/video'
const reqAvatarFile = createReqFiles('avatarfile', CONFIG.STORAGE.AVATARS_DIR, AVATAR_MIMETYPE_EXT)
async function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) {
const body: UserUpdate = req.body
const user = res.locals.user as UserModel
+ const roleChanged = body.role !== undefined && body.role !== user.role
if (body.email !== undefined) user.email = body.email
if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota
await user.save()
+ // Destroy user token to refresh rights
+ if (roleChanged) {
+ await OAuthTokenModel.deleteUserToken(user.id)
+ }
+
// Don't need to send this update to followers, these attributes are not propagated
return res.sendStatus(204)
let server: ServerInfo
let serverWithRegistrationDisabled: ServerInfo
let userAccessToken = ''
+ const user = {
+ username: 'user1',
+ password: 'my super password'
+ }
// ---------------------------------------------------------------
await setAccessTokensToServers([ server ])
- const user = {
- username: 'user1',
- password: 'my super password'
- }
const videoQuota = 42000000
await createUser(server.url, server.accessToken, user.username, user.password, videoQuota)
userAccessToken = await userLogin(server, user)
await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
})
+ it('Should fail when updating root role', async function () {
+ const fields = {
+ role: UserRole.MODERATOR
+ }
+
+ await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
+ })
+
it('Should succeed with the correct params', async function () {
const fields = {
email: 'email@example.com',
}
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
+ userAccessToken = await userLogin(server, user)
})
})
import 'mocha'
import { UserRole } from '../../../../shared/index'
import {
- createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, getUserInformation,
- getUsersList,
- getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo,
- runServer, ServerInfo, serverLogin, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo
+ createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating,
+ getUserInformation, getUsersList, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo,
+ registerUser, removeUser, removeVideo, runServer, ServerInfo, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo, userLogin
} from '../../utils/index'
import { follow } from '../../utils/server/follows'
import { setAccessTokensToServers } from '../../utils/users/login'
let accessTokenUser: string
let videoId: number
let userId: number
+ const user = {
+ username: 'user_1',
+ password: 'super password'
+ }
before(async function () {
this.timeout(30000)
it('Should be able to upload a video again')
it('Should be able to create a new user', async function () {
- await createUser(server.url, accessToken, 'user_1', 'super password', 2 * 1024 * 1024)
+ await createUser(server.url, accessToken, user.username,user.password, 2 * 1024 * 1024)
})
it('Should be able to login with this user', async function () {
- server.user = {
- username: 'user_1',
- password: 'super password'
- }
-
- accessTokenUser = await serverLogin(server)
+ accessTokenUser = await userLogin(server, user)
})
it('Should be able to get the user information', async function () {
accessToken: accessTokenUser,
newPassword: 'new password'
})
- server.user.password = 'new password'
+ user.password = 'new password'
- await login(server.url, server.client, server.user, 200)
+ await userLogin(server, user, 200)
})
it('Should be able to change the NSFW display attribute', async function () {
expect(user.id).to.be.a('number')
})
+ it('Should have removed the user token', async function () {
+ await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
+
+ accessTokenUser = await userLogin(server, user)
+ })
+
it('Should not be able to delete a user by a moderator', async function () {
await removeUser(server.url, 2, accessTokenUser, 403)
})
})
it('Should not be able to login with this user', async function () {
- // server.user is already set to user 1
- await login(server.url, server.client, server.user, 400)
+ await userLogin(server, user, 400)
})
it('Should not have videos of this user', async function () {
})
it('Should be able to login with this registered user', async function () {
- server.user = {
+ const user15 = {
username: 'user_15',
password: 'my super password'
}
- accessToken = await serverLogin(server)
+ accessToken = await userLogin(server, user15)
})
it('Should have the correct video quota', async function () {