Initialise comments (#3328)
* Initial scaffolding for comments CRUD APIs
* add actions
* add assets
* state management for existing comments and creating new
* add ui components
* add overlay comments wrapper to baseWidget
* add toggle comment mode button at editor header
* trigger tests
* Disallow commenting as someone else
* Add applicationId for comments
* lint
* Add overlay blacklist to prevent component interaction while adding comments
* Comment thread style updates
* Placeholder comment context menu
* Controlled comment thread visibility for making new comments visible by default
* Update comment type description
* Reset input on save
* Resolve comment thread button ui
* fix close on esc key, dont create new comment on outside click
* Submit on enter
* add emoji picker
* Attempt at adding a websocket server in Java
* CRUD APIs for comment threads
* Add API for getting all threads in application
* Move types to a separate file
* Initial commit for real time server (RTS)
* Add script to start RTS
* Fix position property
* Use create comment thread API
* Use add comment to thread API
* Add custom cursor
* Dispatch logout init on 401 errors
* Allow CORS for real time connection
* Add more logs to RTS
* Fix construction of MongoClient
* WIP: Real time comments
* Enable comments
* Minor updates
* Read backend API base URL from environment
* Escape to reset comments mode
* Set popover position as auto and boundary as scroll parent
* Disable warning
* Added permissions for comment threads
* Add resolved API for comment threads
* Migration to set commenting permission on existing apps
* Fix updates bringing the RTS down
* Show view latest button, scroll to bottom on creating a new comment
* Cleanup comment reducer
* Move to typescript for RTS
* Add missing server.ts and tsconfig files
* Resolve / unresolve comment
* Scaffold app comments
* Minor fixes: comment on top of all widgets, add toggle button at viewer header
* Reconnect socket on creating a new app, set connected status in store
* Retry socket connection flow
* Integration tests for comments with api mocks using msw
* Fix circular depependency
* rm file
* Minor cleanup and comments
* Minor refactors: move isScrolledToBottom to common hooks, decouple prevent interactions overlay from comments wrapper
* Use policies when pushing updates in RTS
* ENV var to set if comments are enabled
* Fix: check if editor/viewer is initialised before waiting for init action
* Add tests for comments reducer
* Revert "ENV var to set if comments are enabled"
This reverts commit 988efeaa69d378d943a387e1e73510334958adc5.
* Enable comments for users with appsmith email
* lint
* fix
* Try running a socket.io server inside backend
* Update comment reducer tests
* Init mentions within comments
* Fix comment thread updates with email rooms
* Minor fixes
* Refactors / review suggestions
* lint
* increase cache limit for builds
* Comment out tests for feature that's under development
* Add Dockerfile for RTS
* Fix policies missing for first comment in threads
* Use draftJS for comments input with mentions support
* fix fixtures
* Use thread's policies when querying for threads
* Update socket.io to v4
* Add support for richer body with mentions
* Update comment body type to RawDraftContentState
* fix stale method
* Fix mentions search
* Minor cleanups
* Comment context menu and thread UI updates
* revert: Scaffold app comments
* Yarn dependencies
* Delete comment using id api added
* Init app comments
* Add test for creating thread
* Api for delete comment with id
* Test comment creation response and policies
* Copy comment links
* Fix reset editor state
* Delete valid comment testcase added
* Delete comment TC : code refactor
* Don't allow creating comments with an empty body
* Pin comments WIP[]
* Ignore dependency-reduced-pom.xml files from VCS
* Cleanup of some dev-only files, for review
* Delete comment
* Update socket.io to v4 in RTS
* Pin and resolve comment thread object added in commentThread
* Pin and resolve comment thread object added in commentThread
* Update comment thread API
* Added creationTime and updationTime in comment thread response
* Added creationTime and updationTime in comment thread response
* Added human readable id to comment threads, fallback to username for null name in user document
* Refactor
* lint
* fix test, rm duplicate selector
* comment out saga used for dev
* CommentThread viewed status, username fallback for getName=null, username field added in pin & resolve status
* lint
* trigger tests
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Abhijeet <abhi.nagarnaik@gmail.com>
2021-04-29 10:33:51 +00:00
|
|
|
import http from "http"
|
|
|
|
|
import path from "path"
|
|
|
|
|
import express from "express"
|
|
|
|
|
import SocketIO from "socket.io"
|
|
|
|
|
import { MongoClient, ObjectId } from "mongodb"
|
|
|
|
|
import type mongodb from "mongodb"
|
|
|
|
|
import axios from "axios"
|
|
|
|
|
|
|
|
|
|
const MONGODB_URI = process.env.APPSMITH_MONGODB_URI
|
|
|
|
|
if (MONGODB_URI == null || MONGODB_URI === "" || !MONGODB_URI.startsWith("mongodb")) {
|
|
|
|
|
console.error("Please provide a valid value for `APPSMITH_MONGODB_URI`.")
|
|
|
|
|
process.exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const API_BASE_URL = process.env.APPSMITH_API_BASE_URL
|
|
|
|
|
if (API_BASE_URL == null || API_BASE_URL === "") {
|
|
|
|
|
console.error("Please provide a valid value for `APPSMITH_API_BASE_URL`.")
|
|
|
|
|
process.exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("Connecting to MongoDB at", MONGODB_URI)
|
|
|
|
|
|
|
|
|
|
const ROOMS = {}
|
|
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
interface Policy {
|
|
|
|
|
permission: string
|
|
|
|
|
users: string[]
|
|
|
|
|
groups: string[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
|
const app = express()
|
|
|
|
|
const server = new http.Server(app)
|
|
|
|
|
const io = new SocketIO.Server(server, {
|
|
|
|
|
// TODO: Remove this CORS configuration.
|
|
|
|
|
cors: {
|
|
|
|
|
origin: "*",
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const port = 8091
|
|
|
|
|
|
|
|
|
|
app.get("/", (req, res) => {
|
|
|
|
|
res.redirect("/index.html")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
app.get("/info", (req, res) => {
|
|
|
|
|
return res.json({ rooms: ROOMS })
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
io.on("connection", (socket) => {
|
|
|
|
|
socket.join("default_room")
|
|
|
|
|
onSocketConnected(socket)
|
|
|
|
|
.catch((error) => console.error("Error in socket connected handler", error))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
watchMongoDB(io)
|
|
|
|
|
.catch((error) => console.error("Error watching MongoDB", error))
|
|
|
|
|
|
|
|
|
|
app.use(express.static(path.join(__dirname, "static")))
|
|
|
|
|
server.listen(port, () => {
|
|
|
|
|
console.log(`RTS running at http://localhost:${port}`)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function onSocketConnected(socket) {
|
|
|
|
|
const connectionCookie = socket.handshake.headers.cookie
|
|
|
|
|
console.log("new user connected with cookie", connectionCookie)
|
|
|
|
|
|
|
|
|
|
socket.on("disconnect", () => {
|
|
|
|
|
console.log("user disconnected", connectionCookie)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
let isAuthenticated = true
|
|
|
|
|
|
|
|
|
|
if (connectionCookie != null && connectionCookie !== "") {
|
|
|
|
|
isAuthenticated = await tryAuth(socket, connectionCookie)
|
|
|
|
|
socket.emit("authStatus", { isAuthenticated })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
socket.on("auth", async ({ cookie }) => {
|
|
|
|
|
isAuthenticated = await tryAuth(socket, cookie)
|
|
|
|
|
socket.emit("authStatus", { isAuthenticated })
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function tryAuth(socket, cookie) {
|
|
|
|
|
const sessionCookie = cookie.match(/\bSESSION=\S+/)[0]
|
|
|
|
|
let response
|
|
|
|
|
try {
|
|
|
|
|
response = await axios.request({
|
|
|
|
|
method: "GET",
|
|
|
|
|
url: API_BASE_URL + "/applications/new",
|
|
|
|
|
headers: {
|
|
|
|
|
Cookie: sessionCookie,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (error.response?.status === 401) {
|
|
|
|
|
console.info("Couldn't authenticate user with cookie:", sessionCookie)
|
|
|
|
|
} else {
|
|
|
|
|
console.error("Error authenticating", error)
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const email = response.data.data.user.email
|
|
|
|
|
ROOMS[email] = []
|
|
|
|
|
socket.join("email:" + email)
|
|
|
|
|
console.log("A socket joined email:" + email)
|
|
|
|
|
|
|
|
|
|
/*for (const org of response.data.data.organizationApplications) {
|
|
|
|
|
for (const app of org.applications) {
|
|
|
|
|
ROOMS[email].push(app.id)
|
|
|
|
|
console.log("Joining", app.id)
|
|
|
|
|
socket.join("application:" + app.id)
|
|
|
|
|
}
|
|
|
|
|
}//*/
|
|
|
|
|
|
|
|
|
|
socket.on("disconnect", (reason) => {
|
|
|
|
|
delete ROOMS[email]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function watchMongoDB(io) {
|
|
|
|
|
const client = await MongoClient.connect(MONGODB_URI, { useUnifiedTopology: true });
|
|
|
|
|
const db = client.db()
|
|
|
|
|
|
|
|
|
|
interface CommentThread {
|
|
|
|
|
applicationId: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Comment {
|
|
|
|
|
threadId: string
|
|
|
|
|
policies: Policy[]
|
2021-04-30 10:02:34 +00:00
|
|
|
createdAt: string
|
|
|
|
|
updatedAt: string
|
|
|
|
|
creationTime: string
|
|
|
|
|
updationTime: string
|
Initialise comments (#3328)
* Initial scaffolding for comments CRUD APIs
* add actions
* add assets
* state management for existing comments and creating new
* add ui components
* add overlay comments wrapper to baseWidget
* add toggle comment mode button at editor header
* trigger tests
* Disallow commenting as someone else
* Add applicationId for comments
* lint
* Add overlay blacklist to prevent component interaction while adding comments
* Comment thread style updates
* Placeholder comment context menu
* Controlled comment thread visibility for making new comments visible by default
* Update comment type description
* Reset input on save
* Resolve comment thread button ui
* fix close on esc key, dont create new comment on outside click
* Submit on enter
* add emoji picker
* Attempt at adding a websocket server in Java
* CRUD APIs for comment threads
* Add API for getting all threads in application
* Move types to a separate file
* Initial commit for real time server (RTS)
* Add script to start RTS
* Fix position property
* Use create comment thread API
* Use add comment to thread API
* Add custom cursor
* Dispatch logout init on 401 errors
* Allow CORS for real time connection
* Add more logs to RTS
* Fix construction of MongoClient
* WIP: Real time comments
* Enable comments
* Minor updates
* Read backend API base URL from environment
* Escape to reset comments mode
* Set popover position as auto and boundary as scroll parent
* Disable warning
* Added permissions for comment threads
* Add resolved API for comment threads
* Migration to set commenting permission on existing apps
* Fix updates bringing the RTS down
* Show view latest button, scroll to bottom on creating a new comment
* Cleanup comment reducer
* Move to typescript for RTS
* Add missing server.ts and tsconfig files
* Resolve / unresolve comment
* Scaffold app comments
* Minor fixes: comment on top of all widgets, add toggle button at viewer header
* Reconnect socket on creating a new app, set connected status in store
* Retry socket connection flow
* Integration tests for comments with api mocks using msw
* Fix circular depependency
* rm file
* Minor cleanup and comments
* Minor refactors: move isScrolledToBottom to common hooks, decouple prevent interactions overlay from comments wrapper
* Use policies when pushing updates in RTS
* ENV var to set if comments are enabled
* Fix: check if editor/viewer is initialised before waiting for init action
* Add tests for comments reducer
* Revert "ENV var to set if comments are enabled"
This reverts commit 988efeaa69d378d943a387e1e73510334958adc5.
* Enable comments for users with appsmith email
* lint
* fix
* Try running a socket.io server inside backend
* Update comment reducer tests
* Init mentions within comments
* Fix comment thread updates with email rooms
* Minor fixes
* Refactors / review suggestions
* lint
* increase cache limit for builds
* Comment out tests for feature that's under development
* Add Dockerfile for RTS
* Fix policies missing for first comment in threads
* Use draftJS for comments input with mentions support
* fix fixtures
* Use thread's policies when querying for threads
* Update socket.io to v4
* Add support for richer body with mentions
* Update comment body type to RawDraftContentState
* fix stale method
* Fix mentions search
* Minor cleanups
* Comment context menu and thread UI updates
* revert: Scaffold app comments
* Yarn dependencies
* Delete comment using id api added
* Init app comments
* Add test for creating thread
* Api for delete comment with id
* Test comment creation response and policies
* Copy comment links
* Fix reset editor state
* Delete valid comment testcase added
* Delete comment TC : code refactor
* Don't allow creating comments with an empty body
* Pin comments WIP[]
* Ignore dependency-reduced-pom.xml files from VCS
* Cleanup of some dev-only files, for review
* Delete comment
* Update socket.io to v4 in RTS
* Pin and resolve comment thread object added in commentThread
* Pin and resolve comment thread object added in commentThread
* Update comment thread API
* Added creationTime and updationTime in comment thread response
* Added creationTime and updationTime in comment thread response
* Added human readable id to comment threads, fallback to username for null name in user document
* Refactor
* lint
* fix test, rm duplicate selector
* comment out saga used for dev
* CommentThread viewed status, username fallback for getName=null, username field added in pin & resolve status
* lint
* trigger tests
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Abhijeet <abhi.nagarnaik@gmail.com>
2021-04-29 10:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const threadCollection: mongodb.Collection<CommentThread> = db.collection("commentThread")
|
|
|
|
|
|
2021-04-30 10:02:34 +00:00
|
|
|
const commentChangeStream = db.collection("comment").watch(
|
|
|
|
|
[
|
|
|
|
|
// Prevent server-internal fields from being sent to the client.
|
|
|
|
|
{
|
|
|
|
|
$unset: [
|
|
|
|
|
"deletedAt",
|
|
|
|
|
"deleted",
|
|
|
|
|
"_class",
|
|
|
|
|
].map(f => "fullDocument." + f)
|
|
|
|
|
},
|
2021-04-30 10:52:16 +00:00
|
|
|
],
|
2021-04-30 10:02:34 +00:00
|
|
|
{ fullDocument: "updateLookup" }
|
|
|
|
|
);
|
|
|
|
|
|
Initialise comments (#3328)
* Initial scaffolding for comments CRUD APIs
* add actions
* add assets
* state management for existing comments and creating new
* add ui components
* add overlay comments wrapper to baseWidget
* add toggle comment mode button at editor header
* trigger tests
* Disallow commenting as someone else
* Add applicationId for comments
* lint
* Add overlay blacklist to prevent component interaction while adding comments
* Comment thread style updates
* Placeholder comment context menu
* Controlled comment thread visibility for making new comments visible by default
* Update comment type description
* Reset input on save
* Resolve comment thread button ui
* fix close on esc key, dont create new comment on outside click
* Submit on enter
* add emoji picker
* Attempt at adding a websocket server in Java
* CRUD APIs for comment threads
* Add API for getting all threads in application
* Move types to a separate file
* Initial commit for real time server (RTS)
* Add script to start RTS
* Fix position property
* Use create comment thread API
* Use add comment to thread API
* Add custom cursor
* Dispatch logout init on 401 errors
* Allow CORS for real time connection
* Add more logs to RTS
* Fix construction of MongoClient
* WIP: Real time comments
* Enable comments
* Minor updates
* Read backend API base URL from environment
* Escape to reset comments mode
* Set popover position as auto and boundary as scroll parent
* Disable warning
* Added permissions for comment threads
* Add resolved API for comment threads
* Migration to set commenting permission on existing apps
* Fix updates bringing the RTS down
* Show view latest button, scroll to bottom on creating a new comment
* Cleanup comment reducer
* Move to typescript for RTS
* Add missing server.ts and tsconfig files
* Resolve / unresolve comment
* Scaffold app comments
* Minor fixes: comment on top of all widgets, add toggle button at viewer header
* Reconnect socket on creating a new app, set connected status in store
* Retry socket connection flow
* Integration tests for comments with api mocks using msw
* Fix circular depependency
* rm file
* Minor cleanup and comments
* Minor refactors: move isScrolledToBottom to common hooks, decouple prevent interactions overlay from comments wrapper
* Use policies when pushing updates in RTS
* ENV var to set if comments are enabled
* Fix: check if editor/viewer is initialised before waiting for init action
* Add tests for comments reducer
* Revert "ENV var to set if comments are enabled"
This reverts commit 988efeaa69d378d943a387e1e73510334958adc5.
* Enable comments for users with appsmith email
* lint
* fix
* Try running a socket.io server inside backend
* Update comment reducer tests
* Init mentions within comments
* Fix comment thread updates with email rooms
* Minor fixes
* Refactors / review suggestions
* lint
* increase cache limit for builds
* Comment out tests for feature that's under development
* Add Dockerfile for RTS
* Fix policies missing for first comment in threads
* Use draftJS for comments input with mentions support
* fix fixtures
* Use thread's policies when querying for threads
* Update socket.io to v4
* Add support for richer body with mentions
* Update comment body type to RawDraftContentState
* fix stale method
* Fix mentions search
* Minor cleanups
* Comment context menu and thread UI updates
* revert: Scaffold app comments
* Yarn dependencies
* Delete comment using id api added
* Init app comments
* Add test for creating thread
* Api for delete comment with id
* Test comment creation response and policies
* Copy comment links
* Fix reset editor state
* Delete valid comment testcase added
* Delete comment TC : code refactor
* Don't allow creating comments with an empty body
* Pin comments WIP[]
* Ignore dependency-reduced-pom.xml files from VCS
* Cleanup of some dev-only files, for review
* Delete comment
* Update socket.io to v4 in RTS
* Pin and resolve comment thread object added in commentThread
* Pin and resolve comment thread object added in commentThread
* Update comment thread API
* Added creationTime and updationTime in comment thread response
* Added creationTime and updationTime in comment thread response
* Added human readable id to comment threads, fallback to username for null name in user document
* Refactor
* lint
* fix test, rm duplicate selector
* comment out saga used for dev
* CommentThread viewed status, username fallback for getName=null, username field added in pin & resolve status
* lint
* trigger tests
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Abhijeet <abhi.nagarnaik@gmail.com>
2021-04-29 10:33:51 +00:00
|
|
|
commentChangeStream.on("change", async (event: mongodb.ChangeEventCR<Comment>) => {
|
|
|
|
|
console.log("comment event", event)
|
|
|
|
|
const comment: Comment = event.fullDocument
|
|
|
|
|
const { applicationId }: CommentThread = await threadCollection.findOne(
|
|
|
|
|
{ _id: new ObjectId(comment.threadId) },
|
|
|
|
|
{ projection: { applicationId: 1 } },
|
|
|
|
|
)
|
|
|
|
|
|
2021-04-30 10:02:34 +00:00
|
|
|
comment.creationTime = comment.createdAt
|
|
|
|
|
comment.updationTime = comment.updatedAt
|
|
|
|
|
delete comment.createdAt
|
|
|
|
|
delete comment.updatedAt
|
|
|
|
|
|
Initialise comments (#3328)
* Initial scaffolding for comments CRUD APIs
* add actions
* add assets
* state management for existing comments and creating new
* add ui components
* add overlay comments wrapper to baseWidget
* add toggle comment mode button at editor header
* trigger tests
* Disallow commenting as someone else
* Add applicationId for comments
* lint
* Add overlay blacklist to prevent component interaction while adding comments
* Comment thread style updates
* Placeholder comment context menu
* Controlled comment thread visibility for making new comments visible by default
* Update comment type description
* Reset input on save
* Resolve comment thread button ui
* fix close on esc key, dont create new comment on outside click
* Submit on enter
* add emoji picker
* Attempt at adding a websocket server in Java
* CRUD APIs for comment threads
* Add API for getting all threads in application
* Move types to a separate file
* Initial commit for real time server (RTS)
* Add script to start RTS
* Fix position property
* Use create comment thread API
* Use add comment to thread API
* Add custom cursor
* Dispatch logout init on 401 errors
* Allow CORS for real time connection
* Add more logs to RTS
* Fix construction of MongoClient
* WIP: Real time comments
* Enable comments
* Minor updates
* Read backend API base URL from environment
* Escape to reset comments mode
* Set popover position as auto and boundary as scroll parent
* Disable warning
* Added permissions for comment threads
* Add resolved API for comment threads
* Migration to set commenting permission on existing apps
* Fix updates bringing the RTS down
* Show view latest button, scroll to bottom on creating a new comment
* Cleanup comment reducer
* Move to typescript for RTS
* Add missing server.ts and tsconfig files
* Resolve / unresolve comment
* Scaffold app comments
* Minor fixes: comment on top of all widgets, add toggle button at viewer header
* Reconnect socket on creating a new app, set connected status in store
* Retry socket connection flow
* Integration tests for comments with api mocks using msw
* Fix circular depependency
* rm file
* Minor cleanup and comments
* Minor refactors: move isScrolledToBottom to common hooks, decouple prevent interactions overlay from comments wrapper
* Use policies when pushing updates in RTS
* ENV var to set if comments are enabled
* Fix: check if editor/viewer is initialised before waiting for init action
* Add tests for comments reducer
* Revert "ENV var to set if comments are enabled"
This reverts commit 988efeaa69d378d943a387e1e73510334958adc5.
* Enable comments for users with appsmith email
* lint
* fix
* Try running a socket.io server inside backend
* Update comment reducer tests
* Init mentions within comments
* Fix comment thread updates with email rooms
* Minor fixes
* Refactors / review suggestions
* lint
* increase cache limit for builds
* Comment out tests for feature that's under development
* Add Dockerfile for RTS
* Fix policies missing for first comment in threads
* Use draftJS for comments input with mentions support
* fix fixtures
* Use thread's policies when querying for threads
* Update socket.io to v4
* Add support for richer body with mentions
* Update comment body type to RawDraftContentState
* fix stale method
* Fix mentions search
* Minor cleanups
* Comment context menu and thread UI updates
* revert: Scaffold app comments
* Yarn dependencies
* Delete comment using id api added
* Init app comments
* Add test for creating thread
* Api for delete comment with id
* Test comment creation response and policies
* Copy comment links
* Fix reset editor state
* Delete valid comment testcase added
* Delete comment TC : code refactor
* Don't allow creating comments with an empty body
* Pin comments WIP[]
* Ignore dependency-reduced-pom.xml files from VCS
* Cleanup of some dev-only files, for review
* Delete comment
* Update socket.io to v4 in RTS
* Pin and resolve comment thread object added in commentThread
* Pin and resolve comment thread object added in commentThread
* Update comment thread API
* Added creationTime and updationTime in comment thread response
* Added creationTime and updationTime in comment thread response
* Added human readable id to comment threads, fallback to username for null name in user document
* Refactor
* lint
* fix test, rm duplicate selector
* comment out saga used for dev
* CommentThread viewed status, username fallback for getName=null, username field added in pin & resolve status
* lint
* trigger tests
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Abhijeet <abhi.nagarnaik@gmail.com>
2021-04-29 10:33:51 +00:00
|
|
|
let target = io
|
|
|
|
|
let shouldEmit = false
|
|
|
|
|
|
|
|
|
|
for (const email of findPolicyEmails(comment.policies, "read:comments")) {
|
|
|
|
|
shouldEmit = true
|
|
|
|
|
console.log("Emitting comment to email", email)
|
|
|
|
|
target = target.to("email:" + email)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shouldEmit) {
|
|
|
|
|
const eventName = event.operationType + ":" + event.ns.coll
|
|
|
|
|
console.log("Emitting", eventName)
|
|
|
|
|
target.emit(eventName, { comment })
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const threadChangeStream = threadCollection.watch(
|
|
|
|
|
[
|
|
|
|
|
// Prevent server-internal fields from being sent to the client.
|
|
|
|
|
{
|
|
|
|
|
$unset: [
|
|
|
|
|
"deletedAt",
|
|
|
|
|
"deleted",
|
|
|
|
|
"_class",
|
|
|
|
|
].map(f => "fullDocument." + f)
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
{ fullDocument: "updateLookup" }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
threadChangeStream.on("change", async (event: mongodb.ChangeEventCR) => {
|
|
|
|
|
console.log("thread event", event)
|
|
|
|
|
const thread = event.fullDocument
|
|
|
|
|
if (thread == null) {
|
|
|
|
|
// This happens when `event.operationType === "drop"`, when a comment is deleted.
|
|
|
|
|
console.error("Null document recieved for comment change event", event)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 10:02:34 +00:00
|
|
|
thread.creationTime = thread.createdAt
|
|
|
|
|
thread.updationTime = thread.updatedAt
|
|
|
|
|
delete thread.createdAt
|
|
|
|
|
delete thread.updatedAt
|
|
|
|
|
thread.isViewed = false
|
|
|
|
|
|
Initialise comments (#3328)
* Initial scaffolding for comments CRUD APIs
* add actions
* add assets
* state management for existing comments and creating new
* add ui components
* add overlay comments wrapper to baseWidget
* add toggle comment mode button at editor header
* trigger tests
* Disallow commenting as someone else
* Add applicationId for comments
* lint
* Add overlay blacklist to prevent component interaction while adding comments
* Comment thread style updates
* Placeholder comment context menu
* Controlled comment thread visibility for making new comments visible by default
* Update comment type description
* Reset input on save
* Resolve comment thread button ui
* fix close on esc key, dont create new comment on outside click
* Submit on enter
* add emoji picker
* Attempt at adding a websocket server in Java
* CRUD APIs for comment threads
* Add API for getting all threads in application
* Move types to a separate file
* Initial commit for real time server (RTS)
* Add script to start RTS
* Fix position property
* Use create comment thread API
* Use add comment to thread API
* Add custom cursor
* Dispatch logout init on 401 errors
* Allow CORS for real time connection
* Add more logs to RTS
* Fix construction of MongoClient
* WIP: Real time comments
* Enable comments
* Minor updates
* Read backend API base URL from environment
* Escape to reset comments mode
* Set popover position as auto and boundary as scroll parent
* Disable warning
* Added permissions for comment threads
* Add resolved API for comment threads
* Migration to set commenting permission on existing apps
* Fix updates bringing the RTS down
* Show view latest button, scroll to bottom on creating a new comment
* Cleanup comment reducer
* Move to typescript for RTS
* Add missing server.ts and tsconfig files
* Resolve / unresolve comment
* Scaffold app comments
* Minor fixes: comment on top of all widgets, add toggle button at viewer header
* Reconnect socket on creating a new app, set connected status in store
* Retry socket connection flow
* Integration tests for comments with api mocks using msw
* Fix circular depependency
* rm file
* Minor cleanup and comments
* Minor refactors: move isScrolledToBottom to common hooks, decouple prevent interactions overlay from comments wrapper
* Use policies when pushing updates in RTS
* ENV var to set if comments are enabled
* Fix: check if editor/viewer is initialised before waiting for init action
* Add tests for comments reducer
* Revert "ENV var to set if comments are enabled"
This reverts commit 988efeaa69d378d943a387e1e73510334958adc5.
* Enable comments for users with appsmith email
* lint
* fix
* Try running a socket.io server inside backend
* Update comment reducer tests
* Init mentions within comments
* Fix comment thread updates with email rooms
* Minor fixes
* Refactors / review suggestions
* lint
* increase cache limit for builds
* Comment out tests for feature that's under development
* Add Dockerfile for RTS
* Fix policies missing for first comment in threads
* Use draftJS for comments input with mentions support
* fix fixtures
* Use thread's policies when querying for threads
* Update socket.io to v4
* Add support for richer body with mentions
* Update comment body type to RawDraftContentState
* fix stale method
* Fix mentions search
* Minor cleanups
* Comment context menu and thread UI updates
* revert: Scaffold app comments
* Yarn dependencies
* Delete comment using id api added
* Init app comments
* Add test for creating thread
* Api for delete comment with id
* Test comment creation response and policies
* Copy comment links
* Fix reset editor state
* Delete valid comment testcase added
* Delete comment TC : code refactor
* Don't allow creating comments with an empty body
* Pin comments WIP[]
* Ignore dependency-reduced-pom.xml files from VCS
* Cleanup of some dev-only files, for review
* Delete comment
* Update socket.io to v4 in RTS
* Pin and resolve comment thread object added in commentThread
* Pin and resolve comment thread object added in commentThread
* Update comment thread API
* Added creationTime and updationTime in comment thread response
* Added creationTime and updationTime in comment thread response
* Added human readable id to comment threads, fallback to username for null name in user document
* Refactor
* lint
* fix test, rm duplicate selector
* comment out saga used for dev
* CommentThread viewed status, username fallback for getName=null, username field added in pin & resolve status
* lint
* trigger tests
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Abhijeet <abhi.nagarnaik@gmail.com>
2021-04-29 10:33:51 +00:00
|
|
|
let target = io
|
|
|
|
|
let shouldEmit = false
|
|
|
|
|
|
|
|
|
|
for (const email of findPolicyEmails(thread.policies, "read:commentThreads")) {
|
|
|
|
|
shouldEmit = true
|
|
|
|
|
console.log("Emitting thread to email", email)
|
|
|
|
|
target = target.to("email:" + email)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shouldEmit) {
|
|
|
|
|
const eventName = event.operationType + ":" + event.ns.coll
|
|
|
|
|
console.log("Emitting", eventName)
|
|
|
|
|
target.emit(eventName, { thread })
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
process.on("exit", () => {
|
|
|
|
|
(commentChangeStream != null ? commentChangeStream.close() : Promise.bind(client).resolve())
|
|
|
|
|
.then(client.close.bind(client))
|
|
|
|
|
.finally("Fin")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
console.log("Watching MongoDB")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function findPolicyEmails(policies: Policy[], permission: string): string[] {
|
|
|
|
|
const emails: string[] = []
|
|
|
|
|
for (const policy of policies) {
|
|
|
|
|
if (policy.permission === permission) {
|
|
|
|
|
for (const email of policy.users) {
|
|
|
|
|
console.log("Emitting comment to email", email)
|
|
|
|
|
emails.push(email)
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return emails
|
|
|
|
|
}
|