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);
invariant(menuItem.type === "button", "passed action must be a button");
if (!menuItem.visible) {
return null;
}
return (
<SidebarLink
onClick={menuItem.onClick}

View File

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

View File

@@ -25,6 +25,7 @@ function Security() {
documentEmbeds: team.documentEmbeds,
guestSignin: team.guestSignin,
defaultUserRole: team.defaultUserRole,
memberCollectionCreate: team.memberCollectionCreate,
});
const showSuccessMessage = React.useMemo(
@@ -102,6 +103,19 @@ function Security() {
onChange={handleChange}
/>
</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
label={t("Default role")}

View File

@@ -17,6 +17,7 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => {
sharing,
guestSignin,
documentEmbeds,
memberCollectionCreate,
collaborativeEditing,
defaultCollectionId,
defaultUserRole,
@@ -41,6 +42,9 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => {
if (avatarUrl !== undefined) {
team.avatarUrl = avatarUrl;
}
if (memberCollectionCreate !== undefined) {
team.memberCollectionCreate = memberCollectionCreate;
}
if (defaultCollectionId !== undefined) {
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
documentEmbeds: boolean;
@Default(true)
@Column
memberCollectionCreate: boolean;
@Default(false)
@Column
collaborativeEditing: boolean;

View File

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

View File

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

View File

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