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