ActivityPub-federated video streaming platform using P2P directly in your web browser
Add quota used in users list
Chocobozzza76138ff56ad
diff --git a/client/src/app/+admin/users/shared/user.service.ts b/client/src/app/+admin/users/shared/user.service.tsindex ad7fb1eeeb..a0e2f666d3 100644--- a/client/src/app/+admin/users/shared/user.service.ts+++ b/client/src/app/+admin/users/shared/user.service.ts@@ -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})}}diff --git a/client/src/app/+admin/users/user-list/user-list.component.html b/client/src/app/+admin/users/user-list/user-list.component.htmlindex a92fe95ef7..bb1b264428 100644--- a/client/src/app/+admin/users/user-list/user-list.component.html+++ b/client/src/app/+admin/users/user-list/user-list.component.html@@ -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">diff --git a/client/src/app/shared/video-import/video-import.service.ts b/client/src/app/shared/video-import/video-import.service.tsindex f63bfb2b1c..fc34dbf2d3 100644--- a/client/src/app/shared/video-import/video-import.service.ts+++ b/client/src/app/shared/video-import/video-import.service.ts@@ -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'diff --git a/server/models/account/user.ts b/server/models/account/user.tsindex 81b0651fdf..0150df4ce6 100644--- a/server/models/account/user.ts+++ b/server/models/account/user.ts@@ -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) {diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.tsindex 77aa00f608..04dcc8fd1a 100644--- a/server/tests/api/users/users.ts+++ b/server/tests/api/users/users.ts@@ -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.bodyexpect(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 () {diff --git a/shared/models/users/user.model.ts b/shared/models/users/user.model.tsindex 8eddaa4966..455211aa33 100644--- a/shared/models/users/user.model.ts+++ b/shared/models/users/user.model.ts@@ -17,4 +17,6 @@ export interface User {blocked: booleanblockedReason?: string++ videoQuotaUsed?: number}