}
ngOnInit () {
- this.loadSort()
+ this.initialize()
}
protected loadData () {
}
ngOnInit () {
- this.loadSort()
+ this.initialize()
}
async removeFollowing (follow: ActorFollow) {
ngOnInit () {
this.loadJobState()
- this.loadSort()
+ this.initialize()
}
onJobStateChanged () {
}
ngOnInit () {
- this.loadSort()
+ this.initialize()
}
openModerationCommentModal (videoAbuse: VideoAbuse) {
}
ngOnInit () {
- this.loadSort()
+ this.initialize()
}
getVideoUrl (videoBlacklist: VideoBlacklist) {
<div>
<input
type="text" name="table-filter" id="table-filter" i18n-placeholder placeholder="Filter..."
+ (keyup)="onSearch($event.target.value)"
>
</div>
</div>
}
ngOnInit () {
- this.loadSort()
+ this.initialize()
this.bulkUserActions = [
{
protected loadData () {
this.selectedUsers = []
- this.userService.getUsers(this.pagination, this.sort)
+ this.userService.getUsers(this.pagination, this.sort, this.search)
.subscribe(
resultList => {
this.users = resultList.data
}
ngOnInit () {
- this.loadSort()
+ this.initialize()
}
protected loadData () {
}
ngOnInit () {
- this.loadSort()
+ this.initialize()
}
isVideoImportSuccess (videoImport: VideoImport) {
<ng-container *ngIf="user && userActions.length !== 0">
<my-user-ban-modal #userBanModal (userBanned)="onUserBanned()"></my-user-ban-modal>
- <my-action-dropdown [actions]="userActions" [entry]="user" [buttonSize]="buttonSize"></my-action-dropdown>
+ <my-action-dropdown [actions]="userActions" [entry]="user" [buttonSize]="buttonSize" [placement]="placement"></my-action-dropdown>
</ng-container>
\ No newline at end of file
@Input() user: User
@Input() buttonSize: 'normal' | 'small' = 'normal'
+ @Input() placement = 'left'
@Output() userChanged = new EventEmitter()
@Output() userDeleted = new EventEmitter()
import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'
import { SortMeta } from 'primeng/components/common/sortmeta'
-
import { RestPagination } from './rest-pagination'
+import { Subject } from 'rxjs'
+import { debounceTime, distinctUntilChanged } from 'rxjs/operators'
export abstract class RestTable {
abstract sort: SortMeta
abstract pagination: RestPagination
+ protected search: string
+ private searchStream: Subject<string>
private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name
protected abstract loadData (): void
+ initialize () {
+ this.loadSort()
+ this.initSearch()
+ }
+
loadSort () {
const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey)
peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort))
}
+ initSearch () {
+ this.searchStream = new Subject()
+
+ this.searchStream
+ .pipe(
+ debounceTime(400),
+ distinctUntilChanged()
+ )
+ .subscribe(search => {
+ this.search = search
+ this.loadData()
+ })
+ }
+
+ onSearch (search: string) {
+ this.searchStream.next(search)
+ }
}
.pipe(catchError(err => this.restExtractor.handleError(err)))
}
- getUsers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<User>> {
+ getUsers (pagination: RestPagination, sort: SortMeta, search?: string): Observable<ResultList<User>> {
let params = new HttpParams()
params = this.restService.addRestGetParams(params, pagination, sort)
+ if (search) params = params.append('search', search)
+
return this.authHttp.get<ResultList<User>>(UserService.BASE_USERS_URL, { params })
.pipe(
map(res => this.restExtractor.convertResultListDateToHuman(res)),
}
async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) {
- const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort)
+ const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
return this.count()
}
- static listForApi (start: number, count: number, sort: string) {
+ static listForApi (start: number, count: number, sort: string, search?: string) {
+ let where = undefined
+ if (search) {
+ where = {
+ [Sequelize.Op.or]: [
+ {
+ email: {
+ [Sequelize.Op.iLike]: '%' + search + '%'
+ }
+ },
+ {
+ username: {
+ [ Sequelize.Op.iLike ]: '%' + search + '%'
+ }
+ }
+ ]
+ }
+ }
+
const query = {
attributes: {
include: [
},
offset: start,
limit: count,
- order: getSort(sort)
+ order: getSort(sort),
+ where
}
return UserModel.findAndCountAll(query)
it('Should be able to upload a video again')
it('Should be able to create a new user', async function () {
- await createUser(server.url, accessToken, user.username,user.password, 2 * 1024 * 1024)
+ await createUser(server.url, accessToken, user.username, user.password, 2 * 1024 * 1024)
})
it('Should be able to login with this user', async function () {
expect(users[ 1 ].nsfwPolicy).to.equal('display')
})
+ it('Should search user by username', async function () {
+ const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
+ const users = res.body.data as User[]
+
+ expect(res.body.total).to.equal(1)
+ expect(users.length).to.equal(1)
+
+ expect(users[ 0 ].username).to.equal('root')
+ })
+
+ it('Should search user by email', async function () {
+ {
+ const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
+ const users = res.body.data as User[]
+
+ expect(res.body.total).to.equal(1)
+ expect(users.length).to.equal(1)
+
+ expect(users[ 0 ].username).to.equal('user_1')
+ expect(users[ 0 ].email).to.equal('user_1@example.com')
+ }
+
+ {
+ const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
+ const users = res.body.data as User[]
+
+ expect(res.body.total).to.equal(2)
+ expect(users.length).to.equal(2)
+
+ expect(users[ 0 ].username).to.equal('root')
+ expect(users[ 1 ].username).to.equal('user_1')
+ }
+ })
+
it('Should update my password', async function () {
await updateMyUser({
url: server.url,
.expect('Content-Type', /json/)
}
-function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string) {
+function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string, search?: string) {
const path = '/api/v1/users'
return request(url)
.query({ start })
.query({ count })
.query({ sort })
+ .query({ search })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.expect(200)