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

OAuth integration #128

Merged
merged 45 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
76026e3
feat(login): login using oauth
matthieusieben Jun 12, 2024
cf37682
Various fixes linked to oauth
matthieusieben Jul 2, 2024
ed59541
style: various minor updates
matthieusieben Jul 2, 2024
2b07e2b
fix(external-labelers): avoid un-necessary invalidation of queries
matthieusieben Jul 2, 2024
93102bb
tidy
matthieusieben Jul 2, 2024
72196d3
fix(oauth): adapt to latest client changes
matthieusieben Jul 9, 2024
b24adb2
feat(tabs): expose current view
matthieusieben Jul 9, 2024
a6e51d0
Merge remote-tracking branch 'origin/main' into oauth-matthieu
matthieusieben Jul 9, 2024
99f27ce
fix: external labelers
matthieusieben Jul 9, 2024
a52ee6f
improve init time
matthieusieben Jul 9, 2024
b3be988
fix(repositories): list profiles using labeler instead of PDS
matthieusieben Jul 10, 2024
7059cf2
style: remove un-necessary "encoding" param from api calls
matthieusieben Jul 10, 2024
64ed75c
fix: rename import from @atproto/api
matthieusieben Jul 11, 2024
a6966a5
:rightwards_twisted_arrows: Merge with upstream
foysalit Aug 8, 2024
7cae67c
:bug: Adjust for new oauth and atproto api package changes
foysalit Aug 13, 2024
82594d8
:white_check_mark: Add manual wait
foysalit Aug 13, 2024
1f830ac
:broom: Cleanup
foysalit Aug 13, 2024
cde9677
:twisted_rightwards_arrows: Merge with upstream
foysalit Aug 23, 2024
664e531
:broom: Cleanup
foysalit Aug 23, 2024
9043ba1
Adapt to latest SDK changes
matthieusieben Aug 28, 2024
bc8c2a7
fix definition of loopback client
matthieusieben Aug 28, 2024
3b2ce66
Fix cleint_id and metadata
matthieusieben Aug 29, 2024
ad6137f
:bug: Fix initial setup sequence bugs
foysalit Aug 29, 2024
def67fd
:sparkles: Add feature flag for oauth login tab
foysalit Aug 29, 2024
efafeea
fix logout not happening error
matthieusieben Aug 29, 2024
1079db0
Allow automatic hiding of tabs
matthieusieben Aug 30, 2024
b1161e8
wip: config
matthieusieben Aug 30, 2024
42e224d
wip: auth
matthieusieben Aug 30, 2024
2eb4791
Update components/shell/ConfigurationFlow.tsx
matthieusieben Aug 30, 2024
0ab7fd4
Merge remote-tracking branch 'origin/main' into oauth-matthieu
matthieusieben Aug 30, 2024
35e7f92
Update lib/client-config.ts
matthieusieben Aug 30, 2024
8339284
Update lib/constants.ts
matthieusieben Aug 30, 2024
b97202d
Update cypress/support/api.ts
matthieusieben Aug 30, 2024
c45e715
add missing NEXT_PUBLIC_HANDLE_RESOLVER_URL in env config
matthieusieben Aug 30, 2024
d8e8d28
update dep
matthieusieben Aug 30, 2024
7a3934d
code cleanup
matthieusieben Aug 30, 2024
1e718b2
restore default OZONE_PUBLIC_URL for dev mode
matthieusieben Aug 30, 2024
d3944a4
remove dev OZONE_PUBLIC_URL
matthieusieben Aug 30, 2024
82fa7df
fix local dev (yarn dev)
matthieusieben Aug 30, 2024
1e8d436
Add compatibility with legacy credentials
matthieusieben Aug 30, 2024
b5dfbcd
adapt to main merge
matthieusieben Sep 2, 2024
83243e8
:white_check_mark: Set correct fixture
foysalit Sep 2, 2024
9c51f6a
:white_check_mark: set cypress env vars for github ci
foysalit Sep 2, 2024
5425da0
:bug: Allow Only/Exclude/Indifferent filters for appeal status (#170)
foysalit Sep 3, 2024
b9e8fd8
Merge remote-tracking branch 'origin/main' into oauth-matthieu
matthieusieben Sep 3, 2024
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
10 changes: 9 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"extends": "next/core-web-vitals"
"extends": "next/core-web-vitals",
"rules": {
"react-hooks/exhaustive-deps": [
"warn",
{
"additionalHooks": "(useSignaledEffect)"
}
]
}
}
118 changes: 65 additions & 53 deletions app/actions/ModActionPanel/QuickAction.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: This is badly named so that we can rebuild this component without breaking the old one
import { useQuery } from '@tanstack/react-query'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import {
ComAtprotoModerationDefs,
ToolsOzoneModerationDefs,
Expand All @@ -10,9 +10,7 @@
import { ButtonPrimary, ButtonSecondary } from '@/common/buttons'
import { Checkbox, FormLabel, Input, Textarea } from '@/common/forms'
import { PropsOf } from '@/lib/types'
import client from '@/lib/client'
import { BlobList } from './BlobList'
import { queryClient } from 'components/QueryClient'
import {
LabelChip,
LabelList,
Expand All @@ -38,8 +36,8 @@
import { MOD_EVENTS } from '@/mod-event/constants'
import { ModEventList } from '@/mod-event/EventList'
import { ModEventSelectorButton } from '@/mod-event/SelectorButton'
import { createSubjectFromId } from '@/reports/helpers/subject'
import { SubjectReviewStateBadge } from '@/subject/ReviewStateMarker'
import { useCreateSubjectFromId } from '@/reports/helpers/subject'
import { getProfileUriForDid } from '@/reports/helpers/subject'
import { Dialog } from '@headlessui/react'
import { SubjectSwitchButton } from '@/common/SubjectSwitchButton'
Expand All @@ -50,7 +48,7 @@
import { MessageActorMeta } from '@/dms/MessageActorMeta'
import { ModEventDetailsPopover } from '@/mod-event/DetailsPopover'
import { LockClosedIcon } from '@heroicons/react/24/solid'
import { checkPermission } from '@/lib/server-config'
import { useLabelerAgent, usePermission } from '@/shell/ConfigurationContext'

const FORM_ID = 'mod-action-panel'
const useBreakpoint = createBreakpoint({ xs: 340, sm: 640 })
Expand Down Expand Up @@ -144,7 +142,10 @@
const getDeactivatedAt = ({
repo,
record,
}: Awaited<ReturnType<typeof getSubject>>) => {
}: {
repo?: ToolsOzoneModerationDefs.RepoViewDetail
record?: ToolsOzoneModerationDefs.RecordViewDetail
}) => {
const deactivatedAt = repo?.deactivatedAt || record?.repo?.deactivatedAt

if (!deactivatedAt) {
Expand All @@ -160,6 +161,10 @@
replaceFormWithEvents: boolean
} & Pick<Props, 'setSubject' | 'subject' | 'subjectOptions' | 'onSubmit'>,
) {
const queryClient = useQueryClient()
const labelerAgent = useLabelerAgent()
const accountDid = labelerAgent.assertDid

const {
subject,
setSubject,
Expand All @@ -173,16 +178,13 @@
isSubmitting: boolean
error: string
}>({ isSubmitting: false, error: '' })
const { data: subjectStatus, refetch: refetchSubjectStatus } = useQuery({
// subject of the report
queryKey: ['modSubjectStatus', { subject }],
queryFn: () => getSubjectStatus(subject),
})
const { data: { record, repo } = {}, refetch: refetchSubject } = useQuery({
// subject of the report
queryKey: ['modActionSubject', { subject }],
queryFn: () => getSubject(subject),
})

const { data: subjectStatus, refetch: refetchSubjectStatus } =
useSubjectStatusQuery(subject)

const { data: { record, repo } = {}, refetch: refetchSubject } =
useSubjectQuery(subject)

const isSubjectDid = subject.startsWith('did:')
const isReviewClosed =
subjectStatus?.reviewState === ToolsOzoneModerationDefs.REVIEWCLOSED
Expand All @@ -207,7 +209,7 @@
const deactivatedAt = getDeactivatedAt(
repo ? { repo } : record ? { record } : {},
)
const canManageChat = checkPermission('canManageChat')
const canManageChat = usePermission('canManageChat')

// navigate to next or prev report
const navigateQueue = (delta: 1 | -1) => {
Expand Down Expand Up @@ -253,6 +255,9 @@
window.removeEventListener('keydown', downHandler)
}
}, [])

