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 /shared | |
parent | 20516920d2b72c8a18bc24b9740f7176aa962da2 (diff) | |
download | PeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.tar.gz PeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.tar.zst PeerTube-edbc9325462ddf4536775871ebc25e06f46612d1.zip |
Add server API to abuse messages
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/moderation/abuses.ts | 86 | ||||
-rw-r--r-- | shared/models/moderation/abuse/abuse-message.model.ts | 9 | ||||
-rw-r--r-- | shared/models/moderation/abuse/abuse.model.ts | 19 | ||||
-rw-r--r-- | shared/models/moderation/abuse/index.ts | 1 |
4 files changed, 107 insertions, 8 deletions
diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts index 62af9556e..7db75cebb 100644 --- a/shared/extra-utils/moderation/abuses.ts +++ b/shared/extra-utils/moderation/abuses.ts | |||
@@ -54,7 +54,7 @@ function reportAbuse (options: { | |||
54 | }) | 54 | }) |
55 | } | 55 | } |
56 | 56 | ||
57 | function getAbusesList (options: { | 57 | function getAdminAbusesList (options: { |
58 | url: string | 58 | url: string |
59 | token: string | 59 | token: string |
60 | 60 | ||
@@ -117,6 +117,48 @@ function getAbusesList (options: { | |||
117 | }) | 117 | }) |
118 | } | 118 | } |
119 | 119 | ||
120 | function getUserAbusesList (options: { | ||
121 | url: string | ||
122 | token: string | ||
123 | |||
124 | start?: number | ||
125 | count?: number | ||
126 | sort?: string | ||
127 | |||
128 | id?: number | ||
129 | search?: string | ||
130 | state?: AbuseState | ||
131 | }) { | ||
132 | const { | ||
133 | url, | ||
134 | token, | ||
135 | start, | ||
136 | count, | ||
137 | sort, | ||
138 | id, | ||
139 | search, | ||
140 | state | ||
141 | } = options | ||
142 | const path = '/api/v1/users/me/abuses' | ||
143 | |||
144 | const query = { | ||
145 | id, | ||
146 | search, | ||
147 | state, | ||
148 | start, | ||
149 | count, | ||
150 | sort: sort || 'createdAt' | ||
151 | } | ||
152 | |||
153 | return makeGetRequest({ | ||
154 | url, | ||
155 | path, | ||
156 | token, | ||
157 | query, | ||
158 | statusCodeExpected: 200 | ||
159 | }) | ||
160 | } | ||
161 | |||
120 | function updateAbuse ( | 162 | function updateAbuse ( |
121 | url: string, | 163 | url: string, |
122 | token: string, | 164 | token: string, |
@@ -146,11 +188,49 @@ function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExp | |||
146 | }) | 188 | }) |
147 | } | 189 | } |
148 | 190 | ||
191 | function listAbuseMessages (url: string, token: string, abuseId: number, statusCodeExpected = 200) { | ||
192 | const path = '/api/v1/abuses/' + abuseId + '/messages' | ||
193 | |||
194 | return makeGetRequest({ | ||
195 | url, | ||
196 | token, | ||
197 | path, | ||
198 | statusCodeExpected | ||
199 | }) | ||
200 | } | ||
201 | |||
202 | function deleteAbuseMessage (url: string, token: string, abuseId: number, messageId: number, statusCodeExpected = 204) { | ||
203 | const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId | ||
204 | |||
205 | return makeDeleteRequest({ | ||
206 | url, | ||
207 | token, | ||
208 | path, | ||
209 | statusCodeExpected | ||
210 | }) | ||
211 | } | ||
212 | |||
213 | function addAbuseMessage (url: string, token: string, abuseId: number, message: string, statusCodeExpected = 200) { | ||
214 | const path = '/api/v1/abuses/' + abuseId + '/messages' | ||
215 | |||
216 | return makePostBodyRequest({ | ||
217 | url, | ||
218 | token, | ||
219 | path, | ||
220 | fields: { message }, | ||
221 | statusCodeExpected | ||
222 | }) | ||
223 | } | ||
224 | |||
149 | // --------------------------------------------------------------------------- | 225 | // --------------------------------------------------------------------------- |
150 | 226 | ||
151 | export { | 227 | export { |
152 | reportAbuse, | 228 | reportAbuse, |
153 | getAbusesList, | 229 | getAdminAbusesList, |
154 | updateAbuse, | 230 | updateAbuse, |
155 | deleteAbuse | 231 | deleteAbuse, |
232 | getUserAbusesList, | ||
233 | listAbuseMessages, | ||
234 | deleteAbuseMessage, | ||
235 | addAbuseMessage | ||
156 | } | 236 | } |
diff --git a/shared/models/moderation/abuse/abuse-message.model.ts b/shared/models/moderation/abuse/abuse-message.model.ts new file mode 100644 index 000000000..02072d5ce --- /dev/null +++ b/shared/models/moderation/abuse/abuse-message.model.ts | |||
@@ -0,0 +1,9 @@ | |||
1 | import { AccountSummary } from '@shared/models' | ||
2 | |||
3 | export interface AbuseMessage { | ||
4 | id: number | ||
5 | message: string | ||
6 | byModerator: boolean | ||
7 | |||
8 | account: AccountSummary | ||
9 | } | ||
diff --git a/shared/models/moderation/abuse/abuse.model.ts b/shared/models/moderation/abuse/abuse.model.ts index 0a0c6bd35..7f126ba4a 100644 --- a/shared/models/moderation/abuse/abuse.model.ts +++ b/shared/models/moderation/abuse/abuse.model.ts | |||
@@ -4,7 +4,7 @@ import { AbusePredefinedReasonsString } from './abuse-reason.model' | |||
4 | import { VideoConstant } from '../../videos/video-constant.model' | 4 | import { VideoConstant } from '../../videos/video-constant.model' |
5 | import { VideoChannel } from '../../videos/channel/video-channel.model' | 5 | import { VideoChannel } from '../../videos/channel/video-channel.model' |
6 | 6 | ||
7 | export interface VideoAbuse { | 7 | export interface AdminVideoAbuse { |
8 | id: number | 8 | id: number |
9 | name: string | 9 | name: string |
10 | uuid: string | 10 | uuid: string |
@@ -23,7 +23,7 @@ export interface VideoAbuse { | |||
23 | nthReport: number | 23 | nthReport: number |
24 | } | 24 | } |
25 | 25 | ||
26 | export interface VideoCommentAbuse { | 26 | export interface AdminVideoCommentAbuse { |
27 | id: number | 27 | id: number |
28 | threadId: number | 28 | threadId: number |
29 | 29 | ||
@@ -38,7 +38,7 @@ export interface VideoCommentAbuse { | |||
38 | deleted: boolean | 38 | deleted: boolean |
39 | } | 39 | } |
40 | 40 | ||
41 | export interface Abuse { | 41 | export interface AdminAbuse { |
42 | id: number | 42 | id: number |
43 | 43 | ||
44 | reason: string | 44 | reason: string |
@@ -50,8 +50,8 @@ export interface Abuse { | |||
50 | state: VideoConstant<AbuseState> | 50 | state: VideoConstant<AbuseState> |
51 | moderationComment?: string | 51 | moderationComment?: string |
52 | 52 | ||
53 | video?: VideoAbuse | 53 | video?: AdminVideoAbuse |
54 | comment?: VideoCommentAbuse | 54 | comment?: AdminVideoCommentAbuse |
55 | 55 | ||
56 | createdAt: Date | 56 | createdAt: Date |
57 | updatedAt: Date | 57 | updatedAt: Date |
@@ -59,6 +59,8 @@ export interface Abuse { | |||
59 | countReportsForReporter?: number | 59 | countReportsForReporter?: number |
60 | countReportsForReportee?: number | 60 | countReportsForReportee?: number |
61 | 61 | ||
62 | countMessages: number | ||
63 | |||
62 | // FIXME: deprecated in 2.3, remove the following properties | 64 | // FIXME: deprecated in 2.3, remove the following properties |
63 | 65 | ||
64 | // @deprecated | 66 | // @deprecated |
@@ -71,3 +73,10 @@ export interface Abuse { | |||
71 | // @deprecated | 73 | // @deprecated |
72 | nth?: number | 74 | nth?: number |
73 | } | 75 | } |
76 | |||
77 | export type UserVideoAbuse = Omit<AdminVideoAbuse, 'countReports' | 'nthReport'> | ||
78 | |||
79 | export type UserVideoCommentAbuse = AdminVideoCommentAbuse | ||
80 | |||
81 | export type UserAbuse = Omit<AdminAbuse, 'reporterAccount' | 'countReportsForReportee' | 'countReportsForReporter' | 'startAt' | 'endAt' | ||
82 | | 'count' | 'nth'> | ||
diff --git a/shared/models/moderation/abuse/index.ts b/shared/models/moderation/abuse/index.ts index 55046426a..b518517a6 100644 --- a/shared/models/moderation/abuse/index.ts +++ b/shared/models/moderation/abuse/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | export * from './abuse-create.model' | 1 | export * from './abuse-create.model' |
2 | export * from './abuse-filter.type' | 2 | export * from './abuse-filter.type' |
3 | export * from './abuse-message.model' | ||
3 | export * from './abuse-reason.model' | 4 | export * from './abuse-reason.model' |
4 | export * from './abuse-state.model' | 5 | export * from './abuse-state.model' |
5 | export * from './abuse-update.model' | 6 | export * from './abuse-update.model' |