Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Takedown policy association #261

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions app/actions/ModActionPanel/QuickAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
import { SubjectTag } from 'components/tags/SubjectTag'
import { HighProfileWarning } from '@/repositories/HighProfileWarning'
import { EmailComposer } from 'components/email/Composer'
import { ActionPolicySelector } from '@/reports/ModerationForm/ActionPolicySelector'

const FORM_ID = 'mod-action-panel'
const useBreakpoint = createBreakpoint({ xs: 340, sm: 640 })
Expand Down Expand Up @@ -266,6 +267,10 @@ function Form(
coreEvent.durationInHours = Number(formData.get('durationInHours'))
}

if (formData.get('policy')) {
coreEvent.policy = String(formData.get('policy'))
}

if (
(isTakedownEvent || isAckEvent) &&
formData.get('acknowledgeAccountSubjects')
Expand Down Expand Up @@ -666,16 +671,35 @@ function Form(
<ModEventDetailsPopover modEventType={modEventType} />
</div>
{shouldShowDurationInHoursField && (
<FormLabel
label=""
htmlFor="durationInHours"
className={`mb-3 mt-2`}
>
<ActionDurationSelector
action={modEventType}
labelText={isMuteEvent ? 'Mute duration' : ''}
/>
</FormLabel>
<div className="flex flex-row gap-2">
<FormLabel
label=""
htmlFor="durationInHours"
className={`mb-3 mt-2`}
>
<ActionDurationSelector
action={modEventType}
onChange={(e) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to the objective of this PR but wanted to add it in since it's been requested by mods a few times in the past.

if (e.target.value === '0') {
// When permanent takedown is selected, auto check ack all checkbox
const ackAllCheckbox =
document.querySelector<HTMLInputElement>(
'input[name="acknowledgeAccountSubjects"]',
)
if (ackAllCheckbox && !ackAllCheckbox.checked) {
ackAllCheckbox.checked = true
}
}
}}
labelText={isMuteEvent ? 'Mute duration' : ''}
/>
</FormLabel>
{isTakedownEvent && (
<div className="mt-2 w-full">
<ActionPolicySelector name="policy" />
</div>
)}
</div>
)}

{isMuteReporterEvent && (
Expand Down
9 changes: 8 additions & 1 deletion app/configure/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ import { WorkspacePanel } from '@/workspace/Panel'
import { useWorkspaceOpener } from '@/common/useWorkspaceOpener'
import { SetsConfig } from '@/config/Sets'
import { ProtectedTagsConfig } from '@/config/ProtectedTags'
import { PoliciesConfig } from '@/config/Policies'

enum Views {
Configure,
Members,
Sets,
ProtectedTags,
Policies,
}

const TabKeys = {
configure: Views.Configure,
members: Views.Members,
sets: Views.Sets,
protectedTags: Views.ProtectedTags,
policies: Views.Policies,
}

export default function ConfigurePageContent() {
Expand Down Expand Up @@ -73,6 +76,10 @@ export default function ConfigurePageContent() {
view: Views.Sets,
label: 'Sets',
},
{
view: Views.Policies,
label: 'Policies',
},
{
view: Views.ProtectedTags,
label: 'Protected Tags',
Expand All @@ -90,8 +97,8 @@ export default function ConfigurePageContent() {
{currentView === Views.Configure && <LabelerConfig />}
{currentView === Views.Members && <MemberConfig />}
{currentView === Views.Sets && <SetsConfig />}
{currentView === Views.Sets && <SetsConfig />}
{currentView === Views.ProtectedTags && <ProtectedTagsConfig />}
{currentView === Views.Policies && <PoliciesConfig />}

<ModActionPanelQuick
open={!!quickOpenParam}
Expand Down
101 changes: 101 additions & 0 deletions components/config/Policies.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { ActionButton, LinkButton } from '@/common/buttons'
import { Input } from '@/common/forms'
import { PolicyEditor } from '@/setting/policy/Editor'
import { PolicyList } from '@/setting/policy/List'
import { usePolicyListSetting } from '@/setting/policy/usePolicyList'
import { createPolicyPageLink } from '@/setting/policy/utils'
import { useServerConfig } from '@/shell/ConfigurationContext'
import { ToolsOzoneTeamDefs } from '@atproto/api'
import { PlusIcon, MagnifyingGlassIcon } from '@heroicons/react/24/outline'
import { useRouter, useSearchParams } from 'next/navigation'

export function PoliciesConfig() {
const router = useRouter()
const searchParams = useSearchParams()
const searchQuery = searchParams.get('search')
const { role } = useServerConfig()
const canManagePolicies = role === ToolsOzoneTeamDefs.ROLEADMIN
const showPoliciesCreateForm = searchParams.has('create')

return (
<div className="pt-4">
<div className="flex flex-row justify-between mb-4">
{typeof searchQuery === 'string' ? (
<>
<Input
type="text"
autoFocus
className="w-3/4"
placeholder="Search policies..."
value={searchQuery}
onChange={(e) => {
const url = createPolicyPageLink({ search: e.target.value })
router.push(url)
}}
/>{' '}
<LinkButton
size="sm"
className="ml-1"
appearance="outlined"
href={createPolicyPageLink({})}
>
Cancel
</LinkButton>
</>
) : (
<>
<div className="flex flex-row items-center">
<h4 className="font-medium text-gray-700 dark:text-gray-100">
Manage Policies
</h4>
</div>
{!showPoliciesCreateForm && (
<div className="flex flex-row items-center">
{canManagePolicies && (
<LinkButton
size="sm"
appearance="primary"
href={createPolicyPageLink({ create: 'true' })}
>
<PlusIcon className="h-3 w-3 mr-1" />
<span className="text-xs">Add New Policy</span>
</LinkButton>
)}

<LinkButton
size="sm"
className="ml-1"
appearance="outlined"
href={createPolicyPageLink({ search: '' })}
>
<MagnifyingGlassIcon className="h-4 w-4" />
</LinkButton>
</div>
)}
</>
)}
</div>
{showPoliciesCreateForm && (
<div className="mb-4">
<PolicyEditor
onCancel={() => {
const url = createPolicyPageLink({})
router.push(url)
}}
onSuccess={() => {
const url = createPolicyPageLink({})
router.push(url)
}}
/>
</div>
)}

<PolicyList
{...{
searchQuery,
canEdit: canManagePolicies,
}}
/>
</div>
)
}
22 changes: 21 additions & 1 deletion components/mod-event/EventItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { useConfigurationContext } from '@/shell/ConfigurationContext'
import { ItemTitle } from './ItemTitle'
import { PreviewCard } from '@/common/PreviewCard'
import { ModEventViewWithDetails } from './useModEventList'
import { ClockIcon, DocumentTextIcon } from '@heroicons/react/24/solid'
import Link from 'next/link'

const LinkToAuthor = ({
creatorHandle,
Expand Down Expand Up @@ -185,8 +187,26 @@ const TakedownOrMute = ({
</div>
</div>
{expiresAt && (
<p className="mt-1">Until {dateFormatter.format(expiresAt)}</p>
<p className="mt-1 flex flex-row items-center">
<ClockIcon className="h-3 w-3 inline-block mr-1" />
Until {dateFormatter.format(expiresAt)}
</p>
)}
{modEvent.event.policy ? (
<p className="pb-1 flex flex-row items-center">
<DocumentTextIcon className="h-3 w-3 inline-block mr-1" />
<i>
Under{' '}
<Link
prefetch={false}
href={`/configure?tab=policies&search=${modEvent.event.policy}`}
>
<u>{`${modEvent.event.policy}`}</u>
</Link>{' '}
policy
</i>
</p>
) : null}
{modEvent.event.comment ? (
<p className="pb-1">{`${modEvent.event.comment}`}</p>
) : null}
Expand Down
12 changes: 12 additions & 0 deletions components/mod-event/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useState } from 'react'
import { RepoFinder } from '@/repositories/Finder'
import { Dropdown } from '@/common/Dropdown'
import { ChevronDownIcon } from '@heroicons/react/24/solid'
import { ActionPolicySelector } from '@/reports/ModerationForm/ActionPolicySelector'

export const EventFilterPanel = ({
limit,
Expand Down Expand Up @@ -271,6 +272,17 @@ export const EventFilterPanel = ({
</FormLabel>
</div>
</div>
{types.includes(MOD_EVENTS.TAKEDOWN) && (
<div className="flex flex-row gap-2 mt-2">
<FormLabel label="Policy" className="flex-1">
<ActionPolicySelector
onSelect={(policy) => {
changeListFilter({ field: 'policy', value: policy })
}}
/>
</FormLabel>
</div>
)}
{types.includes(MOD_EVENTS.TAG) && (
<div className="flex flex-row gap-2 mt-2">
<FormLabel label="Added Tags" className="flex-1 max-w-sm">
Expand Down
8 changes: 8 additions & 0 deletions components/mod-event/useModEventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
removedLabels: [],
addedTags: '',
removedTags: '',
policy: '',
showContentPreview: false,
limit: 25,
}
Expand Down Expand Up @@ -157,6 +158,7 @@
| { field: 'removedLabels'; value: string[] }
| { field: 'addedTags'; value: string }
| { field: 'removedTags'; value: string }
| { field: 'policy'; value: string }
| { field: 'limit'; value: number }

type EventListAction =
Expand Down Expand Up @@ -246,6 +248,7 @@
addedTags,
removedTags,
reportTypes,
policy,
limit,
} = listState
const queryParams: ToolsOzoneModerationQueryEvents.QueryParams = {
Expand Down Expand Up @@ -335,6 +338,10 @@
})
}

if (filterTypes.includes(MOD_EVENTS.TAKEDOWN) && policy) {
queryParams.policy = policy

Check failure on line 342 in components/mod-event/useModEventList.tsx

View workflow job for this annotation

GitHub Actions / Build

Property 'policy' does not exist on type 'QueryParams'.
}

const { data } = await labelerAgent.tools.ozone.moderation.queryEvents({
...queryParams,
})
Expand Down Expand Up @@ -372,6 +379,7 @@
listState.createdBy ||
listState.subject ||
listState.oldestFirst ||
listState.policy ||
listState.reportTypes.length > 0 ||
listState.addedLabels.length > 0 ||
listState.removedLabels.length > 0 ||
Expand Down
Loading
Loading