🐛 Allow admin to delete any comment (#715)

This commit is contained in:
Luke Vella 2023-06-28 15:51:00 +01:00 committed by GitHub
parent f65934216c
commit d8b4e86a90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -18,6 +18,8 @@ import * as React from "react";
import { Controller, useForm } from "react-hook-form";
import { Trans } from "@/components/trans";
import { usePermissions } from "@/contexts/permissions";
import { useRole } from "@/contexts/role";
import { usePostHog } from "@/utils/posthog";
import { requiredString } from "../../utils/form-validation";
@ -25,7 +27,7 @@ import NameInput from "../name-input";
import TruncatedLinkify from "../poll/truncated-linkify";
import UserAvatar from "../poll/user-avatar";
import { usePoll } from "../poll-context";
import { isUnclaimed, useUser } from "../user-provider";
import { useUser } from "../user-provider";
interface CommentForm {
authorName: string;
@ -34,7 +36,7 @@ interface CommentForm {
const Discussion: React.FunctionComponent = () => {
const { t } = useTranslation();
const { poll, admin } = usePoll();
const { poll } = usePoll();
const pollId = poll.id;
@ -80,6 +82,8 @@ const Discussion: React.FunctionComponent = () => {
});
const [isWriting, setIsWriting] = React.useState(false);
const role = useRole();
const { isUser } = usePermissions();
if (!comments) {
return null;
@ -95,7 +99,7 @@ const Discussion: React.FunctionComponent = () => {
<div className="space-y-4 p-4">
{comments.map((comment) => {
const canDelete =
admin || session.ownsObject(comment) || isUnclaimed(comment);
role === "admin" || (comment.userId && isUser(comment.userId));
return (
<div className="" key={comment.id}>

View file

@ -19,6 +19,7 @@ export const usePermissions = () => {
const { participants } = useParticipants();
const isClosed = poll.closed === true || poll.event !== null;
return {
isUser: (userId: string) => userId === user.id || userId === context.userId,
canAddNewParticipant: !isClosed,
canEditParticipant: (participantId: string) => {
if (isClosed) {