Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: wang yan <[email protected]>
  • Loading branch information
wy65701436 committed Aug 14, 2024
1 parent c06dd64 commit e3df940
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7846,7 +7846,7 @@ definitions:
type: array
items:
$ref: '#/definitions/RobotPermission'
Creator:
creator:
type: string
description: The creator of the robot
creation_time:
Expand Down
2 changes: 1 addition & 1 deletion make/migrations/postgresql/0150_2.12.0_schema.up.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Add new column robot for artifact table to add a new column to record the creator of the robot
Add new column creator for robot table to add a new column to record the creator of the robot
*/
ALTER TABLE robot ADD COLUMN IF NOT EXISTS creator varchar(255);
UPDATE robot SET creator = 'unknown' WHERE creator IS NULL;
1 change: 1 addition & 0 deletions src/controller/robot/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (d *controller) Create(ctx context.Context, r *Robot) (int64, string, error
if r.Level == LEVELPROJECT {
name = fmt.Sprintf("%s+%s", r.ProjectName, r.Name)
}

robotID, err := d.robotMgr.Create(ctx, &model.Robot{
Name: name,
Description: r.Description,
Expand Down
7 changes: 5 additions & 2 deletions src/controller/robot/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package robot

import (
"context"
"github.com/goharbor/harbor/src/common/security"
testsec "github.com/goharbor/harbor/src/testing/common/security"
"os"
"testing"

Expand Down Expand Up @@ -102,7 +104,9 @@ func (suite *ControllerTestSuite) TestCreate() {
robotMgr := &robot.Manager{}

c := controller{robotMgr: robotMgr, rbacMgr: rbacMgr, proMgr: projectMgr}
ctx := context.TODO()
secCtx := &testsec.Context{}
secCtx.On("GetUsername").Return("security-context-user")
ctx := security.NewContext(context.Background(), secCtx)
projectMgr.On("Get", mock.Anything, mock.Anything).Return(&proModels.Project{ProjectID: 1, Name: "library"}, nil)
robotMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), nil)
rbacMgr.On("CreateRbacPolicy", mock.Anything, mock.Anything, mock.Anything).Return(int64(1), nil)
Expand All @@ -113,7 +117,6 @@ func (suite *ControllerTestSuite) TestCreate() {
Name: "testcreate",
Description: "testcreate",
Duration: 0,
Creator: "tester",
},
ProjectName: "library",
Level: LEVELPROJECT,
Expand Down
4 changes: 2 additions & 2 deletions src/server/v2.0/handler/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (rAPI *robotAPI) CreateRobot(ctx context.Context, params operation.CreateRo
return rAPI.SendError(ctx, err)
}

secCtx, err := rAPI.GetSecurityContext(ctx)
sc, err := rAPI.GetSecurityContext(ctx)
if err != nil {
return rAPI.SendError(ctx, err)
}
Expand All @@ -73,7 +73,7 @@ func (rAPI *robotAPI) CreateRobot(ctx context.Context, params operation.CreateRo
Description: params.Robot.Description,
Duration: params.Robot.Duration,
Visible: true,
Creator: secCtx.GetUsername(),
Creator: sc.GetUsername(),
},
Level: params.Robot.Level,
}
Expand Down

0 comments on commit e3df940

Please sign in to comment.