Skip to content

Commit

Permalink
feat: Allow disabling collection creation for members (#3270)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Mar 24, 2022
1 parent 53d96d2 commit 6af9246
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/components/Sidebar/components/SidebarAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions app/models/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class Team extends BaseModel {
@observable
defaultCollectionId: string | null;

@Field
@observable
memberCollectionCreate: boolean;

@Field
@observable
guestSignin: boolean;
Expand Down
14 changes: 14 additions & 0 deletions app/scenes/Settings/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function Security() {
documentEmbeds: team.documentEmbeds,
guestSignin: team.guestSignin,
defaultUserRole: team.defaultUserRole,
memberCollectionCreate: team.memberCollectionCreate,
});

const showSuccessMessage = React.useMemo(
Expand Down Expand Up @@ -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")}
Expand Down
4 changes: 4 additions & 0 deletions server/commands/teamUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => {
sharing,
guestSignin,
documentEmbeds,
memberCollectionCreate,
collaborativeEditing,
defaultCollectionId,
defaultUserRole,
Expand All @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions server/migrations/20220319060408-collection-create-permission.js
Original file line number Diff line number Diff line change
@@ -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");
}
};
4 changes: 4 additions & 0 deletions server/models/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class Team extends ParanoidModel {
@Column
documentEmbeds: boolean;

@Default(true)
@Column
memberCollectionCreate: boolean;

@Default(false)
@Column
collaborativeEditing: boolean;
Expand Down
5 changes: 4 additions & 1 deletion server/policies/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions server/presenters/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions server/routes/api/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ router.post("team.update", auth(), async (ctx) => {
sharing,
guestSignin,
documentEmbeds,
memberCollectionCreate,
collaborativeEditing,
defaultCollectionId,
defaultUserRole,
Expand All @@ -37,6 +38,7 @@ router.post("team.update", auth(), async (ctx) => {
sharing,
guestSignin,
documentEmbeds,
memberCollectionCreate,
collaborativeEditing,
defaultCollectionId,
defaultUserRole,
Expand Down
2 changes: 2 additions & 0 deletions shared/i18n/locales/en_US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 6af9246

Please sign in to comment.