@@ -48,9 +48,10 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
4848 tx.run(
4949 """
5050 |MATCH (workspace :Workspace)
51- |WHERE (:User { username: {currentUser} })-[:FOLLOWING|:CREATED ]->(workspace) OR workspace.isPublic
51+ |WHERE (:User { username: {currentUser} })-[:FOLLOWING|:OWNS ]->(workspace) OR workspace.isPublic
5252 |MATCH (creator :User)-[:CREATED]->(workspace)<-[:FOLLOWING]-(follower :User)
53- |RETURN workspace, creator, collect(distinct follower) as followers
53+ |MATCH (owner :User)-[:OWNS]->(workspace)
54+ |RETURN workspace, creator, owner, collect(distinct follower) as followers
5455 """ .stripMargin,
5556 parameters(
5657 " currentUser" , currentUser
@@ -59,9 +60,10 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
5960 summary.list().asScala.toList.map { r =>
6061 val workspace = r.get(" workspace" )
6162 val creator = DBUser .fromNeo4jValue(r.get(" creator" ))
63+ val owner = DBUser .fromNeo4jValue(r.get(" owner" ))
6264 val followers = r.get(" followers" ).asList[DBUser ](DBUser .fromNeo4jValue(_)).asScala.toList
6365
64- WorkspaceMetadata .fromNeo4jValue(workspace, creator, followers)
66+ WorkspaceMetadata .fromNeo4jValue(workspace, creator, owner, followers)
6567 }
6668 }
6769 }
@@ -70,9 +72,10 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
7072 tx.run(
7173 """
7274 |MATCH (workspace :Workspace {id: {id} })
73- |WHERE (:User { username: {currentUser} })-[:FOLLOWING|:CREATED ]->(workspace) OR workspace.isPublic
75+ |WHERE (:User { username: {currentUser} })-[:FOLLOWING|:OWNS ]->(workspace) OR workspace.isPublic
7476 |MATCH (creator :User)-[:CREATED]->(workspace)<-[:FOLLOWING]-(follower :User)
75- |RETURN workspace, creator, collect(distinct follower) as followers
77+ |MATCH (owner :User)-[:OWNS]->(workspace)
78+ |RETURN workspace, creator, owner, collect(distinct follower) as followers
7679 """ .stripMargin,
7780 parameters(
7881 " currentUser" , currentUser,
@@ -85,9 +88,10 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
8588 ).map { r =>
8689 val workspace = r.head.get(" workspace" )
8790 val creator = DBUser .fromNeo4jValue(r.head.get(" creator" ))
91+ val owner = DBUser .fromNeo4jValue(r.head.get(" owner" ))
8892 val followers = r.head.get(" followers" ).asList[DBUser ](DBUser .fromNeo4jValue(_)).asScala.toList
8993
90- WorkspaceMetadata .fromNeo4jValue(workspace, creator, followers)
94+ WorkspaceMetadata .fromNeo4jValue(workspace, creator, owner, followers)
9195 }
9296 }
9397 }
@@ -96,9 +100,10 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
96100 tx.run(
97101 """
98102 |MATCH (workspace: Workspace { id: {id} })
99- |WHERE (:User { username: {currentUser} })-[:FOLLOWING|:CREATED ]->(workspace) OR workspace.isPublic
103+ |WHERE (:User { username: {currentUser} })-[:FOLLOWING|:OWNS ]->(workspace) OR workspace.isPublic
100104 |
101105 |OPTIONAL MATCH (workspace)<-[:PART_OF]-(node :WorkspaceNode)<-[:CREATED]-(nodeCreator :User)
106+ |
102107 |OPTIONAL MATCH (node)-[:PARENT]->(parentNode :WorkspaceNode)
103108 |
104109 |OPTIONAL MATCH (:Resource {uri: node.uri})<-[todo:TODO|:PROCESSING_EXTERNALLY]-(:Extractor)
@@ -147,6 +152,7 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
147152 |CREATE (w: Workspace {id: {id}, name: {name}, isPublic: {isPublic}, tagColor: {tagColor}})
148153 |CREATE (w)<-[:CREATED]-(u)
149154 |CREATE (w)<-[:FOLLOWING]-(u)
155+ |CREATE (w)<-[:OWNS]-(u)
150156 |
151157 |CREATE (u)-[:CREATED]->(f: WorkspaceNode {id: {rootFolderId}, name: {name}, type: 'folder'})-[:PART_OF]->(w)
152158 |
@@ -170,10 +176,10 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
170176 override def updateWorkspaceFollowers (currentUser : String , id : String , followers : List [String ]): Attempt [Unit ] = attemptTransaction { tx =>
171177 tx.run(
172178 """
173- |MATCH (workspace :Workspace {id: {workspaceId}})<-[:CREATED ]-(creator :User {username: {username}})
179+ |MATCH (workspace :Workspace {id: {workspaceId}})<-[:OWNS ]-(owner :User {username: {username}})
174180 |
175181 |OPTIONAL MATCH (existingFollower :User)-[existingFollow :FOLLOWING]->(workspace)
176- | WHERE existingFollower.username <> creator .username
182+ | WHERE existingFollower.username <> owner .username
177183 |
178184 |OPTIONAL MATCH (newFollower :User)
179185 | WHERE newFollower.username IN {followers}
@@ -201,7 +207,7 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
201207 override def updateWorkspaceIsPublic (currentUser : String , id : String , isPublic : Boolean ): Attempt [Unit ] = attemptTransaction { tx =>
202208 tx.run(
203209 """
204- |MATCH (workspace :Workspace {id: {workspaceId}})<-[:CREATED ]-(creator :User {username: {username}})
210+ |MATCH (workspace :Workspace {id: {workspaceId}})<-[:OWNS ]-(owner :User {username: {username}})
205211 |
206212 |SET workspace.isPublic = {isPublic}
207213 |
@@ -222,7 +228,7 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
222228 override def updateWorkspaceName (currentUser : String , id : String , name : String ): Attempt [Unit ] = attemptTransaction { tx =>
223229 tx.run(
224230 """
225- |MATCH (rootNode :WorkspaceNode)-[:PART_OF]->(workspace :Workspace {id: {workspaceId}})<-[:CREATED ]-(creator :User {username: {username}})
231+ |MATCH (rootNode :WorkspaceNode)-[:PART_OF]->(workspace :Workspace {id: {workspaceId}})<-[:OWNS ]-(owner :User {username: {username}})
226232 | WHERE NOT exists((rootNode)-[:PARENT]->(:WorkspaceNode))
227233 |
228234 |SET workspace.name = {name}
@@ -241,11 +247,36 @@ class Neo4jAnnotations(driver: Driver, executionContext: ExecutionContext, query
241247 }
242248 }
243249
250+ override def updateWorkspaceOwner (currentUser : String , id : String , owner : String ): Attempt [Unit ] = attemptTransaction { tx =>
251+ val query = """
252+ MATCH (user: User { username: {username}})
253+ |MATCH (newOwner: User { username: {owner}})
254+ |MATCH (workspace: Workspace {id:{workspaceId}} )<-[ownsRelationship:OWNS]-(currentOwner:User)
255+ |WHERE (:Permission {name: "CanPerformAdminOperations"})<-[:HAS_PERMISSION]-(user)
256+ |CREATE (workspace)<-[:FOLLOWING]-(newOwner)
257+ |CREATE (workspace)<-[:OWNS]-(newOwner)
258+ |DELETE ownsRelationship
259+ """ .stripMargin
260+ tx.run(
261+ query,
262+ parameters(
263+ " workspaceId" , id,
264+ " owner" , owner,
265+ " username" , currentUser
266+ )
267+ ).flatMap {
268+ case r if r.summary().counters().relationshipsCreated() != 2 =>
269+ Attempt .Left (IllegalStateFailure (s " Error when updating workspace owner, unexpected properties set ${r.summary().counters().propertiesSet()}" ))
270+ case _ =>
271+ Attempt .Right (())
272+ }
273+ }
274+
244275 override def deleteWorkspace (currentUser : String , workspace : String ): Attempt [Unit ] = attemptTransaction { tx =>
245276 tx.run(
246277 """
247278 |MATCH (user: User { username: {username} })
248- |MATCH (workspace: Workspace {id: {workspaceId}})<-[:CREATED ]-(u:User)
279+ |MATCH (workspace: Workspace {id: {workspaceId}})<-[:OWNS ]-(u:User)
249280 |WHERE u.username = {username} OR (workspace.isPublic and (:Permission {name: "CanPerformAdminOperations"})<-[:HAS_PERMISSION]-(user))
250281 |MATCH (workspace)<-[:PART_OF]-(node: WorkspaceNode)
251282 |
0 commit comments