From f328890190d80baecef6dc9470f5bc12e3ff017d Mon Sep 17 00:00:00 2001 From: contradiction29 Date: Tue, 23 Apr 2024 11:47:15 +0900 Subject: [PATCH 1/6] Add userId for fctPostEditHisotory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 編集履歴からユーザー名を削除する下準備として、fctPostEditHistoryにユーザーidを格納するようにした。 --- app/routes/_layout.archives.edit.$postId.tsx | 5 ++++- prisma/schema.prisma | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/routes/_layout.archives.edit.$postId.tsx b/app/routes/_layout.archives.edit.$postId.tsx index e2821999..98fdd1a3 100644 --- a/app/routes/_layout.archives.edit.$postId.tsx +++ b/app/routes/_layout.archives.edit.$postId.tsx @@ -8,7 +8,7 @@ import { ClientOnly } from "remix-utils/client-only"; import MarkdownEditor from "~/components/MarkdownEditor.client"; import { useState } from "react"; import { marked } from 'marked'; -import { requireUserId } from "~/modules/session.server"; +import { getSession, requireUserId } from "~/modules/session.server"; import * as diff from 'diff'; import { createEmbedding } from "~/modules/embedding.server"; @@ -363,6 +363,8 @@ export async function action({ request, params }: ActionFunctionArgs) { const postContent = formData.get("postContent")?.toString() || ""; const tags = formData.getAll("tags") as string[]; const userName = formData.get("userName")?.toString() || ""; + const session = await getSession(request.headers.get('Cookie')); + const userId = session.get('userId'); const postId = Number(params.postId); @@ -429,6 +431,7 @@ export async function action({ request, params }: ActionFunctionArgs) { postId, postRevisionNumber: newRevisionNumber, editorUserName: userName, + editorUserId: userId, postTitleBeforeEdit: latestPost.postTitle, postTitleAfterEdit: postTitle, postContentBeforeEdit: latestPost.postContent, diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 449306a5..967680f0 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -128,6 +128,7 @@ model FctPostEditHistory { postEditDateJst DateTime @default(dbgenerated("(now() AT TIME ZONE 'jst'::text)")) @map("post_edit_date_jst") @db.Timestamptz(6) postEditDateGmt DateTime @default(dbgenerated("(now() AT TIME ZONE 'utc'::text)")) @map("post_edit_date_gmt") @db.Timestamptz(6) editorUserName String @map("editor_user_name") @db.VarChar(255) + editorUserId String @map("editor_user_id") postTitleBeforeEdit String @map("post_title_before_edit") @db.VarChar(255) postTitleAfterEdit String @map("post_title_after_edit") @db.VarChar(255) postContentBeforeEdit String @map("post_content_before_edit") From ec238f8b53b2afa6611b48a16746bf3b76ae4a22 Mon Sep 17 00:00:00 2001 From: contradiction29 Date: Tue, 23 Apr 2024 12:04:54 +0900 Subject: [PATCH 2/6] Show editor id inseted of user name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Googleログインの導入に伴い、ユーザー名の表示を取りやめる。 --- app/routes/_layout.archives.edit.$postId.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/routes/_layout.archives.edit.$postId.tsx b/app/routes/_layout.archives.edit.$postId.tsx index 98fdd1a3..cd4a2349 100644 --- a/app/routes/_layout.archives.edit.$postId.tsx +++ b/app/routes/_layout.archives.edit.$postId.tsx @@ -132,7 +132,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) { select: { postRevisionNumber: true, postEditDateJst: true, - editorUserName: true, + editorUserId: true, postTitleBeforeEdit: true, postTitleAfterEdit: true, postContentBeforeEdit: true, @@ -314,7 +314,7 @@ export default function EditPost() { {edit.postRevisionNumber} {edit.postEditDateJst.toLocaleString()} - {edit.editorUserName} + {edit.editorUserId.slice(0,8)} {diff.diffChars(edit.postTitleBeforeEdit, edit.postTitleAfterEdit).map((part, index) => { if (part.added || part.removed) { From 3e5ec5edfdfe082008f3250e4fdc87a2037860b0 Mon Sep 17 00:00:00 2001 From: contradiction29 Date: Tue, 23 Apr 2024 12:15:56 +0900 Subject: [PATCH 3/6] Remove username from edit system --- app/routes/_layout.archives.edit.$postId.tsx | 14 +++++++------- prisma/schema.prisma | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/routes/_layout.archives.edit.$postId.tsx b/app/routes/_layout.archives.edit.$postId.tsx index cd4a2349..b19aa369 100644 --- a/app/routes/_layout.archives.edit.$postId.tsx +++ b/app/routes/_layout.archives.edit.$postId.tsx @@ -20,7 +20,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) { where : { postId: Number(postId) }, select : { postId: true, - userName: true, + userId: true, lastHeartBeatAtUTC: true }, }); @@ -39,10 +39,10 @@ export async function loader({ params, request }: LoaderFunctionArgs) { if (nowEditingInfo){ const userName = await prisma.userProfiles.findUniqueOrThrow({ - select: { userName: true }, + select: { userId: true }, where: { userId }, }); - if (nowEditingInfo.userName === userName.userName){ + if (nowEditingInfo.userId === userName.userId){ isEditing = false; } } @@ -55,7 +55,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) { postMarkdown: null, tagNames: null, allTagsForSearch: null, - editingUserName: nowEditingInfo.userName, + editingUserName: nowEditingInfo.userId, postId, isEditing: true, userName: null, @@ -71,14 +71,14 @@ export async function loader({ params, request }: LoaderFunctionArgs) { }); } const userName = await prisma.userProfiles.findUniqueOrThrow({ - select: { userName: true }, + select: { userId: true }, where: { userId }, }); await prisma.nowEditingPages.create({ data: { postId: Number(postId), - userName: userName.userName, + userId: userName.userId, }, }); @@ -147,7 +147,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) { tagNames, postMarkdown, allTagsForSearch, - userName: userName.userName, + userName: userName.userId, editingUserName:null, isEditing:false, postId, diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 967680f0..e45987dd 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -80,7 +80,6 @@ model FctCommentVoteHisotry { model userProfiles { userId String @id @map("user_id") @db.Uuid - userName String @unique @map("user_name") userCreatedAt DateTime @default(now()) @map("user_created_at") @db.Timestamptz(6) userEmail String @unique @map("user_email") now_editing_pages nowEditingPages[] @@ -90,10 +89,10 @@ model userProfiles { model nowEditingPages { postId Int @id @unique @default(autoincrement()) @map("post_id") - userName String @map("user_name") + userId String @map("user_id") lastHeartBeatAtUTC DateTime @default(dbgenerated("(now() AT TIME ZONE 'utc'::text)")) @map("last_heart_beat_at_utc") @db.Timestamptz(6) dim_posts DimPosts @relation(fields: [postId], references: [postId], onDelete: Cascade, onUpdate: Cascade, map: "public_now_editing_pages_post_id_fkey") - user_profiles userProfiles @relation(fields: [userName], references: [userName], onDelete: Cascade, map: "public_now_editing_pages_user_name_fkey") + user_profiles userProfiles @relation(fields: [userId], references: [userId], onDelete: Cascade, map: "public_now_editing_pages_user_id_fkey") @@map("now_editing_pages") } From 04e1a5168aa9b23671ea5f652c687accb3c937fc Mon Sep 17 00:00:00 2001 From: contradiction29 Date: Tue, 23 Apr 2024 12:23:32 +0900 Subject: [PATCH 4/6] Remove user name from fctPostEditHistory --- prisma/schema.prisma | 1 - 1 file changed, 1 deletion(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e45987dd..b5a72ffe 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -126,7 +126,6 @@ model FctPostEditHistory { postRevisionNumber Int @map("post_revision_number") postEditDateJst DateTime @default(dbgenerated("(now() AT TIME ZONE 'jst'::text)")) @map("post_edit_date_jst") @db.Timestamptz(6) postEditDateGmt DateTime @default(dbgenerated("(now() AT TIME ZONE 'utc'::text)")) @map("post_edit_date_gmt") @db.Timestamptz(6) - editorUserName String @map("editor_user_name") @db.VarChar(255) editorUserId String @map("editor_user_id") postTitleBeforeEdit String @map("post_title_before_edit") @db.VarChar(255) postTitleAfterEdit String @map("post_title_after_edit") @db.VarChar(255) From d3e0bec3bb9534ff705a51511dd9d2054541561d Mon Sep 17 00:00:00 2001 From: contradiction29 Date: Tue, 23 Apr 2024 12:26:39 +0900 Subject: [PATCH 5/6] Remove user_name related action from signup page --- app/routes/_layout.signup.tsx | 41 ++--------------------------------- 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/app/routes/_layout.signup.tsx b/app/routes/_layout.signup.tsx index 27d44eb9..fd5651aa 100644 --- a/app/routes/_layout.signup.tsx +++ b/app/routes/_layout.signup.tsx @@ -9,22 +9,11 @@ export async function action({ request }: ActionFunctionArgs) { const form = await request.formData(); const email = form.get("email")?.toString(); const password = form.get("password")?.toString(); - const username = form.get("username")?.toString(); - if (!email || !password || !username) { + if (!email || !password ) { return json({ status: 500, message: "Email, password and username are required" }); } - const isUserNameExist = await prisma.userProfiles.findFirst({ - where: { - userName: username, - }, - }); - - if (isUserNameExist) { - return json({ status: 500, message: "ユーザー名が既に登録されています" }); - } - const url = new URL(request.url); const origin = url.origin; const emailRedirectTo = `${origin}/login`; @@ -47,16 +36,13 @@ export async function action({ request }: ActionFunctionArgs) { } try { - console.log(userId, username, email) await prisma.userProfiles.create({ data: { userId: userId, - userName: username, userEmail: email, }, }); } catch (error) { - console.log(error) return json({ status: 500, message: "ユーザー登録に失敗しました" }); } @@ -66,12 +52,11 @@ export async function action({ request }: ActionFunctionArgs) { export default function Component() { const actionData = useActionData(); const [isRegistering, setIsRegistering] = useState(false); - const [userName, setUserName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [passwordError, setPasswordError] = useState(""); - const isDisabled = !email || !password || !userName || passwordError !== ""; + const isDisabled = !email || !password || passwordError !== ""; const handlePasswordChange = (e: React.ChangeEvent) => { const newPassword = e.target.value; @@ -94,28 +79,6 @@ export default function Component() { onSubmit={() => setIsRegistering(true)} >

ユーザー新規登録

-
- - setUserName(e.target.value)} - required - /> - {!userName && ( -

ユーザー名を入力してください。

- )} -