ソースを参照

Merge pull request #10557 from growilabs/imprv/174459-only-display-public-pages-in-activity-log

imprv: Only display public page names in Activity Log
Yuki Takei 4 ヶ月 前
コミット
2e3f65b10c

BIN
apps/app/.swc/plugins/v7_linux_x86_64_0.106.16/85face98bcf0ea217842cb93383692497c6ae8a7da71a76bf3d93a3a42b4228c


+ 46 - 3
apps/app/src/client/components/RecentActivity/ActivityListItem.tsx

@@ -41,6 +41,14 @@ type ActivityListItemProps = {
   activity: ActivityHasTargetPage,
 }
 
+type AllowPageDisplayPayload = {
+  grant: number | undefined,
+  status: string,
+  wip: boolean,
+  deletedAt?: Date,
+  path: string,
+}
+
 const translateAction = (action: SupportedActivityActionType): string => {
   return ActivityActionTranslationMap[action] || 'unknown_action';
 };
@@ -58,6 +66,27 @@ const calculateTimePassed = (date: Date, locale: Locale): string => {
   return timePassed;
 };
 
+const pageAllowedForDisplay = (allowDisplayPayload: AllowPageDisplayPayload): boolean => {
+  const {
+    grant, status, wip, deletedAt,
+  } = allowDisplayPayload;
+  if (grant !== 1) return false;
+
+  if (status !== 'published') return false;
+
+  if (wip) return false;
+
+  if (deletedAt) return false;
+
+  return true;
+};
+
+const setPath = (path: string, allowed: boolean): string => {
+  if (allowed) return path;
+
+  return '';
+};
+
 
 export const ActivityListItem = ({ props }: { props: ActivityListItemProps }): JSX.Element => {
   const { t, i18n } = useTranslation();
@@ -65,7 +94,21 @@ export const ActivityListItem = ({ props }: { props: ActivityListItemProps }): J
   const dateFnsLocale = getLocale(currentLangCode);
 
   const { activity } = props;
-  const targetPagePath = activity.target.path;
+
+  const {
+    path, grant, status, wip, deletedAt,
+  } = activity.target;
+
+
+  const allowDisplayPayload: AllowPageDisplayPayload = {
+    grant,
+    status,
+    wip,
+    deletedAt,
+    path,
+  };
+
+  const isPageAllowed = pageAllowedForDisplay(allowDisplayPayload);
 
   const action = activity.action as SupportedActivityActionType;
   const keyToTranslate = translateAction(action);
@@ -81,11 +124,11 @@ export const ActivityListItem = ({ props }: { props: ActivityListItemProps }): J
         <div className="flex-grow-1 ms-2">
           <div className="activity-path-line mb-0">
             <a
-              href={targetPagePath}
+              href={setPath(path, isPageAllowed)}
               className="activity-target-link fw-bold text-wrap d-block"
             >
               <span>
-                {targetPagePath}
+                {setPath(path, isPageAllowed)}
               </span>
             </a>
           </div>

+ 5 - 0
apps/app/src/interfaces/activity.ts

@@ -694,9 +694,14 @@ export type ActivityHasTargetPage = IActivityHasId & {
   target: IPopulatedPageTarget;
 };
 
+import type { PageGrant } from '@growi/core';
 export interface IPopulatedPageTarget {
   _id: string;
   path: string;
+  status: string;
+  grant?: PageGrant;
+  wip: boolean;
+  deletedAt: Date;
 }
 
 export interface PopulatedUserActivitiesResult {