This commit is contained in:
kolaente 2021-09-04 20:32:51 +02:00
parent 4b389ae02c
commit dc5290bb33
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
11 changed files with 48 additions and 39 deletions

View File

@ -21,6 +21,7 @@ import (
"os" "os"
"strconv" "strconv"
"time" "time"
"xorm.io/xorm" "xorm.io/xorm"
"code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/config"

View File

@ -1,24 +1,30 @@
// Copyright 2021 Vikunja and contriubtors. All rights reserved. // Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
// //
// This file is part of Vikunja. // This program is free software: you can redistribute it and/or modify
// // it under the terms of the GNU Affero General Public Licensee as published by
// Vikunja is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// Vikunja is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU Affero General Public Licensee for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU Affero General Public Licensee
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
package models package models
import ( import (
"archive/zip" "archive/zip"
"encoding/json"
"fmt"
"io"
"os"
"strconv"
"time"
"code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/cron" "code.vikunja.io/api/pkg/cron"
"code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/db"
@ -28,12 +34,6 @@ import (
"code.vikunja.io/api/pkg/user" "code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils" "code.vikunja.io/api/pkg/utils"
"code.vikunja.io/api/pkg/version" "code.vikunja.io/api/pkg/version"
"encoding/json"
"fmt"
"io"
"os"
"strconv"
"time"
"xorm.io/xorm" "xorm.io/xorm"
) )

View File

@ -18,15 +18,16 @@ package dump
import ( import (
"archive/zip" "archive/zip"
"fmt"
"io"
"os"
"code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/utils" "code.vikunja.io/api/pkg/utils"
"code.vikunja.io/api/pkg/version" "code.vikunja.io/api/pkg/version"
"fmt"
"github.com/spf13/viper" "github.com/spf13/viper"
"io"
"os"
) )
// Dump creates a zip file with all vikunja files at filename // Dump creates a zip file with all vikunja files at filename

View File

@ -17,11 +17,12 @@
package handler package handler
import ( import (
"net/http"
"code.vikunja.io/api/pkg/modules/migration" "code.vikunja.io/api/pkg/modules/migration"
user2 "code.vikunja.io/api/pkg/user" user2 "code.vikunja.io/api/pkg/user"
"code.vikunja.io/web/handler" "code.vikunja.io/web/handler"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"net/http"
) )
func status(ms migration.MigratorName, c echo.Context) error { func status(ms migration.MigratorName, c echo.Context) error {

View File

@ -17,12 +17,13 @@
package handler package handler
import ( import (
"net/http"
"code.vikunja.io/api/pkg/models" "code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/migration" "code.vikunja.io/api/pkg/modules/migration"
user2 "code.vikunja.io/api/pkg/user" user2 "code.vikunja.io/api/pkg/user"
"code.vikunja.io/web/handler" "code.vikunja.io/web/handler"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"net/http"
) )
type FileMigratorWeb struct { type FileMigratorWeb struct {

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public Licensee // You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
package vikunja_file package vikunjafile
import ( import (
"os" "os"

View File

@ -14,33 +14,34 @@
// You should have received a copy of the GNU Affero General Public Licensee // You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
package vikunja_file package vikunjafile
import ( import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/migration"
"code.vikunja.io/api/pkg/user"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"strconv" "strconv"
"strings" "strings"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/migration"
"code.vikunja.io/api/pkg/user"
) )
const logPrefix = "[Vikunja File Import] " const logPrefix = "[Vikunja File Import] "
type VikunjaFileMigrator struct { type FileMigrator struct {
} }
func (v *VikunjaFileMigrator) Name() string { func (v *FileMigrator) Name() string {
return "vikunja-file" return "vikunja-file"
} }
func (v *VikunjaFileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) error { func (v *FileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) error {
r, err := zip.NewReader(file, size) r, err := zip.NewReader(file, size)
if err != nil { if err != nil {
return fmt.Errorf("could not open import file: %s", err) return fmt.Errorf("could not open import file: %s", err)

View File

@ -14,21 +14,22 @@
// You should have received a copy of the GNU Affero General Public Licensee // You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
package vikunja_file package vikunjafile
import ( import (
"os"
"testing"
"code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user" "code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"os"
"testing"
) )
func TestVikunjaFileMigrator_Migrate(t *testing.T) { func TestVikunjaFileMigrator_Migrate(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
m := &VikunjaFileMigrator{} m := &FileMigrator{}
u := &user.User{ID: 1} u := &user.User{ID: 1}
f, err := os.Open(config.ServiceRootpath.GetString() + "/pkg/modules/migration/vikunja-file/export.zip") f, err := os.Open(config.ServiceRootpath.GetString() + "/pkg/modules/migration/vikunja-file/export.zip")

View File

@ -17,9 +17,10 @@
package v1 package v1
import ( import (
vikunja_file "code.vikunja.io/api/pkg/modules/migration/vikunja-file"
"net/http" "net/http"
vikunja_file "code.vikunja.io/api/pkg/modules/migration/vikunja-file"
microsofttodo "code.vikunja.io/api/pkg/modules/migration/microsoft-todo" microsofttodo "code.vikunja.io/api/pkg/modules/migration/microsoft-todo"
"code.vikunja.io/api/pkg/modules/migration/trello" "code.vikunja.io/api/pkg/modules/migration/trello"
@ -93,7 +94,7 @@ func Info(c echo.Context) error {
EmailRemindersEnabled: config.ServiceEnableEmailReminders.GetBool(), EmailRemindersEnabled: config.ServiceEnableEmailReminders.GetBool(),
UserDeletionEnabled: config.ServiceEnableUserDeletion.GetBool(), UserDeletionEnabled: config.ServiceEnableUserDeletion.GetBool(),
AvailableMigrators: []string{ AvailableMigrators: []string{
(&vikunja_file.VikunjaFileMigrator{}).Name(), (&vikunja_file.FileMigrator{}).Name(),
}, },
Legal: legalInfo{ Legal: legalInfo{
ImprintURL: config.LegalImprintURL.GetString(), ImprintURL: config.LegalImprintURL.GetString(),

View File

@ -17,6 +17,8 @@
package v1 package v1
import ( import (
"net/http"
"code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/events" "code.vikunja.io/api/pkg/events"
"code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/files"
@ -24,7 +26,6 @@ import (
"code.vikunja.io/api/pkg/user" "code.vikunja.io/api/pkg/user"
"code.vikunja.io/web/handler" "code.vikunja.io/web/handler"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"net/http"
"xorm.io/xorm" "xorm.io/xorm"
) )

View File

@ -47,12 +47,13 @@
package routes package routes
import ( import (
vikunja_file "code.vikunja.io/api/pkg/modules/migration/vikunja-file"
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"time" "time"
vikunja_file "code.vikunja.io/api/pkg/modules/migration/vikunja-file"
"code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/log"
@ -637,7 +638,7 @@ func registerMigrations(m *echo.Group) {
vikunjaFileMigrationHandler := &migrationHandler.FileMigratorWeb{ vikunjaFileMigrationHandler := &migrationHandler.FileMigratorWeb{
MigrationStruct: func() migration.FileMigrator { MigrationStruct: func() migration.FileMigrator {
return &vikunja_file.VikunjaFileMigrator{} return &vikunja_file.FileMigrator{}
}, },
} }
vikunjaFileMigrationHandler.RegisterRoutes(m) vikunjaFileMigrationHandler.RegisterRoutes(m)