Skip to content

armgit / posta

Public Imported from GitHub
0

Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.

feat(workspace): prevent deletion of personal workspaces

Jonas Kaninda2ea132b4ffe5
diff --git a/internal/handlers/workspace_handler.go b/internal/handlers/workspace_handler.go
index f36f218..bde0c6f 100644
--- a/internal/handlers/workspace_handler.go
+++ b/internal/handlers/workspace_handler.go
@@ -288,6 +288,14 @@ func (h *WorkspaceHandler) Update(c *okapi.Context, req *UpdateWorkspaceRequest)
func (h *WorkspaceHandler) Delete(c *okapi.Context) error {
wsID := c.GetInt("workspace_id")
+ ws, err := h.workspaceRepo.FindByID(uint(wsID))
+ if err != nil {
+ return c.AbortNotFound("workspace not found")
+ }
+ if ws.IsPersonal {
+ return c.AbortBadRequest("personal workspace cannot be deleted")
+ }
+
if err := h.workspaceRepo.Delete(uint(wsID)); err != nil {
return c.AbortInternalServerError("failed to delete workspace")
}
diff --git a/web/src/views/workspaces/WorkspaceSettings.vue b/web/src/views/workspaces/WorkspaceSettings.vue
index e9735f7..ed84dd0 100644
--- a/web/src/views/workspaces/WorkspaceSettings.vue
+++ b/web/src/views/workspaces/WorkspaceSettings.vue
@@ -94,6 +94,8 @@ const myRole = computed(() => {
})
const isAdminOrOwner = computed(() => myRole.value === 'owner' || myRole.value === 'admin')
const isOwner = computed(() => myRole.value === 'owner')
+// Personal workspaces are auto-provisioned and cannot be deleted (enforced server-side).
+const isPersonal = computed(() => ws.value?.is_personal ?? false)
async function withWorkspace<T>(fn: () => Promise<T>): Promise<T> {
const prevWs = wsStore.currentWorkspaceId
@@ -615,13 +617,18 @@ watch(activeTab, (value) => {
</div>
</div>
- <div v-if="isOwner" class="card-body" style="border-top: 1px solid var(--border-primary);">
+ <div v-if="isOwner && !isPersonal" class="card-body" style="border-top: 1px solid var(--border-primary);">
<h4 style="color: var(--danger-600); margin-bottom: 8px;">Danger Zone</h4>
<p style="font-size: 13px; color: var(--text-muted); margin-bottom: 12px;">
Deleting this workspace will permanently remove all its resources. This cannot be undone.
</p>
<button class="btn btn-danger" @click="deleteWorkspace">Delete Workspace</button>
</div>
+ <div v-else-if="isOwner && isPersonal" class="card-body" style="border-top: 1px solid var(--border-primary);">
+ <p style="font-size: 13px; color: var(--text-muted);">
+ This is your personal workspace and cannot be deleted. It is removed only if you delete your account.
+ </p>
+ </div>
</div>
<!-- Data Management (GDPR) Tab — admin/owner only -->