diff --git a/apps/api/src/db/migrations/20240108060056_remove_profile_restrictions/migration.sql b/apps/api/src/db/migrations/20240108060056_remove_profile_restrictions/migration.sql new file mode 100644 index 000000000000..2e05c764d270 --- /dev/null +++ b/apps/api/src/db/migrations/20240108060056_remove_profile_restrictions/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the `ProfileRestriction` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE "ProfileRestriction"; diff --git a/apps/api/src/db/schema.prisma b/apps/api/src/db/schema.prisma index 39e29918d361..68f19993bdea 100644 --- a/apps/api/src/db/schema.prisma +++ b/apps/api/src/db/schema.prisma @@ -40,17 +40,6 @@ model Preference { createdAt DateTime @default(now()) } -model ProfileRestriction { - id String @id - isFlagged Boolean @default(false) - isSuspended Boolean @default(false) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - // Indexes - @@index([isFlagged, isSuspended]) -} - model MembershipNft { id String @id dismissedOrMinted Boolean @default(false) diff --git a/apps/api/src/routes/internal/cron/cleanPostgres.ts b/apps/api/src/routes/internal/cron/cleanPostgres.ts index 9514850fc7c4..940cba7ce083 100644 --- a/apps/api/src/routes/internal/cron/cleanPostgres.ts +++ b/apps/api/src/routes/internal/cron/cleanPostgres.ts @@ -37,11 +37,6 @@ export const post: Handler = async (req, res) => { } try { - // Cleanup ProfileRestriction - await prisma.profileRestriction.deleteMany({ - where: { isFlagged: false, isSuspended: false } - }); - // Cleanup Preference await prisma.preference.deleteMany({ where: { highSignalNotificationFilter: false, isPride: false } diff --git a/apps/api/src/routes/internal/restrictions/update.ts b/apps/api/src/routes/internal/restrictions/update.ts deleted file mode 100644 index 27d85889188e..000000000000 --- a/apps/api/src/routes/internal/restrictions/update.ts +++ /dev/null @@ -1,53 +0,0 @@ -import type { Handler } from 'express'; - -import logger from '@hey/lib/logger'; -import catchedError from '@utils/catchedError'; -import validateIsStaff from '@utils/middlewares/validateIsStaff'; -import prisma from '@utils/prisma'; -import { invalidBody, noBody, notAllowed } from '@utils/responses'; -import { boolean, object, string } from 'zod'; - -type ExtensionRequest = { - id: string; - isFlagged: boolean; - isSuspended: boolean; -}; - -const validationSchema = object({ - id: string(), - isFlagged: boolean(), - isSuspended: boolean() -}); - -export const post: Handler = async (req, res) => { - const { body } = req; - - if (!body) { - return noBody(res); - } - - const validation = validationSchema.safeParse(body); - - if (!validation.success) { - return invalidBody(res); - } - - if (!(await validateIsStaff(req))) { - return notAllowed(res); - } - - const { id, isFlagged, isSuspended } = body as ExtensionRequest; - - try { - const restrictions = await prisma.profileRestriction.upsert({ - create: { id, isFlagged, isSuspended, updatedAt: new Date() }, - update: { isFlagged, isSuspended, updatedAt: new Date() }, - where: { id: id } - }); - logger.info(`Updated restrictions for ${id}`); - - return res.status(200).json({ restrictions, success: true }); - } catch (error) { - return catchedError(res, error); - } -}; diff --git a/apps/api/src/routes/preferences/get.ts b/apps/api/src/routes/preferences/get.ts index 33ea0763ce25..1e11410889a1 100644 --- a/apps/api/src/routes/preferences/get.ts +++ b/apps/api/src/routes/preferences/get.ts @@ -19,28 +19,21 @@ export const get: Handler = async (req, res) => { } try { - const [ - preference, - pro, - features, - membershipNft, - restriction, - trustedProfile - ] = await prisma.$transaction([ - prisma.preference.findUnique({ where: { id: id as string } }), - prisma.pro.findFirst({ where: { profileId: id as string } }), - prisma.profileFeature.findMany({ - select: { feature: { select: { key: true } } }, - where: { - enabled: true, - feature: { enabled: true }, - profileId: id as string - } - }), - prisma.membershipNft.findUnique({ where: { id: id as string } }), - prisma.profileRestriction.findUnique({ where: { id: id as string } }), - prisma.trustedProfile.findUnique({ where: { id: id as string } }) - ]); + const [preference, pro, features, membershipNft, trustedProfile] = + await prisma.$transaction([ + prisma.preference.findUnique({ where: { id: id as string } }), + prisma.pro.findFirst({ where: { profileId: id as string } }), + prisma.profileFeature.findMany({ + select: { feature: { select: { key: true } } }, + where: { + enabled: true, + feature: { enabled: true }, + profileId: id as string + } + }), + prisma.membershipNft.findUnique({ where: { id: id as string } }), + prisma.trustedProfile.findUnique({ where: { id: id as string } }) + ]); const response: Preferences = { features: features.map((feature: any) => feature.feature?.key), @@ -50,10 +43,8 @@ export const get: Handler = async (req, res) => { highSignalNotificationFilter: Boolean( preference?.highSignalNotificationFilter ), - isFlagged: Boolean(restriction?.isFlagged), isPride: Boolean(preference?.isPride), isPro: Boolean(pro), - isSuspended: Boolean(restriction?.isSuspended), isTrusted: Boolean(trustedProfile) }; diff --git a/apps/api/tests/preferences/get.spec.ts b/apps/api/tests/preferences/get.spec.ts index 93523a00e18b..e45cab552081 100644 --- a/apps/api/tests/preferences/get.spec.ts +++ b/apps/api/tests/preferences/get.spec.ts @@ -21,7 +21,5 @@ describe('preferences/get', () => { expect(response.data.result.isTrusted).toBeTruthy(); expect(response.data.result.highSignalNotificationFilter).toBeTruthy(); expect(response.data.result.isPride).toBeTruthy(); - expect(response.data.result.isFlagged).toBeFalsy(); - expect(response.data.result.isSuspended).toBeFalsy(); }); }); diff --git a/apps/web/src/components/Common/Providers/PreferencesProvider.tsx b/apps/web/src/components/Common/Providers/PreferencesProvider.tsx index 3f8b6ed47074..3044079cb609 100644 --- a/apps/web/src/components/Common/Providers/PreferencesProvider.tsx +++ b/apps/web/src/components/Common/Providers/PreferencesProvider.tsx @@ -59,8 +59,8 @@ const PreferencesProvider: FC = () => { // Restriction setRestriction({ - isFlagged: preferences.isFlagged, - isSuspended: preferences.isSuspended + isFlagged: preferences.features.includes(FeatureFlag.Flagged), + isSuspended: preferences.features.includes(FeatureFlag.Suspended) }); // Feature flags diff --git a/apps/web/src/components/Shared/GlobalBanners/Flagged.tsx b/apps/web/src/components/Shared/GlobalBanners/Flagged.tsx index 534b45115e74..0e4afadfafcb 100644 --- a/apps/web/src/components/Shared/GlobalBanners/Flagged.tsx +++ b/apps/web/src/components/Shared/GlobalBanners/Flagged.tsx @@ -15,8 +15,8 @@ const Flagged: FC = () => { return (
- - + +
diff --git a/apps/web/src/components/Shared/GlobalBanners/ProtectProfile.tsx b/apps/web/src/components/Shared/GlobalBanners/ProtectProfile.tsx index f6f595d3c237..9606cde91adf 100644 --- a/apps/web/src/components/Shared/GlobalBanners/ProtectProfile.tsx +++ b/apps/web/src/components/Shared/GlobalBanners/ProtectProfile.tsx @@ -69,8 +69,8 @@ const ProtectProfile: FC = () => { return (
- - + +
diff --git a/apps/web/src/components/Shared/GlobalBanners/Suspended.tsx b/apps/web/src/components/Shared/GlobalBanners/Suspended.tsx index 386696d566c6..a59cd5d33549 100644 --- a/apps/web/src/components/Shared/GlobalBanners/Suspended.tsx +++ b/apps/web/src/components/Shared/GlobalBanners/Suspended.tsx @@ -15,8 +15,8 @@ const Suspended: FC = () => { return (
- - + +
diff --git a/apps/web/src/components/Staff/Users/Overview/Tool/Restrictions.tsx b/apps/web/src/components/Staff/Users/Overview/Tool/Restrictions.tsx deleted file mode 100644 index 168651f30a50..000000000000 --- a/apps/web/src/components/Staff/Users/Overview/Tool/Restrictions.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import type { Preferences } from '@hey/types/hey'; - -import { NoSymbolIcon } from '@heroicons/react/24/outline'; -import { HEY_API_URL } from '@hey/data/constants'; -import { Toggle } from '@hey/ui'; -import getAuthWorkerHeaders from '@lib/getAuthWorkerHeaders'; -import axios from 'axios'; -import { type FC, useEffect, useState } from 'react'; -import toast from 'react-hot-toast'; - -import ToggleWrapper from './ToggleWrapper'; - -interface RestrictionsProps { - preferences: Preferences; - profileId: string; -} - -const Restrictions: FC = ({ preferences, profileId }) => { - const [disabled, setDisabled] = useState(false); - const [isFlagged, setIsFlagged] = useState(false); - const [isSuspended, setIsSuspended] = useState(false); - - useEffect(() => { - if (preferences) { - setIsFlagged(preferences.isFlagged); - setIsSuspended(preferences.isSuspended); - } - }, [preferences]); - - const updateRestriction = async ( - isFlagged: boolean, - isSuspended: boolean - ) => { - setDisabled(true); - toast.promise( - axios.post( - `${HEY_API_URL}/internal/restrictions/update`, - { id: profileId, isFlagged, isSuspended }, - { headers: getAuthWorkerHeaders() } - ), - { - error: () => { - setDisabled(false); - return 'Error updating restriction'; - }, - loading: 'Updating restriction...', - success: () => { - setDisabled(false); - setIsFlagged(isFlagged); - setIsSuspended(isSuspended); - - return 'Restriction updated'; - } - } - ); - }; - - return ( - <> -
- -
Restrictions
-
-
- - updateRestriction(!isFlagged, isSuspended)} - /> - - - updateRestriction(isFlagged, !isSuspended)} - /> - -
- - ); -}; - -export default Restrictions; diff --git a/apps/web/src/components/Staff/Users/Overview/Tool/index.tsx b/apps/web/src/components/Staff/Users/Overview/Tool/index.tsx index 658ec1e1c0ed..b81e96b39f48 100644 --- a/apps/web/src/components/Staff/Users/Overview/Tool/index.tsx +++ b/apps/web/src/components/Staff/Users/Overview/Tool/index.tsx @@ -27,7 +27,6 @@ import LeafwatchDetails from './LeafwatchDetails'; import ManagedProfiles from './ManagedProfiles'; import OnchainIdentities from './OnchainIdentities'; import Rank from './Rank'; -import Restrictions from './Restrictions'; interface ProfileStaffToolProps { profile: Profile; @@ -161,7 +160,6 @@ const ProfileStaffTool: FC = ({ profile }) => { {preferences ? ( <> -