feat: Allow disabling collection creation for members (#3270)

This commit is contained in:
Tom Moor
2022-03-24 16:02:50 -07:00
committed by GitHub
parent 53d96d2cb3
commit 6af9246f26
10 changed files with 54 additions and 1 deletions

View File

@@ -21,6 +21,10 @@ function SidebarAction({ action, ...rest }: Props) {
const menuItem = actionToMenuItem(action, context); const menuItem = actionToMenuItem(action, context);
invariant(menuItem.type === "button", "passed action must be a button"); invariant(menuItem.type === "button", "passed action must be a button");
if (!menuItem.visible) {
return null;
}
return ( return (
<SidebarLink <SidebarLink
onClick={menuItem.onClick} onClick={menuItem.onClick}

View File

@@ -31,6 +31,10 @@ class Team extends BaseModel {
@observable @observable
defaultCollectionId: string | null; defaultCollectionId: string | null;
@Field
@observable
memberCollectionCreate: boolean;
@Field @Field
@observable @observable
guestSignin: boolean; guestSignin: boolean;

View File

@@ -25,6 +25,7 @@ function Security() {
documentEmbeds: team.documentEmbeds, documentEmbeds: team.documentEmbeds,
guestSignin: team.guestSignin, guestSignin: team.guestSignin,
defaultUserRole: team.defaultUserRole, defaultUserRole: team.defaultUserRole,
memberCollectionCreate: team.memberCollectionCreate,
}); });
const showSuccessMessage = React.useMemo( const showSuccessMessage = React.useMemo(
@@ -102,6 +103,19 @@ function Security() {
onChange={handleChange} onChange={handleChange}
/> />
</SettingRow> </SettingRow>
<SettingRow
label={t("Collection creation")}
name="memberCollectionCreate"
description={t(
"Allow members to create new collections within the knowledge base"
)}
>
<Switch
id="memberCollectionCreate"
checked={data.memberCollectionCreate}
onChange={handleChange}
/>
</SettingRow>
<SettingRow <SettingRow
label={t("Default role")} label={t("Default role")}

View File

@@ -17,6 +17,7 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => {
sharing, sharing,
guestSignin, guestSignin,
documentEmbeds, documentEmbeds,
memberCollectionCreate,
collaborativeEditing, collaborativeEditing,
defaultCollectionId, defaultCollectionId,
defaultUserRole, defaultUserRole,
@@ -41,6 +42,9 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => {
if (avatarUrl !== undefined) { if (avatarUrl !== undefined) {
team.avatarUrl = avatarUrl; team.avatarUrl = avatarUrl;
} }
if (memberCollectionCreate !== undefined) {
team.memberCollectionCreate = memberCollectionCreate;
}
if (defaultCollectionId !== undefined) { if (defaultCollectionId !== undefined) {
team.defaultCollectionId = defaultCollectionId; team.defaultCollectionId = defaultCollectionId;
} }

View File

@@ -0,0 +1,15 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn("teams", "memberCollectionCreate", {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: false,
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn("teams", "memberCollectionCreate");
}
};

View File

@@ -89,6 +89,10 @@ class Team extends ParanoidModel {
@Column @Column
documentEmbeds: boolean; documentEmbeds: boolean;
@Default(true)
@Column
memberCollectionCreate: boolean;
@Default(false) @Default(false)
@Column @Column
collaborativeEditing: boolean; collaborativeEditing: boolean;

View File

@@ -8,7 +8,10 @@ allow(User, "createCollection", Team, (user, team) => {
if (!team || user.isViewer || user.teamId !== team.id) { if (!team || user.isViewer || user.teamId !== team.id) {
return false; return false;
} }
return true; if (user.isAdmin || team.memberCollectionCreate) {
return true;
}
return false;
}); });
allow(User, "importCollection", Team, (actor, team) => { allow(User, "importCollection", Team, (actor, team) => {

View File

@@ -6,6 +6,7 @@ export default function present(team: Team) {
name: team.name, name: team.name,
avatarUrl: team.logoUrl, avatarUrl: team.logoUrl,
sharing: team.sharing, sharing: team.sharing,
memberCollectionCreate: team.memberCollectionCreate,
collaborativeEditing: team.collaborativeEditing, collaborativeEditing: team.collaborativeEditing,
defaultCollectionId: team.defaultCollectionId, defaultCollectionId: team.defaultCollectionId,
documentEmbeds: team.documentEmbeds, documentEmbeds: team.documentEmbeds,

View File

@@ -16,6 +16,7 @@ router.post("team.update", auth(), async (ctx) => {
sharing, sharing,
guestSignin, guestSignin,
documentEmbeds, documentEmbeds,
memberCollectionCreate,
collaborativeEditing, collaborativeEditing,
defaultCollectionId, defaultCollectionId,
defaultUserRole, defaultUserRole,
@@ -37,6 +38,7 @@ router.post("team.update", auth(), async (ctx) => {
sharing, sharing,
guestSignin, guestSignin,
documentEmbeds, documentEmbeds,
memberCollectionCreate,
collaborativeEditing, collaborativeEditing,
defaultCollectionId, defaultCollectionId,
defaultUserRole, defaultUserRole,

View File

@@ -616,6 +616,8 @@
"When enabled, documents can be shared publicly on the internet by any team member": "When enabled, documents can be shared publicly on the internet by any team member", "When enabled, documents can be shared publicly on the internet by any team member": "When enabled, documents can be shared publicly on the internet by any team member",
"Rich service embeds": "Rich service embeds", "Rich service embeds": "Rich service embeds",
"Links to supported services are shown as rich embeds within your documents": "Links to supported services are shown as rich embeds within your documents", "Links to supported services are shown as rich embeds within your documents": "Links to supported services are shown as rich embeds within your documents",
"Collection creation": "Collection creation",
"Allow members to create new collections within the knowledge base": "Allow members to create new collections within the knowledge base",
"Default role": "Default role", "Default role": "Default role",
"The default user role for new accounts. Changing this setting does not affect existing user accounts.": "The default user role for new accounts. Changing this setting does not affect existing user accounts.", "The default user role for new accounts. Changing this setting does not affect existing user accounts.": "The default user role for new accounts. Changing this setting does not affect existing user accounts.",
"Sharing is currently disabled.": "Sharing is currently disabled.", "Sharing is currently disabled.": "Sharing is currently disabled.",