Skip to content

Commit

Permalink
Fix #599 Policy
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Dec 14, 2023
1 parent 4f4fa0d commit c2568ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
14 changes: 11 additions & 3 deletions internal/handler/v2/config/policy/config_create_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,21 @@ func ConfigCreatePolicy(w http.ResponseWriter, r *http.Request) {
return
}

// updates organisation policy url
err = updateOrganisationPolicyUrl(savedPolicy.Url, organisationId)
count, err := prepo.GetPolicyCountByOrganisation()
if err != nil {
m := fmt.Sprintf("Failed to update organisation policy url: %v", organisationId)
m := "Failed to count policies"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
if count == 1 {
// updates organisation policy url
err = updateOrganisationPolicyUrl(savedPolicy.Url, organisationId)
if err != nil {
m := fmt.Sprintf("Failed to update organisation policy url: %v", organisationId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
}

// Constructing the response
var resp addPolicyResp
Expand Down
15 changes: 12 additions & 3 deletions internal/handler/v2/config/policy/config_update_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,22 @@ func ConfigUpdatePolicy(w http.ResponseWriter, r *http.Request) {
return
}

// updates organisation policy url
err = updateOrganisationPolicyUrl(savedPolicy.Url, organisationId)
policyRepo.Init(organisationId)
first_policy, err := policyRepo.GetFirstPolicy()
if err != nil {
m := fmt.Sprintf("Failed to update organisation policy url: %v", organisationId)
m := "Failed to fetch first policy"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
if first_policy.Id == toBeUpdatedPolicy.Id {
// updates organisation policy url
err = updateOrganisationPolicyUrl(savedPolicy.Url, organisationId)
if err != nil {
m := fmt.Sprintf("Failed to update organisation policy url: %v", organisationId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
}

// Constructing the response
var resp updatePolicyResp
Expand Down
2 changes: 1 addition & 1 deletion internal/tenant/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func SingleTenantConfiguration(config *config.Configuration) {
createOrganisation(config, orgType, organisationAdminId)

// delete all policies
deleteAllPolicies()
// deleteAllPolicies()

// Load image assets for organisation
err := fixture.LoadImageAssetsForSingleTenantConfiguration()
Expand Down

0 comments on commit c2568ef

Please sign in to comment.