Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: add verification for reporting operations

shuai520f089f7d2d
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 7bbbe748..473286cd 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -689,6 +689,8 @@ ui:
empty: Cannot be empty.
msg:
empty: Please select a reason.
+ not_a_url: URL format is incorrect.
+ url_not_match: URL origin does not match the current website.
tag_modal:
title: Create new tag
form:
@@ -1838,8 +1840,8 @@ ui:
queued_user: Queued user
filter_label: Type
reputation: reputation
- flag_post_type: Flagged this post as {{ type }}
- flag_user_type: Flagged this user as {{ type }}
+ flag_post_type: Flagged this post as {{ type }}.
+ flag_user_type: Flagged this user as {{ type }}.
edit_post: Edit post
list_post: List post
unlist_post: Unlist post
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index af81d9e6..53f8eef5 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -626,6 +626,7 @@ export interface BaseReviewItem {
export interface FlagReviewItem extends BaseReviewItem {
reason: ReasonItem;
+ reason_content: string;
submitter_user: UserInfoBase;
}
diff --git a/ui/src/hooks/useReportModal/index.tsx b/ui/src/hooks/useReportModal/index.tsx
index 88cd2442..27101c59 100644
--- a/ui/src/hooks/useReportModal/index.tsx
+++ b/ui/src/hooks/useReportModal/index.tsx
@@ -107,6 +107,43 @@ const useReportModal = (callback?: () => void) => {
setShow(false);
};
+ const checkValidate = () => {
+ if (reportType.haveContent && !content.value) {
+ setContent({
+ value: content.value,
+ isInvalid: true,
+ errorMsg: t('remark.empty'),
+ });
+ return false;
+ }
+
+ if (reportType.type === 60) {
+ // a duplicate
+ let url: URL | undefined;
+ try {
+ url = new URL(content.value);
+ } catch {
+ setContent({
+ value: content.value,
+ isInvalid: true,
+ errorMsg: t('msg.not_a_url'),
+ });
+ }
+ if (!url) return false;
+
+ if (url.origin !== window.location.origin) {
+ setContent({
+ value: content.value,
+ isInvalid: true,
+ errorMsg: t('msg.url_not_match'),
+ });
+ return false;
+ }
+ }
+
+ return true;
+ };
+
const handleSubmit = () => {
if (!params) {
return;
@@ -116,14 +153,10 @@ const useReportModal = (callback?: () => void) => {
return;
}
- if (reportType.haveContent && !content.value) {
- setContent({
- value: content.value,
- isInvalid: true,
- errorMsg: t('remark.empty'),
- });
+ if (!checkValidate()) {
return;
}
+
if (params.type === 'question' && params.action === 'close') {
if (params?.source === 'review') {
putFlagReviewAction({
diff --git a/ui/src/index.scss b/ui/src/index.scss
index 8dd77087..b174fbc5 100644
--- a/ui/src/index.scss
+++ b/ui/src/index.scss
@@ -348,3 +348,7 @@ img[src=""] {
.max-width-200 {
max-width: 200px;
}
+
+.alert-exist {
+ color: var(--an-alert-exist-color);
+}
diff --git a/ui/src/pages/Questions/Detail/index.scss b/ui/src/pages/Questions/Detail/index.scss
index 5db9050b..b2327d79 100644
--- a/ui/src/pages/Questions/Detail/index.scss
+++ b/ui/src/pages/Questions/Detail/index.scss
@@ -20,9 +20,6 @@
.answer-item {
border-top: 1px solid var(--an-answer-item-border-top);
}
-.alert-exist {
- color: var(--an-alert-exist-color);
-}
@media screen and (max-width: 768px) {
.questionDetailPage {
diff --git a/ui/src/pages/Questions/Detail/index.tsx b/ui/src/pages/Questions/Detail/index.tsx
index b289ac68..2130ddf7 100644
--- a/ui/src/pages/Questions/Detail/index.tsx
+++ b/ui/src/pages/Questions/Detail/index.tsx
@@ -80,16 +80,21 @@ const Index = () => {
const isModerator = userInfo?.role_id === 3;
const isLogged = Boolean(userInfo?.access_token);
const loggedUserRank = userInfo?.rank;
- const { state: locationState } = useLocation();
+ const location = useLocation();
useEffect(() => {
- if (locationState?.isReview) {
+ if (location.state?.isReview) {
toastStore.getState().show({
msg: t('review', { keyPrefix: 'toast' }),
variant: 'warning',
});
+
+ // remove state isReview
+ const newLocation = { ...location };
+ delete newLocation.state;
+ window.history.replaceState(null, '', newLocation.pathname);
}
- }, [locationState]);
+ }, [location.state]);
const requestAnswers = async () => {
const res = await getAnswers({
diff --git a/ui/src/pages/Review/components/FlagContent/index.tsx b/ui/src/pages/Review/components/FlagContent/index.tsx
index 17c3b7da..43f3bbfc 100644
--- a/ui/src/pages/Review/components/FlagContent/index.tsx
+++ b/ui/src/pages/Review/components/FlagContent/index.tsx
@@ -133,7 +133,7 @@ const Index: FC<IProps> = ({ refreshCount }) => {
<Alert variant="info" className="border-0 rounded-0 mb-0">
<Stack
direction="horizontal"
- gap={0.5}
+ gap={1}
className="align-items-center mb-2">
<BaseUserCard
data={submitter_user}
@@ -153,6 +153,19 @@ const Index: FC<IProps> = ({ refreshCount }) => {
{object_type !== 'user'
? t('flag_post_type', { type: reason?.name })
: t('flag_user_type', { type: reason?.name })}
+
+ {flagItemData?.reason_content &&
+ reason?.content_type &&
+ (reason?.reason_type !== 60 ? (
+ <span> {flagItemData?.reason_content}</span>
+ ) : (
+ <a href={flagItemData.reason_content} className="alert-exist">
+ <strong>
+ {' '}
+ {t('show_exist', { keyPrefix: 'question_detail' })}
+ </strong>
+ </a>
+ ))}
</p>
</Stack>
</Alert>
diff --git a/ui/src/pages/Tags/Info/index.tsx b/ui/src/pages/Tags/Info/index.tsx
index ce09c997..7c620715 100644
--- a/ui/src/pages/Tags/Info/index.tsx
+++ b/ui/src/pages/Tags/Info/index.tsx
@@ -39,7 +39,7 @@ import { loggedUserInfoStore, toastStore } from '@/stores';
const TagIntroduction = () => {
const userInfo = loggedUserInfoStore((state) => state.user);
- const { state: locationState } = useLocation();
+ const location = useLocation();
const isLogged = Boolean(userInfo?.access_token);
const [isEdit, setEditState] = useState(false);
const { tagName } = useParams();
@@ -62,13 +62,18 @@ const TagIntroduction = () => {
title: pageTitle,
});
useEffect(() => {
- if (locationState?.isReview) {
+ if (location.state?.isReview) {
toastStore.getState().show({
msg: t('review', { keyPrefix: 'toast' }),
variant: 'warning',
});
+
+ // remove state isReview
+ const newLocation = { ...location };
+ delete newLocation.state;
+ window.history.replaceState(null, '', newLocation.pathname);
}
- }, [locationState]);
+ }, [location.state]);
useEffect(() => {
const fmt = document.querySelector('.content.fmt') as HTMLElement;