feat: add user banning
This commit is contained in:
1 parent
27de21a752
commit
10d70ea145
3 files changed
+36
-4
No files matched your search
@@ -32,7 +32,7 @@
|
|||||||
$: if (item) resetReason()
|
$: if (item) resetReason()
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!item || !$profile?.user || !community || !$profile?.jwt) return
|
if (!item || !$profile?.user || !$profile?.jwt) return
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
@@ -63,6 +63,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (community) {
|
||||||
await getClient().banFromCommunity({
|
await getClient().banFromCommunity({
|
||||||
auth: $profile.jwt,
|
auth: $profile.jwt,
|
||||||
ban: !banned,
|
ban: !banned,
|
||||||
@@ -72,6 +73,16 @@
|
|||||||
remove_data: deleteData,
|
remove_data: deleteData,
|
||||||
expires: date ? Math.floor(date / 1000) : undefined,
|
expires: date ? Math.floor(date / 1000) : undefined,
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
await getClient().banPerson({
|
||||||
|
auth: $profile.jwt,
|
||||||
|
ban: !banned,
|
||||||
|
person_id: item.id,
|
||||||
|
reason: reason || undefined,
|
||||||
|
remove_data: deleteData,
|
||||||
|
expires: date ? Math.floor(date / 1000) : undefined,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
open = false
|
open = false
|
||||||
|
|
||||||
@@ -94,7 +105,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal bind:open>
|
<Modal bind:open class="max-w-xl w-full">
|
||||||
<h1 slot="title">{banned ? 'Unbanning' : 'Banning'} user</h1>
|
<h1 slot="title">{banned ? 'Unbanning' : 'Banning'} user</h1>
|
||||||
{#if item}
|
{#if item}
|
||||||
<form class="flex flex-col gap-4" on:submit|preventDefault={submit}>
|
<form class="flex flex-col gap-4" on:submit|preventDefault={submit}>
|
||||||
@@ -102,6 +113,11 @@
|
|||||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||||
<span class="font-bold">{item.name}</span>
|
<span class="font-bold">{item.name}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<p>
|
||||||
|
{banned ? 'Unbanning' : 'Banning'} from {community
|
||||||
|
? community.name
|
||||||
|
: 'site'}
|
||||||
|
</p>
|
||||||
<TextArea
|
<TextArea
|
||||||
required
|
required
|
||||||
bind:value={reason}
|
bind:value={reason}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export function remove(item: PostView | CommentView) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ban(banned: boolean, item: Person, community: Community) {
|
export function ban(banned: boolean, item: Person, community?: Community) {
|
||||||
modals.update((m) => ({
|
modals.update((m) => ({
|
||||||
...m,
|
...m,
|
||||||
banning: {
|
banning: {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
Icon,
|
Icon,
|
||||||
NoSymbol,
|
NoSymbol,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
|
ShieldExclamation,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
@@ -27,10 +28,12 @@
|
|||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { ban, isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
let blocking = false
|
let blocking = false
|
||||||
|
let banning = false
|
||||||
|
|
||||||
async function blockUser(block: number) {
|
async function blockUser(block: number) {
|
||||||
if (!$profile?.user || !$profile?.jwt) throw new Error('Unauthenticated')
|
if (!$profile?.user || !$profile?.jwt) throw new Error('Unauthenticated')
|
||||||
@@ -177,7 +180,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mx-auto">
|
<div class="mx-auto">
|
||||||
<StickyCard class="w-full">
|
<StickyCard>
|
||||||
<Avatar
|
<Avatar
|
||||||
width={64}
|
width={64}
|
||||||
url={data.person_view.person.avatar}
|
url={data.person_view.person.avatar}
|
||||||
@@ -211,6 +214,19 @@
|
|||||||
<Icon slot="icon" solid size="16" src={Envelope} />
|
<Icon slot="icon" solid size="16" src={Envelope} />
|
||||||
Message
|
Message
|
||||||
</Button>
|
</Button>
|
||||||
|
{#if isAdmin($profile?.user)}
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
color="danger"
|
||||||
|
loading={banning}
|
||||||
|
disabled={banning}
|
||||||
|
on:click={() =>
|
||||||
|
ban(data.person_view.person.banned, data.person_view.person)}
|
||||||
|
>
|
||||||
|
<Icon slot="icon" mini size="16" src={ShieldExclamation} />
|
||||||
|
{data.person_view.person.banned ? 'Unban' : 'Ban'}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
<Button
|
<Button
|
||||||
size="lg"
|
size="lg"
|
||||||
color="danger"
|
color="danger"
|
||||||
|
|||||||
Reference in new issue
Block a user