Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 4a08e44

Browse files
Adds the ability to specify the workspace visibility (private/public) via the workspace configuration.
1 parent 58a84de commit 4a08e44

File tree

8 files changed

+109
-2
lines changed

8 files changed

+109
-2
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repositories {
99
}
1010

1111
dependencies {
12-
api 'com.structurizr:structurizr-client:1.25.1'
12+
api 'com.structurizr:structurizr-client:1.26.1'
1313
api 'com.structurizr:structurizr-import:1.5.0'
1414

1515
testImplementation 'org.codehaus.groovy:groovy-jsr223:3.0.16'
@@ -27,7 +27,7 @@ targetCompatibility = 11
2727

2828
description = 'Structurizr DSL'
2929
group = 'com.structurizr'
30-
version = '1.31.1'
30+
version = '1.32.0'
3131

3232
test {
3333
useJUnitPlatform()

docs/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.32.0 (28th July 2023)
4+
5+
- Adds the ability to specify the workspace `visibility` (private/public) via the workspace configuration.
6+
- Updates structurizr/java to [v1.26.1](https://github.com/structurizr/java/releases/tag/v1.26.1).
7+
38
## 1.31.1 (26th July 2023)
49

510
- Fixes https://github.com/structurizr/dsl/issues/308 (Hidden (e.g. .DS_Store) file causes exception during !include <directory>).

docs/language-reference.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,9 +1514,18 @@ configuration {
15141514

15151515
Permitted children:
15161516

1517+
- [visibility](#visibility)
15171518
- [users](#users)
15181519
- [properties](#properties)
15191520

1521+
### visibility
1522+
1523+
The `visibility` keyword can be used to set the [visibility of the workspace](https://structurizr.com/help/workspace-sharing).
1524+
1525+
```
1526+
visibility <private|public>
1527+
```
1528+
15201529
### users
15211530

15221531
The `users` block can be used to specify the users who should have read-only or read-write access to a workspace. Each username (e.g. e-mail address) and role pair should be specified on their own line. Valid roles are `read` (read-only) and `write` (read-write).

src/main/java/com/structurizr/dsl/ConfigurationDslContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
final class ConfigurationDslContext extends DslContext {
44

5+
private static final int FIRST_PROPERTY_INDEX = 1;
6+
7+
private static final String PRIVATE = "private";
8+
private static final String PUBLIC = "public";
9+
510
@Override
611
protected String[] getPermittedTokens() {
712
return new String[] {
13+
StructurizrDslTokens.VISIBILITY_TOKEN,
814
StructurizrDslTokens.USERS_TOKEN,
915
StructurizrDslTokens.PROPERTIES_TOKEN
1016
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.structurizr.dsl;
2+
3+
import com.structurizr.configuration.Visibility;
4+
5+
final class ConfigurationParser extends AbstractParser {
6+
7+
private static final String GRAMMAR = "visibility <private|public>";
8+
9+
private static final int FIRST_PROPERTY_INDEX = 1;
10+
11+
private static final String PRIVATE = "private";
12+
private static final String PUBLIC = "public";
13+
14+
void parseVisibility(DslContext context, Tokens tokens) {
15+
if (tokens.hasMoreThan(FIRST_PROPERTY_INDEX)) {
16+
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
17+
}
18+
19+
if (tokens.includes(FIRST_PROPERTY_INDEX)) {
20+
String visibility = tokens.get(1).toLowerCase();
21+
22+
if (visibility.equalsIgnoreCase(PRIVATE)) {
23+
context.getWorkspace().getConfiguration().setVisibility(Visibility.Private);
24+
} else if (visibility.equalsIgnoreCase(PUBLIC)) {
25+
context.getWorkspace().getConfiguration().setVisibility(Visibility.Public);
26+
} else {
27+
throw new RuntimeException("The visibility \"" + visibility + "\" is not valid");
28+
}
29+
} else {
30+
throw new RuntimeException("Expected: " + GRAMMAR);
31+
}
32+
}
33+
34+
}

src/main/java/com/structurizr/dsl/StructurizrDslParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,9 @@ void parse(List<String> lines, File dslFile) throws StructurizrDslParserExceptio
786786
} else if (CONFIGURATION_TOKEN.equalsIgnoreCase(firstToken) && inContext(WorkspaceDslContext.class)) {
787787
startContext(new ConfigurationDslContext());
788788

789+
} else if (VISIBILITY_TOKEN.equalsIgnoreCase(firstToken) && inContext(ConfigurationDslContext.class)) {
790+
new ConfigurationParser().parseVisibility(getContext(), tokens);
791+
789792
} else if (USERS_TOKEN.equalsIgnoreCase(firstToken) && inContext(ConfigurationDslContext.class)) {
790793
startContext(new UsersDslContext());
791794

src/main/java/com/structurizr/dsl/StructurizrDslTokens.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class StructurizrDslTokens {
8888
static final String THEME_TOKEN = "theme";
8989
static final String THEMES_TOKEN = "themes";
9090
static final String CONFIGURATION_TOKEN = "configuration";
91+
static final String VISIBILITY_TOKEN = "visibility";
9192
static final String TERMINOLOGY_TOKEN = "terminology";
9293
static final String TERMINOLOGY_RELATIONSHIP_TOKEN = "relationship";
9394
static final String USERS_TOKEN = "users";
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.structurizr.dsl;
2+
3+
import com.structurizr.configuration.Visibility;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.fail;
8+
9+
class ConfigurationParserTests extends AbstractTests {
10+
11+
private final ConfigurationParser parser = new ConfigurationParser();
12+
13+
@Test
14+
void test_parseVisibility_ThrowsAnException_WhenThereAreTooManyTokens() {
15+
try {
16+
parser.parseVisibility(context(), tokens("visibility", "public", "extra"));
17+
fail();
18+
} catch (Exception e) {
19+
assertEquals("Too many tokens, expected: visibility <private|public>", e.getMessage());
20+
}
21+
}
22+
23+
@Test
24+
void test_parseVisibility_ThrowsAnException_WhenTheVisibilityIsMissing() {
25+
try {
26+
parser.parseVisibility(context(), tokens("visibility"));
27+
fail();
28+
} catch (Exception e) {
29+
assertEquals("Expected: visibility <private|public>", e.getMessage());
30+
}
31+
}
32+
33+
@Test
34+
void test_parseVisibility_ThrowsAnException_WhenTheVisibilityIsNotValid() {
35+
try {
36+
parser.parseVisibility(context(), tokens("visibility", "shared"));
37+
fail();
38+
} catch (Exception e) {
39+
assertEquals("The visibility \"shared\" is not valid", e.getMessage());
40+
}
41+
}
42+
43+
@Test
44+
void test_parseVisibility_SetsTheVisibility() {
45+
parser.parseVisibility(context(), tokens("visibility", "public"));
46+
assertEquals(Visibility.Public, workspace.getConfiguration().getVisibility());
47+
}
48+
49+
}

0 commit comments

Comments
 (0)