const createSubjectFromId = useCreateSubjectFromId()

// on form submit
const onFormSubmit = async (
ev: FormEvent<HTMLFormElement> & { target: HTMLFormElement },
Expand Down Expand Up @@ -380,7 +385,7 @@
labelSubmissions.push(
onSubmit({
subject: { ...subjectInfo, cid: labelCid },
createdBy: client.session.did,
createdBy: accountDid,
subjectBlobCids: formData
.getAll('subjectBlobCids')
.map((cid) => String(cid)),
Expand All @@ -402,7 +407,7 @@
labelSubmissions.push(
onSubmit({
subject: subjectInfo,
createdBy: client.session.did,
createdBy: accountDid,
subjectBlobCids: formData
.getAll('subjectBlobCids')
.map((cid) => String(cid)),
Expand All @@ -415,7 +420,7 @@
} else {
await onSubmit({
subject: subjectInfo,
createdBy: client.session.did,
createdBy: accountDid,
subjectBlobCids,
event: coreEvent,
})
Expand All @@ -424,7 +429,7 @@
if (formData.get('additionalAcknowledgeEvent')) {
await onSubmit({
subject: subjectInfo,
createdBy: client.session.did,
createdBy: accountDid,
subjectBlobCids: formData
.getAll('subjectBlobCids')
.map((cid) => String(cid)),
Expand Down Expand Up @@ -680,7 +685,7 @@
name="labels"
formId={FORM_ID}
defaultLabels={currentLabels.filter((label) => {
const serviceDid = client.getServiceDid()?.split('#')[0]

Check failure on line 688 in app/actions/ModActionPanel/QuickAction.tsx

View workflow job for this annotation

GitHub Actions / Build

Cannot find name 'client'.
const isExternalLabel = allLabels.some((l) => {
return l.val === label && l.src !== serviceDid
})
Expand Down Expand Up @@ -830,41 +835,48 @@
)
}

async function getSubject(subject: string) {
if (subject.startsWith('did:')) {
const { data: repo } = await client.api.tools.ozone.moderation.getRepo(
{
did: subject,
},
{ headers: client.proxyHeaders() },
)
return { repo }
} else if (subject.startsWith('at://')) {
const { data: record } = await client.api.tools.ozone.moderation.getRecord(
{
uri: subject,
},
{ headers: client.proxyHeaders() },
)

return { record }
} else {
return {}
}
function useSubjectQuery(subject: string) {
const labelerAgent = useLabelerAgent()

return useQuery({
// subject of the report
queryKey: ['modActionSubject', { subject }],
queryFn: async () => {
if (subject.startsWith('did:')) {
const { data: repo } =
await labelerAgent.api.tools.ozone.moderation.getRepo({
did: subject,
})
return { repo }
} else if (subject.startsWith('at://')) {
const { data: record } =
await labelerAgent.api.tools.ozone.moderation.getRecord({
uri: subject,
})
return { record }
} else {
return {}
}
},
})
}

async function getSubjectStatus(subject: string) {
const {
data: { subjectStatuses },
} = await client.api.tools.ozone.moderation.queryStatuses(
{
subject,
includeMuted: true,
limit: 1,
function useSubjectStatusQuery(subject: string) {
const labelerAgent = useLabelerAgent()
return useQuery({
// subject of the report
queryKey: ['modSubjectStatus', { subject }],
queryFn: async () => {
const {
data: { subjectStatuses },
} = await labelerAgent.api.tools.ozone.moderation.queryStatuses({
subject,
includeMuted: true,
limit: 1,
})
return subjectStatuses.at(0) || null
},
{ headers: client.proxyHeaders() },
)
return subjectStatuses.at(0) || null
})
}

function isMultiPress(ev: KeyboardEvent) {
Expand Down
12 changes: 5 additions & 7 deletions app/actions/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
'use client'
import { useQuery } from '@tanstack/react-query'
import client from '@/lib/client'
import { Loading, LoadingFailed } from '@/common/Loader'
import { EventView } from '@/mod-event/View'
import { useLabelerAgent } from '@/shell/ConfigurationContext'

export default function Action({ params }: { params: { id: string } }) {
const labelerAgent = useLabelerAgent()
const id = decodeURIComponent(params.id)

const { data: action, error } = useQuery({
queryKey: ['action', { id }],
queryFn: async () => {
const { data } = await client.api.tools.ozone.moderation.getEvent(
{
id: parseInt(id, 10),
},
{ headers: client.proxyHeaders() },
)
const { data } = await labelerAgent.api.tools.ozone.moderation.getEvent({
id: parseInt(id, 10),
})
return data
},
})
Expand Down
7 changes: 4 additions & 3 deletions app/communication-template/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import { Loading, LoadingFailed } from '@/common/Loader'
import { useCommunicationTemplateList } from 'components/communication-template/hooks'
import { CommunicationTemplateDeleteConfirmationModal } from 'components/communication-template/delete-confirmation-modal'
import { ActionButton, LinkButton } from '@/common/buttons'
import client from '@/lib/client'
import { ErrorInfo } from '@/common/ErrorInfo'
import { checkPermission } from '@/lib/server-config'
import { usePermission } from '@/shell/ConfigurationContext'

export default function CommunicationTemplatePage() {
const { data, error, isLoading } = useCommunicationTemplateList({})
Expand All @@ -25,7 +24,9 @@ export default function CommunicationTemplatePage() {
: []
useTitle(`Communication Templates`)

if (!checkPermission('canManageTemplates')) {
const canManageTemplates = usePermission('canManageTemplates')

if (!canManageTemplates) {
return (
<ErrorInfo type="warn">
Sorry, you don{"'"}t have permission to manage communication templates.
Expand Down
21 changes: 9 additions & 12 deletions app/configure/page-content.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useEffect } from 'react'
import { useTitle } from 'react-use'
import client from '@/lib/client'
import { useSession } from '@/lib/useSession'
import { Tabs, TabView } from '@/common/Tabs'
import { LabelerConfig } from 'components/config/Labeler'
import { MemberConfig } from 'components/config/Member'
import { ModActionPanelQuick } from 'app/actions/ModActionPanel/QuickAction'
import { ToolsOzoneModerationEmitEvent } from '@atproto/api'
import { emitEvent } from '@/mod-event/helpers/emitEvent'
import { useEmitEvent } from '@/mod-event/helpers/emitEvent'
import { usePathname, useSearchParams, useRouter } from 'next/navigation'
import { useConfigurationContext } from '@/shell/ConfigurationContext'
import { WorkspacePanel } from '@/workspace/Panel'
import { useWorkspaceOpener } from '@/common/useWorkspaceOpener'

Expand All @@ -24,11 +23,12 @@ const TabKeys = {

export default function ConfigurePageContent() {
useTitle('Configure')
const session = useSession()
useEffect(() => {
client.reconfigure() // Ensure config is up to date
}, [])
const isServiceAccount = !!session && session?.did === session?.config.did

const { reconfigure } = useConfigurationContext()
useEffect(() => void reconfigure(), [reconfigure]) // Ensure config is up to date

const emitEvent = useEmitEvent()

const searchParams = useSearchParams()
const router = useRouter()
const pathname = usePathname()
Expand All @@ -54,7 +54,6 @@ export default function ConfigurePageContent() {
router.push((pathname ?? '') + '?' + newParams.toString())
}

if (!session) return null
const views: TabView<Views>[] = [
{
view: Views.Configure,
Expand All @@ -74,9 +73,7 @@ export default function ConfigurePageContent() {
views={views}
fullWidth
/>
{currentView === Views.Configure && (
<LabelerConfig session={session} isServiceAccount={isServiceAccount} />
)}
{currentView === Views.Configure && <LabelerConfig />}
{currentView === Views.Members && <MemberConfig />}

<ModActionPanelQuick
Expand Down
13 changes: 6 additions & 7 deletions app/events/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
'use client'
import { useQuery } from '@tanstack/react-query'
import { useTitle } from 'react-use'
import client from '@/lib/client'

import { Loading, LoadingFailed } from '@/common/Loader'
import { EventView } from '@/mod-event/View'
import { MOD_EVENT_TITLES } from '@/mod-event/constants'
import { useLabelerAgent } from '@/shell/ConfigurationContext'

export default function EventViewPage({ params }: { params: { id: string } }) {
const id = decodeURIComponent(params.id)
const labelerAgent = useLabelerAgent()
const { data: event, error } = useQuery({
queryKey: ['event', { id }],
queryFn: async () => {
const { data } = await client.api.tools.ozone.moderation.getEvent(
{
id: parseInt(id, 10),
},
{ headers: client.proxyHeaders() },
)
const { data } = await labelerAgent.api.tools.ozone.moderation.getEvent({
id: parseInt(id, 10),
})
return data
},
})
Expand Down
3 changes: 2 additions & 1 deletion app/events/page-content.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useTitle } from 'react-use'
import { ModEventList } from '@/mod-event/EventList'
import { emitEvent } from '@/mod-event/helpers/emitEvent'
import { useEmitEvent } from '@/mod-event/helpers/emitEvent'
import { ToolsOzoneModerationEmitEvent } from '@atproto/api'
import { ModActionPanelQuick } from 'app/actions/ModActionPanel/QuickAction'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { WorkspacePanel } from '@/workspace/Panel'
import { useWorkspaceOpener } from '@/common/useWorkspaceOpener'

export default function EventListPageContent() {
const emitEvent = useEmitEvent()
const searchParams = useSearchParams()
const router = useRouter()
const pathname = usePathname()
Expand Down
Loading
Loading