Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collaborative Workspace Memos #3673

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,9 @@ definitions:
enableLinkPreview:
type: boolean
description: enable_link_preview enables links preview.
enableMembersEdit:
type: boolean
title: enable_members_edit any member can edit workspace memos
apiv1WorkspaceSetting:
type: object
properties:
Expand Down
2 changes: 2 additions & 0 deletions proto/api/v1/workspace_setting_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ message WorkspaceMemoRelatedSetting {
bool enable_double_click_edit = 5;
// enable_link_preview enables links preview.
bool enable_link_preview = 6;
// enable_members_edit any member can edit workspace memos
bool enable_members_edit = 7;
}

message GetWorkspaceSettingRequest {
Expand Down
18 changes: 15 additions & 3 deletions proto/gen/api/v1/workspace_setting_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions proto/gen/store/workspace_setting.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/store/workspace_setting.proto
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ message WorkspaceMemoRelatedSetting {
bool enable_double_click_edit = 5;
// enable_link_preview enables links preview.
bool enable_link_preview = 6;
// enable_members_edit any member can edit workspace memos
bool enable_members_edit = 7;
}
9 changes: 8 additions & 1 deletion server/router/api/v1/memo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get current user")
}
if memo.CreatorID != user.ID {

workspaceMemoRelatedSetting, err := s.Store.GetWorkspaceMemoRelatedSetting(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get workspace memo related setting")
}

membersCanEdit := memo.Visibility == store.Protected && workspaceMemoRelatedSetting.EnableMembersEdit
if !membersCanEdit && memo.CreatorID != user.ID {
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}

Expand Down
2 changes: 2 additions & 0 deletions server/router/api/v1/workspace_setting_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func convertWorkspaceMemoRelatedSettingFromStore(setting *storepb.WorkspaceMemoR
EnableAutoCompact: setting.EnableAutoCompact,
EnableDoubleClickEdit: setting.EnableDoubleClickEdit,
EnableLinkPreview: setting.EnableLinkPreview,
EnableMembersEdit: setting.EnableMembersEdit,
}
}

Expand All @@ -234,5 +235,6 @@ func convertWorkspaceMemoRelatedSettingToStore(setting *v1pb.WorkspaceMemoRelate
EnableAutoCompact: setting.EnableAutoCompact,
EnableDoubleClickEdit: setting.EnableDoubleClickEdit,
EnableLinkPreview: setting.EnableLinkPreview,
EnableMembersEdit: setting.EnableMembersEdit,
}
}
10 changes: 8 additions & 2 deletions web/src/components/MemoContent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import clsx from "clsx";
import { memo, useEffect, useRef, useState } from "react";
import useCurrentUser from "@/hooks/useCurrentUser";
import { useMemoStore } from "@/store/v1";
import { useMemoStore, useWorkspaceSettingStore } from "@/store/v1";
import { Node, NodeType } from "@/types/proto/api/v1/markdown_service";
import { WorkspaceMemoRelatedSetting, WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
import { useTranslate } from "@/utils/i18n";
import Renderer from "./Renderer";
import { RendererContext } from "./types";
Expand Down Expand Up @@ -30,10 +31,15 @@ const MemoContent: React.FC<Props> = (props: Props) => {
const t = useTranslate();
const currentUser = useCurrentUser();
const memoStore = useMemoStore();
const workspaceSettingStore = useWorkspaceSettingStore();
const workspaceMemoRelatedSetting =
workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED).memoRelatedSetting ||
WorkspaceMemoRelatedSetting.fromPartial({});
const memoContentContainerRef = useRef<HTMLDivElement>(null);
const [showCompactMode, setShowCompactMode] = useState<boolean>(false);
const memo = memoName ? memoStore.getMemoByName(memoName) : null;
const allowEdit = !props.readonly && memo && currentUser?.name === memo.creator;
const membersCanEdit = memo?.visibility === "PROTECTED" && workspaceMemoRelatedSetting.enableMembersEdit;
const allowEdit = !props.readonly && memo && (membersCanEdit || memo.creator === currentUser?.name);

// Initial compact mode.
useEffect(() => {
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/MemoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const MemoView: React.FC<Props> = (props: Props) => {
(relation) => relation.type === MemoRelation_Type.COMMENT && relation.relatedMemo === memo.name,
).length;
const relativeTimeFormat = Date.now() - memo.displayTime!.getTime() > 1000 * 60 * 60 * 24 ? "datetime" : "auto";
const readonly = memo.creator !== user?.name;
const membersCanEdit = memo?.visibility === "PROTECTED" && workspaceMemoRelatedSetting.enableMembersEdit;
const readonly = !user || (!membersCanEdit && memo.creator !== user.name);
const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.uid}`);

// Initial related data: creator.
Expand Down
7 changes: 7 additions & 0 deletions web/src/components/Settings/MemoRelatedSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ const MemoRelatedSettings = () => {
onChange={(event) => updatePartialSetting({ enableDoubleClickEdit: event.target.checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.enable-members-edit")}</span>
<Switch
checked={memoRelatedSetting.enableMembersEdit}
onChange={(event) => updatePartialSetting({ enableMembersEdit: event.target.checked })}
/>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span>Content length limit(Byte)</span>
<Input
Expand Down
3 changes: 2 additions & 1 deletion web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
"enable-double-click-to-edit": "Enable double click to edit",
"enable-password-login": "Enable password login",
"enable-password-login-warning": "This will enable password login for all users. Continue only if you want to users to be able to log in using both SSO and password",
"enable-members-edit": "Let members edit workspace's memos",
"max-upload-size": "Maximum upload size (MiB)",
"max-upload-size-hint": "Recommended value is 32 MiB.",
"server-name": "Server Name"
Expand All @@ -311,4 +312,4 @@
"timeline": {
"title": "Timeline"
}
}
}
3 changes: 2 additions & 1 deletion web/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
"enable-double-click-to-edit": "Activer le double-clic pour modifier",
"enable-password-login": "Activer la connexion par mot de passe",
"enable-password-login-warning": "Ceci activera la connexion par mot de passe pour tous les utilisateurs. Ne continuez que si vous souhaitez que les utilisateurs puissent se connecter à la fois par SSO et par mot de passe",
"enable-members-edit": "Permet aux membres de modifier les memos en Accès Membre",
"max-upload-size": "Taille maximale du téléversement (MiB)",
"max-upload-size-hint": "La valeur recommandée est 32 MiB.",
"server-name": "Nom du serveur"
Expand All @@ -311,4 +312,4 @@
"timeline": {
"title": "Timeline"
}
}
}