Assorted cleanup, minor bug fixes, styling fixes, eslint rules (#5165
* fix: Logic error in toast fix: Remove useless component * fix: Logout not clearing all stores * Add icons to notification settings * Add eslint rule to enforce spaced comment * Add eslint rule for arrow-body-style * Add eslint rule to enforce self-closing components * Add menu to api key settings Fix: Deleting webhook subscription does not remove from UI Split webhook subscriptions into active and inactive Styling updates
This commit is contained in:
@@ -123,14 +123,13 @@ class AuthenticationProvider extends Model {
|
||||
}
|
||||
};
|
||||
|
||||
enable = (options?: SaveOptions<AuthenticationProvider>) => {
|
||||
return this.update(
|
||||
enable = (options?: SaveOptions<AuthenticationProvider>) =>
|
||||
this.update(
|
||||
{
|
||||
enabled: true,
|
||||
},
|
||||
options
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default AuthenticationProvider;
|
||||
|
||||
@@ -477,12 +477,10 @@ class Collection extends ParanoidModel {
|
||||
id: string
|
||||
) => {
|
||||
children = await Promise.all(
|
||||
children.map(async (childDocument) => {
|
||||
return {
|
||||
...childDocument,
|
||||
children: await removeFromChildren(childDocument.children, id),
|
||||
};
|
||||
})
|
||||
children.map(async (childDocument) => ({
|
||||
...childDocument,
|
||||
children: await removeFromChildren(childDocument.children, id),
|
||||
}))
|
||||
);
|
||||
const match = find(children, {
|
||||
id,
|
||||
@@ -562,8 +560,8 @@ class Collection extends ParanoidModel {
|
||||
|
||||
const { id } = updatedDocument;
|
||||
|
||||
const updateChildren = (documents: NavigationNode[]) => {
|
||||
return Promise.all(
|
||||
const updateChildren = (documents: NavigationNode[]) =>
|
||||
Promise.all(
|
||||
documents.map(async (document) => {
|
||||
if (document.id === id) {
|
||||
document = {
|
||||
@@ -577,7 +575,6 @@ class Collection extends ParanoidModel {
|
||||
return document;
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
this.documentStructure = await updateChildren(this.documentStructure);
|
||||
// Sequelize doesn't seem to set the value with splice on JSONB field
|
||||
@@ -619,8 +616,8 @@ class Collection extends ParanoidModel {
|
||||
);
|
||||
} else {
|
||||
// Recursively place document
|
||||
const placeDocument = (documentList: NavigationNode[]) => {
|
||||
return documentList.map((childDocument) => {
|
||||
const placeDocument = (documentList: NavigationNode[]) =>
|
||||
documentList.map((childDocument) => {
|
||||
if (document.parentDocumentId === childDocument.id) {
|
||||
childDocument.children.splice(
|
||||
index !== undefined ? index : childDocument.children.length,
|
||||
@@ -633,7 +630,6 @@ class Collection extends ParanoidModel {
|
||||
|
||||
return childDocument;
|
||||
});
|
||||
};
|
||||
|
||||
this.documentStructure = placeDocument(this.documentStructure);
|
||||
}
|
||||
|
||||
@@ -668,8 +668,8 @@ class Document extends ParanoidModel {
|
||||
};
|
||||
|
||||
// Delete a document, archived or otherwise.
|
||||
delete = (userId: string) => {
|
||||
return this.sequelize.transaction(async (transaction: Transaction) => {
|
||||
delete = (userId: string) =>
|
||||
this.sequelize.transaction(async (transaction: Transaction) => {
|
||||
if (!this.archivedAt && !this.template && this.collectionId) {
|
||||
// delete any children and remove from the document structure
|
||||
const collection = await Collection.findByPk(this.collectionId, {
|
||||
@@ -699,11 +699,8 @@ class Document extends ParanoidModel {
|
||||
);
|
||||
return this;
|
||||
});
|
||||
};
|
||||
|
||||
getTimestamp = () => {
|
||||
return Math.round(new Date(this.updatedAt).getTime() / 1000);
|
||||
};
|
||||
getTimestamp = () => Math.round(new Date(this.updatedAt).getTime() / 1000);
|
||||
|
||||
getSummary = () => {
|
||||
const plainText = DocumentHelper.toPlainText(this);
|
||||
|
||||
@@ -34,39 +34,31 @@ import Fix from "./decorators/Fix";
|
||||
],
|
||||
}))
|
||||
@Scopes(() => ({
|
||||
withCollectionPermissions: (userId: string) => {
|
||||
return {
|
||||
include: [
|
||||
{
|
||||
model: Document.scope("withDrafts"),
|
||||
paranoid: true,
|
||||
as: "document",
|
||||
include: [
|
||||
{
|
||||
attributes: [
|
||||
"id",
|
||||
"permission",
|
||||
"sharing",
|
||||
"teamId",
|
||||
"deletedAt",
|
||||
],
|
||||
model: Collection.scope({
|
||||
method: ["withMembership", userId],
|
||||
}),
|
||||
as: "collection",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
association: "user",
|
||||
paranoid: false,
|
||||
},
|
||||
{
|
||||
association: "team",
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
withCollectionPermissions: (userId: string) => ({
|
||||
include: [
|
||||
{
|
||||
model: Document.scope("withDrafts"),
|
||||
paranoid: true,
|
||||
as: "document",
|
||||
include: [
|
||||
{
|
||||
attributes: ["id", "permission", "sharing", "teamId", "deletedAt"],
|
||||
model: Collection.scope({
|
||||
method: ["withMembership", userId],
|
||||
}),
|
||||
as: "collection",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
association: "user",
|
||||
paranoid: false,
|
||||
},
|
||||
{
|
||||
association: "team",
|
||||
},
|
||||
],
|
||||
}),
|
||||
}))
|
||||
@Table({ tableName: "shares", modelName: "share" })
|
||||
@Fix
|
||||
|
||||
@@ -202,9 +202,8 @@ class Team extends ParanoidModel {
|
||||
* @param fallback An optional fallback value, defaults to false.
|
||||
* @returns The preference value if set, else undefined
|
||||
*/
|
||||
public getPreference = (preference: TeamPreference, fallback = false) => {
|
||||
return this.preferences?.[preference] ?? fallback;
|
||||
};
|
||||
public getPreference = (preference: TeamPreference, fallback = false) =>
|
||||
this.preferences?.[preference] ?? fallback;
|
||||
|
||||
provisionFirstCollection = async (userId: string) => {
|
||||
await this.sequelize!.transaction(async (transaction) => {
|
||||
|
||||
@@ -286,13 +286,8 @@ class User extends ParanoidModel {
|
||||
* @param type The type of notification event
|
||||
* @returns The current preference
|
||||
*/
|
||||
public subscribedToEventType = (type: NotificationEventType) => {
|
||||
return (
|
||||
this.notificationSettings[type] ??
|
||||
NotificationEventDefaults[type] ??
|
||||
false
|
||||
);
|
||||
};
|
||||
public subscribedToEventType = (type: NotificationEventType) =>
|
||||
this.notificationSettings[type] ?? NotificationEventDefaults[type] ?? false;
|
||||
|
||||
/**
|
||||
* User flags are for storing information on a user record that is not visible
|
||||
@@ -321,9 +316,7 @@ class User extends ParanoidModel {
|
||||
* @param flag The flag to retrieve
|
||||
* @returns The flag value
|
||||
*/
|
||||
public getFlag = (flag: UserFlag) => {
|
||||
return this.flags?.[flag] ?? 0;
|
||||
};
|
||||
public getFlag = (flag: UserFlag) => this.flags?.[flag] ?? 0;
|
||||
|
||||
/**
|
||||
* User flags are for storing information on a user record that is not visible
|
||||
@@ -367,9 +360,8 @@ class User extends ParanoidModel {
|
||||
* @param fallback An optional fallback value, defaults to false.
|
||||
* @returns The preference value if set, else undefined
|
||||
*/
|
||||
public getPreference = (preference: UserPreference, fallback = false) => {
|
||||
return this.preferences?.[preference] ?? fallback;
|
||||
};
|
||||
public getPreference = (preference: UserPreference, fallback = false) =>
|
||||
this.preferences?.[preference] ?? fallback;
|
||||
|
||||
collectionIds = async (options = {}) => {
|
||||
const collectionStubs = await Collection.scope({
|
||||
@@ -448,8 +440,8 @@ class User extends ParanoidModel {
|
||||
* @param expiresAt The time the token will expire at
|
||||
* @returns The session token
|
||||
*/
|
||||
getJwtToken = (expiresAt?: Date) => {
|
||||
return JWT.sign(
|
||||
getJwtToken = (expiresAt?: Date) =>
|
||||
JWT.sign(
|
||||
{
|
||||
id: this.id,
|
||||
expiresAt: expiresAt ? expiresAt.toISOString() : undefined,
|
||||
@@ -457,7 +449,6 @@ class User extends ParanoidModel {
|
||||
},
|
||||
this.jwtSecret
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a temporary token that is only used for transferring a session
|
||||
@@ -466,8 +457,8 @@ class User extends ParanoidModel {
|
||||
*
|
||||
* @returns The transfer token
|
||||
*/
|
||||
getTransferToken = () => {
|
||||
return JWT.sign(
|
||||
getTransferToken = () =>
|
||||
JWT.sign(
|
||||
{
|
||||
id: this.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
@@ -476,7 +467,6 @@ class User extends ParanoidModel {
|
||||
},
|
||||
this.jwtSecret
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a temporary token that is only used for logging in from an email
|
||||
@@ -484,8 +474,8 @@ class User extends ParanoidModel {
|
||||
*
|
||||
* @returns The email signin token
|
||||
*/
|
||||
getEmailSigninToken = () => {
|
||||
return JWT.sign(
|
||||
getEmailSigninToken = () =>
|
||||
JWT.sign(
|
||||
{
|
||||
id: this.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
@@ -493,15 +483,14 @@ class User extends ParanoidModel {
|
||||
},
|
||||
this.jwtSecret
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a list of teams that have a user matching this user's email.
|
||||
*
|
||||
* @returns A promise resolving to a list of teams
|
||||
*/
|
||||
availableTeams = async () => {
|
||||
return Team.findAll({
|
||||
availableTeams = async () =>
|
||||
Team.findAll({
|
||||
include: [
|
||||
{
|
||||
model: this.constructor as typeof User,
|
||||
@@ -510,7 +499,6 @@ class User extends ParanoidModel {
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
demote = async (to: UserRole, options?: SaveOptions<User>) => {
|
||||
const res = await (this.constructor as typeof User).findAndCountAll({
|
||||
@@ -560,12 +548,11 @@ class User extends ParanoidModel {
|
||||
}
|
||||
};
|
||||
|
||||
promote = () => {
|
||||
return this.update({
|
||||
promote = () =>
|
||||
this.update({
|
||||
isAdmin: true,
|
||||
isViewer: false,
|
||||
});
|
||||
};
|
||||
|
||||
// hooks
|
||||
|
||||
|
||||
@@ -192,9 +192,8 @@ export default class DocumentHelper {
|
||||
const dom = new JSDOM(html);
|
||||
const doc = dom.window.document;
|
||||
|
||||
const containsDiffElement = (node: Element | null) => {
|
||||
return node && node.innerHTML.includes("data-operation-index");
|
||||
};
|
||||
const containsDiffElement = (node: Element | null) =>
|
||||
node && node.innerHTML.includes("data-operation-index");
|
||||
|
||||
// We use querySelectorAll to get a static NodeList as we'll be modifying
|
||||
// it as we iterate, rather than getting content.childNodes.
|
||||
|
||||
@@ -90,7 +90,7 @@ export default class ProsemirrorHelper {
|
||||
: "article";
|
||||
|
||||
const rtl = isRTL(node.textContent);
|
||||
const content = <div id="content" className="ProseMirror"></div>;
|
||||
const content = <div id="content" className="ProseMirror" />;
|
||||
const children = (
|
||||
<>
|
||||
{options?.title && <h1 dir={rtl ? "rtl" : "ltr"}>{options.title}</h1>}
|
||||
|
||||
Reference in New Issue
Block a user