diff --git a/go.mod b/go.mod index 759824ced..073739c90 100644 --- a/go.mod +++ b/go.mod @@ -46,6 +46,7 @@ require ( github.com/labstack/gommon v0.3.0 github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef github.com/lib/pq v1.7.0 + github.com/magiconair/properties v1.8.1 github.com/mailru/easyjson v0.7.0 // indirect github.com/mattn/go-sqlite3 v2.0.3+incompatible github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect diff --git a/pkg/db/db.go b/pkg/db/db.go index a56ab55d3..94aaae0d9 100644 --- a/pkg/db/db.go +++ b/pkg/db/db.go @@ -72,6 +72,11 @@ func CreateDBEngine() (engine *xorm.Engine, err error) { log.Fatalf("Unknown database type %s", config.DatabaseType.GetString()) } + loc, err := time.LoadLocation(config.ServiceTimeZone.GetString()) + if err != nil { + log.Fatalf("Could not parse timezone '%s': %s", config.ServiceTimeZone.GetString(), err) + } + engine.SetTZLocation(loc) engine.SetMapper(core.GonicMapper{}) logger := log.NewXormLogger("") engine.SetLogger(logger) diff --git a/pkg/db/test.go b/pkg/db/test.go index f6274e368..c104225e3 100644 --- a/pkg/db/test.go +++ b/pkg/db/test.go @@ -21,6 +21,7 @@ import ( "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/log" "os" + "time" "xorm.io/core" "xorm.io/xorm" ) @@ -49,6 +50,11 @@ func CreateTestEngine() (engine *xorm.Engine, err error) { logger := log.NewXormLogger("DEBUG") logger.ShowSQL(os.Getenv("UNIT_TESTS_VERBOSE") == "1") engine.SetLogger(logger) + loc, err := time.LoadLocation(config.ServiceTimeZone.GetString()) + if err != nil { + log.Fatalf("Could not parse timezone '%s': %s", config.ServiceTimeZone.GetString(), err) + } + engine.SetTZLocation(loc) x = engine return } diff --git a/pkg/models/label_task_test.go b/pkg/models/label_task_test.go index 5e406f6b3..91551db89 100644 --- a/pkg/models/label_task_test.go +++ b/pkg/models/label_task_test.go @@ -48,11 +48,15 @@ func TestLabelTask_ReadAll(t *testing.T) { Label: Label{ ID: 4, Title: "Label #4 - visible via other task", + Created: testCreatedTime, + Updated: testUpdatedTime, CreatedByID: 2, CreatedBy: &user.User{ ID: 2, Username: "user2", Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.", + Created: testCreatedTime, + Updated: testUpdatedTime, }, }, }, diff --git a/pkg/models/label_test.go b/pkg/models/label_test.go index 14febf60b..a612bf309 100644 --- a/pkg/models/label_test.go +++ b/pkg/models/label_test.go @@ -71,6 +71,8 @@ func TestLabel_ReadAll(t *testing.T) { Title: "Label #1", CreatedByID: 1, CreatedBy: user1, + Created: testCreatedTime, + Updated: testUpdatedTime, }, }, { @@ -79,17 +81,23 @@ func TestLabel_ReadAll(t *testing.T) { Title: "Label #2", CreatedByID: 1, CreatedBy: user1, + Created: testCreatedTime, + Updated: testUpdatedTime, }, }, { Label: Label{ ID: 4, Title: "Label #4 - visible via other task", + Created: testCreatedTime, + Updated: testUpdatedTime, CreatedByID: 2, CreatedBy: &user.User{ ID: 2, Username: "user2", Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.", + Created: testCreatedTime, + Updated: testUpdatedTime, }, }, }, diff --git a/pkg/models/main_test.go b/pkg/models/main_test.go index c38a467d5..2520c689d 100644 --- a/pkg/models/main_test.go +++ b/pkg/models/main_test.go @@ -20,12 +20,28 @@ import ( "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/user" + "fmt" "os" "testing" + "time" ) func TestMain(m *testing.M) { + var err error + testCreatedTime, err = time.ParseInLocation(time.RFC3339Nano, "2018-12-01T15:13:12.0+00:00", time.Local) + if err != nil { + fmt.Printf("Error setting up time: %s", err) + os.Exit(1) + } + testCreatedTime = testCreatedTime.Local() + testUpdatedTime, err = time.ParseInLocation(time.RFC3339Nano, "2018-12-02T15:13:12.0+00:00", time.Local) + if err != nil { + fmt.Printf("Error setting up time: %s", err) + os.Exit(1) + } + testUpdatedTime = testUpdatedTime.Local() + // Set default config config.InitDefaultConfig() // We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly diff --git a/pkg/models/models.go b/pkg/models/models.go index 589b56304..78fa5e8e8 100644 --- a/pkg/models/models.go +++ b/pkg/models/models.go @@ -22,6 +22,7 @@ import ( "code.vikunja.io/api/pkg/log" _ "github.com/go-sql-driver/mysql" // Because. _ "github.com/lib/pq" // Because. + "time" "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" // Because. @@ -29,6 +30,9 @@ import ( var ( x *xorm.Engine + + testCreatedTime time.Time + testUpdatedTime time.Time ) // GetTables returns all structs which are also a table. diff --git a/pkg/user/user.go b/pkg/user/user.go index 4992fadc7..7ff26ac59 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -139,7 +139,9 @@ func getUser(user *User, withEmail bool) (userOut *User, err error) { userOut = &User{} // To prevent a panic if user is nil *userOut = *user exists, err := x.Get(userOut) - + if err != nil { + return nil, err + } if !exists { return &User{}, ErrUserDoesNotExist{UserID: user.ID} }