From c40ca71b0b34568b1624501ff29ab24ff1b8f30e Mon Sep 17 00:00:00 2001 From: elraphty Date: Mon, 17 Feb 2025 23:14:27 +0100 Subject: [PATCH] added check for duplicate workspaces --- handlers/workspaces.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/handlers/workspaces.go b/handlers/workspaces.go index 207809204..816e68e4a 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -505,16 +505,34 @@ func (oh *workspaceHandler) GetUserDropdownWorkspaces(w http.ResponseWriter, r * hasRole := oh.configUserHasAccess(user.OwnerPubKey, uuid, db.ViewReport) hasBountyRoles := oh.configUserHasManageBountyRoles(user.OwnerPubKey, uuid) + alreadyAdded := false + + if workspace.OwnerPubKey == user.OwnerPubKey { + alreadyAdded = true + } + // don't add deleted workspaces to the list if !workspace.Deleted && hasBountyRoles { - if hasRole { + + // check if workspace has already been added to the list + for _, existingWorkspace := range workspaces { + if existingWorkspace.Uuid == workspace.Uuid { + alreadyAdded = true + } + } + + if hasRole && !alreadyAdded { budget := oh.db.GetWorkspaceBudget(uuid) workspace.Budget = budget.TotalBudget } else { workspace.Budget = 0 } + workspace.BountyCount = bountyCount - workspaces = append(workspaces, workspace) + + if !alreadyAdded { + workspaces = append(workspaces, workspace) + } } }