Skip to content

Commit

Permalink
Merge branch 'beta/1.11.0' into cmd-master
Browse files Browse the repository at this point in the history
  • Loading branch information
nshumoogum committed Jul 26, 2018
2 parents 7bc74d5 + 18608c0 commit 084e9e3
Show file tree
Hide file tree
Showing 77 changed files with 1,731 additions and 1,165 deletions.
9 changes: 7 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ func Routes(cfg config.Configuration, router *mux.Router, dataStore store.DataSt
func (d *PublishCheck) Check(handle func(http.ResponseWriter, *http.Request), action string) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

defer request.DrainBody(r)

ctx := r.Context()
vars := mux.Vars(r)
datasetID := vars["dataset_id"]
Expand All @@ -210,6 +208,7 @@ func (d *PublishCheck) Check(handle func(http.ResponseWriter, *http.Request), ac
err = errs.ErrInternalServer
}

request.DrainBody(r)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -234,10 +233,12 @@ func (d *PublishCheck) Check(handle func(http.ResponseWriter, *http.Request), ac
log.ErrorCtx(ctx, errors.WithMessage(err, "failed to model version resource based on request"), data)

if auditErr := d.Auditor.Record(ctx, action, audit.Unsuccessful, auditParams); auditErr != nil {
request.DrainBody(r)
http.Error(w, errs.ErrInternalServer.Error(), http.StatusInternalServerError)
return
}

request.DrainBody(r)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
Expand Down Expand Up @@ -274,10 +275,12 @@ func (d *PublishCheck) Check(handle func(http.ResponseWriter, *http.Request), ac
log.ErrorCtx(ctx, errors.WithMessage(err, "failed to marshal new version resource based on request"), data)

if auditErr := d.Auditor.Record(ctx, action, audit.Unsuccessful, auditParams); auditErr != nil {
request.DrainBody(r)
http.Error(w, errs.ErrInternalServer.Error(), http.StatusInternalServerError)
return
}

request.DrainBody(r)
http.Error(w, err.Error(), http.StatusForbidden)
return
}
Expand All @@ -300,10 +303,12 @@ func (d *PublishCheck) Check(handle func(http.ResponseWriter, *http.Request), ac
data["version"] = currentVersion
log.ErrorCtx(ctx, err, data)
if auditErr := d.Auditor.Record(ctx, action, audit.Unsuccessful, auditParams); auditErr != nil {
request.DrainBody(r)
http.Error(w, errs.ErrInternalServer.Error(), http.StatusInternalServerError)
return
}

request.DrainBody(r)
http.Error(w, err.Error(), http.StatusForbidden)
return
}
Expand Down
3 changes: 3 additions & 0 deletions api/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ func (api *DatasetAPI) addDataset(w http.ResponseWriter, r *http.Request) {
HRef: fmt.Sprintf("%s/datasets/%s", api.host, datasetID),
}

// Remove latest version from new dataset resource, this cannot be added at this point
dataset.Links.LatestVersion = nil

dataset.LastUpdated = time.Now()

datasetDoc := &models.DatasetUpdate{
Expand Down
3 changes: 2 additions & 1 deletion api/dimensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ONSdigital/go-ns/audit"
"github.com/ONSdigital/go-ns/common"
"github.com/ONSdigital/go-ns/log"
"github.com/gedge/mgo/bson"
"github.com/globalsign/mgo/bson"
"github.com/gorilla/mux"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -187,6 +187,7 @@ func (api *DatasetAPI) getDimensionOptions(w http.ResponseWriter, r *http.Reques
for i := range results.Items {
results.Items[i].Links.Version.HRef = fmt.Sprintf("%s/datasets/%s/editions/%s/versions/%s",
api.host, datasetID, edition, versionID)
results.Items[i].Links.Version.ID = versionID
}

b, err := json.Marshal(results)
Expand Down
2 changes: 1 addition & 1 deletion api/dimensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ONSdigital/go-ns/audit"
"github.com/ONSdigital/go-ns/audit/auditortest"
"github.com/ONSdigital/go-ns/common"
"github.com/gedge/mgo/bson"
"github.com/globalsign/mgo/bson"
. "github.com/smartystreets/goconvey/convey"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"dimensions": {
"geography": {
"option": {
"id": "K02000001",
"href": "http://localhost:8081/code-lists/uk-only/codes/K02000001"
"href": "http://localhost:8081/code-lists/uk-only/codes/K02000001",
"id": "K02000001"
}
},
"time": {
"option": {
"id": "16-Aug",
"href": "http://localhost:8081/code-lists/time/codes/16-Aug"
"href": "http://localhost:8081/code-lists/time/codes/16-Aug",
"id": "16-Aug"
}
}
},
Expand All @@ -22,8 +22,8 @@
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1/observations?time=16-Aug&aggregate=*&geography=K02000001"
},
"version": {
"id": "1",
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1"
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1",
"id": "1"
}
},
"observations": [{
Expand Down Expand Up @@ -56,7 +56,7 @@
"offset": 0,
"total_observations": 2,
"usage_notes": [{
"title": "data_marking",
"note": "this marks the observation with a special character"
"note": "this marks the observation with a special character",
"title": "data_marking"
}]
}
20 changes: 10 additions & 10 deletions api/observation_test_data/expectedDocWithSingleObservation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"dimensions": {
"aggregate": {
"option": {
"id": "cpi1dim1S40403",
"href": "http://localhost:8081/code-lists/cpih1dim1aggid/codes/cpi1dim1S40403"
"href": "http://localhost:8081/code-lists/cpih1dim1aggid/codes/cpi1dim1S40403",
"id": "cpi1dim1S40403"
}
},
"geography": {
"option": {
"id": "K02000001",
"href": "http://localhost:8081/code-lists/uk-only/codes/K02000001"
"href": "http://localhost:8081/code-lists/uk-only/codes/K02000001",
"id": "K02000001"
}
},
"time": {
"option": {
"id": "16-Aug",
"href": "http://localhost:8081/code-lists/time/codes/16-Aug"
"href": "http://localhost:8081/code-lists/time/codes/16-Aug",
"id": "16-Aug"
}
}
},
Expand All @@ -28,8 +28,8 @@
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1/observations?time=16-Aug&aggregate=cpi1dim1S40403&geography=K02000001"
},
"version": {
"id": "1",
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1"
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1",
"id": "1"
}
},
"observations": [{
Expand All @@ -42,7 +42,7 @@
"offset": 0,
"total_observations": 1,
"usage_notes": [{
"title": "data_marking",
"note": "this marks the obsevation with a special character"
"note": "this marks the obsevation with a special character",
"title": "data_marking"
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"dimensions": {
"aggregate": {
"option": {
"id": "cpi1dim1S40403",
"href": "http://localhost:8081/code-lists/cpih1dim1aggid/codes/cpi1dim1S40403"
"href": "http://localhost:8081/code-lists/cpih1dim1aggid/codes/cpi1dim1S40403",
"id": "cpi1dim1S40403"
}
},
"geography": {
"option": {
"id": "K02000001",
"href": "http://localhost:8081/code-lists/uk-only/codes/K02000001"
"href": "http://localhost:8081/code-lists/uk-only/codes/K02000001",
"id": "K02000001"
}
},
"time": {
"option": {
"id": "16-Aug",
"href": "http://localhost:8081/code-lists/time/codes/16-Aug"
"href": "http://localhost:8081/code-lists/time/codes/16-Aug",
"id": "16-Aug"
}
}
},
Expand All @@ -28,8 +28,8 @@
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1/observations?time=16-Aug&AggregaTe=cpi1dim1S40403&GEOGRAPHY=K02000001"
},
"version": {
"id": "1",
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1"
"href": "http://localhost:8080/datasets/cpih012/editions/2017/versions/1",
"id": "1"
}
},
"observations": [{
Expand All @@ -42,7 +42,7 @@
"offset": 0,
"total_observations": 1,
"usage_notes": [{
"title": "data_marking",
"note": "this marks the obsevation with a special character"
"note": "this marks the obsevation with a special character",
"title": "data_marking"
}]
}
7 changes: 6 additions & 1 deletion api/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ func (api *DatasetAPI) updateVersion(ctx context.Context, body io.ReadCloser, ve

// attempt to update the version
currentDataset, currentVersion, versionUpdate, err := func() (*models.DatasetUpdate, *models.Version, *models.Version, error) {
defer body.Close()
versionUpdate, err := models.CreateVersion(body)
if err != nil {
log.ErrorCtx(ctx, errors.WithMessage(err, "putVersion endpoint: failed to model version resource based on request"), data)
Expand Down Expand Up @@ -547,6 +546,8 @@ func populateNewVersionDoc(currentVersion *models.Version, version *models.Versi
}
}

// TODO - Data Integrity - Updating downloads should be locked down to services
// with permissions to do so, currently a user could update these fields
if version.Downloads == nil {
version.Downloads = currentVersion.Downloads
} else {
Expand All @@ -563,6 +564,10 @@ func populateNewVersionDoc(currentVersion *models.Version, version *models.Versi
}
}

if version.UsageNotes == nil {
version.UsageNotes = currentVersion.UsageNotes
}

return version
}

Expand Down
2 changes: 1 addition & 1 deletion api/webendpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/ONSdigital/go-ns/audit/auditortest"
"github.com/gedge/mgo/bson"
"github.com/globalsign/mgo/bson"

"github.com/ONSdigital/dp-dataset-api/config"
"github.com/ONSdigital/dp-dataset-api/mocks"
Expand Down
5 changes: 5 additions & 0 deletions apierrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
ErrAddDatasetAlreadyExists = errors.New("forbidden - dataset already exists")
ErrAddUpdateDatasetBadRequest = errors.New("failed to parse json body")
ErrAuditActionAttemptedFailure = errors.New("internal server error")
ErrConflictUpdatingInstance = errors.New("conflict updating instance resource")
ErrDatasetNotFound = errors.New("dataset not found")
ErrDeleteDatasetNotFound = errors.New("dataset not found")
ErrDeletePublishedDatasetForbidden = errors.New("a published dataset cannot be deleted")
Expand Down Expand Up @@ -61,6 +62,10 @@ var (
ErrUnableToReadMessage: true,
}

ConflictRequestMap = map[error]bool{
ErrConflictUpdatingInstance: true,
}

ForbiddenMap = map[error]bool{
ErrExpectedResourceStateOfCreated: true,
ErrExpectedResourceStateOfSubmitted: true,
Expand Down
Loading

0 comments on commit 084e9e3

Please sign in to comment.