From 0fe8209ae123a3c7f18d1f7a66726779e6e935c5 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Mon, 5 Sep 2016 11:22:12 +0800 Subject: [PATCH] the name can be same with others when creating and updating policies --- api/replication_policy.go | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/api/replication_policy.go b/api/replication_policy.go index bcfa18791..3777f6209 100644 --- a/api/replication_policy.go +++ b/api/replication_policy.go @@ -91,15 +91,17 @@ func (pa *RepPolicyAPI) Post() { policy := &models.RepPolicy{} pa.DecodeJSONReqAndValidate(policy) - po, err := dao.GetRepPolicyByName(policy.Name) - if err != nil { - log.Errorf("failed to get policy %s: %v", policy.Name, err) - pa.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) - } + /* + po, err := dao.GetRepPolicyByName(policy.Name) + if err != nil { + log.Errorf("failed to get policy %s: %v", policy.Name, err) + pa.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) + } - if po != nil { - pa.CustomAbort(http.StatusConflict, "name is already used") - } + if po != nil { + pa.CustomAbort(http.StatusConflict, "name is already used") + } + */ project, err := dao.GetProjectByID(policy.ProjectID) if err != nil { @@ -169,18 +171,20 @@ func (pa *RepPolicyAPI) Put() { policy.ProjectID = originalPolicy.ProjectID pa.Validate(policy) - // check duplicate name - if policy.Name != originalPolicy.Name { - po, err := dao.GetRepPolicyByName(policy.Name) - if err != nil { - log.Errorf("failed to get policy %s: %v", policy.Name, err) - pa.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) - } + /* + // check duplicate name + if policy.Name != originalPolicy.Name { + po, err := dao.GetRepPolicyByName(policy.Name) + if err != nil { + log.Errorf("failed to get policy %s: %v", policy.Name, err) + pa.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) + } - if po != nil { - pa.CustomAbort(http.StatusConflict, "name is already used") + if po != nil { + pa.CustomAbort(http.StatusConflict, "name is already used") + } } - } + */ if policy.TargetID != originalPolicy.TargetID { //target of policy can not be modified when the policy is enabled