Skip to content

Commit f4d14d7

Browse files
committed
fix(mps-sync-plugin): persist whether a connection should be used for a specific repository only
When a new connection is added via `IModelSyncService.addServer` a repository ID can optionally be provided and then the connection is only used for that repository and the JWT token will usually also only be valid for that repository. The `modelix.xml` previously didn't make this distinction and when the state was reloaded from disk a previously global connection turned into a repository scoped one.
1 parent 93c7ac3 commit f4d14d7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ModelSyncService.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ class ModelSyncService(val project: Project) :
192192
bindings.map { bindingEntry ->
193193
Element("binding").also {
194194
it.children.add(Element("enabled").also { it.text = bindingEntry.value.enabled.toString() })
195-
it.children.add(Element("url").also { it.text = bindingEntry.key.connectionProperties.url })
195+
it.children.add(
196+
Element("url").also {
197+
it.text = bindingEntry.key.connectionProperties.url
198+
it.setAttribute("repositoryScoped", "${bindingEntry.key.connectionProperties.repositoryId != null}")
199+
},
200+
)
196201
bindingEntry.key.connectionProperties.oauthClientId?.let { oauthClientId ->
197202
it.children.add(Element("oauthClientId").also { it.text = oauthClientId })
198203
}
@@ -214,7 +219,7 @@ class ModelSyncService(val project: Project) :
214219
BindingId(
215220
connectionProperties = ModelServerConnectionProperties(
216221
url = element.getChild("url")?.text ?: return@mapNotNull null,
217-
repositoryId = repositoryId,
222+
repositoryId = repositoryId.takeIf { element.getChild("url")?.getAttribute("repositoryScoped")?.value != "false" },
218223
oauthClientId = element.getChild("oauthClientId")?.text,
219224
oauthClientSecret = element.getChild("oauthClientSecret")?.text,
220225
),
@@ -288,7 +293,7 @@ class ModelSyncService(val project: Project) :
288293
val id = BindingId(connection.properties, branchRef)
289294
updateBindingState(id) { oldBinding ->
290295
BindingState(
291-
versionHash = lastSyncedVersionHash ?: oldBinding?.versionHash,
296+
versionHash = lastSyncedVersionHash ?: oldBinding.versionHash,
292297
enabled = true,
293298
)
294299
}

mps-sync-plugin3/src/test/kotlin/org/modelix/mps/sync3/ProjectSyncTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ class ProjectSyncTest : MPSTestBase() {
549549
<component name="modelix-sync">
550550
<binding>
551551
<enabled>true</enabled>
552-
<url>http://localhost:$port</url>
552+
<url repositoryScoped="false">http://localhost:$port</url>
553553
<repository>${branchRef.repositoryId.id}</repository>
554554
<branch>${branchRef.branchName}</branch>
555555
<versionHash>${version1.getContentHash()}</versionHash>

0 commit comments

Comments
 (0)