Skip to content

Commit

Permalink
Fixes #98
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Dec 27, 2023
1 parent 6939784 commit 9f47ec8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

@Controller
public class DecisionsController extends AbstractWorkspaceController {

Expand Down Expand Up @@ -55,7 +58,7 @@ public String showPublicDecisions(
@PathVariable("component") String component,
ModelMap model
) {
model.addAttribute("scope", toScope(softwareSystem, container, component));
model.addAttribute("scope", Base64.getEncoder().encodeToString(toScope(softwareSystem, container, component).getBytes(StandardCharsets.UTF_8)));
model.addAttribute("showHeader", true);

return showPublicView(VIEW, workspaceId, version, model, false);
Expand Down Expand Up @@ -104,7 +107,7 @@ public String showSharedDecisions(
@PathVariable("token") String token,
ModelMap model
) {
model.addAttribute("scope", toScope(softwareSystem, container, component));
model.addAttribute("scope", Base64.getEncoder().encodeToString(toScope(softwareSystem, container, component).getBytes(StandardCharsets.UTF_8)));
model.addAttribute("showHeader", true);

return showSharedView(VIEW, workspaceId, token, version, model, false);
Expand Down Expand Up @@ -155,19 +158,19 @@ public String showAuthenticatedDecisions(
return show404Page(model);
}

model.addAttribute("scope", toScope(softwareSystem, container, component));
model.addAttribute("scope", Base64.getEncoder().encodeToString(toScope(softwareSystem, container, component).getBytes(StandardCharsets.UTF_8)));
model.addAttribute("showHeader", true);

return showAuthenticatedView(VIEW, workspaceMetaData, version, model, false, false);
}

String toScope(String softwareSystem, String container, String component) {
if (softwareSystem != null && container != null && component != null) {
return HtmlUtils.filterHtml(softwareSystem) + "/" + HtmlUtils.filterHtml(container) + "/" + HtmlUtils.filterHtml(component);
return softwareSystem + "/" + container + "/" + component;
} else if (softwareSystem != null && container != null) {
return HtmlUtils.filterHtml(softwareSystem) + "/" + HtmlUtils.filterHtml(container);
return softwareSystem + "/" + container;
} else if (softwareSystem != null) {
return HtmlUtils.filterHtml(softwareSystem);
return softwareSystem;
} else {
return WORKSPACE_SCOPE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.structurizr.onpremises.web.workspace;

import com.structurizr.onpremises.component.workspace.WorkspaceMetaData;
import com.structurizr.onpremises.util.HtmlUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
Expand All @@ -10,6 +9,9 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

@Controller
public class DocumentationController extends AbstractWorkspaceController {

Expand Down Expand Up @@ -55,7 +57,7 @@ public String showPublicDocumentation(
@PathVariable("component") String component,
ModelMap model
) {
model.addAttribute("scope", toScope(softwareSystem, container, component));
model.addAttribute("scope", Base64.getEncoder().encodeToString(toScope(softwareSystem, container, component).getBytes(StandardCharsets.UTF_8)));
model.addAttribute("showHeader", true);

return showPublicView(VIEW, workspaceId, version, model, false);
Expand Down Expand Up @@ -104,7 +106,7 @@ public String showSharedDocumentation(
@PathVariable("token") String token,
ModelMap model
) {
model.addAttribute("scope", toScope(softwareSystem, container, component));
model.addAttribute("scope", Base64.getEncoder().encodeToString(toScope(softwareSystem, container, component).getBytes(StandardCharsets.UTF_8)));
model.addAttribute("showHeader", true);

return showSharedView(VIEW, workspaceId, token, version, model, false);
Expand Down Expand Up @@ -155,19 +157,19 @@ public String showAuthenticatedDocumentation(
return show404Page(model);
}

model.addAttribute("scope", toScope(softwareSystem, container, component));
model.addAttribute("scope", Base64.getEncoder().encodeToString(toScope(softwareSystem, container, component).getBytes(StandardCharsets.UTF_8)));
model.addAttribute("showHeader", true);

return showAuthenticatedView(VIEW, workspaceMetaData, version, model, false, false);
}

String toScope(String softwareSystem, String container, String component) {
if (softwareSystem != null && container != null && component != null) {
return HtmlUtils.filterHtml(softwareSystem) + "/" + HtmlUtils.filterHtml(container) + "/" + HtmlUtils.filterHtml(component);
return softwareSystem + "/" + container + "/" + component;
} else if (softwareSystem != null && container != null) {
return HtmlUtils.filterHtml(softwareSystem) + "/" + HtmlUtils.filterHtml(container);
return softwareSystem + "/" + container;
} else if (softwareSystem != null) {
return HtmlUtils.filterHtml(softwareSystem);
return softwareSystem;
} else {
return WORKSPACE_SCOPE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/share/1", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand Down Expand Up @@ -154,7 +154,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/share/1/token", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand Down Expand Up @@ -213,7 +213,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/workspace/1", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand All @@ -238,7 +238,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/workspace/1", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand All @@ -263,7 +263,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/workspace/1", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/share/1", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand Down Expand Up @@ -154,7 +154,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/share/1/token", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand Down Expand Up @@ -213,7 +213,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/workspace/1", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand All @@ -238,7 +238,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/workspace/1", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand All @@ -263,7 +263,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom
assertSame(workspaceMetaData, model.getAttribute("workspace"));
assertEquals("anNvbg==", model.getAttribute("workspaceAsJson"));
assertEquals("/workspace/1", model.getAttribute("urlPrefix"));
assertEquals("*", model.getAttribute("scope"));
assertEquals("Kg==", model.getAttribute("scope"));
}

@Test
Expand Down

0 comments on commit 9f47ec8

Please sign in to comment.