Add quota used in users list
This commit is contained in:
parent
614d1ae928
commit
a76138ff56
6 changed files with 44 additions and 10 deletions
|
@ -4,9 +4,9 @@ import { Injectable } from '@angular/core'
|
|||
import { BytesPipe } from 'ngx-pipes'
|
||||
import { SortMeta } from 'primeng/components/common/sortmeta'
|
||||
import { Observable } from 'rxjs'
|
||||
import { ResultList, UserCreate, UserUpdate } from '../../../../../../shared'
|
||||
import { ResultList, UserCreate, UserUpdate, User } from '../../../../../../shared'
|
||||
import { environment } from '../../../../environments/environment'
|
||||
import { RestExtractor, RestPagination, RestService, User } from '../../../shared'
|
||||
import { RestExtractor, RestPagination, RestService } from '../../../shared'
|
||||
import { I18n } from '@ngx-translate/i18n-polyfill'
|
||||
|
||||
@Injectable()
|
||||
|
@ -79,8 +79,11 @@ export class UserService {
|
|||
videoQuota = this.bytesPipe.transform(user.videoQuota, 0)
|
||||
}
|
||||
|
||||
const videoQuotaUsed = this.bytesPipe.transform(user.videoQuotaUsed, 0)
|
||||
|
||||
return Object.assign(user, {
|
||||
videoQuota
|
||||
videoQuota,
|
||||
videoQuotaUsed
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
<span *ngIf="user.blocked" class="banned-info">(banned)</span>
|
||||
</td>
|
||||
<td>{{ user.email }}</td>
|
||||
<td>{{ user.videoQuota }}</td>
|
||||
<td>{{ user.videoQuotaUsed }} / {{ user.videoQuota }}</td>
|
||||
<td>{{ user.roleLabel }}</td>
|
||||
<td>{{ user.createdAt }}</td>
|
||||
<td class="action-cell">
|
||||
|
|
|
@ -5,9 +5,8 @@ import { Observable } from 'rxjs'
|
|||
import { VideoImport } from '../../../../../shared'
|
||||
import { environment } from '../../../environments/environment'
|
||||
import { RestExtractor, RestService } from '../rest'
|
||||
import { VideoImportCreate } from '../../../../../shared/models/videos'
|
||||
import { VideoImportCreate, VideoUpdate } from '../../../../../shared/models/videos'
|
||||
import { objectToFormData } from '@app/shared/misc/utils'
|
||||
import { VideoUpdate } from '../../../../../shared/models/videos'
|
||||
import { ResultList } from '../../../../../shared/models/result-list.model'
|
||||
import { UserService } from '@app/shared/users/user.service'
|
||||
import { SortMeta } from 'primeng/components/common/sortmeta'
|
||||
|
|
|
@ -161,6 +161,25 @@ export class UserModel extends Model<UserModel> {
|
|||
|
||||
static listForApi (start: number, count: number, sort: string) {
|
||||
const query = {
|
||||
attributes: {
|
||||
include: [
|
||||
[
|
||||
Sequelize.literal(
|
||||
'(' +
|
||||
'SELECT COALESCE(SUM("size"), 0) FROM ' +
|
||||
'(' +
|
||||
'SELECT MAX("videoFile"."size") AS "size" FROM "videoFile" ' +
|
||||
'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' +
|
||||
'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
|
||||
'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
|
||||
'WHERE "account"."userId" = "UserModel"."id" GROUP BY "video"."id"' +
|
||||
') t' +
|
||||
')'
|
||||
),
|
||||
'videoQuotaUsed'
|
||||
] as any // FIXME: typings
|
||||
]
|
||||
},
|
||||
offset: start,
|
||||
limit: count,
|
||||
order: getSort(sort)
|
||||
|
@ -168,6 +187,9 @@ export class UserModel extends Model<UserModel> {
|
|||
|
||||
return UserModel.findAndCountAll(query)
|
||||
.then(({ rows, count }) => {
|
||||
console.log(rows[0])
|
||||
console.log(rows[0]['videoQuotaUsed'])
|
||||
console.log(rows[0].get('videoQuotaUsed'))
|
||||
return {
|
||||
data: rows,
|
||||
total: count
|
||||
|
@ -249,8 +271,7 @@ export class UserModel extends Model<UserModel> {
|
|||
'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' +
|
||||
'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
|
||||
'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
|
||||
'INNER JOIN "user" ON "account"."userId" = "user"."id" ' +
|
||||
'WHERE "user"."id" = $userId GROUP BY "video"."id") t'
|
||||
'WHERE "account"."userId" = $userId GROUP BY "video"."id") t'
|
||||
|
||||
const options = {
|
||||
bind: { userId: user.id },
|
||||
|
@ -281,6 +302,8 @@ export class UserModel extends Model<UserModel> {
|
|||
}
|
||||
|
||||
toFormattedJSON (): User {
|
||||
const videoQuotaUsed = this.get('videoQuotaUsed')
|
||||
|
||||
const json = {
|
||||
id: this.id,
|
||||
username: this.username,
|
||||
|
@ -294,7 +317,8 @@ export class UserModel extends Model<UserModel> {
|
|||
blocked: this.blocked,
|
||||
blockedReason: this.blockedReason,
|
||||
account: this.Account.toFormattedJSON(),
|
||||
videoChannels: []
|
||||
videoChannels: [],
|
||||
videoQuotaUsed: videoQuotaUsed !== undefined ? parseInt(videoQuotaUsed, 10) : undefined
|
||||
}
|
||||
|
||||
if (Array.isArray(this.Account.VideoChannels) === true) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import * as chai from 'chai'
|
||||
import 'mocha'
|
||||
import { UserRole } from '../../../../shared/index'
|
||||
import { User, UserRole } from '../../../../shared/index'
|
||||
import {
|
||||
createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating,
|
||||
getUserInformation, getUsersList, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo,
|
||||
|
@ -192,6 +192,12 @@ describe('Test users', function () {
|
|||
const data = res.body
|
||||
|
||||
expect(data.videoQuotaUsed).to.equal(218910)
|
||||
|
||||
const resUsers = await getUsersList(server.url, server.accessToken)
|
||||
|
||||
const users: User[] = resUsers.body.data
|
||||
const tmpUser = users.find(u => u.username === user.username)
|
||||
expect(tmpUser.videoQuotaUsed).to.equal(218910)
|
||||
})
|
||||
|
||||
it('Should be able to list my videos', async function () {
|
||||
|
|
|
@ -17,4 +17,6 @@ export interface User {
|
|||
|
||||
blocked: boolean
|
||||
blockedReason?: string
|
||||
|
||||
videoQuotaUsed?: number
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue