feat: Option for separate edit mode (#4203)
* stash * wip * cleanup * Remove collaborativeEditing toggle, it will always be on in next release. Flip separateEdit -> seamlessEdit * Clarify language, hide toggle when collaborative editing is disabled * Flip boolean to match, easier to reason about
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { has } from "lodash";
|
||||
import { Transaction } from "sequelize";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
import { sequelize } from "@server/database/sequelize";
|
||||
import env from "@server/env";
|
||||
import { Event, Team, TeamDomain, User } from "@server/models";
|
||||
@@ -24,6 +26,7 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => {
|
||||
defaultUserRole,
|
||||
inviteRequired,
|
||||
allowedDomains,
|
||||
preferences,
|
||||
} = params;
|
||||
|
||||
const transaction: Transaction = await sequelize.transaction();
|
||||
@@ -101,6 +104,13 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => {
|
||||
|
||||
team.allowedDomains = newAllowedDomains;
|
||||
}
|
||||
if (preferences) {
|
||||
for (const value of Object.values(TeamPreference)) {
|
||||
if (has(preferences, value)) {
|
||||
team.setPreference(value, Boolean(preferences[value]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const changes = team.changed();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
IsUrl,
|
||||
AllowNull,
|
||||
} from "sequelize-typescript";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import { CollectionPermission, TeamPreference } from "@shared/types";
|
||||
import { getBaseDomain, RESERVED_SUBDOMAINS } from "@shared/utils/domains";
|
||||
import env from "@server/env";
|
||||
import { generateAvatarUrl } from "@server/utils/avatars";
|
||||
@@ -169,6 +169,35 @@ class Team extends ParanoidModel {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preferences that decide behavior for the team.
|
||||
*
|
||||
* @param preference The team preference to set
|
||||
* @param value Sets the preference value
|
||||
* @returns The current team preferences
|
||||
*/
|
||||
public setPreference = (preference: TeamPreference, value: boolean) => {
|
||||
if (!this.preferences) {
|
||||
this.preferences = {};
|
||||
}
|
||||
this.preferences[preference] = value;
|
||||
this.changed("preferences", true);
|
||||
|
||||
return this.preferences;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the passed preference value
|
||||
*
|
||||
* @param preference The user preference to retrieve
|
||||
* @returns The preference value if set, else undefined
|
||||
*/
|
||||
public getPreference = (preference: TeamPreference) => {
|
||||
return !!this.preferences && this.preferences[preference]
|
||||
? this.preferences[preference]
|
||||
: undefined;
|
||||
};
|
||||
|
||||
provisionFirstCollection = async (userId: string) => {
|
||||
await this.sequelize!.transaction(async (transaction) => {
|
||||
const collection = await Collection.create(
|
||||
|
||||
@@ -22,6 +22,7 @@ router.post("team.update", auth(), async (ctx) => {
|
||||
defaultUserRole,
|
||||
inviteRequired,
|
||||
allowedDomains,
|
||||
preferences,
|
||||
} = ctx.body;
|
||||
|
||||
const { user } = ctx.state;
|
||||
@@ -48,6 +49,7 @@ router.post("team.update", auth(), async (ctx) => {
|
||||
defaultUserRole,
|
||||
inviteRequired,
|
||||
allowedDomains,
|
||||
preferences,
|
||||
},
|
||||
user,
|
||||
team,
|
||||
|
||||
@@ -67,6 +67,10 @@ export default function init(app: Koa = new Koa()): Koa {
|
||||
poll: 1000,
|
||||
ignored: ["node_modules", "flow-typed", "server", "build", "__mocks__"],
|
||||
},
|
||||
// Uncomment to test service worker
|
||||
// headers: {
|
||||
// "Service-Worker-Allowed": "/",
|
||||
// },
|
||||
// public path to bind the middleware to
|
||||
// use the same as in webpack
|
||||
publicPath: config.output.publicPath,
|
||||
|
||||
Reference in New Issue
Block a user