Skip to content

Commit

Permalink
Allow moderators to take and reverse actor takedowns (#1330)
Browse files Browse the repository at this point in the history
allow moderators to take and reverse actor takedowns
  • Loading branch information
devinivy authored Jul 14, 2023
1 parent 6b51ecb commit 53c4956
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export default function (server: Server, ctx: AppContext) {
'Must be a full moderator to reverse this type of action',
)
}
// if less than admin access then can reverse takedown on an account
// if less than moderator access then cannot reverse takedown on an account
if (
!access.admin &&
!access.moderator &&
existing.action === TAKEDOWN &&
existing.subjectType === 'com.atproto.admin.defs#repoRef'
) {
throw new AuthRequiredError(
'Must be an admin to reverse an account takedown',
'Must be a full moderator to reverse an account takedown',
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default function (server: Server, ctx: AppContext) {
// apply access rules

// if less than admin access then can not takedown an account
if (!access.admin && action === TAKEDOWN && 'did' in subject) {
if (!access.moderator && action === TAKEDOWN && 'did' in subject) {
throw new AuthRequiredError(
'Must be an admin to perform an account takedown',
'Must be a full moderator to perform an account takedown',
)
}
// if less than moderator access then can only take ack and escalation actions
Expand Down
16 changes: 9 additions & 7 deletions packages/bsky/tests/moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,9 +961,9 @@ describe('moderation', () => {
)
})

it('does not allow non-admin moderators to takedown.', async () => {
const attemptTakedownMod =
agent.api.com.atproto.admin.takeModerationAction(
it('allows full moderators to takedown.', async () => {
const { data: action } =
await agent.api.com.atproto.admin.takeModerationAction(
{
action: TAKEDOWN,
createdBy: 'did:example:moderator',
Expand All @@ -978,9 +978,11 @@ describe('moderation', () => {
headers: network.bsky.adminAuthHeaders('moderator'),
},
)
await expect(attemptTakedownMod).rejects.toThrow(
'Must be an admin to perform an account takedown',
)
// cleanup
await reverse(action.id)
})

it('does not allow non-full moderators to takedown.', async () => {
const attemptTakedownTriage =
agent.api.com.atproto.admin.takeModerationAction(
{
Expand All @@ -998,7 +1000,7 @@ describe('moderation', () => {
},
)
await expect(attemptTakedownTriage).rejects.toThrow(
'Must be an admin to perform an account takedown',
'Must be a full moderator to perform an account takedown',
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export default function (server: Server, ctx: AppContext) {
'Must be a full moderator to reverse this type of action',
)
}
// if less than admin access then can reverse takedown on an account
// if less than moderator access then cannot reverse takedown on an account
if (
!access.admin &&
!access.moderator &&
existing.action === TAKEDOWN &&
existing.subjectType === 'com.atproto.admin.defs#repoRef'
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default function (server: Server, ctx: AppContext) {
// apply access rules

// if less than admin access then can not takedown an account
if (!access.admin && action === TAKEDOWN && 'did' in subject) {
if (!access.moderator && action === TAKEDOWN && 'did' in subject) {
throw new AuthRequiredError(
'Must be an admin to perform an account takedown',
'Must be a full moderator to perform an account takedown',
)
}
// if less than moderator access then can only take ack and escalation actions
Expand Down
16 changes: 9 additions & 7 deletions packages/pds/tests/moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -984,9 +984,9 @@ describe('moderation', () => {
)
})

it('does not allow non-admin moderators to takedown.', async () => {
const attemptTakedownMod =
agent.api.com.atproto.admin.takeModerationAction(
it('allows full moderators to takedown.', async () => {
const { data: action } =
await agent.api.com.atproto.admin.takeModerationAction(
{
action: TAKEDOWN,
createdBy: 'did:example:moderator',
Expand All @@ -1001,9 +1001,11 @@ describe('moderation', () => {
headers: { authorization: moderatorAuth() },
},
)
await expect(attemptTakedownMod).rejects.toThrow(
'Must be an admin to perform an account takedown',
)
// cleanup
await reverse(action.id)
})

it('does not allow non-full moderators to takedown.', async () => {
const attemptTakedownTriage =
agent.api.com.atproto.admin.takeModerationAction(
{
Expand All @@ -1021,7 +1023,7 @@ describe('moderation', () => {
},
)
await expect(attemptTakedownTriage).rejects.toThrow(
'Must be an admin to perform an account takedown',
'Must be a full moderator to perform an account takedown',
)
})

Expand Down

0 comments on commit 53c4956

Please sign in to comment.