fix legacy robot edit issue (#15709)

fixes #15690, for the legacy robot, update is denied.

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2021-10-01 00:41:54 +08:00 committed by GitHub
parent 7345021800
commit 4e984e8c6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -196,7 +196,7 @@ func (rAPI *robotAPI) UpdateRobot(ctx context.Context, params operation.UpdateRo
} }
if !r.Editable { if !r.Editable {
err = rAPI.updateV1Robot(ctx, params, r) err = errors.DeniedError(nil).WithMessage("editing of legacy robot is not allowed")
} else { } else {
err = rAPI.updateV2Robot(ctx, params, r) err = rAPI.updateV2Robot(ctx, params, r)
} }
@ -279,21 +279,6 @@ func (rAPI *robotAPI) validate(d int64, level string, permissions []*models.Robo
return nil return nil
} }
// only disable can be updated for v1 robot
func (rAPI *robotAPI) updateV1Robot(ctx context.Context, params operation.UpdateRobotParams, r *robot.Robot) error {
if err := rAPI.requireAccess(ctx, params.Robot.Level, r.ProjectID, rbac.ActionUpdate); err != nil {
return err
}
r.Disabled = params.Robot.Disable
r.Description = params.Robot.Description
if err := rAPI.robotCtl.Update(ctx, r, &robot.Option{
WithPermission: false,
}); err != nil {
return err
}
return nil
}
func (rAPI *robotAPI) updateV2Robot(ctx context.Context, params operation.UpdateRobotParams, r *robot.Robot) error { func (rAPI *robotAPI) updateV2Robot(ctx context.Context, params operation.UpdateRobotParams, r *robot.Robot) error {
if err := rAPI.validate(params.Robot.Duration, params.Robot.Level, params.Robot.Permissions); err != nil { if err := rAPI.validate(params.Robot.Duration, params.Robot.Level, params.Robot.Permissions); err != nil {
return err return err