Skip to content

Commit

Permalink
Appview: fix takendown blocklist application on actor.getProfile (#…
Browse files Browse the repository at this point in the history
…3108)

appview: fix takendown blocklist application on actor.getProfile
  • Loading branch information
devinivy authored Nov 26, 2024
1 parent 53fcc2f commit 167270b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/bsky/src/api/app/bsky/actor/getProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const hydration = async (input: {
const { ctx, params, skeleton } = input
return ctx.hydrator.hydrateProfilesDetailed(
[skeleton.did],
params.hydrateCtx.copy({ includeTakedowns: true }),
params.hydrateCtx.copy({
includeActorTakedowns: true,
}),
)
}

Expand Down
9 changes: 1 addition & 8 deletions packages/bsky/src/auth-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ import {
unpackIdentityKeys,
} from './data-plane'
import { GetIdentityByDidResponse } from './proto/bsky_pb'
import {
extractMultikey,
extractPrefixedBytes,
hasPrefix,
parseDidKey,
SECP256K1_DID_PREFIX,
SECP256K1_JWT_ALG,
} from '@atproto/crypto'
import { parseDidKey, SECP256K1_JWT_ALG } from '@atproto/crypto'

type ReqCtx = {
req: express.Request
Expand Down
7 changes: 5 additions & 2 deletions packages/bsky/src/hydration/hydrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class HydrateCtx {
labelers = this.vals.labelers
viewer = this.vals.viewer !== null ? serviceRefToDid(this.vals.viewer) : null
includeTakedowns = this.vals.includeTakedowns
includeActorTakedowns = this.vals.includeActorTakedowns
include3pBlocks = this.vals.include3pBlocks
constructor(private vals: HydrateCtxVals) {}
copy<V extends Partial<HydrateCtxVals>>(vals?: V): HydrateCtx & V {
Expand All @@ -76,6 +77,7 @@ export type HydrateCtxVals = {
labelers: ParsedLabelers
viewer: string | null
includeTakedowns?: boolean
includeActorTakedowns?: boolean
include3pBlocks?: boolean
}

Expand Down Expand Up @@ -179,12 +181,13 @@ export class Hydrator {
dids: string[],
ctx: HydrateCtx,
): Promise<HydrationState> {
const includeTakedowns = ctx.includeTakedowns || ctx.includeActorTakedowns
const [actors, labels, profileViewersState] = await Promise.all([
this.actor.getActors(dids, ctx.includeTakedowns),
this.actor.getActors(dids, includeTakedowns),
this.label.getLabelsForSubjects(labelSubjectsForDid(dids), ctx.labelers),
this.hydrateProfileViewers(dids, ctx),
])
if (!ctx.includeTakedowns) {
if (!includeTakedowns) {
actionTakedownLabels(dids, actors, labels)
}
return mergeStates(profileViewersState ?? {}, {
Expand Down
31 changes: 31 additions & 0 deletions packages/bsky/tests/views/labels-takedown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ids } from '../../src/lexicon/lexicons'
describe('bsky takedown labels', () => {
let network: TestNetwork
let agent: AtpAgent
let pdsAgent: AtpAgent
let sc: SeedClient

let takendownSubjects: string[]
Expand All @@ -20,10 +21,21 @@ describe('bsky takedown labels', () => {
dbPostgresSchema: 'bsky_views_takedown_labels',
})
agent = network.bsky.getClient()
pdsAgent = network.pds.getClient()
sc = network.getSeedClient()
await basicSeed(sc)

aliceListRef = await sc.createList(sc.dids.alice, 'alice list', 'mod')
// carol blocks dan via alice's (takendown) list
await sc.addToList(sc.dids.alice, sc.dids.dan, aliceListRef)
await pdsAgent.app.bsky.graph.listblock.create(
{ repo: sc.dids.carol },
{
subject: aliceListRef.uriStr,
createdAt: new Date().toISOString(),
},
sc.getHeaders(sc.dids.carol),
)
carolListRef = await sc.createList(sc.dids.carol, 'carol list', 'mod')
aliceGenRef = await sc.createFeedGen(
sc.dids.alice,
Expand Down Expand Up @@ -159,6 +171,25 @@ describe('bsky takedown labels', () => {
await expect(attempt2).rejects.toThrow('List not found')
})

it('halts application of mod lists', async () => {
const { data: profile } = await agent.app.bsky.actor.getProfile(
{
actor: sc.dids.dan, // blocked via alice's takendown list
},
{
headers: await network.serviceHeaders(
sc.dids.carol,
ids.AppBskyActorGetProfile,
),
},
)
expect(profile.did).toBe(sc.dids.dan)
expect(profile.viewer).not.toBeUndefined()
expect(profile.viewer?.blockedBy).toBe(false)
expect(profile.viewer?.blocking).toBeUndefined()
expect(profile.viewer?.blockingByList).toBeUndefined()
})

it('takesdown feed generators', async () => {
const res = await agent.api.app.bsky.feed.getFeedGenerators({
feeds: [aliceGenRef.uriStr, bobGenRef.uriStr, carolGenRef.uriStr],
Expand Down

0 comments on commit 167270b

Please sign in to comment.