Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove trusted profile table and migrate them to features #4507

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to drop the `TrustedProfile` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropTable
DROP TABLE "TrustedProfile";
5 changes: 0 additions & 5 deletions apps/api/src/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ model Verified {
createdAt DateTime @default(now())
}

model TrustedProfile {
id String @id
createdAt DateTime @default(now())
}

model StaffPick {
id String @id
type StaffPickType
Expand Down
54 changes: 0 additions & 54 deletions apps/api/src/routes/internal/trusted/update.ts

This file was deleted.

8 changes: 3 additions & 5 deletions apps/api/src/routes/preferences/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const get: Handler = async (req, res) => {
}

try {
const [preference, pro, features, membershipNft, trustedProfile] =
const [preference, pro, features, membershipNft] =
await prisma.$transaction([
prisma.preference.findUnique({ where: { id: id as string } }),
prisma.pro.findFirst({ where: { profileId: id as string } }),
Expand All @@ -31,8 +31,7 @@ export const get: Handler = async (req, res) => {
profileId: id as string
}
}),
prisma.membershipNft.findUnique({ where: { id: id as string } }),
prisma.trustedProfile.findUnique({ where: { id: id as string } })
prisma.membershipNft.findUnique({ where: { id: id as string } })
]);

const response: Preferences = {
Expand All @@ -44,8 +43,7 @@ export const get: Handler = async (req, res) => {
preference?.highSignalNotificationFilter
),
isPride: Boolean(preference?.isPride),
isPro: Boolean(pro),
isTrusted: Boolean(trustedProfile)
isPro: Boolean(pro)
};

logger.info('Profile preferences fetched');
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const STAFF_FEATURE_ID = 'eea3b2d2-a60c-4e41-8130-1cb34cc37810';
export const STAFF_MODE_FEATURE_ID = '0e588583-b347-4752-9e1e-0ad4128348e8';
export const GARDENER_FEATURE_ID = '0a441129-182a-4a3f-83cf-a13c5ad8282b';
export const GARDENER_MODE_FEATURE_ID = '9f66a465-e1d7-4123-b329-ddd14fd85510';
export const TRUSTED_PROFILE_FEATURE_ID =
'266c7bc3-93ae-4565-8065-de636bce58b3';

// Cache
// Cache for 1 minute, stale for 30 days
Expand Down
11 changes: 8 additions & 3 deletions apps/api/src/utils/middlewares/validateIsTrusted.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Request } from 'express';

import parseJwt from '@hey/lib/parseJwt';
import { TRUSTED_PROFILE_FEATURE_ID } from '@utils/constants';
import prisma from '@utils/prisma';

import validateLensAccount from './validateLensAccount';
Expand All @@ -23,11 +24,15 @@ const validateIsTrusted = async (request: Request) => {
}

const payload = parseJwt(accessToken);
const data = await prisma.trustedProfile.findFirst({
where: { id: payload.id }
const data = await prisma.profileFeature.findFirst({
where: {
enabled: true,
featureId: TRUSTED_PROFILE_FEATURE_ID,
profileId: payload.id
}
});

if (data?.id) {
if (data?.enabled) {
return true;
}

Expand Down
1 change: 0 additions & 1 deletion apps/api/tests/preferences/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('preferences/get', () => {
expect(response.data.result.features).toBeInstanceOf(Array);
expect(response.data.result.hasDismissedOrMintedMembershipNft).toBeTruthy();
expect(response.data.result.isPro).toBeTruthy();
expect(response.data.result.isTrusted).toBeTruthy();
expect(response.data.result.highSignalNotificationFilter).toBeTruthy();
expect(response.data.result.isPride).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,17 @@ const PreferencesProvider: FC = () => {
// Pro
setIsPro(preferences.isPro);

// Trusted
setIsTrusted(preferences.isTrusted);

// Restriction
setRestriction({
isFlagged: preferences.features.includes(FeatureFlag.Flagged),
isSuspended: preferences.features.includes(FeatureFlag.Suspended)
});

// Feature flags
setFeatureFlags(preferences.features);
setStaffMode(preferences.features.includes(FeatureFlag.StaffMode));
setGardenerMode(
preferences?.features.includes(FeatureFlag.GardenerMode)
);
setRestriction({
isFlagged: preferences.features.includes(FeatureFlag.Flagged),
isSuspended: preferences.features.includes(FeatureFlag.Suspended)
});
setIsTrusted(preferences.features.includes(FeatureFlag.TrustedProfile));

// Membership NFT
setHasDismissedOrMintedMembershipNft(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { FC } from 'react';
import { AdjustmentsVerticalIcon } from '@heroicons/react/24/solid';

import ActivateLifetimePro from './ActivateLifetimePro';
import Trusted from './Trusted';
import Verify from './Verify';

interface AccessProps {
Expand All @@ -22,7 +21,6 @@ const Access: FC<AccessProps> = ({ preferences, profileId }) => {
<div className="mt-3 space-y-2 font-bold">
<Verify profileId={profileId} />
<ActivateLifetimePro isPro={preferences.isPro} profileId={profileId} />
<Trusted isTrusted={preferences.isTrusted} profileId={profileId} />
</div>
</>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/data/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export enum FeatureFlag {
LensMember = 'lens-member',
Staff = 'staff',
StaffMode = 'staff-mode',
Suspended = 'suspended'
Suspended = 'suspended',
TrustedProfile = 'trusted-profile'
}
3 changes: 1 addition & 2 deletions packages/lib/api/getPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ const getPreferences = async (
hasDismissedOrMintedMembershipNft: false,
highSignalNotificationFilter: false,
isPride: false,
isPro: false,
isTrusted: false
isPro: false
};
}
};
Expand Down
1 change: 0 additions & 1 deletion packages/types/hey.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,4 @@ export type Preferences = {
highSignalNotificationFilter: boolean;
isPride: boolean;
isPro: boolean;
isTrusted: boolean;
};