Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Linting
  • Loading branch information
Emyrk committed May 3, 2022
commit 117f838c5c527e983a667d70b6d3a0e565d49f48
14 changes: 0 additions & 14 deletions coderd/coderd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ package coderd_test

import (
"context"
"fmt"
"net/http"
"testing"

"github.com/coder/coder/coderd"
"github.com/go-chi/chi/v5"

"go.uber.org/goleak"

"github.com/stretchr/testify/require"
Expand All @@ -29,12 +24,3 @@ func TestBuildInfo(t *testing.T) {
require.Equal(t, buildinfo.ExternalURL(), buildInfo.ExternalURL, "external URL")
require.Equal(t, buildinfo.Version(), buildInfo.Version, "version")
}

func TestWalk(t *testing.T) {
r, _ := coderd.New(&coderd.Options{})
chiRouter := r.(chi.Router)
chi.Walk(chiRouter, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
fmt.Println(method, route)
return nil
})
}
3 changes: 2 additions & 1 deletion coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@ func (q *fakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams
return tmp, nil
}

func (q *fakeQuerier) GetAllUserRoles(ctx context.Context, userID uuid.UUID) (database.GetAllUserRolesRow, error) {
func (q *fakeQuerier) GetAllUserRoles(_ context.Context, userID uuid.UUID) (database.GetAllUserRolesRow, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

var user *database.User
roles := make([]string, 0)
for _, u := range q.users {
if u.ID == userID {
u := u
roles = append(roles, u.RBACRoles...)
user = &u
break
Expand Down
3 changes: 1 addition & 2 deletions coderd/httpmw/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package httpmw

import (
"context"
"fmt"
"net/http"

"golang.org/x/xerrors"
Expand Down Expand Up @@ -111,7 +110,7 @@ func ExtractUserRoles(db database.Store) func(http.Handler) http.Handler {
role, err := db.GetAllUserRoles(r.Context(), apiKey.UserID)
if err != nil {
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
Message: fmt.Sprintf("roles not found", AuthCookie),
Message: "roles not found",
})
return
}
Expand Down
4 changes: 2 additions & 2 deletions coderd/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
)

// assignableSiteRoles returns all site wide roles that can be assigned.
func (api *api) assignableSiteRoles(rw http.ResponseWriter, r *http.Request) {
func (*api) assignableSiteRoles(rw http.ResponseWriter, _ *http.Request) {
// TODO: @emyrk in the future, allow granular subsets of roles to be returned based on the
// role of the user.
roles := rbac.SiteRoles()
httpapi.Write(rw, http.StatusOK, roles)
}

// assignableSiteRoles returns all site wide roles that can be assigned.
func (api *api) assignableOrgRoles(rw http.ResponseWriter, r *http.Request) {
func (*api) assignableOrgRoles(rw http.ResponseWriter, r *http.Request) {
// TODO: @emyrk in the future, allow granular subsets of roles to be returned based on the
// role of the user.
organization := httpmw.OrganizationParam(r)
Expand Down
3 changes: 2 additions & 1 deletion coderd/roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"net/http"
"testing"

"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/coderd/rbac"
"github.com/coder/coder/codersdk"
"github.com/stretchr/testify/require"
)

func TestListRoles(t *testing.T) {
Expand Down