Skip to content

Commit

Permalink
Allow bulk dids for takedown (#330)
Browse files Browse the repository at this point in the history
- Modifies`takeDownAccountCmd` to take multiple dids for bulk takedowns 
- Renames cli command `takeDownAccount` to standardize with other
commands

Example command:
`./gosky admin take-down --reason="<reason here>" --admin-user="<did
here>" --revert-actions exampleuser.bsky.social
exampleuser2.bsky.social`
  • Loading branch information
whyrusleeping authored Sep 22, 2023
2 parents e600648 + 83c17e3 commit 3eba817
Showing 1 changed file with 54 additions and 53 deletions.
107 changes: 54 additions & 53 deletions cmd/gosky/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ var listInviteTreeCmd = &cli.Command{
}

var takeDownAccountCmd = &cli.Command{
Name: "take-down",
Name: "takeDownAccount",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "admin-password",
Expand Down Expand Up @@ -660,72 +660,73 @@ var takeDownAccountCmd = &cli.Command{
adminKey := cctx.String("admin-password")
xrpcc.AdminToken = &adminKey

did := cctx.Args().First()
if !strings.HasPrefix(did, "did:") {
phr := &api.ProdHandleResolver{}
resp, err := phr.ResolveHandleToDid(ctx, did)
if err != nil {
return err
}

did = resp
}
for _, did := range cctx.Args().Slice() {
if !strings.HasPrefix(did, "did:") {
phr := &api.ProdHandleResolver{}
resp, err := phr.ResolveHandleToDid(ctx, did)
if err != nil {
return err
}

reason := cctx.String("reason")
adminUser := cctx.String("admin-user")
if !strings.HasPrefix(adminUser, "did:") {
phr := &api.ProdHandleResolver{}
resp, err := phr.ResolveHandleToDid(ctx, adminUser)
if err != nil {
return err
did = resp
}

adminUser = resp
}
reason := cctx.String("reason")
adminUser := cctx.String("admin-user")
if !strings.HasPrefix(adminUser, "did:") {
phr := &api.ProdHandleResolver{}
resp, err := phr.ResolveHandleToDid(ctx, adminUser)
if err != nil {
return err
}

if cctx.Bool("revert-actions") {
resp, err := atproto.AdminGetModerationActions(ctx, xrpcc, "", 100, did)
if err != nil {
return err
adminUser = resp
}

for _, act := range resp.Actions {
if act.Action == nil || *act.Action != "com.atproto.admin.defs#acknowledge" {
return fmt.Errorf("will only revert acknowledge actions")
if cctx.Bool("revert-actions") {
resp, err := atproto.AdminGetModerationActions(ctx, xrpcc, "", 100, did)
if err != nil {
return err
}

_, err := atproto.AdminReverseModerationAction(ctx, xrpcc, &atproto.AdminReverseModerationAction_Input{
CreatedBy: adminUser,
Id: act.Id,
Reason: "reverting for takedown",
})
if err != nil {
return fmt.Errorf("failed to revert existing action: %w", err)
for _, act := range resp.Actions {
if act.Action == nil || *act.Action != "com.atproto.admin.defs#acknowledge" {
return fmt.Errorf("will only revert acknowledge actions")
}

_, err := atproto.AdminReverseModerationAction(ctx, xrpcc, &atproto.AdminReverseModerationAction_Input{
CreatedBy: adminUser,
Id: act.Id,
Reason: "reverting for takedown",
})
if err != nil {
return fmt.Errorf("failed to revert existing action: %w", err)
}
}
}

}
}

resp, err := atproto.AdminTakeModerationAction(ctx, xrpcc, &atproto.AdminTakeModerationAction_Input{
Action: "com.atproto.admin.defs#takedown",
Reason: reason,
CreatedBy: adminUser,
Subject: &atproto.AdminTakeModerationAction_Input_Subject{
AdminDefs_RepoRef: &atproto.AdminDefs_RepoRef{
Did: did,
resp, err := atproto.AdminTakeModerationAction(ctx, xrpcc, &atproto.AdminTakeModerationAction_Input{
Action: "com.atproto.admin.defs#takedown",
Reason: reason,
CreatedBy: adminUser,
Subject: &atproto.AdminTakeModerationAction_Input_Subject{
AdminDefs_RepoRef: &atproto.AdminDefs_RepoRef{
Did: did,
},
},
},
})
if err != nil {
return err
}
})
if err != nil {
return err
}

b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
return err
}
b, err := json.MarshalIndent(resp, "", " ")
if err != nil {
return err
}

fmt.Println(string(b))
fmt.Println(string(b))
}
return nil
},
}
Expand Down

0 comments on commit 3eba817

Please sign in to comment.