chore: Move to prettier standard double quotes (#1309)
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
// @flow
|
||||
import { difference } from 'lodash';
|
||||
import type { DocumentEvent } from '../events';
|
||||
import { Document, Revision, Backlink } from '../models';
|
||||
import parseDocumentIds from '../../shared/utils/parseDocumentIds';
|
||||
import slugify from '../utils/slugify';
|
||||
import { difference } from "lodash";
|
||||
import type { DocumentEvent } from "../events";
|
||||
import { Document, Revision, Backlink } from "../models";
|
||||
import parseDocumentIds from "../../shared/utils/parseDocumentIds";
|
||||
import slugify from "../utils/slugify";
|
||||
|
||||
export default class Backlinks {
|
||||
async on(event: DocumentEvent) {
|
||||
switch (event.name) {
|
||||
case 'documents.publish': {
|
||||
case "documents.publish": {
|
||||
const document = await Document.findByPk(event.documentId);
|
||||
const linkIds = parseDocumentIds(document.text);
|
||||
|
||||
@@ -31,7 +31,7 @@ export default class Backlinks {
|
||||
|
||||
break;
|
||||
}
|
||||
case 'documents.update': {
|
||||
case "documents.update": {
|
||||
// no-op for now
|
||||
if (event.data.autosave) return;
|
||||
|
||||
@@ -41,7 +41,7 @@ export default class Backlinks {
|
||||
|
||||
const [currentRevision, previousRevision] = await Revision.findAll({
|
||||
where: { documentId: event.documentId },
|
||||
order: [['createdAt', 'desc']],
|
||||
order: [["createdAt", "desc"]],
|
||||
limit: 2,
|
||||
});
|
||||
const previousLinkIds = previousRevision
|
||||
@@ -98,7 +98,7 @@ export default class Backlinks {
|
||||
where: {
|
||||
documentId: event.documentId,
|
||||
},
|
||||
include: [{ model: Document, as: 'reverseDocument' }],
|
||||
include: [{ model: Document, as: "reverseDocument" }],
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
@@ -123,7 +123,7 @@ export default class Backlinks {
|
||||
|
||||
break;
|
||||
}
|
||||
case 'documents.delete': {
|
||||
case "documents.delete": {
|
||||
await Backlink.destroy({
|
||||
where: {
|
||||
reverseDocumentId: event.documentId,
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||
import { flushdb } from '../test/support';
|
||||
import BacklinksService from './backlinks';
|
||||
import { buildDocument } from '../test/factories';
|
||||
import Backlink from '../models/Backlink';
|
||||
import { flushdb } from "../test/support";
|
||||
import BacklinksService from "./backlinks";
|
||||
import { buildDocument } from "../test/factories";
|
||||
import Backlink from "../models/Backlink";
|
||||
|
||||
const Backlinks = new BacklinksService();
|
||||
|
||||
beforeEach(flushdb);
|
||||
beforeEach(jest.resetAllMocks);
|
||||
|
||||
describe('documents.update', () => {
|
||||
test('should not fail on a document with no previous revisions', async () => {
|
||||
describe("documents.update", () => {
|
||||
test("should not fail on a document with no previous revisions", async () => {
|
||||
const otherDocument = await buildDocument();
|
||||
const document = await buildDocument({
|
||||
text: `[this is a link](${otherDocument.url})`,
|
||||
});
|
||||
|
||||
await Backlinks.on({
|
||||
name: 'documents.update',
|
||||
name: "documents.update",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
@@ -32,7 +32,7 @@ describe('documents.update', () => {
|
||||
expect(backlinks.length).toBe(1);
|
||||
});
|
||||
|
||||
test('should create new backlink records', async () => {
|
||||
test("should create new backlink records", async () => {
|
||||
const otherDocument = await buildDocument();
|
||||
const document = await buildDocument();
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('documents.update', () => {
|
||||
await document.save();
|
||||
|
||||
await Backlinks.on({
|
||||
name: 'documents.update',
|
||||
name: "documents.update",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
@@ -55,14 +55,14 @@ describe('documents.update', () => {
|
||||
expect(backlinks.length).toBe(1);
|
||||
});
|
||||
|
||||
test('should destroy removed backlink records', async () => {
|
||||
test("should destroy removed backlink records", async () => {
|
||||
const otherDocument = await buildDocument();
|
||||
const document = await buildDocument({
|
||||
text: `[this is a link](${otherDocument.url})`,
|
||||
});
|
||||
|
||||
await Backlinks.on({
|
||||
name: 'documents.publish',
|
||||
name: "documents.publish",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
@@ -70,11 +70,11 @@ describe('documents.update', () => {
|
||||
data: { autosave: false },
|
||||
});
|
||||
|
||||
document.text = 'Link is gone';
|
||||
document.text = "Link is gone";
|
||||
await document.save();
|
||||
|
||||
await Backlinks.on({
|
||||
name: 'documents.update',
|
||||
name: "documents.update",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
@@ -89,8 +89,8 @@ describe('documents.update', () => {
|
||||
expect(backlinks.length).toBe(0);
|
||||
});
|
||||
|
||||
test('should update titles in backlinked documents', async () => {
|
||||
const newTitle = 'test';
|
||||
test("should update titles in backlinked documents", async () => {
|
||||
const newTitle = "test";
|
||||
const document = await buildDocument();
|
||||
const otherDocument = await buildDocument();
|
||||
|
||||
@@ -100,7 +100,7 @@ describe('documents.update', () => {
|
||||
|
||||
// ensure the backlinks are created
|
||||
await Backlinks.on({
|
||||
name: 'documents.update',
|
||||
name: "documents.update",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
@@ -114,7 +114,7 @@ describe('documents.update', () => {
|
||||
|
||||
// does the text get updated with the new title
|
||||
await Backlinks.on({
|
||||
name: 'documents.update',
|
||||
name: "documents.update",
|
||||
documentId: otherDocument.id,
|
||||
collectionId: otherDocument.collectionId,
|
||||
teamId: otherDocument.teamId,
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
// @flow
|
||||
import debug from 'debug';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import debug from "debug";
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
|
||||
const log = debug('services');
|
||||
const log = debug("services");
|
||||
const services = {};
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(
|
||||
file =>
|
||||
file.indexOf('.') !== 0 &&
|
||||
file.indexOf(".") !== 0 &&
|
||||
file !== path.basename(__filename) &&
|
||||
!file.includes('.test')
|
||||
!file.includes(".test")
|
||||
)
|
||||
.forEach(fileName => {
|
||||
const servicePath = path.join(__dirname, fileName);
|
||||
const name = path.basename(servicePath.replace(/\.js$/, ''));
|
||||
const name = path.basename(servicePath.replace(/\.js$/, ""));
|
||||
// $FlowIssue
|
||||
const Service = require(servicePath).default;
|
||||
services[name] = new Service();
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
// @flow
|
||||
import { Op } from '../sequelize';
|
||||
import type { DocumentEvent, CollectionEvent, Event } from '../events';
|
||||
import { Op } from "../sequelize";
|
||||
import type { DocumentEvent, CollectionEvent, Event } from "../events";
|
||||
import {
|
||||
Document,
|
||||
Team,
|
||||
Collection,
|
||||
User,
|
||||
NotificationSetting,
|
||||
} from '../models';
|
||||
import mailer from '../mailer';
|
||||
} from "../models";
|
||||
import mailer from "../mailer";
|
||||
|
||||
export default class Notifications {
|
||||
async on(event: Event) {
|
||||
switch (event.name) {
|
||||
case 'documents.publish':
|
||||
case 'documents.update':
|
||||
case "documents.publish":
|
||||
case "documents.update":
|
||||
return this.documentUpdated(event);
|
||||
case 'collections.create':
|
||||
case "collections.create":
|
||||
return this.collectionCreated(event);
|
||||
default:
|
||||
}
|
||||
@@ -50,20 +50,20 @@ export default class Notifications {
|
||||
{
|
||||
model: User,
|
||||
required: true,
|
||||
as: 'user',
|
||||
as: "user",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const eventName =
|
||||
event.name === 'documents.publish' ? 'published' : 'updated';
|
||||
event.name === "documents.publish" ? "published" : "updated";
|
||||
|
||||
notificationSettings.forEach(setting => {
|
||||
// For document updates we only want to send notifications if
|
||||
// the document has been edited by the user with this notification setting
|
||||
// This could be replaced with ability to "follow" in the future
|
||||
if (
|
||||
event.name === 'documents.update' &&
|
||||
event.name === "documents.update" &&
|
||||
!document.collaboratorIds.includes(setting.userId)
|
||||
) {
|
||||
return;
|
||||
@@ -87,7 +87,7 @@ export default class Notifications {
|
||||
{
|
||||
model: User,
|
||||
required: true,
|
||||
as: 'user',
|
||||
as: "user",
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -106,7 +106,7 @@ export default class Notifications {
|
||||
{
|
||||
model: User,
|
||||
required: true,
|
||||
as: 'user',
|
||||
as: "user",
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -114,7 +114,7 @@ export default class Notifications {
|
||||
notificationSettings.forEach(setting =>
|
||||
mailer.collectionNotification({
|
||||
to: setting.user.email,
|
||||
eventName: 'created',
|
||||
eventName: "created",
|
||||
collection,
|
||||
actor: collection.user,
|
||||
unsubscribeUrl: setting.unsubscribeUrl,
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// @flow
|
||||
import type { DocumentEvent, IntegrationEvent, Event } from '../events';
|
||||
import { Document, Integration, Collection, Team } from '../models';
|
||||
import { presentSlackAttachment } from '../presenters';
|
||||
import type { DocumentEvent, IntegrationEvent, Event } from "../events";
|
||||
import { Document, Integration, Collection, Team } from "../models";
|
||||
import { presentSlackAttachment } from "../presenters";
|
||||
|
||||
export default class Slack {
|
||||
async on(event: Event) {
|
||||
switch (event.name) {
|
||||
case 'documents.publish':
|
||||
case 'documents.update':
|
||||
case "documents.publish":
|
||||
case "documents.update":
|
||||
return this.documentUpdated(event);
|
||||
case 'integrations.create':
|
||||
case "integrations.create":
|
||||
return this.integrationCreated(event);
|
||||
default:
|
||||
}
|
||||
@@ -19,14 +19,14 @@ export default class Slack {
|
||||
const integration = await Integration.findOne({
|
||||
where: {
|
||||
id: event.modelId,
|
||||
service: 'slack',
|
||||
type: 'post',
|
||||
service: "slack",
|
||||
type: "post",
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Collection,
|
||||
required: true,
|
||||
as: 'collection',
|
||||
as: "collection",
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -36,9 +36,9 @@ export default class Slack {
|
||||
if (!collection) return;
|
||||
|
||||
await fetch(integration.settings.url, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
text: `👋 Hey there! When documents are published or updated in the *${
|
||||
@@ -59,7 +59,7 @@ export default class Slack {
|
||||
async documentUpdated(event: DocumentEvent) {
|
||||
// lets not send a notification on every autosave update
|
||||
if (
|
||||
event.name === 'documents.update' &&
|
||||
event.name === "documents.update" &&
|
||||
event.data &&
|
||||
event.data.autosave
|
||||
) {
|
||||
@@ -67,7 +67,7 @@ export default class Slack {
|
||||
}
|
||||
|
||||
// lets not send a notification on every CMD+S update
|
||||
if (event.name === 'documents.update' && event.data && !event.data.done) {
|
||||
if (event.name === "documents.update" && event.data && !event.data.done) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ export default class Slack {
|
||||
where: {
|
||||
teamId: document.teamId,
|
||||
collectionId: document.collectionId,
|
||||
service: 'slack',
|
||||
type: 'post',
|
||||
service: "slack",
|
||||
type: "post",
|
||||
},
|
||||
});
|
||||
if (!integration) return;
|
||||
@@ -91,14 +91,14 @@ export default class Slack {
|
||||
|
||||
let text = `${document.createdBy.name} published a new document`;
|
||||
|
||||
if (event.name === 'documents.update') {
|
||||
if (event.name === "documents.update") {
|
||||
text = `${document.updatedBy.name} updated a document`;
|
||||
}
|
||||
|
||||
await fetch(integration.settings.url, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
text,
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
// @flow
|
||||
import type { Event } from '../events';
|
||||
import type { Event } from "../events";
|
||||
import {
|
||||
Document,
|
||||
Collection,
|
||||
Group,
|
||||
CollectionGroup,
|
||||
GroupUser,
|
||||
} from '../models';
|
||||
import { socketio } from '../';
|
||||
import { Op } from '../sequelize';
|
||||
import subHours from 'date-fns/sub_hours';
|
||||
} from "../models";
|
||||
import { socketio } from "../";
|
||||
import { Op } from "../sequelize";
|
||||
import subHours from "date-fns/sub_hours";
|
||||
|
||||
export default class Websockets {
|
||||
async on(event: Event) {
|
||||
if (process.env.WEBSOCKETS_ENABLED !== 'true' || !socketio) return;
|
||||
if (process.env.WEBSOCKETS_ENABLED !== "true" || !socketio) return;
|
||||
|
||||
switch (event.name) {
|
||||
case 'documents.publish':
|
||||
case 'documents.restore':
|
||||
case 'documents.archive':
|
||||
case 'documents.unarchive': {
|
||||
case "documents.publish":
|
||||
case "documents.restore":
|
||||
case "documents.archive":
|
||||
case "documents.unarchive": {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
return socketio
|
||||
.to(`collection-${document.collectionId}`)
|
||||
.emit('entities', {
|
||||
.emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -41,13 +41,13 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'documents.delete': {
|
||||
case "documents.delete": {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
if (!document.publishedAt) {
|
||||
return socketio.to(`user-${document.createdById}`).emit('entities', {
|
||||
return socketio.to(`user-${document.createdById}`).emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -60,7 +60,7 @@ export default class Websockets {
|
||||
|
||||
return socketio
|
||||
.to(`collection-${document.collectionId}`)
|
||||
.emit('entities', {
|
||||
.emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -75,16 +75,16 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'documents.pin':
|
||||
case 'documents.unpin':
|
||||
case 'documents.update': {
|
||||
case "documents.pin":
|
||||
case "documents.unpin":
|
||||
case "documents.update": {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
return socketio
|
||||
.to(`collection-${document.collectionId}`)
|
||||
.emit('entities', {
|
||||
.emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -94,10 +94,10 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'documents.create': {
|
||||
case "documents.create": {
|
||||
const document = await Document.findByPk(event.documentId);
|
||||
|
||||
return socketio.to(`user-${event.actorId}`).emit('entities', {
|
||||
return socketio.to(`user-${event.actorId}`).emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -112,13 +112,13 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'documents.star':
|
||||
case 'documents.unstar': {
|
||||
case "documents.star":
|
||||
case "documents.unstar": {
|
||||
return socketio.to(`user-${event.actorId}`).emit(event.name, {
|
||||
documentId: event.documentId,
|
||||
});
|
||||
}
|
||||
case 'documents.move': {
|
||||
case "documents.move": {
|
||||
const documents = await Document.findAll({
|
||||
where: {
|
||||
id: event.data.documentIds,
|
||||
@@ -126,7 +126,7 @@ export default class Websockets {
|
||||
paranoid: false,
|
||||
});
|
||||
documents.forEach(document => {
|
||||
socketio.to(`collection-${document.collectionId}`).emit('entities', {
|
||||
socketio.to(`collection-${document.collectionId}`).emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -137,14 +137,14 @@ export default class Websockets {
|
||||
});
|
||||
});
|
||||
event.data.collectionIds.forEach(collectionId => {
|
||||
socketio.to(`collection-${collectionId}`).emit('entities', {
|
||||
socketio.to(`collection-${collectionId}`).emit("entities", {
|
||||
event: event.name,
|
||||
collectionIds: [{ id: collectionId }],
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
case 'collections.create': {
|
||||
case "collections.create": {
|
||||
const collection = await Collection.findByPk(event.collectionId, {
|
||||
paranoid: false,
|
||||
});
|
||||
@@ -155,7 +155,7 @@ export default class Websockets {
|
||||
? `collection-${collection.id}`
|
||||
: `team-${collection.teamId}`
|
||||
)
|
||||
.emit('entities', {
|
||||
.emit("entities", {
|
||||
event: event.name,
|
||||
collectionIds: [
|
||||
{
|
||||
@@ -170,18 +170,18 @@ export default class Websockets {
|
||||
? `collection-${collection.id}`
|
||||
: `team-${collection.teamId}`
|
||||
)
|
||||
.emit('join', {
|
||||
.emit("join", {
|
||||
event: event.name,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
}
|
||||
case 'collections.update':
|
||||
case 'collections.delete': {
|
||||
case "collections.update":
|
||||
case "collections.delete": {
|
||||
const collection = await Collection.findByPk(event.collectionId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
return socketio.to(`team-${collection.teamId}`).emit('entities', {
|
||||
return socketio.to(`team-${collection.teamId}`).emit("entities", {
|
||||
event: event.name,
|
||||
collectionIds: [
|
||||
{
|
||||
@@ -191,7 +191,7 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'collections.add_user': {
|
||||
case "collections.add_user": {
|
||||
// the user being added isn't yet in the websocket channel for the collection
|
||||
// so they need to be notified separately
|
||||
socketio.to(`user-${event.userId}`).emit(event.name, {
|
||||
@@ -208,12 +208,12 @@ export default class Websockets {
|
||||
});
|
||||
|
||||
// tell any user clients to connect to the websocket channel for the collection
|
||||
return socketio.to(`user-${event.userId}`).emit('join', {
|
||||
return socketio.to(`user-${event.userId}`).emit("join", {
|
||||
event: event.name,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
}
|
||||
case 'collections.remove_user': {
|
||||
case "collections.remove_user": {
|
||||
const membershipUserIds = await Collection.membershipUserIds(
|
||||
event.collectionId
|
||||
);
|
||||
@@ -222,8 +222,8 @@ export default class Websockets {
|
||||
// Even though we just removed a user from the collection
|
||||
// the user still has access through some means
|
||||
// treat this like an add, so that the client re-syncs policies
|
||||
socketio.to(`user-${event.userId}`).emit('collections.add_user', {
|
||||
event: 'collections.add_user',
|
||||
socketio.to(`user-${event.userId}`).emit("collections.add_user", {
|
||||
event: "collections.add_user",
|
||||
userId: event.userId,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
@@ -231,21 +231,21 @@ export default class Websockets {
|
||||
// let everyone with access to the collection know a user was removed
|
||||
socketio
|
||||
.to(`collection-${event.collectionId}`)
|
||||
.emit('collections.remove_user', {
|
||||
.emit("collections.remove_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to disconnect from the websocket channel for the collection
|
||||
socketio.to(`user-${event.userId}`).emit('leave', {
|
||||
socketio.to(`user-${event.userId}`).emit("leave", {
|
||||
event: event.name,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'collections.add_group': {
|
||||
case "collections.add_group": {
|
||||
const group = await Group.findByPk(event.data.groupId);
|
||||
|
||||
// the users being added are not yet in the websocket channel for the collection
|
||||
@@ -253,21 +253,21 @@ export default class Websockets {
|
||||
for (const groupMembership of group.groupMemberships) {
|
||||
socketio
|
||||
.to(`user-${groupMembership.userId}`)
|
||||
.emit('collections.add_user', {
|
||||
.emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: groupMembership.userId,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to connect to the websocket channel for the collection
|
||||
socketio.to(`user-${groupMembership.userId}`).emit('join', {
|
||||
socketio.to(`user-${groupMembership.userId}`).emit("join", {
|
||||
event: event.name,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'collections.remove_group': {
|
||||
case "collections.remove_group": {
|
||||
const group = await Group.findByPk(event.data.groupId);
|
||||
const membershipUserIds = await Collection.membershipUserIds(
|
||||
event.collectionId
|
||||
@@ -279,7 +279,7 @@ export default class Websockets {
|
||||
// treat this like an add, so that the client re-syncs policies
|
||||
socketio
|
||||
.to(`user-${groupMembership.userId}`)
|
||||
.emit('collections.add_user', {
|
||||
.emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: groupMembership.userId,
|
||||
collectionId: event.collectionId,
|
||||
@@ -288,14 +288,14 @@ export default class Websockets {
|
||||
// let users in the channel know they were removed
|
||||
socketio
|
||||
.to(`user-${groupMembership.userId}`)
|
||||
.emit('collections.remove_user', {
|
||||
.emit("collections.remove_user", {
|
||||
event: event.name,
|
||||
userId: groupMembership.userId,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to disconnect to the websocket channel for the collection
|
||||
socketio.to(`user-${groupMembership.userId}`).emit('leave', {
|
||||
socketio.to(`user-${groupMembership.userId}`).emit("leave", {
|
||||
event: event.name,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
@@ -303,13 +303,13 @@ export default class Websockets {
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'groups.create':
|
||||
case 'groups.update': {
|
||||
case "groups.create":
|
||||
case "groups.update": {
|
||||
const group = await Group.findByPk(event.modelId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
return socketio.to(`team-${group.teamId}`).emit('entities', {
|
||||
return socketio.to(`team-${group.teamId}`).emit("entities", {
|
||||
event: event.name,
|
||||
groupIds: [
|
||||
{
|
||||
@@ -319,7 +319,7 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'groups.add_user': {
|
||||
case "groups.add_user": {
|
||||
// do an add user for every collection that the group is a part of
|
||||
const collectionGroupMemberships = await CollectionGroup.findAll({
|
||||
where: { groupId: event.modelId },
|
||||
@@ -328,7 +328,7 @@ export default class Websockets {
|
||||
for (const collectionGroup of collectionGroupMemberships) {
|
||||
// the user being added isn't yet in the websocket channel for the collection
|
||||
// so they need to be notified separately
|
||||
socketio.to(`user-${event.userId}`).emit('collections.add_user', {
|
||||
socketio.to(`user-${event.userId}`).emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
@@ -337,21 +337,21 @@ export default class Websockets {
|
||||
// let everyone with access to the collection know a user was added
|
||||
socketio
|
||||
.to(`collection-${collectionGroup.collectionId}`)
|
||||
.emit('collections.add_user', {
|
||||
.emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to connect to the websocket channel for the collection
|
||||
return socketio.to(`user-${event.userId}`).emit('join', {
|
||||
return socketio.to(`user-${event.userId}`).emit("join", {
|
||||
event: event.name,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'groups.remove_user': {
|
||||
case "groups.remove_user": {
|
||||
const collectionGroupMemberships = await CollectionGroup.findAll({
|
||||
where: { groupId: event.modelId },
|
||||
});
|
||||
@@ -360,7 +360,7 @@ export default class Websockets {
|
||||
// if the user has any memberships remaining on the collection
|
||||
// we need to emit add instead of remove
|
||||
const collection = await Collection.scope({
|
||||
method: ['withMembership', event.userId],
|
||||
method: ["withMembership", event.userId],
|
||||
}).findByPk(collectionGroup.collectionId);
|
||||
|
||||
const hasMemberships =
|
||||
@@ -370,7 +370,7 @@ export default class Websockets {
|
||||
if (hasMemberships) {
|
||||
// the user still has access through some means...
|
||||
// treat this like an add, so that the client re-syncs policies
|
||||
socketio.to(`user-${event.userId}`).emit('collections.add_user', {
|
||||
socketio.to(`user-${event.userId}`).emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
@@ -379,14 +379,14 @@ export default class Websockets {
|
||||
// let everyone with access to the collection know a user was removed
|
||||
socketio
|
||||
.to(`collection-${collectionGroup.collectionId}`)
|
||||
.emit('collections.remove_user', {
|
||||
.emit("collections.remove_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to disconnect from the websocket channel for the collection
|
||||
socketio.to(`user-${event.userId}`).emit('leave', {
|
||||
socketio.to(`user-${event.userId}`).emit("leave", {
|
||||
event: event.name,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
@@ -394,12 +394,12 @@ export default class Websockets {
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'groups.delete': {
|
||||
case "groups.delete": {
|
||||
const group = await Group.findByPk(event.modelId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
socketio.to(`team-${group.teamId}`).emit('entities', {
|
||||
socketio.to(`team-${group.teamId}`).emit("entities", {
|
||||
event: event.name,
|
||||
groupIds: [
|
||||
{
|
||||
@@ -443,7 +443,7 @@ export default class Websockets {
|
||||
// treat this like an add, so that the client re-syncs policies
|
||||
socketio
|
||||
.to(`user-${groupUser.userId}`)
|
||||
.emit('collections.add_user', {
|
||||
.emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: groupUser.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
@@ -452,14 +452,14 @@ export default class Websockets {
|
||||
// let everyone with access to the collection know a user was removed
|
||||
socketio
|
||||
.to(`collection-${collectionGroup.collectionId}`)
|
||||
.emit('collections.remove_user', {
|
||||
.emit("collections.remove_user", {
|
||||
event: event.name,
|
||||
userId: groupUser.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to disconnect from the websocket channel for the collection
|
||||
socketio.to(`user-${groupUser.userId}`).emit('leave', {
|
||||
socketio.to(`user-${groupUser.userId}`).emit("leave", {
|
||||
event: event.name,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user