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
shuaie7fb6192910b
diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex bb038dfd..2d703838 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -680,6 +680,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 tagform:@@ -1829,8 +1831,8 @@ ui:queued_user: Queued userfilter_label: Typereputation: 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 postlist_post: List postunlist_post: Unlist postdiff --git a/ui/src/common/interface.ts b/ui/src/common/interface.tsindex 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.tsxindex 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.scssindex 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.scssindex 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.tsxindex 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.tsxindex 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"><Stackdirection="horizontal"- gap={0.5}+ gap={1}className="align-items-center mb-2"><BaseUserCarddata={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.tsxindex 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;