Skip to content

Commit

Permalink
api: update EditNamespace get owner by id instead of username
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavosbarreto committed Mar 19, 2021
1 parent 10f54ae commit da4e613
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/nsadm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func (s *service) ListMembers(ctx context.Context, namespace string) ([]models.M
return []models.Member{}, ErrNamespaceNotFound
}

func (s *service) EditNamespace(ctx context.Context, namespace, name, ownerUsername string) (*models.Namespace, error) {
func (s *service) EditNamespace(ctx context.Context, namespace, name, owner string) (*models.Namespace, error) {
ns, _ := s.store.GetNamespace(ctx, namespace)
if ns != nil {
user, _ := s.store.GetUserByUsername(ctx, ownerUsername)
user, _ := s.store.GetUserByID(ctx, owner)
if user != nil {
validate := validator.New()
name = strings.ToLower(name)
Expand Down
2 changes: 1 addition & 1 deletion api/nsadm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestEditNamespace(t *testing.T) {
namespace := &models.Namespace{Name: "oldname", Owner: "hash1", TenantID: "a736a52b-5777-4f92-b0b8-e359bf484713"}
namespaceWithNewName := &models.Namespace{Name: "newname", Owner: "hash1", TenantID: "a736a52b-5777-4f92-b0b8-e359bf484713"}

mock.On("GetUserByUsername", ctx, user.Username).Return(user, nil).Once()
mock.On("GetUserByID", ctx, user.ID).Return(user, nil).Once()
mock.On("GetNamespace", ctx, namespace.TenantID).Return(namespace, nil).Twice()
mock.On("EditNamespace", ctx, namespace.TenantID, newName).Return(namespaceWithNewName, nil).Once()
_, err := s.EditNamespace(ctx, namespace.TenantID, newName, namespace.Owner)
Expand Down
8 changes: 4 additions & 4 deletions api/routes/nsadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ func EditNamespace(c apicontext.Context) error {
Name string `json:"name"`
}

username := ""
if v := c.Username(); v != nil {
username = v.ID
id := ""
if v := c.ID(); v != nil {
id = v.ID
}

if err := c.Bind(&req); err != nil {
return err
}

namespace, err := svc.EditNamespace(c.Ctx(), c.Param("id"), req.Name, username)
namespace, err := svc.EditNamespace(c.Ctx(), c.Param("id"), req.Name, id)
if err != nil {
if err == nsadm.ErrUnauthorized {
return c.NoContent(http.StatusForbidden)
Expand Down

0 comments on commit da4e613

Please sign in to comment.