Skip to content

Commit

Permalink
don't pass group ID to get repositories call
Browse files Browse the repository at this point in the history
  • Loading branch information
JAORMX committed Sep 25, 2023
1 parent 43ced75 commit a5a5476
Show file tree
Hide file tree
Showing 6 changed files with 1,602 additions and 1,650 deletions.
1 change: 0 additions & 1 deletion docs/docs/protodocs/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions internal/controlplane/handlers_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,6 @@ func (s *Server) GetRepositoryById(ctx context.Context,
return nil, status.Errorf(codes.InvalidArgument, "repository id not specified")
}

// if we do not have a group, check if we can infer it
if in.GroupId == 0 {
group, err := auth.GetDefaultGroup(ctx)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "cannot infer group id")
}
in.GroupId = group
}

// check if user is authorized
if !IsRequestAuthorized(ctx, in.GroupId) {
return nil, status.Errorf(codes.PermissionDenied, "user is not authorized to access this resource")
}

// read the repository
repo, err := s.store.GetRepositoryByID(ctx, in.RepositoryId)
if errors.Is(err, sql.ErrNoRows) {
Expand All @@ -280,7 +266,10 @@ func (s *Server) GetRepositoryById(ctx context.Context,
return nil, status.Errorf(codes.Internal, "cannot read repository: %v", err)
}

if repo.GroupID != in.GroupId {
groupID := repo.GroupID

// check if user is authorized
if !IsRequestAuthorized(ctx, groupID) {
return nil, status.Errorf(codes.PermissionDenied, "user is not authorized to access this resource")
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/generated/openapi/mediator/v1/mediator.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a5a5476

Please sign in to comment.