diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-24 15:05:51 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-07-31 11:35:19 +0200 |
commit | edbc9325462ddf4536775871ebc25e06f46612d1 (patch) | |
tree | 9671dd51303e75d48d4f4f9a1df7a1960e33780d /server/controllers/api/users | |
parent | 20516920d2b72c8a18bc24b9740f7176aa962da2 (diff) | |
download | PeerTube-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.ts | 26 | ||||
-rw-r--r-- | server/controllers/api/users/my-abuses.ts | 48 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as RateLimit from 'express-rate-limit' | 2 | import * as RateLimit from 'express-rate-limit' |
3 | import { tokensRouter } from '@server/controllers/api/users/token' | ||
4 | import { Hooks } from '@server/lib/plugins/hooks' | ||
5 | import { MUser, MUserAccountDefault } from '@server/types/models' | ||
3 | import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared' | 6 | import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared' |
7 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
8 | import { UserRegister } from '../../../../shared/models/users/user-register.model' | ||
9 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' | ||
4 | import { logger } from '../../../helpers/logger' | 10 | import { logger } from '../../../helpers/logger' |
5 | import { generateRandomString, getFormattedObjects } from '../../../helpers/utils' | 11 | import { generateRandomString, getFormattedObjects } from '../../../helpers/utils' |
12 | import { CONFIG } from '../../../initializers/config' | ||
6 | import { WEBSERVER } from '../../../initializers/constants' | 13 | import { WEBSERVER } from '../../../initializers/constants' |
14 | import { sequelizeTypescript } from '../../../initializers/database' | ||
7 | import { Emailer } from '../../../lib/emailer' | 15 | import { Emailer } from '../../../lib/emailer' |
16 | import { Notifier } from '../../../lib/notifier' | ||
17 | import { deleteUserToken } from '../../../lib/oauth-model' | ||
8 | import { Redis } from '../../../lib/redis' | 18 | import { Redis } from '../../../lib/redis' |
9 | import { createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user' | 19 | import { createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user' |
10 | import { | 20 | import { |
@@ -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' |
37 | import { UserModel } from '../../../models/account/user' | 47 | import { UserModel } from '../../../models/account/user' |
38 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' | ||
39 | import { meRouter } from './me' | 48 | import { meRouter } from './me' |
40 | import { deleteUserToken } from '../../../lib/oauth-model' | 49 | import { myAbusesRouter } from './my-abuses' |
41 | import { myBlocklistRouter } from './my-blocklist' | 50 | import { myBlocklistRouter } from './my-blocklist' |
42 | import { myVideoPlaylistsRouter } from './my-video-playlists' | ||
43 | import { myVideosHistoryRouter } from './my-history' | 51 | import { myVideosHistoryRouter } from './my-history' |
44 | import { myNotificationsRouter } from './my-notifications' | 52 | import { myNotificationsRouter } from './my-notifications' |
45 | import { Notifier } from '../../../lib/notifier' | ||
46 | import { mySubscriptionsRouter } from './my-subscriptions' | 53 | import { mySubscriptionsRouter } from './my-subscriptions' |
47 | import { CONFIG } from '../../../initializers/config' | 54 | import { myVideoPlaylistsRouter } from './my-video-playlists' |
48 | import { sequelizeTypescript } from '../../../initializers/database' | ||
49 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
50 | import { UserRegister } from '../../../../shared/models/users/user-register.model' | ||
51 | import { MUser, MUserAccountDefault } from '@server/types/models' | ||
52 | import { Hooks } from '@server/lib/plugins/hooks' | ||
53 | import { tokensRouter } from '@server/controllers/api/users/token' | ||
54 | 55 | ||
55 | const auditLogger = auditLoggerFactory('users') | 56 | const auditLogger = auditLoggerFactory('users') |
56 | 57 | ||
@@ -72,6 +73,7 @@ usersRouter.use('/', mySubscriptionsRouter) | |||
72 | usersRouter.use('/', myBlocklistRouter) | 73 | usersRouter.use('/', myBlocklistRouter) |
73 | usersRouter.use('/', myVideosHistoryRouter) | 74 | usersRouter.use('/', myVideosHistoryRouter) |
74 | usersRouter.use('/', myVideoPlaylistsRouter) | 75 | usersRouter.use('/', myVideoPlaylistsRouter) |
76 | usersRouter.use('/', myAbusesRouter) | ||
75 | usersRouter.use('/', meRouter) | 77 | usersRouter.use('/', meRouter) |
76 | 78 | ||
77 | usersRouter.get('/autocomplete', | 79 | usersRouter.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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { AbuseModel } from '@server/models/abuse/abuse' | ||
3 | import { | ||
4 | abuseListForUserValidator, | ||
5 | abusesSortValidator, | ||
6 | asyncMiddleware, | ||
7 | authenticate, | ||
8 | paginationValidator, | ||
9 | setDefaultPagination, | ||
10 | setDefaultSort | ||
11 | } from '../../../middlewares' | ||
12 | |||
13 | const myAbusesRouter = express.Router() | ||
14 | |||
15 | myAbusesRouter.get('/me/abuses', | ||
16 | authenticate, | ||
17 | paginationValidator, | ||
18 | abusesSortValidator, | ||
19 | setDefaultSort, | ||
20 | setDefaultPagination, | ||
21 | abuseListForUserValidator, | ||
22 | asyncMiddleware(listMyAbuses) | ||
23 | ) | ||
24 | |||
25 | // --------------------------------------------------------------------------- | ||
26 | |||
27 | export { | ||
28 | myAbusesRouter | ||
29 | } | ||
30 | |||
31 | // --------------------------------------------------------------------------- | ||
32 | |||
33 | async 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 | } | ||