]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add quota used in users list
authorChocobozzz <me@florianbigard.com>
Tue, 14 Aug 2018 15:56:51 +0000 (17:56 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 14 Aug 2018 16:01:23 +0000 (18:01 +0200)
client/src/app/+admin/users/shared/user.service.ts
client/src/app/+admin/users/user-list/user-list.component.html
client/src/app/shared/video-import/video-import.service.ts
server/models/account/user.ts
server/tests/api/users/users.ts
shared/models/users/user.model.ts

index ad7fb1eeeb5f8d19f84172b69227fd6568ae7d4d..a0e2f666d32a4891046cd6028e171f7d784ea4f9 100644 (file)
@@ -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
     })
   }
 }
index a92fe95ef71a481e8f446a1624b721b03f750e37..bb1b264428747e91850e5d8ce6a8879302219866 100644 (file)
@@ -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">
index f63bfb2b1c72059934475c2af45b5e81a41551cc..fc34dbf2d33ca748f3273f23484283eac4aba5c8 100644 (file)
@@ -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'
index 81b0651fdf915fc3193f8b62752991ce5c559b9a..0150df4ce6303547abff5f44bc2decdce1af6a70 100644 (file)
@@ -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) {
index 77aa00f60860ed71e0b69c435e767d11bdf546a3..04dcc8fd1a464d654768daf8ecc96cac41b31601 100644 (file)
@@ -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 () {
index 8eddaa49660d7038a5c87bf24073ee167ed69441..455211aa3371e0f73aa56b543ecc53bdc3d769a0 100644 (file)
@@ -17,4 +17,6 @@ export interface User {
 
   blocked: boolean
   blockedReason?: string
+
+  videoQuotaUsed?: number
 }