diff --git a/api-schema.graphql b/api-schema.graphql index 2a5ab8d8..56bf9571 100644 --- a/api-schema.graphql +++ b/api-schema.graphql @@ -468,6 +468,7 @@ type Mutation { adminUpdateRole(input: AdminUpdateRoleInput!, roleId: String!): Role adminUpdateUser(input: AdminUpdateUserInput!, userId: String!): User adminVerifyNetworkAssets: Boolean + adminVerifyUser(userId: String!): Boolean anonVerifyIdentityChallenge(input: VerifyIdentityChallengeInput!): IdentityChallenge logout: Boolean userAddCommunityMember(communityId: String!, input: UserAddCommunityMemberInput!): CommunityMember @@ -783,6 +784,7 @@ type User { name: String private: Boolean profileUrl: String! + pubkeyProfile: String role: UserRole status: UserStatus updatedAt: DateTime diff --git a/libs/api/user/data-access/src/lib/api-user-data-admin.service.ts b/libs/api/user/data-access/src/lib/api-user-data-admin.service.ts index d5b6c5f8..2c251846 100644 --- a/libs/api/user/data-access/src/lib/api-user-data-admin.service.ts +++ b/libs/api/user/data-access/src/lib/api-user-data-admin.service.ts @@ -47,4 +47,8 @@ export class ApiUserDataAdminService { username: newUsername, }) } + + async verifyUser(userId: string) { + return this.data.verify(userId) + } } diff --git a/libs/api/user/data-access/src/lib/api-user-data.service.ts b/libs/api/user/data-access/src/lib/api-user-data.service.ts index 369d075f..2102b39b 100644 --- a/libs/api/user/data-access/src/lib/api-user-data.service.ts +++ b/libs/api/user/data-access/src/lib/api-user-data.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common' import { Prisma } from '@prisma/client' import { ApiCoreService, PagingInputFields } from '@pubkey-link/api-core-data-access' +import { PubKeyIdentityProvider } from '@pubkey-program-library/anchor' import { UserPaging } from './entity/user.entity' @Injectable() @@ -25,7 +26,7 @@ export class ApiUserDataService { } async findOne(userId: string) { - const found = await this.core.data.user.findUnique({ where: { id: userId } }) + const found = await this.core.data.user.findUnique({ where: { id: userId }, include: { identities: true } }) if (!found) { throw new Error(`User ${userId} not found`) } @@ -50,4 +51,34 @@ export class ApiUserDataService { } return true } + + async verify(userId: string) { + const found = await this.findOne(userId) + if (!found.identities.length) { + throw new Error(`Can't verify a user without identities`) + } + let foundPubkeyProfile = null + for (const identity of found.identities) { + console.log(`Checking ${identity.provider} ${identity.providerId}`) + foundPubkeyProfile = await this.core.protocol.getProfileByProvider({ + provider: identity.provider as PubKeyIdentityProvider, + providerId: identity.providerId, + }) + if (foundPubkeyProfile) { + console.log(`We found one, we break!`) + break + } + } + if (foundPubkeyProfile) { + if (found.pubkeyProfile !== foundPubkeyProfile.publicKey.toString()) { + const updated = await this.core.data.user.update({ + where: { id: found.id }, + data: { pubkeyProfile: foundPubkeyProfile.publicKey.toString() }, + }) + + console.log(`Updated ${updated.username}, attached pubkey profile ${updated.pubkeyProfile}`) + } + } + return true + } } diff --git a/libs/api/user/data-access/src/lib/entity/user.entity.ts b/libs/api/user/data-access/src/lib/entity/user.entity.ts index 8cd0365c..b9a10585 100644 --- a/libs/api/user/data-access/src/lib/entity/user.entity.ts +++ b/libs/api/user/data-access/src/lib/entity/user.entity.ts @@ -26,6 +26,8 @@ export class User { @Field({ nullable: true }) name?: string | null @Field({ nullable: true }) + pubkeyProfile?: string | null + @Field({ nullable: true }) username!: string @HideField() identities?: unknown[] | null diff --git a/libs/api/user/feature/src/lib/api-admin-user.resolver.ts b/libs/api/user/feature/src/lib/api-admin-user.resolver.ts index 405b9c25..9912aa30 100644 --- a/libs/api/user/feature/src/lib/api-admin-user.resolver.ts +++ b/libs/api/user/feature/src/lib/api-admin-user.resolver.ts @@ -33,4 +33,9 @@ export class ApiAdminUserResolver { adminUpdateUser(@Args('userId') userId: string, @Args('input') input: AdminUpdateUserInput) { return this.service.admin.updateUser(userId, input) } + + @Mutation(() => Boolean, { nullable: true }) + adminVerifyUser(@Args('userId') userId: string) { + return this.service.admin.verifyUser(userId) + } } diff --git a/libs/sdk/src/generated/graphql-sdk.ts b/libs/sdk/src/generated/graphql-sdk.ts index fea1bd3a..62f88028 100644 --- a/libs/sdk/src/generated/graphql-sdk.ts +++ b/libs/sdk/src/generated/graphql-sdk.ts @@ -498,6 +498,7 @@ export type Mutation = { adminUpdateRole?: Maybe adminUpdateUser?: Maybe adminVerifyNetworkAssets?: Maybe + adminVerifyUser?: Maybe anonVerifyIdentityChallenge?: Maybe logout?: Maybe userAddCommunityMember?: Maybe @@ -673,6 +674,10 @@ export type MutationAdminUpdateUserArgs = { userId: Scalars['String']['input'] } +export type MutationAdminVerifyUserArgs = { + userId: Scalars['String']['input'] +} + export type MutationAnonVerifyIdentityChallengeArgs = { input: VerifyIdentityChallengeInput } @@ -1356,6 +1361,7 @@ export type User = { name?: Maybe private?: Maybe profileUrl: Scalars['String']['output'] + pubkeyProfile?: Maybe role?: Maybe status?: Maybe updatedAt?: Maybe @@ -1583,17 +1589,18 @@ export type MeQuery = { __typename?: 'Query' me?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null identities?: Array<{ __typename?: 'Identity' @@ -2197,17 +2204,18 @@ export type CommunityMemberDetailsFragment = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -2304,17 +2312,18 @@ export type AdminFindManyCommunityMemberQuery = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -2421,17 +2430,18 @@ export type AdminFindOneCommunityMemberQuery = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -2528,17 +2538,18 @@ export type AdminAddCommunityMemberMutation = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -2635,17 +2646,18 @@ export type AdminUpdateCommunityMemberMutation = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -2747,17 +2759,18 @@ export type UserGetCommunityMemberQuery = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -2855,17 +2868,18 @@ export type UserFindManyCommunityMemberQuery = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -2972,17 +2986,18 @@ export type UserFindOneCommunityMemberQuery = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -3079,17 +3094,18 @@ export type UserAddCommunityMemberMutation = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -3186,17 +3202,18 @@ export type UserUpdateCommunityMemberMutation = { userId: string user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null roles?: Array<{ @@ -3769,17 +3786,18 @@ export type IdentityGrantDetailsFragment = { updatedAt?: Date | null grantee?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } @@ -3829,33 +3847,35 @@ export type AdminFindManyIdentityQuery = { updatedAt?: Date | null grantee?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null }> | null owner?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null }> | null @@ -3875,6 +3895,7 @@ export type AdminFindUserByIdentityQuery = { private?: boolean | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null username?: string | null @@ -3959,17 +3980,18 @@ export type UserFindManyIdentityQuery = { updatedAt?: Date | null grantee?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null }> | null @@ -4009,33 +4031,35 @@ export type UserFindOneIdentityQuery = { updatedAt?: Date | null grantee?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null }> | null owner?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } | null @@ -4391,17 +4415,18 @@ export type LogDetailsFragment = { } | null user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } @@ -4563,17 +4588,18 @@ export type UserFindManyLogQuery = { } | null user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null }> @@ -4745,17 +4771,18 @@ export type UserFindOneLogQuery = { } | null user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } | null @@ -4918,17 +4945,18 @@ export type AdminFindManyLogQuery = { } | null user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null }> @@ -5100,17 +5128,18 @@ export type AdminFindOneLogQuery = { } | null user?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } | null @@ -7348,6 +7377,7 @@ export type UserSummaryFragment = { private?: boolean | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null username?: string | null @@ -7355,17 +7385,18 @@ export type UserSummaryFragment = { export type UserDetailsFragment = { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } @@ -7385,17 +7416,18 @@ export type AdminFindManyUserQuery = { __typename?: 'UserPaging' data: Array<{ __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null identities?: Array<{ __typename?: 'Identity' @@ -7436,17 +7468,18 @@ export type AdminFindOneUserQuery = { __typename?: 'Query' item?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } @@ -7460,21 +7493,28 @@ export type AdminUpdateUserMutation = { __typename?: 'Mutation' updated?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } +export type AdminVerifyUserMutationVariables = Exact<{ + userId: Scalars['String']['input'] +}> + +export type AdminVerifyUserMutation = { __typename?: 'Mutation'; verified?: boolean | null } + export type UserFindManyUserQueryVariables = Exact<{ input: UserFindManyUserInput }> @@ -7485,17 +7525,18 @@ export type UserFindManyUserQuery = { __typename?: 'UserPaging' data: Array<{ __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null }> meta: { @@ -7519,17 +7560,18 @@ export type UserFindOneUserQuery = { __typename?: 'Query' item?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } @@ -7542,17 +7584,18 @@ export type UserFindOneUserByIdQuery = { __typename?: 'Query' item?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } @@ -7565,17 +7608,18 @@ export type UserUpdateUserMutation = { __typename?: 'Mutation' updated?: { __typename?: 'User' - avatarUrl?: string | null createdAt?: Date | null + lastLogin?: Date | null + status?: UserStatus | null + updatedAt?: Date | null + avatarUrl?: string | null developer?: boolean | null private?: boolean | null - lastLogin?: Date | null id: string name?: string | null + pubkeyProfile?: string | null profileUrl: string role?: UserRole | null - status?: UserStatus | null - updatedAt?: Date | null username?: string | null } | null } @@ -7602,21 +7646,28 @@ export const DiscordChannelDetailsFragmentDoc = gql` type } ` -export const UserDetailsFragmentDoc = gql` - fragment UserDetails on User { +export const UserSummaryFragmentDoc = gql` + fragment UserSummary on User { avatarUrl - createdAt developer private - lastLogin id name + pubkeyProfile profileUrl role + username + } +` +export const UserDetailsFragmentDoc = gql` + fragment UserDetails on User { + ...UserSummary + createdAt + lastLogin status updatedAt - username } + ${UserSummaryFragmentDoc} ` export const NetworkTokenDetailsFragmentDoc = gql` fragment NetworkTokenDetails on NetworkToken { @@ -7966,18 +8017,6 @@ export const SnapshotItemDetailsFragmentDoc = gql` } } ` -export const UserSummaryFragmentDoc = gql` - fragment UserSummary on User { - avatarUrl - developer - private - id - name - profileUrl - role - username - } -` export const LogoutDocument = gql` mutation logout { logout @@ -9053,6 +9092,11 @@ export const AdminUpdateUserDocument = gql` } ${UserDetailsFragmentDoc} ` +export const AdminVerifyUserDocument = gql` + mutation adminVerifyUser($userId: String!) { + verified: adminVerifyUser(userId: $userId) + } +` export const UserFindManyUserDocument = gql` query userFindManyUser($input: UserFindManyUserInput!) { paging: userFindManyUser(input: $input) { @@ -9230,6 +9274,7 @@ const AdminDeleteUserDocumentString = print(AdminDeleteUserDocument) const AdminFindManyUserDocumentString = print(AdminFindManyUserDocument) const AdminFindOneUserDocumentString = print(AdminFindOneUserDocument) const AdminUpdateUserDocumentString = print(AdminUpdateUserDocument) +const AdminVerifyUserDocumentString = print(AdminVerifyUserDocument) const UserFindManyUserDocumentString = print(UserFindManyUserDocument) const UserFindOneUserDocumentString = print(UserFindOneUserDocument) const UserFindOneUserByIdDocumentString = print(UserFindOneUserByIdDocument) @@ -11942,6 +11987,27 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = variables, ) }, + adminVerifyUser( + variables: AdminVerifyUserMutationVariables, + requestHeaders?: GraphQLClientRequestHeaders, + ): Promise<{ + data: AdminVerifyUserMutation + errors?: GraphQLError[] + extensions?: any + headers: Headers + status: number + }> { + return withWrapper( + (wrappedRequestHeaders) => + client.rawRequest(AdminVerifyUserDocumentString, variables, { + ...requestHeaders, + ...wrappedRequestHeaders, + }), + 'adminVerifyUser', + 'mutation', + variables, + ) + }, userFindManyUser( variables: UserFindManyUserQueryVariables, requestHeaders?: GraphQLClientRequestHeaders, diff --git a/libs/sdk/src/graphql/feature-user.graphql b/libs/sdk/src/graphql/feature-user.graphql index 041d4f39..3bec18ad 100644 --- a/libs/sdk/src/graphql/feature-user.graphql +++ b/libs/sdk/src/graphql/feature-user.graphql @@ -4,24 +4,18 @@ fragment UserSummary on User { private id name + pubkeyProfile profileUrl role username } fragment UserDetails on User { - avatarUrl + ...UserSummary createdAt - developer - private lastLogin - id - name - profileUrl - role status updatedAt - username } mutation adminDeleteUser($userId: String!) { @@ -54,6 +48,9 @@ mutation adminUpdateUser($userId: String!, $input: AdminUpdateUserInput!) { } } +mutation adminVerifyUser($userId: String!) { + verified: adminVerifyUser(userId: $userId) +} query userFindManyUser($input: UserFindManyUserInput!) { paging: userFindManyUser(input: $input) { data { diff --git a/libs/web/user/data-access/src/lib/use-admin-find-many-user.ts b/libs/web/user/data-access/src/lib/use-admin-find-many-user.ts index 19164632..f43c5755 100644 --- a/libs/web/user/data-access/src/lib/use-admin-find-many-user.ts +++ b/libs/web/user/data-access/src/lib/use-admin-find-many-user.ts @@ -49,5 +49,10 @@ export function useAdminFindManyUser(props?: AdminFindManyUserInput) { toastSuccess('User deleted') return query.refetch() }), + verifyUser: (userId: string) => + sdk.adminVerifyUser({ userId }).then(async () => { + toastSuccess('User verified') + await query.refetch() + }), } } diff --git a/libs/web/user/feature/src/lib/admin-user-list-feature.tsx b/libs/web/user/feature/src/lib/admin-user-list-feature.tsx index b27db952..51772025 100644 --- a/libs/web/user/feature/src/lib/admin-user-list-feature.tsx +++ b/libs/web/user/feature/src/lib/admin-user-list-feature.tsx @@ -7,7 +7,8 @@ import { AdminUserUiSelectRole } from './admin-user-ui-select-role' import { AdminUserUiSelectStatus } from './admin-user-ui-select-status' export function AdminUserListFeature() { - const { deleteUser, items, pagination, query, role, setRole, setSearch, setStatus, status } = useAdminFindManyUser() + const { deleteUser, items, pagination, query, role, setRole, setSearch, setStatus, status, verifyUser } = + useAdminFindManyUser() return ( } rightAction={}> @@ -26,6 +27,7 @@ export function AdminUserListFeature() { if (!window.confirm('Are you sure?')) return return deleteUser(user.id) }} + verifyUser={(user) => verifyUser(user.id)} users={items} page={pagination.page} totalRecords={pagination.total} diff --git a/libs/web/user/ui/src/lib/admin-user-ui-table.tsx b/libs/web/user/ui/src/lib/admin-user-ui-table.tsx index 015f981f..e2e4c9bb 100644 --- a/libs/web/user/ui/src/lib/admin-user-ui-table.tsx +++ b/libs/web/user/ui/src/lib/admin-user-ui-table.tsx @@ -2,7 +2,7 @@ import { ActionIcon, Alert, Group, ScrollArea } from '@mantine/core' import { User } from '@pubkey-link/sdk' import { IdentityUiAvatarGroup } from '@pubkey-link/web-core-ui' import { UiTime } from '@pubkey-ui/core' -import { IconPencil, IconTrash, IconUser } from '@tabler/icons-react' +import { IconParking, IconPencil, IconTrash, IconUser } from '@tabler/icons-react' import { DataTable, DataTableProps } from 'mantine-datatable' import { Link } from 'react-router-dom' import { UserUiItem } from './user-ui-item' @@ -16,6 +16,7 @@ interface AdminUserTableProps { totalRecords: DataTableProps['totalRecords'] recordsPerPage: DataTableProps['recordsPerPage'] onPageChange: (page: number) => void + verifyUser: (user: User) => Promise } export function AdminUserUiTable({ @@ -25,6 +26,7 @@ export function AdminUserUiTable({ page, recordsPerPage, totalRecords, + verifyUser, }: AdminUserTableProps) { return ( @@ -83,7 +85,10 @@ export function AdminUserUiTable({ width: '10%', textAlign: 'right', render: (item) => ( - + + verifyUser(item)}> + + diff --git a/libs/web/user/ui/src/lib/user-ui-item.tsx b/libs/web/user/ui/src/lib/user-ui-item.tsx index a0f2bfa8..aff0e5c2 100644 --- a/libs/web/user/ui/src/lib/user-ui-item.tsx +++ b/libs/web/user/ui/src/lib/user-ui-item.tsx @@ -24,7 +24,7 @@ export function UserUiItem({ return ( - + diff --git a/libs/web/user/ui/src/lib/user-ui-username.tsx b/libs/web/user/ui/src/lib/user-ui-username.tsx index 35382ff1..37ae6947 100644 --- a/libs/web/user/ui/src/lib/user-ui-username.tsx +++ b/libs/web/user/ui/src/lib/user-ui-username.tsx @@ -11,6 +11,7 @@ export function UserUiUsername({ to, user }: { to?: string | null; user: User }) {user.username} + {user.pubkeyProfile ? 🅿️ : null} {user.private ? ( diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b96cb8d5..2a0085a8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -306,6 +306,7 @@ model User { developer Boolean @default(false) private Boolean @default(false) name String? + pubkeyProfile String? role UserRole @default(User) status UserStatus @default(Created) username String @unique