Skip to content

Commit bf43bf1

Browse files
committed
Add suspicious user limitations
1 parent efe7e48 commit bf43bf1

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

backend/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@compass/api",
3-
"version": "1.42.1",
3+
"version": "1.43.0",
44
"private": true,
55
"description": "Backend API endpoints",
66
"main": "src/serve.ts",

backend/api/src/create-comment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {type JSONContent} from '@tiptap/core'
22
import {APIErrors, APIHandler} from 'api/helpers/endpoint'
3+
import {isSuspiciousId} from 'common/moderation/suspicious'
34
import {Notification} from 'common/notifications'
45
import {convertComment} from 'common/supabase/comment'
56
import {type Row} from 'common/supabase/utils'
@@ -56,6 +57,7 @@ const validateComment = async (userId: string, creatorId: string, content: JSONC
5657

5758
if (!creator) throw APIErrors.unauthorized('Your account was not found')
5859
if (creator.isBannedFromPosting) throw APIErrors.forbidden('You are banned')
60+
if (isSuspiciousId(creator.id)) throw APIErrors.forbidden('Suspicious users cannot send messages')
5961

6062
const otherUser = await getPrivateUser(userId)
6163
if (!otherUser) throw APIErrors.notFound('Other user not found')

backend/api/src/create-private-user-message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {MAX_COMMENT_JSON_LENGTH} from 'api/create-comment'
22
import {APIErrors, APIHandler} from 'api/helpers/endpoint'
33
import {createPrivateUserMessageMain} from 'api/helpers/private-messages'
4+
import {isSuspiciousId} from 'common/moderation/suspicious'
45
import {createSupabaseDirectClient} from 'shared/supabase/init'
56
import {getUser} from 'shared/utils'
67

@@ -16,6 +17,7 @@ export const createPrivateUserMessage: APIHandler<'create-private-user-message'>
1617
const creator = await getUser(auth.uid)
1718
if (!creator) throw APIErrors.unauthorized('Your account was not found')
1819
if (creator.isBannedFromPosting) throw APIErrors.forbidden('You are banned')
20+
if (isSuspiciousId(creator.id)) throw APIErrors.forbidden('Suspicious users cannot send messages')
1921

2022
const pg = createSupabaseDirectClient()
2123
return await createPrivateUserMessageMain(creator, channelId, content, pg, 'private')
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// If used long-term, consider moving to a database (new user column or new table)
2+
export const suspiciousIds = ['K5Y1nuQopYhvNpnycvKyoNQ1FaK2']
3+
4+
// Suspicious users are flagged in between legit and banned:
5+
// They still have access to the app (including viewing profiles), but are not allowed to
6+
// interact too heavily with people so as not to bother them (no DMs or endorsements)
7+
// Mark a user as suspicious if they message too many people or if they get reported once
8+
// (ban them if reported more than once)
9+
export function isSuspiciousId(id: string) {
10+
return suspiciousIds.includes(id)
11+
}

0 commit comments

Comments
 (0)