2020-02-07 10:27:16 +01:00
|
|
|
import { SortMeta } from 'primeng/api'
|
2021-05-03 14:33:34 +02:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core'
|
2021-05-03 11:06:19 +02:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router'
|
2022-05-24 15:05:39 +02:00
|
|
|
import { AuthService, ConfirmService, LocalStorageService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
|
2022-07-15 15:30:14 +02:00
|
|
|
import { getAPIHost, prepareIcu } from '@app/helpers'
|
2021-05-03 11:06:19 +02:00
|
|
|
import { AdvancedInputFilter } from '@app/shared/shared-forms'
|
2022-02-28 10:41:23 +01:00
|
|
|
import { Actor, DropdownAction } from '@app/shared/shared-main'
|
|
|
|
import { AccountMutedStatus, BlocklistService, UserBanModalComponent, UserModerationDisplayType } from '@app/shared/shared-moderation'
|
2022-01-21 11:03:25 +01:00
|
|
|
import { UserAdminService } from '@app/shared/shared-users'
|
2022-07-15 15:30:14 +02:00
|
|
|
import { logger } from '@root-helpers/logger'
|
2021-06-04 13:31:41 +02:00
|
|
|
import { User, UserRole } from '@shared/models'
|
2016-08-09 21:45:21 +02:00
|
|
|
|
2020-07-23 21:30:04 +02:00
|
|
|
type UserForList = User & {
|
|
|
|
rawVideoQuota: number
|
|
|
|
rawVideoQuotaUsed: number
|
|
|
|
rawVideoQuotaDaily: number
|
|
|
|
rawVideoQuotaUsedDaily: number
|
|
|
|
}
|
|
|
|
|
2016-08-09 21:45:21 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'my-user-list',
|
2016-09-19 22:49:31 +02:00
|
|
|
templateUrl: './user-list.component.html',
|
|
|
|
styleUrls: [ './user-list.component.scss' ]
|
2016-08-09 21:45:21 +02:00
|
|
|
})
|
2021-05-03 14:33:34 +02:00
|
|
|
export class UserListComponent extends RestTable implements OnInit {
|
2022-05-24 15:05:39 +02:00
|
|
|
private static readonly LOCAL_STORAGE_SELECTED_COLUMNS_KEY = 'admin-user-list-selected-columns'
|
|
|
|
|
2019-07-24 16:05:59 +02:00
|
|
|
@ViewChild('userBanModal', { static: true }) userBanModal: UserBanModalComponent
|
2018-10-08 15:15:11 +02:00
|
|
|
|
2022-02-28 10:41:23 +01:00
|
|
|
users: (User & { accountMutedStatus: AccountMutedStatus })[] = []
|
2021-05-03 11:06:19 +02:00
|
|
|
|
2017-09-14 11:57:49 +02:00
|
|
|
totalRecords = 0
|
2018-02-23 14:36:16 +01:00
|
|
|
sort: SortMeta = { field: 'createdAt', order: 1 }
|
2017-09-14 11:57:49 +02:00
|
|
|
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
|
2021-05-03 11:06:19 +02:00
|
|
|
|
2020-07-15 11:17:03 +02:00
|
|
|
highlightBannedUsers = false
|
2018-08-09 17:51:25 +02:00
|
|
|
|
2018-10-08 15:15:11 +02:00
|
|
|
selectedUsers: User[] = []
|
2020-01-15 19:25:51 +01:00
|
|
|
bulkUserActions: DropdownAction<User[]>[][] = []
|
2020-08-11 16:07:53 +02:00
|
|
|
columns: { id: string, label: string }[]
|
2018-10-08 15:15:11 +02:00
|
|
|
|
2021-05-03 11:06:19 +02:00
|
|
|
inputFilters: AdvancedInputFilter[] = [
|
|
|
|
{
|
2021-10-20 09:05:43 +02:00
|
|
|
title: $localize`Advanced filters`,
|
|
|
|
children: [
|
|
|
|
{
|
2021-11-03 14:23:55 +01:00
|
|
|
value: 'banned:true',
|
2021-10-20 09:05:43 +02:00
|
|
|
label: $localize`Banned users`
|
|
|
|
}
|
|
|
|
]
|
2021-05-03 11:06:19 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-02-28 10:41:23 +01:00
|
|
|
userModerationDisplayOptions: UserModerationDisplayType = {
|
|
|
|
instanceAccount: true,
|
|
|
|
instanceUser: true,
|
|
|
|
myAccount: false
|
|
|
|
}
|
|
|
|
|
2021-06-04 13:31:41 +02:00
|
|
|
requiresEmailVerification = false
|
|
|
|
|
2022-05-24 15:05:39 +02:00
|
|
|
private _selectedColumns: string[] = []
|
2019-12-18 15:31:54 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
constructor (
|
2020-11-16 14:47:05 +01:00
|
|
|
protected route: ActivatedRoute,
|
|
|
|
protected router: Router,
|
2018-12-19 16:04:34 +01:00
|
|
|
private notifier: Notifier,
|
2017-01-27 16:54:44 +01:00
|
|
|
private confirmService: ConfirmService,
|
2018-11-21 08:48:29 +01:00
|
|
|
private serverService: ServerService,
|
2019-07-30 09:59:19 +02:00
|
|
|
private auth: AuthService,
|
2022-02-28 10:41:23 +01:00
|
|
|
private blocklist: BlocklistService,
|
2022-05-24 15:05:39 +02:00
|
|
|
private userAdminService: UserAdminService,
|
|
|
|
private peertubeLocalStorage: LocalStorageService
|
2020-11-16 14:47:05 +01:00
|
|
|
) {
|
2017-09-14 11:57:49 +02:00
|
|
|
super()
|
2016-08-09 21:45:21 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 09:59:19 +02:00
|
|
|
get authUser () {
|
|
|
|
return this.auth.getUser()
|
|
|
|
}
|
|
|
|
|
2020-07-15 11:17:03 +02:00
|
|
|
get selectedColumns () {
|
2022-05-24 15:05:39 +02:00
|
|
|
return this._selectedColumns || []
|
2020-07-15 11:17:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-11 16:07:53 +02:00
|
|
|
set selectedColumns (val: string[]) {
|
2020-07-15 11:17:03 +02:00
|
|
|
this._selectedColumns = val
|
2022-05-24 15:05:39 +02:00
|
|
|
|
|
|
|
this.saveSelectedColumns()
|
2020-07-15 11:17:03 +02:00
|
|
|
}
|
|
|
|
|
2018-02-23 14:36:16 +01:00
|
|
|
ngOnInit () {
|
2019-12-18 15:31:54 +01:00
|
|
|
this.serverService.getConfig()
|
2021-06-04 13:31:41 +02:00
|
|
|
.subscribe(config => this.requiresEmailVerification = config.signup.requiresEmailVerification)
|
2019-12-18 15:31:54 +01:00
|
|
|
|
2018-10-08 15:51:38 +02:00
|
|
|
this.initialize()
|
2020-07-02 22:49:51 +02:00
|
|
|
|
2018-10-08 15:15:11 +02:00
|
|
|
this.bulkUserActions = [
|
2020-01-15 19:25:51 +01:00
|
|
|
[
|
|
|
|
{
|
2020-08-12 10:40:04 +02:00
|
|
|
label: $localize`Delete`,
|
|
|
|
description: $localize`Videos will be deleted, comments will be tombstoned.`,
|
2020-01-15 19:25:51 +01:00
|
|
|
handler: users => this.removeUsers(users),
|
|
|
|
isDisplayed: users => users.every(u => this.authUser.canManage(u))
|
|
|
|
},
|
|
|
|
{
|
2020-08-12 10:40:04 +02:00
|
|
|
label: $localize`Ban`,
|
|
|
|
description: $localize`User won't be able to login anymore, but videos and comments will be kept as is.`,
|
2020-01-15 19:25:51 +01:00
|
|
|
handler: users => this.openBanUserModal(users),
|
|
|
|
isDisplayed: users => users.every(u => this.authUser.canManage(u) && u.blocked === false)
|
|
|
|
},
|
|
|
|
{
|
2020-08-12 10:40:04 +02:00
|
|
|
label: $localize`Unban`,
|
2020-01-15 19:25:51 +01:00
|
|
|
handler: users => this.unbanUsers(users),
|
|
|
|
isDisplayed: users => users.every(u => this.authUser.canManage(u) && u.blocked === true)
|
2019-07-30 09:59:19 +02:00
|
|
|
}
|
2020-01-15 19:25:51 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2020-08-12 10:40:04 +02:00
|
|
|
label: $localize`Set Email as Verified`,
|
2020-01-15 19:25:51 +01:00
|
|
|
handler: users => this.setEmailsAsVerified(users),
|
|
|
|
isDisplayed: users => {
|
|
|
|
return this.requiresEmailVerification &&
|
|
|
|
users.every(u => this.authUser.canManage(u) && !u.blocked && u.emailVerified === false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2018-10-08 15:15:11 +02:00
|
|
|
]
|
2020-07-15 11:17:03 +02:00
|
|
|
|
|
|
|
this.columns = [
|
2021-07-21 16:22:18 +02:00
|
|
|
{ id: 'username', label: $localize`Username` },
|
2022-02-28 10:41:23 +01:00
|
|
|
{ id: 'role', label: $localize`Role` },
|
2021-07-21 16:22:18 +02:00
|
|
|
{ id: 'email', label: $localize`Email` },
|
|
|
|
{ id: 'quota', label: $localize`Video quota` },
|
2022-05-24 15:05:39 +02:00
|
|
|
{ id: 'createdAt', label: $localize`Created` },
|
|
|
|
{ id: 'lastLoginDate', label: $localize`Last login` },
|
|
|
|
|
|
|
|
{ id: 'quotaDaily', label: $localize`Daily quota` },
|
|
|
|
{ id: 'pluginAuth', label: $localize`Auth plugin` }
|
2020-07-15 11:17:03 +02:00
|
|
|
]
|
2020-08-11 16:07:53 +02:00
|
|
|
|
2022-05-24 15:05:39 +02:00
|
|
|
this.loadSelectedColumns()
|
|
|
|
}
|
|
|
|
|
|
|
|
loadSelectedColumns () {
|
|
|
|
const result = this.peertubeLocalStorage.getItem(UserListComponent.LOCAL_STORAGE_SELECTED_COLUMNS_KEY)
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
try {
|
|
|
|
this.selectedColumns = JSON.parse(result)
|
|
|
|
return
|
|
|
|
} catch (err) {
|
2022-07-15 15:30:14 +02:00
|
|
|
logger.error('Cannot load selected columns.', err)
|
2022-05-24 15:05:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default behaviour
|
|
|
|
this.selectedColumns = [ 'username', 'role', 'email', 'quota', 'createdAt', 'lastLoginDate' ]
|
|
|
|
return
|
|
|
|
}
|
2020-08-11 16:07:53 +02:00
|
|
|
|
2022-05-24 15:05:39 +02:00
|
|
|
saveSelectedColumns () {
|
|
|
|
this.peertubeLocalStorage.setItem(UserListComponent.LOCAL_STORAGE_SELECTED_COLUMNS_KEY, JSON.stringify(this.selectedColumns))
|
2018-08-09 17:51:25 +02:00
|
|
|
}
|
|
|
|
|
2020-04-08 10:49:26 +02:00
|
|
|
getIdentifier () {
|
|
|
|
return 'UserListComponent'
|
|
|
|
}
|
|
|
|
|
2020-07-15 11:17:03 +02:00
|
|
|
getRoleClass (role: UserRole) {
|
|
|
|
switch (role) {
|
|
|
|
case UserRole.ADMINISTRATOR:
|
|
|
|
return 'badge-purple'
|
|
|
|
case UserRole.MODERATOR:
|
|
|
|
return 'badge-blue'
|
|
|
|
default:
|
|
|
|
return 'badge-yellow'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 16:07:53 +02:00
|
|
|
isSelected (id: string) {
|
|
|
|
return this.selectedColumns.find(c => c === id)
|
|
|
|
}
|
|
|
|
|
|
|
|
getColumn (id: string) {
|
|
|
|
return this.columns.find(c => c.id === id)
|
2020-07-15 11:17:03 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 21:30:04 +02:00
|
|
|
getUserVideoQuotaPercentage (user: UserForList) {
|
2020-07-15 11:17:03 +02:00
|
|
|
return user.rawVideoQuotaUsed * 100 / user.rawVideoQuota
|
|
|
|
}
|
|
|
|
|
2020-07-23 21:30:04 +02:00
|
|
|
getUserVideoQuotaDailyPercentage (user: UserForList) {
|
2020-07-15 11:17:03 +02:00
|
|
|
return user.rawVideoQuotaUsedDaily * 100 / user.rawVideoQuotaDaily
|
|
|
|
}
|
|
|
|
|
2018-10-08 15:15:11 +02:00
|
|
|
openBanUserModal (users: User[]) {
|
|
|
|
for (const user of users) {
|
|
|
|
if (user.username === 'root') {
|
2020-08-12 10:40:04 +02:00
|
|
|
this.notifier.error($localize`You cannot ban root.`)
|
2018-10-08 15:15:11 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.userBanModal.openModal(users)
|
|
|
|
}
|
|
|
|
|
2018-11-15 09:24:56 +01:00
|
|
|
onUserChanged () {
|
2021-05-03 14:33:34 +02:00
|
|
|
this.reloadData()
|
2018-10-08 15:15:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async unbanUsers (users: User[]) {
|
2022-05-24 16:29:01 +02:00
|
|
|
const res = await this.confirmService.confirm(
|
|
|
|
prepareIcu($localize`Do you really want to unban {count, plural, =1 {1 user} other {{count} users}}?`)(
|
|
|
|
{ count: users.length },
|
|
|
|
$localize`Do you really want to unban ${users.length} users?`
|
|
|
|
),
|
|
|
|
$localize`Unban`
|
|
|
|
)
|
|
|
|
|
2018-10-08 15:15:11 +02:00
|
|
|
if (res === false) return
|
|
|
|
|
2022-01-21 11:03:25 +01:00
|
|
|
this.userAdminService.unbanUsers(users)
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
2022-05-24 16:29:01 +02:00
|
|
|
this.notifier.success(
|
2022-06-16 17:05:24 +02:00
|
|
|
prepareIcu($localize`{count, plural, =1 {1 user unbanned.} other {{count} users unbanned.}}`)(
|
2022-05-24 16:29:01 +02:00
|
|
|
{ count: users.length },
|
|
|
|
$localize`${users.length} users unbanned.`
|
|
|
|
)
|
|
|
|
)
|
2021-05-03 14:33:34 +02:00
|
|
|
this.reloadData()
|
2018-10-08 15:15:11 +02:00
|
|
|
},
|
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
2018-10-08 15:15:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async removeUsers (users: User[]) {
|
2022-05-24 16:29:01 +02:00
|
|
|
if (users.some(u => u.username === 'root')) {
|
|
|
|
this.notifier.error($localize`You cannot delete root.`)
|
|
|
|
return
|
2018-10-08 15:15:11 +02:00
|
|
|
}
|
|
|
|
|
2022-05-24 16:29:01 +02:00
|
|
|
const message = $localize`<p>You can't create users or channels with a username that already used by a deleted user/channel.</p>` +
|
|
|
|
$localize`It means the following usernames will be permanently deleted and cannot be recovered:` +
|
|
|
|
'<ul>' + users.map(u => '<li>' + u.username + '</li>').join('') + '</ul>'
|
|
|
|
|
2020-08-12 10:40:04 +02:00
|
|
|
const res = await this.confirmService.confirm(message, $localize`Delete`)
|
2018-10-08 15:15:11 +02:00
|
|
|
if (res === false) return
|
|
|
|
|
2022-01-21 11:03:25 +01:00
|
|
|
this.userAdminService.removeUser(users)
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
2022-05-24 16:29:01 +02:00
|
|
|
this.notifier.success(
|
2022-06-16 17:05:24 +02:00
|
|
|
prepareIcu($localize`{count, plural, =1 {1 user deleted.} other {{count} users deleted.}}`)(
|
2022-05-24 16:29:01 +02:00
|
|
|
{ count: users.length },
|
|
|
|
$localize`${users.length} users deleted.`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
this.reloadData()
|
|
|
|
},
|
2018-10-08 15:15:11 +02:00
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
2018-10-08 15:15:11 +02:00
|
|
|
}
|
|
|
|
|
2021-08-25 16:14:11 +02:00
|
|
|
setEmailsAsVerified (users: User[]) {
|
2022-01-21 11:03:25 +01:00
|
|
|
this.userAdminService.updateUsers(users, { emailVerified: true })
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
2022-05-24 16:29:01 +02:00
|
|
|
this.notifier.success(
|
2022-06-16 17:05:24 +02:00
|
|
|
prepareIcu($localize`{count, plural, =1 {1 user email set as verified.} other {{count} user emails set as verified.}}`)(
|
2022-05-24 16:29:01 +02:00
|
|
|
{ count: users.length },
|
|
|
|
$localize`${users.length} users email set as verified.`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
this.reloadData()
|
|
|
|
},
|
2018-11-21 08:48:29 +01:00
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
2018-11-21 08:48:29 +01:00
|
|
|
}
|
|
|
|
|
2018-10-08 15:15:11 +02:00
|
|
|
isInSelectionMode () {
|
|
|
|
return this.selectedUsers.length !== 0
|
|
|
|
}
|
2018-10-16 01:04:50 +02:00
|
|
|
|
2021-05-03 14:33:34 +02:00
|
|
|
protected reloadData () {
|
2018-10-16 01:04:50 +02:00
|
|
|
this.selectedUsers = []
|
|
|
|
|
2022-01-21 11:03:25 +01:00
|
|
|
this.userAdminService.getUsers({
|
2020-07-02 22:49:51 +02:00
|
|
|
pagination: this.pagination,
|
|
|
|
sort: this.sort,
|
|
|
|
search: this.search
|
2021-08-17 11:27:47 +02:00
|
|
|
}).subscribe({
|
|
|
|
next: resultList => {
|
2022-02-28 10:41:23 +01:00
|
|
|
this.users = resultList.data.map(u => ({
|
|
|
|
...u,
|
|
|
|
|
|
|
|
accountMutedStatus: {
|
|
|
|
...u.account,
|
|
|
|
|
|
|
|
nameWithHost: Actor.CREATE_BY_STRING(u.account.name, u.account.host),
|
|
|
|
|
|
|
|
mutedByInstance: false,
|
|
|
|
mutedByUser: false,
|
|
|
|
mutedServerByInstance: false,
|
|
|
|
mutedServerByUser: false
|
|
|
|
}
|
|
|
|
}))
|
2020-07-02 22:49:51 +02:00
|
|
|
this.totalRecords = resultList.total
|
2022-02-28 10:41:23 +01:00
|
|
|
|
|
|
|
this.loadMutedStatus()
|
2020-07-02 22:49:51 +02:00
|
|
|
},
|
2018-12-19 16:04:34 +01:00
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
2018-10-16 01:04:50 +02:00
|
|
|
}
|
2022-02-28 10:41:23 +01:00
|
|
|
|
|
|
|
private loadMutedStatus () {
|
|
|
|
this.blocklist.getStatus({ accounts: this.users.map(u => u.username + '@' + getAPIHost()) })
|
|
|
|
.subscribe(blockStatus => {
|
|
|
|
for (const user of this.users) {
|
|
|
|
user.accountMutedStatus.mutedByInstance = blockStatus.accounts[user.username + '@' + getAPIHost()].blockedByServer
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2016-08-09 21:45:21 +02:00
|
|
|
}
|