Skip to content

Commit

Permalink
Update workspaces creation handler
Browse files Browse the repository at this point in the history
  • Loading branch information
aliraza556 committed May 31, 2024
1 parent 6bf4dcf commit 1f17919
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
20 changes: 12 additions & 8 deletions cypress/e2e/01_workspaces.cy.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { User, HostName, Workspaces } from '../support/objects/objects';


describe('Create Workspaces', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for(let i = 0; i <= 2; i++) {
for(let i = 0; i < Workspaces.length; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/`,
url: `${HostName}/workspaces`,
headers: { 'x-jwt': `${value}` },
body: Workspaces[i]
}).its('body').should('have.property', 'name', Workspaces[i].name.trim());
body: Workspaces[i],
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.have.property('name', Workspaces[i].name.trim());
});
}
})
})
})
});
});
});


describe('Edit Mission', () => {
it('passes', () => {
Expand Down
27 changes: 14 additions & 13 deletions handlers/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,22 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http

name := workspace.Name

// check if the organization name already exists
workspace_same_name := oh.db.GetWorkspaceByName(name)

if workspace_same_name.Name == name && workspace_same_name.Uuid != workspace.Uuid {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode("Workspace name already exists - " + name + " " + workspace.Uuid + " | " + workspace_same_name.Uuid)
// check if the workspace name already exists
workspaceSameName := oh.db.GetWorkspaceByName(name)
if workspaceSameName.Name == name {
w.WriteHeader(http.StatusConflict)
json.NewEncoder(w).Encode("Workspace name already exists - " + name)
return
} else {
workspace.Created = &now
workspace.Updated = &now
if len(workspace.Uuid) == 0 {
workspace.Uuid = xid.New().String()
}
workspace.Name = name
}

workspace.Created = &now
workspace.Updated = &now
if len(workspace.Uuid) == 0 {
workspace.Uuid = xid.New().String()
}
} else {
workspace.Updated = &now
workspace.Created = existing.Created
}

p, err := oh.db.CreateOrEditWorkspace(workspace)
Expand Down

0 comments on commit 1f17919

Please sign in to comment.