this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

labeler: extract SubjectDid from SubjectUri (for db)

+39 -4
+21 -4
labeler/xrpc_handlers.go
··· 330 330 return s.fetchSingleModerationAction(ctx, body.Id) 331 331 } 332 332 333 + func didFromURI(uri string) string { 334 + parts := strings.SplitN(uri, "/", 4) 335 + if len(parts) < 3 { 336 + return "" 337 + } 338 + if strings.HasPrefix(parts[2], "did:") { 339 + return parts[2] 340 + } 341 + return "" 342 + } 343 + 333 344 func (s *Server) handleComAtprotoAdminTakeModerationAction(ctx context.Context, body *atproto.AdminTakeModerationAction_Input) (*atproto.AdminDefs_ActionView, error) { 334 345 335 346 if body.Action == "" { ··· 361 372 return nil, echo.NewHTTPError(400, "this implementation requires a strong record ref (aka, with CID) in reports") 362 373 } 363 374 row.SubjectType = "com.atproto.repo.recordRef" 364 - // XXX: row.SubjectDid from URI? 365 375 row.SubjectUri = &body.Subject.RepoStrongRef.Uri 376 + row.SubjectDid = didFromURI(body.Subject.RepoStrongRef.Uri) 377 + if row.SubjectDid == "" { 378 + return nil, echo.NewHTTPError(400, "expected URI with a DID: ", row.SubjectUri) 379 + } 366 380 row.SubjectCid = &body.Subject.RepoStrongRef.Cid 367 381 outSubj.RepoStrongRef = &atproto.RepoStrongRef{ 368 382 LexiconTypeID: "com.atproto.repo.strongRef", ··· 417 431 row := models.ModerationReport{ 418 432 ReasonType: *body.ReasonType, 419 433 Reason: body.Reason, 420 - // XXX(bnewbold): from auth, via context? as a new lexicon field? 421 - ReportedByDid: "did:plc:FAKE", 434 + // TODO(bnewbold): temporarily, all reports from labelmaker user 435 + ReportedByDid: s.user.Did, 422 436 } 423 437 var outSubj atproto.ModerationCreateReport_Output_Subject 424 438 if body.Subject.AdminDefs_RepoRef != nil { ··· 439 453 return nil, echo.NewHTTPError(400, "this implementation requires a strong record ref (aka, with CID) in reports") 440 454 } 441 455 row.SubjectType = "com.atproto.repo.recordRef" 442 - // XXX: row.SubjectDid from URI? 443 456 row.SubjectUri = &body.Subject.RepoStrongRef.Uri 457 + row.SubjectDid = didFromURI(body.Subject.RepoStrongRef.Uri) 458 + if row.SubjectDid == "" { 459 + return nil, echo.NewHTTPError(400, "expected URI with a DID: ", row.SubjectUri) 460 + } 444 461 row.SubjectCid = &body.Subject.RepoStrongRef.Cid 445 462 outSubj.RepoStrongRef = &atproto.RepoStrongRef{ 446 463 LexiconTypeID: "com.atproto.repo.strongRef",
+18
labeler/xrpc_test.go
··· 313 313 assert.Equal(1, len(out3.Labels)) 314 314 assert.Equal(&l3, out3.Labels[0]) 315 315 } 316 + 317 + func TestDidFromURI(t *testing.T) { 318 + assert := assert.New(t) 319 + cases := []struct { 320 + input string 321 + expected string 322 + }{ 323 + {input: "", expected: ""}, 324 + {input: "at://did:plc:fake/com.example/abc234", expected: "did:plc:fake"}, 325 + {input: "at://example.com/com.example/abc234", expected: ""}, 326 + {input: "at://did:plc:fake", expected: "did:plc:fake"}, 327 + } 328 + 329 + for _, tc := range cases { 330 + out := didFromURI(tc.input) 331 + assert.Equal(tc.expected, out) 332 + } 333 + }