Skip to content

Commit

Permalink
Merge pull request codeforboston#1534 from codeforboston/revert-1506-…
Browse files Browse the repository at this point in the history
…1431-privacy-setting

Revert "Privacy Setting - Adjusting "Browse Testimony""
  • Loading branch information
Mephistic authored Apr 10, 2024
2 parents e646e94 + 54c3de6 commit 5655516
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 77 deletions.
11 changes: 7 additions & 4 deletions components/db/profile/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ export function useProfile() {
if (profile) {
await updateUserDisplayNameTestimonies(
uid,
isPublic ? profile.fullName ?? "Anonymous" : "private",
profile.fullName ?? "Anonymous",
isPublic
isPublic ? profile.fullName ?? "Anonymous" : "<private user>",
profile.fullName ?? "Anonymous"
)
}
await updateIsPublic(uid, isPublic)
Expand Down Expand Up @@ -129,7 +128,11 @@ export function useProfile() {
if (uid && fullName !== profile?.fullName) {
dispatch({ updatingFullName: true })
// Update the displayName for user's testimonies
await updateUserDisplayNameTestimonies(uid, fullName, fullName)
await updateUserDisplayNameTestimonies(
uid,
profile?.public ? fullName : "<private user>",
fullName
)
await updateFullName(uid, fullName)
dispatch({ updatingFullName: false })
}
Expand Down
3 changes: 0 additions & 3 deletions components/db/testimony/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Timestamp } from "firebase/firestore"
import { httpsCallable } from "firebase/functions"
import {
Array,
Boolean,
InstanceOf,
Literal as L,
Number,
Expand Down Expand Up @@ -45,9 +44,7 @@ export const Testimony = BaseTestimony.extend({
authorRole: Role,
billTitle: String,
version: Number,
public: Boolean,
publishedAt: InstanceOf(Timestamp),
updatedAt: InstanceOf(Timestamp),
representativeId: Optional(String),
senatorId: Optional(String),
senatorDistrict: Optional(String),
Expand Down
19 changes: 12 additions & 7 deletions components/db/testimony/updateUserTestimonies.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import { collection, getDocs, writeBatch } from "firebase/firestore"
import {
collection,
collectionGroup,
getDocs,
query,
updateDoc,
where,
writeBatch
} from "firebase/firestore"
import { firestore } from "../../firebase"

// Updates the displayName for all testimonies under specified user
export const updateUserDisplayNameTestimonies = async (
uid: string,
displayName: string,
fullName: string,
isPublic?: boolean
fullName: string
) => {
const batch = writeBatch(firestore)
return getAllTestimony(uid).then(({ publishedTestimony, draftTestimony }) => {
publishedTestimony.forEach(doc =>
batch.update(doc.ref, {
authorDisplayName: displayName,
fullName: fullName,
public: isPublic
fullName: fullName
})
)
draftTestimony.forEach(doc =>
batch.update(doc.ref, {
authorDisplayName: displayName,
fullName: fullName,
public: isPublic
fullName: fullName
})
)
batch.commit().then(result => result)
Expand Down
3 changes: 1 addition & 2 deletions components/db/testimony/useEditTestimony.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ beforeEach(async () => {
})

let draft: DraftTestimony,
testimony: Omit<Testimony, "publishedAt" | "id" | "updatedAt">,
testimony: Omit<Testimony, "publishedAt" | "id">,
updatedDraft: typeof draft,
updatedTestimony: typeof testimony
beforeEach(() => {
Expand All @@ -46,7 +46,6 @@ beforeEach(() => {
fullName: "Anonymous",
court: court,
position: draft.position,
public: true,
version: 1
}
updatedDraft = { ...draft, content: "update", position: "oppose" }
Expand Down
4 changes: 1 addition & 3 deletions components/moderation/setUp/MockRecords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ export const createMockTestimony = (
billTitle: "An act" + loremIpsum({ count: 2, units: "words" }),
version: 2,
publishedAt: Timestamp.fromDate(new Date()),
updatedAt: Timestamp.fromDate(new Date()),
billId: billId ?? "H1002",
court: 192,
position: "oppose",
content: loremIpsum({ count: 5, units: "words" }),
fullName: "Anonymous",
public: true
fullName: "Anonymous"
}
return testimony
}
Expand Down
6 changes: 3 additions & 3 deletions components/search/testimony/TestimonyHit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const TestimonyResult = ({ hit }: { hit: Hit<Testimony> }) => {
const committee = bill?.currentCommittee
const isOrg = hit.authorRole === "organization"
const writtenBy =
isOrg || hit.public ? (
<Link href={`/profile?id=${hit.authorUid}`}>{hit.fullName}</Link>
isOrg || hit.authorDisplayName !== "<private user>" ? (
<Link href={`/profile?id=${hit.authorUid}`}>{hit.authorDisplayName}</Link>
) : (
hit.fullName
hit.authorDisplayName
)
const { followOrg } = useFlags()

Expand Down
5 changes: 1 addition & 4 deletions components/search/testimony/TestimonySearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ const Layout = () => {
: ["user", "organization"]
return {
...prevState,
refinementList: {
...prevState.refinementList,
authorRole: role
}
refinementList: { ...prevState.refinementList, authorRole: role }
}
})
}
Expand Down
16 changes: 5 additions & 11 deletions components/search/testimony/useTestimonyRefinements.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import { useRefinementListUiProps } from "@alexjball/react-instantsearch-hooks-web"
import { useRefinements } from "../useRefinements"
import { useCallback } from "react"
import { RefinementListItem } from "instantsearch.js/es/connectors/refinement-list/connectRefinementList"

export const useTestimonyRefinements = () => {
const baseProps = { limit: 500, searchable: true }
const propsList = [
useRefinementListUiProps({
transformItems: useCallback(
(i: RefinementListItem[]) => i.filter(i => i.label !== "private"),
[]
),
attribute: "authorDisplayName",
...baseProps,
searchablePlaceholder: "Author Name"
}),
useRefinementListUiProps({
attribute: "court",
...baseProps,
Expand All @@ -30,6 +19,11 @@ export const useTestimonyRefinements = () => {
...baseProps,
searchablePlaceholder: "Bill"
}),
useRefinementListUiProps({
attribute: "authorDisplayName",
...baseProps,
searchablePlaceholder: "Author Name"
}),
useRefinementListUiProps({
attribute: "authorRole",
...baseProps,
Expand Down
4 changes: 1 addition & 3 deletions functions/src/auth/createFakeTestimony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export const createFakeTestimony = functions.https.onCall(
court: 192,
position: "oppose",
fullName: fullName,
content: fullName + " " + fullName + " " + fullName + " " + fullName,
public: true,
updatedAt: Timestamp.now()
content: fullName + " " + fullName + " " + fullName + " " + fullName
}

const testRef = db.doc(`users/${uid}/publishedTestimony/${id}`)
Expand Down
12 changes: 3 additions & 9 deletions functions/src/testimony/publishTestimony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type PublishInfo = {
version: number
editReason?: string
publishedAt: Timestamp
updatedAt: Timestamp
}

class PublishTestimonyTransaction {
Expand Down Expand Up @@ -92,8 +91,7 @@ class PublishTestimonyTransaction {
...publishInfo,
attachmentId: this.attachments.id,
draftAttachmentId: this.attachments.draftId,
fullName: this.profile?.fullName ?? "Anonymous",
public: this.profile?.public ?? true
fullName: this.profile?.fullName ?? "Anonymous"
}
if (this.profile?.representative?.id) {
newPublication.representativeId = this.profile.representative.id
Expand Down Expand Up @@ -220,11 +218,7 @@ class PublishTestimonyTransaction {
const version = await this.getNextPublicationVersion(),
reason = this.draft.editReason

const info: PublishInfo = {
version,
publishedAt: Timestamp.now(),
updatedAt: Timestamp.now()
}
const info: PublishInfo = { version, publishedAt: Timestamp.now() }

if (version > 1) {
if (!reason) throw fail("invalid-argument", "Edit reason is required.")
Expand Down Expand Up @@ -280,7 +274,7 @@ class PublishTestimonyTransaction {
private getDisplayName(): string {
// Check if user has profile and then if they're private
if (this.profile) {
return this.profile.public ? this.profile.fullName : "private"
return this.profile.public ? this.profile.fullName : "<private user>"
} else {
return "Anonymous"
}
Expand Down
9 changes: 2 additions & 7 deletions functions/src/testimony/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ export const {
{ name: "authorUid", type: "string", facet: false },
{ name: "authorRole", type: "string", facet: true },
{ name: "authorDisplayName", type: "string", facet: true },
{ name: "fullName", type: "string", facet: false },
{ name: "version", type: "int32", facet: false },
{ name: "public", type: "bool", facet: false },
{ name: "publishedAt", type: "int64", facet: false },
{ name: "updatedAt", type: "int64", facet: false }
{ name: "publishedAt", type: "int64", facet: false }
],
default_sorting_field: "publishedAt"
},
Expand All @@ -45,9 +42,7 @@ export const {
authorRole: testimony.authorRole,
version: testimony.version,
publishedAt: testimony.publishedAt.toMillis(),
updatedAt: testimony.updatedAt.toMillis(),
fullName: testimony.fullName,
public: testimony.public
fullName: testimony.fullName
}
return TestimonySearchRecord.check(record)
}
Expand Down
7 changes: 0 additions & 7 deletions functions/src/testimony/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Boolean,
InstanceOf,
Literal as L,
Number,
Expand Down Expand Up @@ -36,9 +35,7 @@ export const Testimony = withDefaults(
authorRole: Role,
billTitle: RtString,
version: Number,
public: Boolean,
publishedAt: InstanceOf(Timestamp),
updatedAt: InstanceOf(Timestamp),
representativeId: Optional(RtString),
senatorId: Optional(RtString),
senatorDistrict: Optional(RtString),
Expand All @@ -51,8 +48,6 @@ export const Testimony = withDefaults(
// ID is backfilled
id: "unknown",
publishedAt: Timestamp.fromMillis(0),
updatedAt: Timestamp.fromMillis(0),
public: true,
authorDisplayName: "Anonymous",
fullName: "Anonymous",
billTitle: ""
Expand Down Expand Up @@ -80,9 +75,7 @@ export const TestimonySearchRecord = R({
authorRole: RtString,
authorDisplayName: RtString,
version: Number,
public: Boolean,
publishedAt: Number,
updatedAt: Number,
fullName: RtString
})
export type TestimonySearchRecord = Static<typeof TestimonySearchRecord>
5 changes: 2 additions & 3 deletions scripts/firebase-admin/updateDisplayNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ export const script: Script = async ({ db }) => {
.then(result => result.docs)

const fullName = data.fullName ?? "Anonymous"
const displayName = data.public ? fullName : "private"
const displayName = data.public ? fullName : "<private user>"

for (const doc of publishedTestimony) {
writer.update(doc.ref, {
authorDisplayName: displayName,
fullName: fullName,
updatedAt: Timestamp.now(),
public: data.public ?? false
updatedAt: Timestamp.now()
})
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ Primary.args = {
billTitle: "Bill Title",
version: 1.0,
publishedAt: Timestamp.fromDate(new Date("2022-01-01T00:00:00.000Z")),
updatedAt: Timestamp.fromDate(new Date("2022-01-01T00:00:00.000Z")),
draftAttachmentId: "attachment123",
fullName: "",
public: true
fullName: ""
},
isUser: true,
canEdit: true,
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,9 @@ export const createNewTestimony = async (uid: string, billId: string) => {
version: 2,
billId,
publishedAt: testTimestamp.now(),
updatedAt: testTimestamp.now(),
court: 192,
position: "oppose",
content: "testimony content",
public: true
content: "testimony content"
}

try {
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,14 @@ function createValidatedDraft(authorUid: string, billId: string) {
id: "unknown",
authorRole: "user",
billTitle: "",
fullName: "Anonymous",
public: true,
updatedAt: Timestamp.fromMillis(0)
fullName: "Anonymous"
}

const validation = Testimony.validateWithDefaults(draft)

expect(validation.success).toBeTruthy()

const { publishedAt, updatedAt, ...rest } = draft
const { publishedAt, ...rest } = draft

return { draftId, draft: rest }
}
2 changes: 1 addition & 1 deletion tests/integration/testimony.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe("publishTestimony", () => {
expect(publication?.version).toBe(1)
expect(publication.publishedAt).toBeDefined()
expect(publication.authorUid).toEqual(user.uid)
expect([fullName, "Anonymous", "private"]).toContain(
expect([fullName, "Anonymous", "<private user>"]).toContain(
publication.authorDisplayName
)
expect(publication).toMatchObject(draft)
Expand Down

0 comments on commit 5655516

Please sign in to comment.