Browse Source

Fixed null pointer exception for anonymous user

tags/v1.21.12.1
yan 5 years ago
parent
commit
ed3501afc0
2 changed files with 4 additions and 3 deletions
  1. +1
    -1
      models/dataset.go
  2. +3
    -2
      routers/dataset/dataset.go

+ 1
- 1
models/dataset.go View File

@@ -225,7 +225,7 @@ func GetOwnerDatasetByID(id int64, user *User) (*Dataset, error) {
if !dataset.IsPrivate() {
return dataset, nil
}
if dataset.IsPrivate() && user.ID == dataset.UserID {
if dataset.IsPrivate() && user != nil && user.ID == dataset.UserID {
return dataset, nil
}
return nil, errors.New("dataset not fount")


+ 3
- 2
routers/dataset/dataset.go View File

@@ -160,7 +160,7 @@ func Show(ctx *context.Context) {
user := ctx.User
dataset, err := models.GetOwnerDatasetByID(ctx.ParamsInt64((":id")), user)
if err != nil {
ctx.ServerError("GetDataset", err)
ctx.NotFound("GetDataset", err)
return
}

@@ -185,9 +185,10 @@ func EditDataset(ctx *context.Context) {
repo.RenderAttachmentSettings(ctx)
rel, err := models.GetOwnerDatasetByID(ctx.ParamsInt64(":id"), ctx.User)
if err != nil {
ctx.ServerError("GetDataset", err)
ctx.NotFound("GetDataset", err)
return
}

ctx.Data["ID"] = rel.ID
ctx.Data["title"] = rel.Title
ctx.Data["private"] = rel.IsPrivate()


Loading…
Cancel
Save