Skip to content

Commit

Permalink
add creator for robot
Browse files Browse the repository at this point in the history
add the creator for robot creation

Signed-off-by: wang yan <[email protected]>
  • Loading branch information
wy65701436 committed Aug 14, 2024
1 parent 907709f commit c06dd64
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7846,6 +7846,9 @@ definitions:
type: array
items:
$ref: '#/definitions/RobotPermission'
Creator:
type: string
description: The creator of the robot
creation_time:
type: string
format: date-time
Expand Down
5 changes: 5 additions & 0 deletions make/migrations/postgresql/0150_2.12.0_schema.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
Add new column robot for artifact 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 @@ -130,6 +130,7 @@ func (d *controller) Create(ctx context.Context, r *Robot) (int64, string, error
Duration: r.Duration,
Salt: salt,
Visible: r.Visible,
Creator: r.Creator,
})
if err != nil {
return 0, "", err
Expand Down
1 change: 1 addition & 0 deletions src/controller/robot/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (suite *ControllerTestSuite) TestCreate() {
Name: "testcreate",
Description: "testcreate",
Duration: 0,
Creator: "tester",
},
ProjectName: "library",
Level: LEVELPROJECT,
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/robot/dao/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (suite *DaoTestSuite) robots() {
Description: "test3 description",
ProjectID: 1,
Secret: suite.RandString(10),
Creator: "tester",
})
suite.Nil(err)

Expand Down Expand Up @@ -120,6 +121,7 @@ func (suite *DaoTestSuite) TestGet() {
r, err := suite.dao.Get(orm.Context(), suite.robotID3)
suite.Nil(err)
suite.Equal("test3", r.Name)
suite.Equal("tester", r.Creator)
}

func (suite *DaoTestSuite) TestCount() {
Expand Down
1 change: 1 addition & 0 deletions src/pkg/robot/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Robot struct {
ExpiresAt int64 `orm:"column(expiresat)" json:"expires_at"`
Disabled bool `orm:"column(disabled)" json:"disabled"`
Visible bool `orm:"column(visible)" json:"-"`
Creator string `orm:"column(creator)" json:"creator"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
}
Expand Down
1 change: 1 addition & 0 deletions src/server/v2.0/handler/model/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (r *Robot) ToSwagger() *models.Robot {
Level: r.Level,
Disable: r.Disabled,
Editable: r.Editable,
Creator: r.Creator,
CreationTime: strfmt.DateTime(r.CreationTime),
UpdateTime: strfmt.DateTime(r.UpdateTime),
Permissions: perms,
Expand Down
6 changes: 6 additions & 0 deletions src/server/v2.0/handler/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ func (rAPI *robotAPI) CreateRobot(ctx context.Context, params operation.CreateRo
return rAPI.SendError(ctx, err)
}

secCtx, err := rAPI.GetSecurityContext(ctx)
if err != nil {
return rAPI.SendError(ctx, err)
}

r := &robot.Robot{
Robot: pkg.Robot{
Name: params.Robot.Name,
Description: params.Robot.Description,
Duration: params.Robot.Duration,
Visible: true,
Creator: secCtx.GetUsername(),
},
Level: params.Robot.Level,
}
Expand Down

0 comments on commit c06dd64

Please sign in to comment.