feat: new operator
This commit is contained in:
@@ -61,7 +61,7 @@ export function DashboardLayout({
|
||||
if (userSite.isSuccess && subdomain) {
|
||||
if (
|
||||
!userSite.data?.find((site) => site.username === subdomain) &&
|
||||
!isOperator.data?.data
|
||||
!isOperator.data
|
||||
) {
|
||||
router.push("/dashboard")
|
||||
}
|
||||
|
||||
+50
-18
@@ -8,7 +8,7 @@ import { createClient } from "@urql/core"
|
||||
import axios from "axios"
|
||||
import { indexer } from "~/queries/crossbell"
|
||||
import type { LinkEntity, NoteEntity } from "crossbell.js"
|
||||
import type { Contract } from "crossbell.js"
|
||||
import type { Contract, CharacterOperatorPermission } from "crossbell.js"
|
||||
|
||||
export const checkSubdomain = async ({
|
||||
subdomain,
|
||||
@@ -438,6 +438,12 @@ export async function getNotifications(input: { siteCId: string }) {
|
||||
})
|
||||
}
|
||||
|
||||
const xLogOperatorPermissions: CharacterOperatorPermission[] = [
|
||||
"SET_NOTE_URI",
|
||||
"DELETE_NOTE",
|
||||
"POST_NOTE",
|
||||
]
|
||||
|
||||
export async function addOperator(
|
||||
input: {
|
||||
characterId: number
|
||||
@@ -446,31 +452,53 @@ export async function addOperator(
|
||||
contract?: Contract,
|
||||
) {
|
||||
if (input.operator && input.characterId) {
|
||||
return contract?.addOperator(input.characterId, input.operator)
|
||||
return contract?.grantOperatorPermissionsForCharacter(
|
||||
input.characterId,
|
||||
input.operator,
|
||||
xLogOperatorPermissions,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getOperators(
|
||||
input: {
|
||||
characterId?: number
|
||||
},
|
||||
contract?: Contract,
|
||||
) {
|
||||
export async function getOperators(input: { characterId?: number }) {
|
||||
if (input.characterId) {
|
||||
return contract?.getOperators(input.characterId)
|
||||
const result = await indexer?.getCharacterOperators(input.characterId, {
|
||||
limit: 100,
|
||||
})
|
||||
result.list = result.list
|
||||
.filter(
|
||||
(o) =>
|
||||
o.operator !== "0x0000000000000000000000000000000000000000" &&
|
||||
o.operator !== "0x0f588318a494e4508a121a32b6670b5494ca3357",
|
||||
) // remove 0 and xSync
|
||||
.filter((o) => {
|
||||
for (const permission of xLogOperatorPermissions) {
|
||||
if (!o.permissions.includes(permission)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
export async function isOperators(
|
||||
input: {
|
||||
characterId: number
|
||||
operator: string
|
||||
},
|
||||
contract?: Contract,
|
||||
) {
|
||||
export async function isOperators(input: {
|
||||
characterId: number
|
||||
operator: string
|
||||
}) {
|
||||
if (input.characterId) {
|
||||
return contract?.isOperator(input.characterId, input.operator)
|
||||
const permissions =
|
||||
(await indexer?.getCharacterOperator(input.characterId, input.operator))
|
||||
?.permissions || []
|
||||
for (const permission of xLogOperatorPermissions) {
|
||||
if (!permissions.includes(permission)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export async function removeOperator(
|
||||
@@ -481,7 +509,11 @@ export async function removeOperator(
|
||||
contract?: Contract,
|
||||
) {
|
||||
if (input.characterId) {
|
||||
return contract?.removeOperator(input.characterId, input.operator)
|
||||
return contract?.grantOperatorPermissionsForCharacter(
|
||||
input.characterId,
|
||||
input.operator,
|
||||
[],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,6 @@ export default function SiteSettingsGeneralPage() {
|
||||
id="description"
|
||||
className="input is-block"
|
||||
rows={2}
|
||||
help="Support Markdown"
|
||||
{...form.register("description")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -98,7 +98,7 @@ export default function SiteSettingsNavigationPage() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setItems(operators.data || [])
|
||||
setItems(operators.data?.list.map((o) => o.operator) || [])
|
||||
}, [operators.data])
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
|
||||
+5
-12
@@ -185,32 +185,25 @@ export const useGetNotifications = (data: { siteCId?: string }) => {
|
||||
export const useGetOperators = (
|
||||
data: Parameters<typeof siteModel.getOperators>[0],
|
||||
) => {
|
||||
const contract = useContract()
|
||||
return useQuery(["getOperators", data], async () => {
|
||||
if (!data.characterId) {
|
||||
return null
|
||||
}
|
||||
return (await siteModel.getOperators(data, contract))?.data?.filter(
|
||||
(operator) => operator !== "0x0000000000000000000000000000000000000000",
|
||||
)
|
||||
return siteModel.getOperators(data)
|
||||
})
|
||||
}
|
||||
|
||||
export const useIsOperators = (
|
||||
data: Partial<Parameters<typeof siteModel.isOperators>[0]>,
|
||||
) => {
|
||||
const contract = useContract()
|
||||
return useQuery(["isOperators", data], async () => {
|
||||
if (!data.characterId || !data.operator) {
|
||||
return null
|
||||
}
|
||||
return siteModel.isOperators(
|
||||
{
|
||||
characterId: data.characterId,
|
||||
operator: data.operator,
|
||||
},
|
||||
contract,
|
||||
)
|
||||
return siteModel.isOperators({
|
||||
characterId: data.characterId,
|
||||
operator: data.operator,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user