mirror of
https://github.com/outline/outline.git
synced 2026-12-01 01:14:11 +03:00
feat: Disable commenting per collection (#9295)
* Address PR feedback: Move commenting logic to Collection model - Update openDocumentComments action to use collection.canCreateComment - Update AuthenticatedLayout to check collection-level commenting setting - Update DocumentMeta to use collection commenting preference - Add commenting field to CollectionForm with proper UI - Maintain backward compatibility with team-level preferences * Applied automatic fixes * Disable comment creation UI when collection commenting is disabled - Update Editor component to use collection-level commenting setting - Pass onCreateCommentMark as undefined when commenting is disabled - This removes the shortcut and toolbar icon for comment creation - Maintains backward compatibility with team-level preferences * Fix TypeScript error in Editor component - Fix props destructuring to avoid variable shadowing - Ensure all required props are properly destructured - Maintain correct property order from original implementation * Fix TypeScript error: add missing activeCollectionId parameter - Add activeCollectionId to import document action perform function - This parameter was being used but not declared in the function signature - Fixes TS2304 error: Cannot find name 'activeCollectionId' * fix form * docs --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
This commit is contained in:
1 parent
5b7a5d751c
commit
c02a33a74c
12 files changed
+103
-12
No files matched your search
@@ -750,7 +750,7 @@ export const importDocument = createAction({
|
||||
|
||||
return false;
|
||||
},
|
||||
perform: ({ activeCollectionId, activeDocumentId, stores }) => {
|
||||
perform: ({ activeDocumentId, activeCollectionId, stores }) => {
|
||||
const { documents } = stores;
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
@@ -1081,12 +1081,17 @@ export const openDocumentComments = createAction({
|
||||
analyticsName: "Open comments",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <CommentIcon />,
|
||||
visible: ({ activeDocumentId, stores }) => {
|
||||
visible: ({ activeCollectionId, activeDocumentId, stores }) => {
|
||||
const can = stores.policies.abilities(activeDocumentId ?? "");
|
||||
const collection = activeCollectionId
|
||||
? stores.collections.get(activeCollectionId)
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
!!activeDocumentId &&
|
||||
can.comment &&
|
||||
!!stores.auth.team?.getPreference(TeamPreference.Commenting)
|
||||
(collection?.canCreateComment ??
|
||||
!!stores.auth.team?.getPreference(TeamPreference.Commenting))
|
||||
);
|
||||
},
|
||||
perform: ({ activeDocumentId, stores }) => {
|
||||
|
||||
@@ -49,7 +49,7 @@ type Props = {
|
||||
};
|
||||
|
||||
const AuthenticatedLayout: React.FC = ({ children }: Props) => {
|
||||
const { ui, auth } = useStores();
|
||||
const { ui, auth, collections } = useStores();
|
||||
const location = useLocation();
|
||||
const layoutRef = React.useRef<HTMLDivElement>(null);
|
||||
const can = usePolicy(ui.activeDocumentId);
|
||||
@@ -108,7 +108,9 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => {
|
||||
can.comment &&
|
||||
ui.activeDocumentId &&
|
||||
ui.commentsExpanded &&
|
||||
team.getPreference(TeamPreference.Commenting);
|
||||
(ui.activeCollectionId
|
||||
? collections.get(ui.activeCollectionId)?.canCreateComment
|
||||
: !!team.getPreference(TeamPreference.Commenting));
|
||||
|
||||
const sidebarRight = (
|
||||
<AnimatePresence
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Trans, useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import Icon from "@shared/components/Icon";
|
||||
import { randomElement } from "@shared/random";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import { CollectionPermission, TeamPreference } from "@shared/types";
|
||||
import { IconLibrary } from "@shared/utils/IconLibrary";
|
||||
import { colorPalette } from "@shared/utils/collections";
|
||||
import { CollectionValidation } from "@shared/validations";
|
||||
@@ -31,6 +31,7 @@ export interface FormData {
|
||||
color: string | null;
|
||||
sharing: boolean;
|
||||
permission: CollectionPermission | undefined;
|
||||
commenting?: boolean | null;
|
||||
}
|
||||
|
||||
const useIconColor = (collection?: Collection) => {
|
||||
@@ -83,6 +84,7 @@ export const CollectionForm = observer(function CollectionForm_({
|
||||
icon: collection?.icon,
|
||||
sharing: collection?.sharing ?? true,
|
||||
permission: collection?.permission,
|
||||
commenting: collection?.commenting ?? true,
|
||||
color: iconColor,
|
||||
},
|
||||
});
|
||||
@@ -190,6 +192,15 @@ export const CollectionForm = observer(function CollectionForm_({
|
||||
/>
|
||||
)}
|
||||
|
||||
{team.getPreference(TeamPreference.Commenting) && (
|
||||
<Switch
|
||||
id="commenting"
|
||||
label={t("Commenting")}
|
||||
note={t("Allow commenting on documents within this collection.")}
|
||||
{...register("commenting")}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Flex justify="flex-end">
|
||||
<Button
|
||||
type="submit"
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
type NavigationNode,
|
||||
NavigationNodeType,
|
||||
type ProsemirrorData,
|
||||
TeamPreference,
|
||||
} from "@shared/types";
|
||||
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { sortNavigationNodes } from "@shared/utils/collections";
|
||||
@@ -68,6 +69,13 @@ export default class Collection extends ParanoidModel {
|
||||
direction: "asc" | "desc";
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether commenting is enabled for the collection.
|
||||
*/
|
||||
@Field
|
||||
@observable
|
||||
commenting?: boolean | null;
|
||||
|
||||
/** The child documents of the collection. */
|
||||
@observable
|
||||
documents?: NavigationNode[];
|
||||
@@ -121,6 +129,21 @@ export default class Collection extends ParanoidModel {
|
||||
return !this.permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether comments should be enabled for this collection,
|
||||
*
|
||||
* @returns boolean
|
||||
*/
|
||||
@computed
|
||||
get canCreateComment(): boolean {
|
||||
const teamCommentingEnabled =
|
||||
!!this.store.rootStore.auth.team?.getPreference(
|
||||
TeamPreference.Commenting
|
||||
);
|
||||
|
||||
return teamCommentingEnabled && this.commenting !== false;
|
||||
}
|
||||
|
||||
/** Returns whether the collection description is not empty. */
|
||||
@computed
|
||||
get hasDescription(): boolean {
|
||||
|
||||
@@ -25,7 +25,7 @@ type Props = {
|
||||
};
|
||||
|
||||
function TitleDocumentMeta({ to, document, revision, ...rest }: Props) {
|
||||
const { views, comments, ui } = useStores();
|
||||
const { collections, views, comments, ui } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const match = useRouteMatch();
|
||||
const sidebarContext = useLocationSidebarContext();
|
||||
@@ -41,9 +41,16 @@ function TitleDocumentMeta({ to, document, revision, ...rest }: Props) {
|
||||
const insightsPath = documentInsightsPath(document);
|
||||
const commentsCount = comments.unresolvedCommentsInDocumentCount(document.id);
|
||||
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const collectionCommentingEnabled =
|
||||
collection?.canCreateComment ??
|
||||
!!team.getPreference(TeamPreference.Commenting);
|
||||
|
||||
return (
|
||||
<Meta document={document} revision={revision} to={to} replace {...rest}>
|
||||
{team.getPreference(TeamPreference.Commenting) && can.comment && (
|
||||
{collectionCommentingEnabled && can.comment && (
|
||||
<>
|
||||
•
|
||||
<CommentLink
|
||||
|
||||
@@ -57,7 +57,7 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
const { t } = useTranslation();
|
||||
const match = useRouteMatch();
|
||||
const focusedComment = useFocusedComment();
|
||||
const { ui, comments } = useStores();
|
||||
const { ui, comments, collections } = useStores();
|
||||
const user = useCurrentUser({ rejectOnEmpty: false });
|
||||
const team = useCurrentTeam({ rejectOnEmpty: false });
|
||||
const history = useHistory();
|
||||
@@ -75,6 +75,15 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
...rest
|
||||
} = props;
|
||||
const can = usePolicy(document);
|
||||
|
||||
// Check collection-level commenting setting
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const collectionCommentingEnabled =
|
||||
collection?.canCreateComment ??
|
||||
!!team?.getPreference(TeamPreference.Commenting);
|
||||
|
||||
const iconColor = document.color ?? (last(colorPalette) as string);
|
||||
const childRef = React.useRef<HTMLDivElement>(null);
|
||||
const focusAtStart = React.useCallback(() => {
|
||||
@@ -244,12 +253,12 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
focusedCommentId={focusedComment?.id}
|
||||
onClickCommentMark={handleClickComment}
|
||||
onCreateCommentMark={
|
||||
team?.getPreference(TeamPreference.Commenting) && can.comment
|
||||
collectionCommentingEnabled && can.comment
|
||||
? handleDraftComment
|
||||
: undefined
|
||||
}
|
||||
onDeleteCommentMark={
|
||||
team?.getPreference(TeamPreference.Commenting) && can.comment
|
||||
collectionCommentingEnabled && can.comment
|
||||
? handleRemoveComment
|
||||
: undefined
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up (queryInterface, Sequelize) {
|
||||
await queryInterface.addColumn('collections', 'commenting', {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
});
|
||||
},
|
||||
|
||||
async down (queryInterface, Sequelize) {
|
||||
await queryInterface.removeColumn('collections', 'commenting');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -296,6 +296,12 @@ class Collection extends ParanoidModel<
|
||||
@Column
|
||||
archivedAt: Date | null;
|
||||
|
||||
/** Allows the configuration of commenting per collection. */
|
||||
@AllowNull(true)
|
||||
@Default(null)
|
||||
@Column(DataType.BOOLEAN)
|
||||
commenting: boolean | null;
|
||||
|
||||
// getters
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ export default async function presentCollection(
|
||||
index: collection.index,
|
||||
color: collection.color,
|
||||
permission: collection.permission,
|
||||
commenting: collection.commenting,
|
||||
sharing: collection.sharing,
|
||||
createdAt: collection.createdAt,
|
||||
updatedAt: collection.updatedAt,
|
||||
|
||||
@@ -63,6 +63,7 @@ router.post(
|
||||
icon,
|
||||
sort,
|
||||
index,
|
||||
commenting,
|
||||
} = ctx.input.body;
|
||||
|
||||
const { user } = ctx.state.auth;
|
||||
@@ -80,6 +81,7 @@ router.post(
|
||||
sharing,
|
||||
sort,
|
||||
index,
|
||||
commenting,
|
||||
});
|
||||
|
||||
if (data) {
|
||||
@@ -580,6 +582,7 @@ router.post(
|
||||
color,
|
||||
sort,
|
||||
sharing,
|
||||
commenting,
|
||||
} = ctx.input.body;
|
||||
|
||||
const { user } = ctx.state.auth;
|
||||
@@ -650,6 +653,10 @@ router.post(
|
||||
collection.sort = sort;
|
||||
}
|
||||
|
||||
if (commenting !== undefined) {
|
||||
collection.commenting = commenting;
|
||||
}
|
||||
|
||||
await collection.save({ transaction });
|
||||
await Event.createFromContext(ctx, {
|
||||
name: "collections.update",
|
||||
|
||||
@@ -43,6 +43,7 @@ export const CollectionsCreateSchema = BaseSchema.extend({
|
||||
message: `Must be ${ValidateIndex.maxLength} or fewer characters long`,
|
||||
})
|
||||
.optional(),
|
||||
commenting: z.boolean().nullish(),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -170,6 +171,7 @@ export const CollectionsUpdateSchema = BaseSchema.extend({
|
||||
})
|
||||
.optional(),
|
||||
sharing: z.boolean().optional(),
|
||||
commenting: z.boolean().nullish(),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -163,6 +163,8 @@
|
||||
"The default access for workspace members, you can share with more users or groups later.": "The default access for workspace members, you can share with more users or groups later.",
|
||||
"Public document sharing": "Public document sharing",
|
||||
"Allow documents within this collection to be shared publicly on the internet.": "Allow documents within this collection to be shared publicly on the internet.",
|
||||
"Commenting": "Commenting",
|
||||
"Allow commenting on documents within this collection.": "Allow commenting on documents within this collection.",
|
||||
"Saving": "Saving",
|
||||
"Save": "Save",
|
||||
"Creating": "Creating",
|
||||
@@ -1025,7 +1027,6 @@
|
||||
"Manage optional and beta features. Changing these settings will affect the experience for all members of the workspace.": "Manage optional and beta features. Changing these settings will affect the experience for all members of the workspace.",
|
||||
"Separate editing": "Separate editing",
|
||||
"When enabled documents have a separate editing mode by default instead of being always editable. This setting can be overridden by user preferences.": "When enabled documents have a separate editing mode by default instead of being always editable. This setting can be overridden by user preferences.",
|
||||
"Commenting": "Commenting",
|
||||
"When enabled team members can add comments to documents.": "When enabled team members can add comments to documents.",
|
||||
"Create a group": "Create a group",
|
||||
"Could not load groups": "Could not load groups",
|
||||
|
||||
Reference in new issue
Block a user