Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ frontend/coverage/

.DS_Store
Thumbs.db
.codex/config.toml
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and mitigation vertical slice:
- Ranked, evidence-backed replacement recommendations
- Persisted parent/child mitigation simulations with idempotent replay
- Stateless impact and mitigation previews for user-built draft organizations
- Stable public organization IDs and refresh-safe links for reopening editable
organization maps, inventories, and impact screens
- Draft recommendations that verify eligibility and workflow recovery after the
proposed role assignment, even when the candidate does not already have the
access that the new role would grant
Expand Down Expand Up @@ -60,9 +62,11 @@ docker compose up -d
In a second terminal, start the API:

```powershell
.\backend\mvnw.cmd spring-boot:run
\.\backend\mvnw.cmd spring-boot:run -Dspring-boot.run.profiles=dev
```

With the `dev` profile active, Boot UI is available at <http://localhost:8080/bootui>.

In a third terminal, install and start the frontend:

```powershell
Expand All @@ -75,6 +79,25 @@ amber impact paths, review Bob Chen's recommendation, and test the mitigation to
see the restored green relationship graph alongside the Low residual access
impact.

Editable organizations can be reopened from the homepage using their public ID
with or without the displayed hyphen. Anyone with an organization ID or link can
edit that organization in this portfolio MVP, so do not enter confidential or
personal data.

## Frontend routes

- `/example` opens the read-only Harborline example.
- `/organizations/{publicCode}/map` opens an editable organization map.
- `/organizations/{publicCode}/inventory` opens its detailed inventory.
- `/organizations/{publicCode}/impact` opens a fresh impact-testing screen.

Refreshing any of these routes keeps the same organization and screen. Impact
and mitigation results are intentionally temporary, so refreshing the impact
route clears the previous result while preserving the selected screen. Vite's
development and preview servers provide the required history fallback locally.
Production hosting must rewrite non-asset, non-API routes to
`frontend/index.html` so pasted organization links load correctly.

## API endpoints

- `GET /api/v1/dashboard` loads the default Harborline Commerce dashboard.
Expand All @@ -84,6 +107,12 @@ impact.
- `GET /api/v1/simulations/{simulationId}` retrieves an immutable saved result.
- `POST /api/v1/simulations/{simulationId}/branches` tests and saves a
recommendation as a child mitigation simulation.
- `POST /api/v1/workspaces` creates a blank editable organization and returns
its stable public code.
- `GET /api/v1/workspaces/by-code/{publicCode}` resolves an editable
organization. The Harborline example is intentionally excluded.
- `GET /api/v1/workspaces/{workspaceId}/catalog` loads the editable catalog
after the public code has been resolved.
- `POST /api/v1/workspaces/{workspaceId}/impact-previews` tests a role removal
against the current draft without changing it.
- `POST /api/v1/workspaces/{workspaceId}/impact-previews/mitigations` verifies a
Expand Down
42 changes: 37 additions & 5 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.16</version>
<version>4.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.roleimpact</groupId>
Expand All @@ -28,7 +28,23 @@
</scm>
<properties>
<java.version>21</java.version>
<bootui.version>1.14.1</bootui.version>
<jackson-bom.version>3.1.5</jackson-bom.version>
<jackson2-bom.version>2.21.5</jackson2-bom.version>
<log4j2.version>2.25.5</log4j2.version>
<postgresql.version>42.7.12</postgresql.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson2-bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -39,8 +55,8 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-flyway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -50,11 +66,22 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-jackson2</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>

<dependency>
<groupId>com.julien-dubois.bootui</groupId>
<artifactId>bootui-spring-boot-starter</artifactId>
<version>${bootui.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand All @@ -65,19 +92,24 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<artifactId>testcontainers-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<artifactId>testcontainers-postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

@Entity
@Table(name = "employees")
@Table(name = "employees", uniqueConstraints = {
@UniqueConstraint(
name = "uq_employees_organization_employee_no",
columnNames = { "organization_id", "employee_no" }),
@UniqueConstraint(
name = "uq_employees_organization_email",
columnNames = { "organization_id", "email" })
})
public class EmployeeEntity {

@Id
Expand All @@ -26,13 +34,13 @@ public class EmployeeEntity {
@Column(name = "team_id", nullable = false)
private UUID teamId;

@Column(name = "employee_no", unique = true, length = 40)
@Column(name = "employee_no", length = 40)
private String employeeNumber;

@Column(nullable = false, length = 160)
private String name;

@Column(unique = true, length = 254)
@Column(length = 254)
private String email;

@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public final class DeterministicImpactEngine implements ImpactEngine {
public static final String SCHEMA_VERSION = REQUEST_SCHEMA_VERSION;
public static final String ENGINE_VERSION = "1.2.0";

private static final int MAX_RECOMMENDATIONS = 2;
private static final Comparator<UUID> UUID_ORDER = Comparator.comparing(UUID::toString);
private static final Comparator<EntityRef> ENTITY_ORDER = Comparator
.comparing(EntityRef::name)
Expand Down Expand Up @@ -848,7 +847,6 @@ private static RecommendationOutcome recommendMitigations(
var role = snapshot.roles().get(roleId);
var orderedCandidates = safeCandidates.stream()
.sorted(RECOMMENDATION_ORDER)
.limit(MAX_RECOMMENDATIONS)
.toList();
var recommendations = new ArrayList<Recommendation>();
for (var index = 0; index < orderedCandidates.size(); index++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.roleimpact.workspace.api;

import java.net.URI;
import java.util.List;
import java.util.UUID;

import com.roleimpact.workspace.application.WorkspaceService;
Expand All @@ -27,32 +26,25 @@ public WorkspaceController(WorkspaceService workspaceService) {
this.workspaceService = workspaceService;
}

@GetMapping
public List<WorkspaceResource> list() {
return workspaceService.list();
}

@GetMapping("/{workspaceId}")
public WorkspaceResource get(@PathVariable UUID workspaceId) {
return workspaceService.get(workspaceId);
}

@GetMapping("/by-code/{publicCode}")
public WorkspaceResource getByCode(@PathVariable String publicCode) {
return workspaceService.getEditableByCode(publicCode);
}

@PostMapping
public ResponseEntity<WorkspaceResource> create(@Valid @RequestBody WorkspaceRequest request) {
return created(workspaceService.createBlank(request));
}

@PostMapping("/{sourceWorkspaceId}/clones")
public ResponseEntity<WorkspaceResource> clone(
@PathVariable UUID sourceWorkspaceId,
@Valid @RequestBody WorkspaceRequest request) {
return created(workspaceService.clonePublished(sourceWorkspaceId, request));
}

private ResponseEntity<WorkspaceResource> created(WorkspaceResource workspace) {
URI location = ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/api/v1/workspaces/{id}")
.buildAndExpand(workspace.id())
.path("/api/v1/workspaces/by-code/{publicCode}")
.buildAndExpand(workspace.publicCode())
.toUri();
return ResponseEntity.created(location).body(workspace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public record WorkspaceResource(
String name,
String status,
int currentVersion,
UUID sourceTemplateOrganizationId,
String publicCode,
Instant createdAt,
Instant updatedAt,
WorkspaceCounts counts) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.roleimpact.workspace.application;

import java.security.SecureRandom;
import java.text.Normalizer;
import java.util.Arrays;
import java.util.Locale;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.springframework.stereotype.Component;

@Component
public class WorkspaceCode {

private static final String ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
private static final int TOKEN_LENGTH = 16;
private static final Pattern SHORT_COMPACT = Pattern.compile("^[A-HJ-NP-Z2-9]{19}$");
private static final Pattern SHORT_DISPLAYED = Pattern.compile("^[A-HJ-NP-Z2-9]{3}-[A-HJ-NP-Z2-9]{16}$");
private static final Pattern LONG_COMPACT = Pattern.compile("^[A-HJ-NP-Z2-9]{3}[A-F0-9]{32}$");
private static final Pattern LONG_DISPLAYED = Pattern.compile("^[A-HJ-NP-Z2-9]{3}-[A-F0-9]{32}$");

private final SecureRandom random;

public WorkspaceCode() {
this(new SecureRandom());
}

WorkspaceCode(SecureRandom random) {
this.random = random;
}

public String generate(String organizationName) {
String asciiName = Normalizer.normalize(organizationName, Normalizer.Form.NFD)
.replaceAll("\\p{M}", "")
.toUpperCase(Locale.ROOT);
String initials = Arrays.stream(asciiName.split("[^A-Z0-9]+"))
.filter(token -> !token.isBlank())
.map(token -> token.substring(0, 1))
.collect(Collectors.joining());
String compactName = asciiName.replaceAll("[^A-Z0-9]", "");
String prefixSeed = sanitize(initials + compactName + "ORG");
StringBuilder token = new StringBuilder(TOKEN_LENGTH);
for (int index = 0; index < TOKEN_LENGTH; index++) {
token.append(ALPHABET.charAt(random.nextInt(ALPHABET.length())));
}
return prefixSeed.substring(0, 3) + "-" + token;
}

public static String normalize(String rawCode) {
if (rawCode == null) {
return null;
}
String candidate = rawCode.trim().toUpperCase(Locale.ROOT);
if (SHORT_COMPACT.matcher(candidate).matches() || LONG_COMPACT.matcher(candidate).matches()) {
candidate = candidate.substring(0, 3) + "-" + candidate.substring(3);
}
return SHORT_DISPLAYED.matcher(candidate).matches() || LONG_DISPLAYED.matcher(candidate).matches()
? candidate
: null;
}

private static String sanitize(String value) {
return value.replace('O', 'Q')
.replace('I', 'J')
.replace('0', '2')
.replace('1', '3')
.replaceAll("[^A-HJ-NP-Z2-9]", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ public class WorkspaceNotFoundException extends RuntimeException {
public WorkspaceNotFoundException(UUID id) {
super("Workspace not found: " + id);
}

public WorkspaceNotFoundException(String publicCode) {
super("Organization not found: " + publicCode);
}
}
Loading
Loading