From 1dcab49f0a86e5dcf2f9e20a8303c0a1995e72bf Mon Sep 17 00:00:00 2001 From: opficdev <162981733+opficdev@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:49:05 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=99=84=EB=A3=8C=EB=90=9C=20=EA=B0=9C?= =?UTF-8?q?=EB=B0=9C=20=EB=AA=A9=ED=91=9C=EC=9D=98=20=EC=A0=9C=EB=AA=A9?= =?UTF-8?q?=EA=B3=BC=20=EC=84=A4=EB=AA=85=20=EC=88=98=EC=A0=95=20=ED=97=88?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firestore.rules | 15 +++++++++++++-- .../test/firestore-rules.emulator.test.js | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/firestore.rules b/firestore.rules index 2e9423e..4ee9377 100644 --- a/firestore.rules +++ b/firestore.rules @@ -22,12 +22,23 @@ service cloud.firestore { userDataWriteAllowed(userId); } - // 개발 목표의 생성과 상태 전환 + // 개발 목표의 생성과 상태 전환, 완료된 목표의 제목과 설명 수정 match /developmentGoals/{goalId} { allow read: if request.auth != null && request.auth.uid == userId; - allow create, update: if request.auth != null && request.auth.uid == userId && + allow create: if request.auth != null && request.auth.uid == userId && userDataWriteAllowed(userId) && request.resource.data.get('status', null) != 'completed'; + // 완료된 목표는 상태를 유지한 채 제목, 설명, 갱신 시각만 바꾸는 갱신 허용 + allow update: if request.auth != null && request.auth.uid == userId && + userDataWriteAllowed(userId) && + ( + request.resource.data.get('status', null) != 'completed' || + ( + resource.data.get('status', null) == 'completed' && + request.resource.data.diff(resource.data).affectedKeys() + .hasOnly(['title', 'markdownDescription', 'updatedAt']) + ) + ); // 개발 기록의 생성과 초안, 현재 확정 버전 참조 갱신 match /records/{recordId} { diff --git a/functions/test/firestore-rules.emulator.test.js b/functions/test/firestore-rules.emulator.test.js index 5b65669..e8ee03e 100644 --- a/functions/test/firestore-rules.emulator.test.js +++ b/functions/test/firestore-rules.emulator.test.js @@ -37,6 +37,7 @@ let testEnvironment; try { await assertOwnerCreatesAndTransitionsGoal(); await assertClientCannotCompleteGoal(); + await assertOwnerEditsCompletedGoal(); await assertOwnerCreatesRecordAndSavesDraft(); await assertOwnerConfirmsDraftWithNewVersion(); await assertOwnerReadsVersions(); @@ -79,7 +80,8 @@ async function assertClientCannotCompleteGoal() { await assertFails(updateDoc(doc(db, goalPath), { status: "completed", completedAt: new Date() })); await seed({ [goalPath]: { ...goalData(), status: "completed", completedAt: new Date() } }); - await assertFails(updateDoc(doc(db, goalPath), { title: "changed" })); + await assertFails(updateDoc(doc(db, goalPath), { completedAt: new Date() })); + await assertFails(updateDoc(doc(db, goalPath), { title: "changed", completedAt: new Date() })); await assertSucceeds(updateDoc(doc(db, goalPath), { status: "inProgress", completedAt: deleteField(), @@ -87,6 +89,20 @@ async function assertClientCannotCompleteGoal() { })); } +// 완료된 목표의 상태를 유지한 제목, 설명, 갱신 시각 저장 허용 검증 +async function assertOwnerEditsCompletedGoal() { + await testEnvironment.clearFirestore(); + await seed({ [goalPath]: { ...goalData(), status: "completed", completedAt: new Date() } }); + const db = ownerFirestore(); + + await assertSucceeds(updateDoc(doc(db, goalPath), { + title: "changed", + markdownDescription: "changed description", + updatedAt: new Date() + })); + await assertSucceeds(getDoc(doc(db, goalPath))); +} + // 소유자의 기록 생성과 초안 저장 허용 검증 async function assertOwnerCreatesRecordAndSavesDraft() { await testEnvironment.clearFirestore();