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