Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: check issue assignee role (#849)

STEVENeed8edaeb675
diff --git a/server/issue.go b/server/issue.go
index 6b549b79a2..46e4d0063f 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -126,6 +126,12 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted update issue request").SetInternal(err)
}
+ if issuePatch.AssigneeID != nil {
+ if err := s.validateAssigneeRoleByID(ctx, *issuePatch.AssigneeID); err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Cannot set assignee with user id %d", *issuePatch.AssigneeID)).SetInternal(err)
+ }
+ }
+
issueFind := &api.IssueFind{
ID: &id,
}
@@ -324,6 +330,27 @@ func (s *Server) composeIssueRelationship(ctx context.Context, issue *api.Issue)
return nil
}
+// Only allow Bot/Owner/DBA as the assignee, not Developer.
+func (s *Server) validateAssigneeRoleByID(ctx context.Context, assigneeID int) error {
+ assignee, err := s.PrincipalService.FindPrincipal(ctx, &api.PrincipalFind{
+ ID: &assigneeID,
+ })
+ if err != nil {
+ return err
+ }
+ if assignee == nil {
+ return fmt.Errorf("Principal ID not found: %d", assigneeID)
+ }
+ if err = s.composePrincipalRole(ctx, assignee); err != nil {
+ return err
+ }
+ if assignee.Role != api.Owner && assignee.Role != api.DBA {
+ return fmt.Errorf("%s is not allowed as assignee", assignee.Role)
+ }
+
+ return nil
+}
+
func (s *Server) createIssue(ctx context.Context, issueCreate *api.IssueCreate, creatorID int) (*api.Issue, error) {
// Run pre-condition check first to make sure all tasks are valid, otherwise we will create partial pipelines
// since we are not creating pipeline/stage list/task list in a single transaction.
@@ -333,6 +360,10 @@ func (s *Server) createIssue(ctx context.Context, issueCreate *api.IssueCreate,
return nil, echo.NewHTTPError(http.StatusBadRequest, "Failed to create issue, assignee missing")
}
+ if err := s.validateAssigneeRoleByID(ctx, issueCreate.AssigneeID); err != nil {
+ return nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Cannot set assignee with user id %d", issueCreate.AssigneeID)).SetInternal(err)
+ }
+
// If frontend does not pass the stageList, we will generate it from backend.
pipeline, err := s.createPipelineFromIssue(ctx, issueCreate, creatorID, issueCreate.ValidateOnly)
if err != nil {