Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added include_deleted to getWorkspaceByOwnerAndName #2164

Merged
merged 10 commits into from Jun 8, 2022

Conversation

Kira-Pilot
Copy link
Member

relates to #1955

I'm working on #1955: a ticket that will show deleted workspaces in our UI.
@f0ssel made some helpful changes to getWorkspaces in #2095 to help support the aforementioned UI change.
However, @BrunoQuaresma recently updated the Workspace page so that it no longer uses the getWorkspace route, instead favoring getWorkspaceByOwnerAndName.

This PR attempts to add an include_deleted param to getWorkspaceByOwnerAndName so I can continue work on #1955. I've never touched Go before so please let me know what I've broken 馃Ч

P.S. It would be great to generate a type for this addition but idk how to do that.

@Kira-Pilot Kira-Pilot requested review from a team June 8, 2022 13:14
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just a couple of things:

  1. I think we don't need to actually check if the include_deleted parameter is a valid boolean; just checking if it is equal to the string true should be enough here. I know this is taken from existing code though, so I'm willing to defer to others on this.
  2. Would it be possible to add a unit test for this new behaviour in workspace_test.go? I'm up for pairing on this with you if you'd like!

coderd/workspaces.go Outdated Show resolved Hide resolved
workspace, err = api.Database.GetWorkspaceByOwnerIDAndName(r.Context(), database.GetWorkspaceByOwnerIDAndNameParams{
OwnerID: owner.ID,
Name: workspaceName,
Deleted: includeDeleted,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works as intended. The param here in the SQL matches for deleted = $includeDeleted.

So if you set this to true, the workspace will not show if the workspace is deleted. We will need to update the SQL too, or just always return deleted workspaces by default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See how it's handled here:

if workspace.Deleted && !showDeleted {
httpapi.Write(rw, http.StatusGone, httpapi.Response{
Message: fmt.Sprintf("Workspace %q was deleted, you can view this workspace by specifying '?deleted=true' and trying again.", workspace.ID.String()),
})
return
}

I think the deleted query param is kinda annoying as you have to know the state of the workspace to query it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Emyrk Hmm, testing it in the UI seems to work.

  1. if include_deleted is false, then we never enter this code block (because errors.Is(err, sql.ErrNoRows) is false
  2. otherwise we enter this code block and try to query for a deleted workspace

In either case, if we get nothing back, we then go into the httpapi.Forbidden(rw) block below. I agree editing the SQL would also work. I just didn't know what other ramifications that would have.

Let me know if I'm misunderstanding your comment!

@Kira-Pilot
Copy link
Member Author

@johnstcn
Thanks! Would love to pair on that test; maybe a little later today if you have time?

Copy link
Contributor

@presleyp presleyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this tagged the frontend for review but I'm approving to unblock you on that front!

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some drive-by code style suggestions, looks good to me!

coderd/workspaces.go Outdated Show resolved Hide resolved
coderd/workspaces.go Outdated Show resolved Hide resolved
coderd/workspaces.go Outdated Show resolved Hide resolved
Kira-Pilot and others added 5 commits June 8, 2022 10:25
defining vars in the scope of conditional

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
avoid newline

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks Kira!

coderd/workspaces_test.go Outdated Show resolved Hide resolved
@@ -83,6 +83,7 @@
"workspaceapp",
"workspaceapps",
"workspacebuilds",
"workspacename",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃憤

@Kira-Pilot Kira-Pilot merged commit 3bc122b into main Jun 8, 2022
@Kira-Pilot Kira-Pilot deleted the add-includes-deleted/kira-pilot branch June 8, 2022 18:04
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
* feat: added include_deleted

relates to #1955

* Update coderd/workspaces.go

defining vars in the scope of conditional

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update coderd/workspaces.go

avoid newline

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update coderd/workspaces.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* PR feedback

* wrote test, added type

* Update coderd/workspaces_test.go

shortening test name

Co-authored-by: Cian Johnston <cian@coder.com>

* taking out api.ts change for now

* casing

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Co-authored-by: Cian Johnston <cian@coder.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants