forked from vikunja/vikunja
136 lines
4.9 KiB
Go
136 lines
4.9 KiB
Go
// Vikunja is a to-do list application to facilitate your life.
|
|
// Copyright 2018-present Vikunja and contributors. All rights reserved.
|
|
//
|
|
// 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
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public Licensee for more details.
|
|
//
|
|
// 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/>.
|
|
|
|
package kanboard
|
|
|
|
import (
|
|
"github.com/ybbus/jsonrpc/v2"
|
|
|
|
"code.vikunja.io/api/pkg/config"
|
|
"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"
|
|
)
|
|
|
|
// Migration represents the trello migration struct
|
|
type Migration struct {
|
|
Token string `json:"code"`
|
|
}
|
|
|
|
type kanboardBoard struct {
|
|
}
|
|
|
|
func init() {
|
|
}
|
|
|
|
// Name is used to get the name of the trello migration - we're using the docs here to annotate the status route.
|
|
// @Summary Get migration status
|
|
// @Description Returns if the current user already did the migation or not. This is useful to show a confirmation message in the frontend if the user is trying to do the same migration again.
|
|
// @tags migration
|
|
// @Produce json
|
|
// @Security JWTKeyAuth
|
|
// @Success 200 {object} migration.Status "The migration status"
|
|
// @Failure 500 {object} models.Message "Internal server error"
|
|
// @Router /migration/trello/status [get]
|
|
func (m *Migration) Name() string {
|
|
return "kanboard"
|
|
}
|
|
|
|
// AuthURL returns the url users need to authenticate against
|
|
// @Summary Get the auth url from trello
|
|
// @Description Returns the auth url where the user needs to get its auth code. This code can then be used to migrate everything from trello to Vikunja.
|
|
// @tags migration
|
|
// @Produce json
|
|
// @Security JWTKeyAuth
|
|
// @Success 200 {object} handler.AuthURL "The auth url."
|
|
// @Failure 500 {object} models.Message "Internal server error"
|
|
// @Router /migration/trello/auth [get]
|
|
func (m *Migration) AuthURL() string {
|
|
return ""
|
|
}
|
|
|
|
func getKanboardData(endpoint string, token string) (kanboardData []kanboardBoard, err error) {
|
|
|
|
rpcClient := jsonrpc.NewClient(endpoint)
|
|
|
|
err = rpcClient.CallFor(&kanboardData, "getAllProjects")
|
|
|
|
return
|
|
}
|
|
|
|
// Converts all previously obtained data from trello into the vikunja format.
|
|
// `trelloData` should contain all boards with their projects and cards respectively.
|
|
func convertKanboardDataToVikunja(kanboardData []kanboardBoard, token string) (fullVikunjaHierachie []*models.ProjectWithTasksAndBuckets, err error) {
|
|
|
|
log.Debugf("[Kanboard Migration] ")
|
|
|
|
fullVikunjaHierachie = []*models.ProjectWithTasksAndBuckets{
|
|
{
|
|
Project: models.Project{
|
|
Title: "Imported from Kanboard",
|
|
},
|
|
ChildProjects: []*models.ProjectWithTasksAndBuckets{},
|
|
},
|
|
}
|
|
|
|
log.Debugf("[Kanboard Migration] Converting %d boards to vikunja projects", len(kanboardData))
|
|
|
|
return
|
|
}
|
|
|
|
// Migrate gets all tasks from trello for a user and puts them into vikunja
|
|
// @Summary Migrate all projects, tasks etc. from trello
|
|
// @Description Migrates all projects, tasks, notes, reminders, subtasks and files from trello to vikunja.
|
|
// @tags migration
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security JWTKeyAuth
|
|
// @Param migrationCode body kanboard.Migration true "The auth token previously obtained from the auth url. See the docs for /migration/kanboard/auth."
|
|
// @Success 200 {object} models.Message "A message telling you everything was migrated successfully."
|
|
// @Failure 500 {object} models.Message "Internal server error"
|
|
// @Router /migration/kanboard/migrate [post]
|
|
func (m *Migration) Migrate(u *user.User) (err error) {
|
|
log.Debugf("[Kanboard Migration] Starting migration for user %d", u.ID)
|
|
log.Debugf("[Kanboard Migration] Getting all kanboard data for user %d", u.ID)
|
|
|
|
trelloData, err := getKanboardData(config.MigrationKanboardApiEndpoint.GetString(), config.MigrationKanboardApiToken.GetString())
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
log.Debugf("[Kanboard Migration] Got all kanboard data for user %d", u.ID)
|
|
log.Debugf("[Kanboard Migration] Start converting kanboard data for user %d", u.ID)
|
|
|
|
fullVikunjaHierachie, err := convertKanboardDataToVikunja(trelloData, m.Token)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
log.Debugf("[Kanboard Migration] Done migrating kanboard data for user %d", u.ID)
|
|
log.Debugf("[Kanboard Migration] Start inserting kanboard data for user %d", u.ID)
|
|
|
|
err = migration.InsertFromStructure(fullVikunjaHierachie, u)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
log.Debugf("[Kanboard Migration] Done inserting kanboard data for user %d", u.ID)
|
|
log.Debugf("[Kanboard Migration] Migration done for user %d", u.ID)
|
|
|
|
return nil
|
|
}
|