aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-24 15:05:51 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-31 11:35:19 +0200
commitedbc9325462ddf4536775871ebc25e06f46612d1 (patch)
tree9671dd51303e75d48d4f4f9a1df7a1960e33780d /server/controllers/api/users
parent20516920d2b72c8a18bc24b9740f7176aa962da2 (diff)
downloadPeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.tar.gz
PeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.tar.zst
PeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.zip
Add server API to abuse messages
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r--server/controllers/api/users/index.ts26
-rw-r--r--server/controllers/api/users/my-abuses.ts48
2 files changed, 62 insertions, 12 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 5939f6125..d339c2a1c 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -1,10 +1,20 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as RateLimit from 'express-rate-limit' 2import * as RateLimit from 'express-rate-limit'
3import { tokensRouter } from '@server/controllers/api/users/token'
4import { Hooks } from '@server/lib/plugins/hooks'
5import { MUser, MUserAccountDefault } from '@server/types/models'
3import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared' 6import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared'
7import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
8import { UserRegister } from '../../../../shared/models/users/user-register.model'
9import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
4import { logger } from '../../../helpers/logger' 10import { logger } from '../../../helpers/logger'
5import { generateRandomString, getFormattedObjects } from '../../../helpers/utils' 11import { generateRandomString, getFormattedObjects } from '../../../helpers/utils'
12import { CONFIG } from '../../../initializers/config'
6import { WEBSERVER } from '../../../initializers/constants' 13import { WEBSERVER } from '../../../initializers/constants'
14import { sequelizeTypescript } from '../../../initializers/database'
7import { Emailer } from '../../../lib/emailer' 15import { Emailer } from '../../../lib/emailer'
16import { Notifier } from '../../../lib/notifier'
17import { deleteUserToken } from '../../../lib/oauth-model'
8import { Redis } from '../../../lib/redis' 18import { Redis } from '../../../lib/redis'
9import { createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user' 19import { createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user'
10import { 20import {
@@ -18,9 +28,9 @@ import {
18 setDefaultPagination, 28 setDefaultPagination,
19 setDefaultSort, 29 setDefaultSort,
20 userAutocompleteValidator, 30 userAutocompleteValidator,
21 usersListValidator,
22 usersAddValidator, 31 usersAddValidator,
23 usersGetValidator, 32 usersGetValidator,
33 usersListValidator,
24 usersRegisterValidator, 34 usersRegisterValidator,
25 usersRemoveValidator, 35 usersRemoveValidator,
26 usersSortValidator, 36 usersSortValidator,
@@ -35,22 +45,13 @@ import {
35 usersVerifyEmailValidator 45 usersVerifyEmailValidator
36} from '../../../middlewares/validators' 46} from '../../../middlewares/validators'
37import { UserModel } from '../../../models/account/user' 47import { UserModel } from '../../../models/account/user'
38import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
39import { meRouter } from './me' 48import { meRouter } from './me'
40import { deleteUserToken } from '../../../lib/oauth-model' 49import { myAbusesRouter } from './my-abuses'
41import { myBlocklistRouter } from './my-blocklist' 50import { myBlocklistRouter } from './my-blocklist'
42import { myVideoPlaylistsRouter } from './my-video-playlists'
43import { myVideosHistoryRouter } from './my-history' 51import { myVideosHistoryRouter } from './my-history'
44import { myNotificationsRouter } from './my-notifications' 52import { myNotificationsRouter } from './my-notifications'
45import { Notifier } from '../../../lib/notifier'
46import { mySubscriptionsRouter } from './my-subscriptions' 53import { mySubscriptionsRouter } from './my-subscriptions'
47import { CONFIG } from '../../../initializers/config' 54import { myVideoPlaylistsRouter } from './my-video-playlists'
48import { sequelizeTypescript } from '../../../initializers/database'
49import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
50import { UserRegister } from '../../../../shared/models/users/user-register.model'
51import { MUser, MUserAccountDefault } from '@server/types/models'
52import { Hooks } from '@server/lib/plugins/hooks'
53import { tokensRouter } from '@server/controllers/api/users/token'
54 55
55const auditLogger = auditLoggerFactory('users') 56const auditLogger = auditLoggerFactory('users')
56 57
@@ -72,6 +73,7 @@ usersRouter.use('/', mySubscriptionsRouter)
72usersRouter.use('/', myBlocklistRouter) 73usersRouter.use('/', myBlocklistRouter)
73usersRouter.use('/', myVideosHistoryRouter) 74usersRouter.use('/', myVideosHistoryRouter)
74usersRouter.use('/', myVideoPlaylistsRouter) 75usersRouter.use('/', myVideoPlaylistsRouter)
76usersRouter.use('/', myAbusesRouter)
75usersRouter.use('/', meRouter) 77usersRouter.use('/', meRouter)
76 78
77usersRouter.get('/autocomplete', 79usersRouter.get('/autocomplete',
diff --git a/server/controllers/api/users/my-abuses.ts b/server/controllers/api/users/my-abuses.ts
new file mode 100644
index 000000000..e43fc483e
--- /dev/null
+++ b/server/controllers/api/users/my-abuses.ts
@@ -0,0 +1,48 @@
1import * as express from 'express'
2import { AbuseModel } from '@server/models/abuse/abuse'
3import {
4 abuseListForUserValidator,
5 abusesSortValidator,
6 asyncMiddleware,
7 authenticate,
8 paginationValidator,
9 setDefaultPagination,
10 setDefaultSort
11} from '../../../middlewares'
12
13const myAbusesRouter = express.Router()
14
15myAbusesRouter.get('/me/abuses',
16 authenticate,
17 paginationValidator,
18 abusesSortValidator,
19 setDefaultSort,
20 setDefaultPagination,
21 abuseListForUserValidator,
22 asyncMiddleware(listMyAbuses)
23)
24
25// ---------------------------------------------------------------------------
26
27export {
28 myAbusesRouter
29}
30
31// ---------------------------------------------------------------------------
32
33async function listMyAbuses (req: express.Request, res: express.Response) {
34 const resultList = await AbuseModel.listForUserApi({
35 start: req.query.start,
36 count: req.query.count,
37 sort: req.query.sort,
38 id: req.query.id,
39 search: req.query.search,
40 state: req.query.state,
41 user: res.locals.oauth.token.User
42 })
43
44 return res.json({
45 total: resultList.total,
46 data: resultList.data.map(d => d.toFormattedAdminJSON())
47 })
48}