Skip to content

Commit

Permalink
Add filter url query, fix time validation (#3269)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuofan authored Dec 3, 2021
1 parent 58c6a2d commit 1f750f1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ type ComponentFilter struct {
State State `json:"state,omitempty"`
base.DefaultProvider

projectID uint64 `json:"-"`
Iterations []apistructs.Iteration `json:"-"`
Members []apistructs.Member `json:"-"`
FrontendUrlQuery string `json:"-"`
projectID uint64 `json:"-"`
Iterations []apistructs.Iteration `json:"-"`
Members []apistructs.Member `json:"-"`
}

type State struct {
Conditions []filter.PropCondition `json:"conditions,omitempty"`
Values FrontendConditions `json:"values,omitempty"`
Base64UrlQueryParams string `json:"filter__urlQuery,omitempty"`
Conditions []filter.PropCondition `json:"conditions,omitempty"`
Values FrontendConditions `json:"values,omitempty"`
}

type FrontendConditions struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package filter

import (
"context"
"encoding/base64"
"encoding/json"
"strconv"
"time"

Expand Down Expand Up @@ -44,6 +46,10 @@ func (f *ComponentFilter) Render(ctx context.Context, c *cptype.Component, scena
return err
}
f.projectID = projectID
if q := cputil.GetInParamByKey(ctx, "filter__urlQuery"); q != nil {
f.FrontendUrlQuery = q.(string)
}

iterations, iterationOptions, err := f.getPropIterationsOptions()
if err != nil {
return err
Expand All @@ -58,7 +64,7 @@ func (f *ComponentFilter) Render(ctx context.Context, c *cptype.Component, scena
}

switch event.Operation {
case cptype.InitializeOperation:
case cptype.InitializeOperation, cptype.RenderingOperation:
f.Props = filter.Props{
Delay: 1000,
}
Expand All @@ -68,7 +74,18 @@ func (f *ComponentFilter) Render(ctx context.Context, c *cptype.Component, scena
Reload: true,
},
}
f.State.Values.IterationIDs = []int64{defaultIterationRetriever(iterations)}
if f.FrontendUrlQuery != "" {
b, err := base64.StdEncoding.DecodeString(f.FrontendUrlQuery)
if err != nil {
return err
}
f.State.Values = FrontendConditions{}
if err := json.Unmarshal(b, &f.State.Values); err != nil {
return err
}
} else {
f.State.Values.IterationIDs = []int64{defaultIterationRetriever(iterations)}
}
}

f.State.Conditions = []filter.PropCondition{
Expand Down Expand Up @@ -100,9 +117,22 @@ func (f *ComponentFilter) Render(ctx context.Context, c *cptype.Component, scena
HaveFilter: true,
},
}
urlParam, err := f.generateUrlQueryParams()
if err != nil {
return err
}
f.State.Base64UrlQueryParams = urlParam
return nil
}

func (f *ComponentFilter) generateUrlQueryParams() (string, error) {
fb, err := json.Marshal(f.State.Values)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(fb), nil
}

func (f *ComponentFilter) getPropIterationsOptions() (map[int64]apistructs.Iteration, []filter.PropConditionOption, error) {
iterations, err := f.bdl.ListProjectIterations(apistructs.IterationPagingRequest{
PageNo: 1, PageSize: 1000,
Expand Down
20 changes: 12 additions & 8 deletions modules/dop/services/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,19 @@ func (svc *Issue) UpdateIssue(req apistructs.IssueUpdateRequest) error {
return apierrors.ErrGetIssue.InternalError(err)
}

if req.PlanFinishedAt != nil && req.PlanStartedAt != nil && req.PlanStartedAt.After(*req.PlanFinishedAt) {
return fmt.Errorf("plan started is after plan finished time")
}
if req.PlanFinishedAt != nil && issueModel.PlanStartedAt != nil && issueModel.PlanStartedAt.After(*req.PlanFinishedAt) {
return apierrors.ErrUpdateIssue.InvalidParameter("plan finished at")
}
if req.PlanStartedAt != nil && issueModel.PlanFinishedAt != nil && req.PlanStartedAt.After(*issueModel.PlanFinishedAt) {
return apierrors.ErrUpdateIssue.InvalidParameter("plan started at")
if req.PlanFinishedAt != nil && req.PlanStartedAt != nil {
if req.PlanStartedAt.After(*req.PlanFinishedAt) {
return fmt.Errorf("plan started is after plan finished time")
}
} else {
if req.PlanFinishedAt != nil && issueModel.PlanStartedAt != nil && issueModel.PlanStartedAt.After(*req.PlanFinishedAt) {
return apierrors.ErrUpdateIssue.InvalidParameter("plan finished at")
}
if req.PlanStartedAt != nil && issueModel.PlanFinishedAt != nil && req.PlanStartedAt.After(*issueModel.PlanFinishedAt) {
return apierrors.ErrUpdateIssue.InvalidParameter("plan started at")
}
}

//如果是BUG从打开或者重新打开切换状态为已解决,修改责任人为当前用户
if issueModel.Type == apistructs.IssueTypeBug {
currentState, err := svc.db.GetIssueStateByID(issueModel.State)
Expand Down

0 comments on commit 1f750f1

Please sign in to comment.