aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/app/+admin/follows/followers-list/followers-list.component.ts2
-rw-r--r--client/src/app/+admin/follows/following-list/following-list.component.ts2
-rw-r--r--client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts2
-rw-r--r--client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts2
-rw-r--r--client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts2
-rw-r--r--client/src/app/+admin/users/user-list/user-list.component.html1
-rw-r--r--client/src/app/+admin/users/user-list/user-list.component.ts4
-rw-r--r--client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts2
-rw-r--r--client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts2
-rw-r--r--client/src/app/shared/moderation/user-moderation-dropdown.component.html2
-rw-r--r--client/src/app/shared/moderation/user-moderation-dropdown.component.ts1
-rw-r--r--client/src/app/shared/rest/rest-table.ts27
-rw-r--r--client/src/app/shared/users/user.service.ts4
-rw-r--r--server/controllers/api/users/index.ts2
-rw-r--r--server/models/account/user.ts23
-rw-r--r--server/tests/api/users/users.ts36
-rw-r--r--server/tests/utils/users/users.ts3
17 files changed, 100 insertions, 17 deletions
diff --git a/client/src/app/+admin/follows/followers-list/followers-list.component.ts b/client/src/app/+admin/follows/followers-list/followers-list.component.ts
index ca993dcd3..4a25b7ff3 100644
--- a/client/src/app/+admin/follows/followers-list/followers-list.component.ts
+++ b/client/src/app/+admin/follows/followers-list/followers-list.component.ts
@@ -28,7 +28,7 @@ export class FollowersListComponent extends RestTable implements OnInit {
28 } 28 }
29 29
30 ngOnInit () { 30 ngOnInit () {
31 this.loadSort() 31 this.initialize()
32 } 32 }
33 33
34 protected loadData () { 34 protected loadData () {
diff --git a/client/src/app/+admin/follows/following-list/following-list.component.ts b/client/src/app/+admin/follows/following-list/following-list.component.ts
index dd57884c6..70235a48d 100644
--- a/client/src/app/+admin/follows/following-list/following-list.component.ts
+++ b/client/src/app/+admin/follows/following-list/following-list.component.ts
@@ -29,7 +29,7 @@ export class FollowingListComponent extends RestTable implements OnInit {
29 } 29 }
30 30
31 ngOnInit () { 31 ngOnInit () {
32 this.loadSort() 32 this.initialize()
33 } 33 }
34 34
35 async removeFollowing (follow: ActorFollow) { 35 async removeFollowing (follow: ActorFollow) {
diff --git a/client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts b/client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
index 866ba1b23..44778ab56 100644
--- a/client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
+++ b/client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
@@ -34,7 +34,7 @@ export class JobsListComponent extends RestTable implements OnInit {
34 34
35 ngOnInit () { 35 ngOnInit () {
36 this.loadJobState() 36 this.loadJobState()
37 this.loadSort() 37 this.initialize()
38 } 38 }
39 39
40 onJobStateChanged () { 40 onJobStateChanged () {
diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
index 681db7434..9837af586 100644
--- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
+++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts
@@ -57,7 +57,7 @@ export class VideoAbuseListComponent extends RestTable implements OnInit {
57 } 57 }
58 58
59 ngOnInit () { 59 ngOnInit () {
60 this.loadSort() 60 this.initialize()
61 } 61 }
62 62
63 openModerationCommentModal (videoAbuse: VideoAbuse) { 63 openModerationCommentModal (videoAbuse: VideoAbuse) {
diff --git a/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts b/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
index bb051d00f..e491edaca 100644
--- a/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
+++ b/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.ts
@@ -39,7 +39,7 @@ export class VideoBlacklistListComponent extends RestTable implements OnInit {
39 } 39 }
40 40
41 ngOnInit () { 41 ngOnInit () {
42 this.loadSort() 42 this.initialize()
43 } 43 }
44 44
45 getVideoUrl (videoBlacklist: VideoBlacklist) { 45 getVideoUrl (videoBlacklist: VideoBlacklist) {
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.html
index 9d1f2e34a..ae8921802 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
@@ -25,6 +25,7 @@
25 <div> 25 <div>
26 <input 26 <input
27 type="text" name="table-filter" id="table-filter" i18n-placeholder placeholder="Filter..." 27 type="text" name="table-filter" id="table-filter" i18n-placeholder placeholder="Filter..."
28 (keyup)="onSearch($event.target.value)"
28 > 29 >
29 </div> 30 </div>
30 </div> 31 </div>
diff --git a/client/src/app/+admin/users/user-list/user-list.component.ts b/client/src/app/+admin/users/user-list/user-list.component.ts
index f3e7e0ead..33384dc35 100644
--- a/client/src/app/+admin/users/user-list/user-list.component.ts
+++ b/client/src/app/+admin/users/user-list/user-list.component.ts
@@ -35,7 +35,7 @@ export class UserListComponent extends RestTable implements OnInit {
35 } 35 }
36 36
37 ngOnInit () { 37 ngOnInit () {
38 this.loadSort() 38 this.initialize()
39 39
40 this.bulkUserActions = [ 40 this.bulkUserActions = [
41 { 41 {
@@ -58,7 +58,7 @@ export class UserListComponent extends RestTable implements OnInit {
58 protected loadData () { 58 protected loadData () {
59 this.selectedUsers = [] 59 this.selectedUsers = []
60 60
61 this.userService.getUsers(this.pagination, this.sort) 61 this.userService.getUsers(this.pagination, this.sort, this.search)
62 .subscribe( 62 .subscribe(
63 resultList => { 63 resultList => {
64 this.users = resultList.data 64 this.users = resultList.data
diff --git a/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts b/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts
index 13517b9f4..520278671 100644
--- a/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts
+++ b/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts
@@ -31,7 +31,7 @@ export class MyAccountOwnershipComponent extends RestTable implements OnInit {
31 } 31 }
32 32
33 ngOnInit () { 33 ngOnInit () {
34 this.loadSort() 34 this.initialize()
35 } 35 }
36 36
37 protected loadData () { 37 protected loadData () {
diff --git a/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts b/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts
index d9fb20446..5b920c98d 100644
--- a/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts
+++ b/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts
@@ -27,7 +27,7 @@ export class MyAccountVideoImportsComponent extends RestTable implements OnInit
27 } 27 }
28 28
29 ngOnInit () { 29 ngOnInit () {
30 this.loadSort() 30 this.initialize()
31 } 31 }
32 32
33 isVideoImportSuccess (videoImport: VideoImport) { 33 isVideoImportSuccess (videoImport: VideoImport) {
diff --git a/client/src/app/shared/moderation/user-moderation-dropdown.component.html b/client/src/app/shared/moderation/user-moderation-dropdown.component.html
index 2c477ab23..01db7cd4a 100644
--- a/client/src/app/shared/moderation/user-moderation-dropdown.component.html
+++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.html
@@ -1,5 +1,5 @@
1<ng-container *ngIf="user && userActions.length !== 0"> 1<ng-container *ngIf="user && userActions.length !== 0">
2 <my-user-ban-modal #userBanModal (userBanned)="onUserBanned()"></my-user-ban-modal> 2 <my-user-ban-modal #userBanModal (userBanned)="onUserBanned()"></my-user-ban-modal>
3 3
4 <my-action-dropdown [actions]="userActions" [entry]="user" [buttonSize]="buttonSize"></my-action-dropdown> 4 <my-action-dropdown [actions]="userActions" [entry]="user" [buttonSize]="buttonSize" [placement]="placement"></my-action-dropdown>
5</ng-container> \ No newline at end of file 5</ng-container> \ No newline at end of file
diff --git a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
index 174e9f024..105c99d8b 100644
--- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
+++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
@@ -17,6 +17,7 @@ export class UserModerationDropdownComponent implements OnInit {
17 17
18 @Input() user: User 18 @Input() user: User
19 @Input() buttonSize: 'normal' | 'small' = 'normal' 19 @Input() buttonSize: 'normal' | 'small' = 'normal'
20 @Input() placement = 'left'
20 21
21 @Output() userChanged = new EventEmitter() 22 @Output() userChanged = new EventEmitter()
22 @Output() userDeleted = new EventEmitter() 23 @Output() userDeleted = new EventEmitter()
diff --git a/client/src/app/shared/rest/rest-table.ts b/client/src/app/shared/rest/rest-table.ts
index fe1a91d2d..26748f245 100644
--- a/client/src/app/shared/rest/rest-table.ts
+++ b/client/src/app/shared/rest/rest-table.ts
@@ -1,8 +1,9 @@
1import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' 1import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
2import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent' 2import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'
3import { SortMeta } from 'primeng/components/common/sortmeta' 3import { SortMeta } from 'primeng/components/common/sortmeta'
4
5import { RestPagination } from './rest-pagination' 4import { RestPagination } from './rest-pagination'
5import { Subject } from 'rxjs'
6import { debounceTime, distinctUntilChanged } from 'rxjs/operators'
6 7
7export abstract class RestTable { 8export abstract class RestTable {
8 9
@@ -11,10 +12,17 @@ export abstract class RestTable {
11 abstract sort: SortMeta 12 abstract sort: SortMeta
12 abstract pagination: RestPagination 13 abstract pagination: RestPagination
13 14
15 protected search: string
16 private searchStream: Subject<string>
14 private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name 17 private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name
15 18
16 protected abstract loadData (): void 19 protected abstract loadData (): void
17 20
21 initialize () {
22 this.loadSort()
23 this.initSearch()
24 }
25
18 loadSort () { 26 loadSort () {
19 const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey) 27 const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey)
20 28
@@ -46,4 +54,21 @@ export abstract class RestTable {
46 peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) 54 peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort))
47 } 55 }
48 56
57 initSearch () {
58 this.searchStream = new Subject()
59
60 this.searchStream
61 .pipe(
62 debounceTime(400),
63 distinctUntilChanged()
64 )
65 .subscribe(search => {
66 this.search = search
67 this.loadData()
68 })
69 }
70
71 onSearch (search: string) {
72 this.searchStream.next(search)
73 }
49} 74}
diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts
index 0eb3870b0..27a81f0a2 100644
--- a/client/src/app/shared/users/user.service.ts
+++ b/client/src/app/shared/users/user.service.ts
@@ -158,10 +158,12 @@ export class UserService {
158 .pipe(catchError(err => this.restExtractor.handleError(err))) 158 .pipe(catchError(err => this.restExtractor.handleError(err)))
159 } 159 }
160 160
161 getUsers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<User>> { 161 getUsers (pagination: RestPagination, sort: SortMeta, search?: string): Observable<ResultList<User>> {
162 let params = new HttpParams() 162 let params = new HttpParams()
163 params = this.restService.addRestGetParams(params, pagination, sort) 163 params = this.restService.addRestGetParams(params, pagination, sort)
164 164
165 if (search) params = params.append('search', search)
166
165 return this.authHttp.get<ResultList<User>>(UserService.BASE_USERS_URL, { params }) 167 return this.authHttp.get<ResultList<User>>(UserService.BASE_USERS_URL, { params })
166 .pipe( 168 .pipe(
167 map(res => this.restExtractor.convertResultListDateToHuman(res)), 169 map(res => this.restExtractor.convertResultListDateToHuman(res)),
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 0b0081520..4f8137c03 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -238,7 +238,7 @@ async function autocompleteUsers (req: express.Request, res: express.Response, n
238} 238}
239 239
240async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) { 240async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) {
241 const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort) 241 const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search)
242 242
243 return res.json(getFormattedObjects(resultList.data, resultList.total)) 243 return res.json(getFormattedObjects(resultList.data, resultList.total))
244} 244}
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index e56b0bf40..39654cfcf 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -181,7 +181,25 @@ export class UserModel extends Model<UserModel> {
181 return this.count() 181 return this.count()
182 } 182 }
183 183
184 static listForApi (start: number, count: number, sort: string) { 184 static listForApi (start: number, count: number, sort: string, search?: string) {
185 let where = undefined
186 if (search) {
187 where = {
188 [Sequelize.Op.or]: [
189 {
190 email: {
191 [Sequelize.Op.iLike]: '%' + search + '%'
192 }
193 },
194 {
195 username: {
196 [ Sequelize.Op.iLike ]: '%' + search + '%'
197 }
198 }
199 ]
200 }
201 }
202
185 const query = { 203 const query = {
186 attributes: { 204 attributes: {
187 include: [ 205 include: [
@@ -204,7 +222,8 @@ export class UserModel extends Model<UserModel> {
204 }, 222 },
205 offset: start, 223 offset: start,
206 limit: count, 224 limit: count,
207 order: getSort(sort) 225 order: getSort(sort),
226 where
208 } 227 }
209 228
210 return UserModel.findAndCountAll(query) 229 return UserModel.findAndCountAll(query)
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 8b9c6b455..513bca8a0 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -180,7 +180,7 @@ describe('Test users', function () {
180 it('Should be able to upload a video again') 180 it('Should be able to upload a video again')
181 181
182 it('Should be able to create a new user', async function () { 182 it('Should be able to create a new user', async function () {
183 await createUser(server.url, accessToken, user.username,user.password, 2 * 1024 * 1024) 183 await createUser(server.url, accessToken, user.username, user.password, 2 * 1024 * 1024)
184 }) 184 })
185 185
186 it('Should be able to login with this user', async function () { 186 it('Should be able to login with this user', async function () {
@@ -322,6 +322,40 @@ describe('Test users', function () {
322 expect(users[ 1 ].nsfwPolicy).to.equal('display') 322 expect(users[ 1 ].nsfwPolicy).to.equal('display')
323 }) 323 })
324 324
325 it('Should search user by username', async function () {
326 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
327 const users = res.body.data as User[]
328
329 expect(res.body.total).to.equal(1)
330 expect(users.length).to.equal(1)
331
332 expect(users[ 0 ].username).to.equal('root')
333 })
334
335 it('Should search user by email', async function () {
336 {
337 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
338 const users = res.body.data as User[]
339
340 expect(res.body.total).to.equal(1)
341 expect(users.length).to.equal(1)
342
343 expect(users[ 0 ].username).to.equal('user_1')
344 expect(users[ 0 ].email).to.equal('user_1@example.com')
345 }
346
347 {
348 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
349 const users = res.body.data as User[]
350
351 expect(res.body.total).to.equal(2)
352 expect(users.length).to.equal(2)
353
354 expect(users[ 0 ].username).to.equal('root')
355 expect(users[ 1 ].username).to.equal('user_1')
356 }
357 })
358
325 it('Should update my password', async function () { 359 it('Should update my password', async function () {
326 await updateMyUser({ 360 await updateMyUser({
327 url: server.url, 361 url: server.url,
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index 41d8ce265..d77233d62 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -112,7 +112,7 @@ function getUsersList (url: string, accessToken: string) {
112 .expect('Content-Type', /json/) 112 .expect('Content-Type', /json/)
113} 113}
114 114
115function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string) { 115function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string, search?: string) {
116 const path = '/api/v1/users' 116 const path = '/api/v1/users'
117 117
118 return request(url) 118 return request(url)
@@ -120,6 +120,7 @@ function getUsersListPaginationAndSort (url: string, accessToken: string, start:
120 .query({ start }) 120 .query({ start })
121 .query({ count }) 121 .query({ count })
122 .query({ sort }) 122 .query({ sort })
123 .query({ search })
123 .set('Accept', 'application/json') 124 .set('Accept', 'application/json')
124 .set('Authorization', 'Bearer ' + accessToken) 125 .set('Authorization', 'Bearer ' + accessToken)
125 .expect(200) 126 .expect(200)