Skip to content

Commit

Permalink
chore: handle latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
idilhaq committed Dec 9, 2024
1 parent d52021d commit 72330cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion core/appeal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,7 @@ func getPolicy(a *domain.Appeal, p *domain.Provider, policiesMap map[string]map[
}

dynamicPolicyConfigData = pc.Policy
break
}
}

Expand All @@ -1570,7 +1571,12 @@ func getPolicy(a *domain.Appeal, p *domain.Provider, policiesMap map[string]map[
policyData := strings.Split(dynamicPolicyConfigData, "@")
dynamicPolicyConfig.ID = policyData[0]
if len(policyData) > 1 {
version, err := strconv.Atoi(policyData[1])
var version int
if policyData[1] == "latest" {
version = 0
} else {
version, err = strconv.Atoi(policyData[1])
}
if err != nil {
return nil, fmt.Errorf("invalid policy version: %w", err)
}
Expand Down
8 changes: 6 additions & 2 deletions core/appeal/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,11 @@ func (s *ServiceTestSuite) TestCreate() {
Policies: []*domain.ProviderPolicy{
{
When: "$appeal.resource.type == 'dataset'",
Policy: "policy_dataset",
Policy: "policy_dataset@latest",
},
{
When: "$appeal.resource.type == 'dataset2'",
Policy: "policy_dataset@2",
},
},
},
Expand Down Expand Up @@ -1687,7 +1691,7 @@ func (s *ServiceTestSuite) TestCreate() {
},
{
ID: "policy_table",
Version: 1,
Version: 2,
Steps: []*domain.Step{
{
Name: "step_1",
Expand Down

0 comments on commit 72330cf

Please sign in to comment.