Skip to content

Commit

Permalink
feat: remove profile restriction table and migrate them to features (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Jan 8, 2024
2 parents 41b6b37 + 66fde83 commit 2bbeb64
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 194 deletions.
Original file line number Diff line number Diff line change
@@ -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";
11 changes: 0 additions & 11 deletions apps/api/src/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions apps/api/src/routes/internal/cron/cleanPostgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
53 changes: 0 additions & 53 deletions apps/api/src/routes/internal/restrictions/update.ts

This file was deleted.

39 changes: 15 additions & 24 deletions apps/api/src/routes/preferences/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
};

Expand Down
2 changes: 0 additions & 2 deletions apps/api/tests/preferences/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Shared/GlobalBanners/Flagged.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const Flagged: FC = () => {

return (
<div className="border-b border-red-300 bg-red-500/20">
<GridLayout className="!p-5">
<GridItemEight className="!mb-0 space-y-1">
<GridLayout>
<GridItemEight className="space-y-1">
<div className="flex items-center space-x-2 text-red-700">
<FlagIcon className="size-5" />
<div className="text-base font-bold sm:text-lg">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const ProtectProfile: FC = () => {

return (
<div className="border-b border-red-300 bg-red-500/20">
<GridLayout className="!p-5">
<GridItemEight className="!mb-0 space-y-1">
<GridLayout>
<GridItemEight className="space-y-1">
<div className="flex items-center space-x-2 text-red-700">
<LockOpenIcon className="size-5" />
<div className="text-base font-bold sm:text-lg">
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Shared/GlobalBanners/Suspended.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const Suspended: FC = () => {

return (
<div className="border-b border-red-300 bg-red-500/20">
<GridLayout className="!p-5">
<GridItemEight className="!mb-0 space-y-1">
<GridLayout>
<GridItemEight className="space-y-1">
<div className="flex items-center space-x-2 text-red-700">
<NoSymbolIcon className="size-5" />
<div className="text-base font-bold sm:text-lg">
Expand Down
84 changes: 0 additions & 84 deletions apps/web/src/components/Staff/Users/Overview/Tool/Restrictions.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions apps/web/src/components/Staff/Users/Overview/Tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,7 +160,6 @@ const ProfileStaffTool: FC<ProfileStaffToolProps> = ({ profile }) => {
{preferences ? (
<>
<Access preferences={preferences} profileId={profile.id} />
<Restrictions preferences={preferences} profileId={profile.id} />
<div className="divider my-5 border-dashed border-yellow-600" />
<FeatureFlags
features={preferences.features || []}
Expand Down
4 changes: 3 additions & 1 deletion packages/data/feature-flags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export enum FeatureFlag {
Flagged = 'flagged',
Gardener = 'gardener',
GardenerMode = 'gardener-mode',
LensMember = 'lens-member',
Staff = 'staff',
StaffMode = 'staff-mode'
StaffMode = 'staff-mode',
Suspended = 'suspended'
}
2 changes: 0 additions & 2 deletions packages/lib/api/getPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ const getPreferences = async (
features: [],
hasDismissedOrMintedMembershipNft: false,
highSignalNotificationFilter: false,
isFlagged: false,
isPride: false,
isPro: false,
isSuspended: false,
isTrusted: false
};
}
Expand Down
2 changes: 0 additions & 2 deletions packages/types/hey.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ export type Preferences = {
features: string[];
hasDismissedOrMintedMembershipNft: boolean;
highSignalNotificationFilter: boolean;
isFlagged: boolean;
isPride: boolean;
isPro: boolean;
isSuspended: boolean;
isTrusted: boolean;
};

2 comments on commit 2bbeb64

@vercel
Copy link

@vercel vercel bot commented on 2bbeb64 Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 2bbeb64 Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./apps/web

heyxyz.vercel.app
web-heyxyz.vercel.app
web-git-main-heyxyz.vercel.app
hey.xyz

Please sign in to comment.