Compare commits

..

6 Commits

Author SHA1 Message Date
357eee1b6c chore(deps): update dev-dependencies
Some checks failed
continuous-integration/drone/pr Build is failing
2024-02-10 14:06:20 +00:00
2e57b6e409
chore: release preparation
All checks were successful
continuous-integration/drone/push Build is passing
2024-02-10 14:46:33 +01:00
8752ae2a0b
fix(webhook): fetch all event details before sending the webhook
All checks were successful
continuous-integration/drone/push Build is passing
Resolves https://community.vikunja.io/t/webhook-comment-data-issues/1952
2024-02-10 14:15:32 +01:00
7edb53ca12
fix(export): don't crash when an exported file does not exist
All checks were successful
continuous-integration/drone/push Build is passing
Related to https://github.com/go-vikunja/vikunja/issues/110
2024-02-10 13:45:12 +01:00
25a03d1789
chore: remove unused import 2024-02-10 13:31:19 +01:00
5ab9fb89bb
fix(tasks): check for cycles during creation of task relations and prevent them 2024-02-10 13:30:41 +01:00
14 changed files with 464 additions and 47 deletions

View File

@ -7,6 +7,108 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
All releases can be found on https://code.vikunja.io/api/releases.
## [0.23.0] - 2024-02-10
### Bug Fixes
* *(assignees)* Use correct amount of spacing in assignee selection
* *(ci)* cd to frontend in frontend pipelines
* *(ci)* Deploy packages into the correct directory
* *(ci)* Swagger docs generate should use the correct url
* *(ci)* Typo
* *(ci)* Update shasum
* *(docs)* Old install pages redirect
* *(editor)* Don't set editor content intitially
* *(export)* Don't crash when an exported file does not exist
* *(filters)* Add explicit check for string slice filter
* *(gantt)* Correctly import languages from dayjs
* *(kanban)* Assignee spacing
* *(kanban)* Bottom spacing of labels
* *(notifications)* Mark all notifications as read in ui directly when marking as read on the server
* *(progress)* Cleanup unused css
* *(progress)* Less rounding
* *(reminders)* Set reminder date on datepicker when editing a reminder
* *(task)* Make sure the drag handle is shown as intended
* *(task)* Move cover image setter to store
* *(task)* Remove default task color
* *(tasks)* Check for cycles during creation of task relations and prevent them
* *(tasks)* Show any errors happening during task load
* *(tests)* Adjust gantt rows identifier
* *(webhook)* Fetch all event details before sending the webhook
### Features
* Merge API, Frontend and Desktop repos
* *(ci)* Combine api and frontend drone configs
* *(ci)* Merge desktop ci config
* *(ci)* Save .tags file to generate release tags
* *(ci)* Run desktop build without waiting on the frontend when not doing release builds
* *(ci)* Run desktop pipeline only on PRs
* *(editor)* Use primary color for currently selected node
* *(filters)* Log type if unknown filter type
* *(progress)* Move customizations into progress bar component
### Dependencies
* *(deps)* Update dependency @4tw/cypress-drag-drop to v1.8.1 (#693)
* *(deps)* Update dependency @fortawesome/vue-fontawesome to v3.0.6
* *(deps)* Update dependency @kyvg/vue3-notification to v3.1.4
* *(deps)* Update dependency @types/node to v20.11.10
* *(deps)* Update dependency autoprefixer to v10.3.3 (#684)
* *(deps)* Update dependency autoprefixer to v10.3.4 (#697)
* *(deps)* Update dependency axios to v0.21.2 (#698)
* *(deps)* Update dependency axios to v0.21.3 (#700)
* *(deps)* Update dependency cypress to v8.3.1 (#689)
* *(deps)* Update dependency electron to v28.2.1 (#186)
* *(deps)* Update dependency electron to v28.2.2 (#187)
* *(deps)* Update dependency esbuild to v0.12.23 (#683)
* *(deps)* Update dependency esbuild to v0.12.24 (#688)
* *(deps)* Update dependency esbuild to v0.12.25 (#696)
* *(deps)* Update dependency esbuild to v0.14.53 (#2217)
* *(deps)* Update dependency eslint-plugin-vue to v7.17.0 (#686)
* *(deps)* Update dependency floating-vue to v5.2.1
* *(deps)* Update dependency floating-vue to v5.2.2
* *(deps)* Update dependency jest to v27.1.0 (#687)
* *(deps)* Update dependency marked to v3.0.1 (#677)
* *(deps)* Update dependency marked to v3.0.2 (#682)
* *(deps)* Update dependency postcss to v8.4.19 (#2673)
* *(deps)* Update dependency sass to v1.38.1 (#679)
* *(deps)* Update dependency sass to v1.38.2 (#690)
* *(deps)* Update dependency sass to v1.39.0 (#695)
* *(deps)* Update dependency typescript to v4.4.2 (#685)
* *(deps)* Update dependency ufo to v1.4.0
* *(deps)* Update dependency vite to v2.5.1 (#680)
* *(deps)* Update dependency vite to v2.5.2 (#692)
* *(deps)* Update dependency vite to v2.5.3 (#694)
* *(deps)* Update dependency vite-plugin-pwa to v0.11.2 (#681)
* *(deps)* Update dependency vue to v3.2.45
* *(deps)* Update dependency vue-i18n to v9.9.1
* *(deps)* Update goreleaser/nfpm docker tag to v2.35.3 (#1692)
* *(deps)* Update module github.com/arran4/golang-ical to v0.2.4
* *(deps)* Update module github.com/mattn/go-sqlite3 to v1.14.21
* *(deps)* Update module github.com/mattn/go-sqlite3 to v1.14.22
* *(deps)* Update module github.com/swaggo/swag to v1.16.3
* *(deps)* Update module github.com/yuin/goldmark to v1.7.0
* *(deps)* Update pnpm to v8.15.0
* *(deps)* Update pnpm to v8.15.1
* *(deps)* Update sentry-javascript monorepo to v7.100.1
* *(deps)* Update sentry-javascript monorepo to v7.17.2 (#2587)
* *(deps)* Update sentry-javascript monorepo to v7.19.0 (#2670)
* *(deps)* Update sentry-javascript monorepo to v7.99.0
* *(deps)* Update src.techknowlogick.com/xgo digest to 45b9ea6
* *(deps)* Update src.techknowlogick.com/xgo digest to 5aae655
* *(deps)* Update tiptap to v2.2.0
* *(deps)* Update tiptap to v2.2.1
* *(deps)* Update typescript-eslint monorepo to v4.29.3 (#676)
* *(deps)* Update typescript-eslint monorepo to v4.30.0 (#691)
### Miscellaneous Tasks
* *(Expandable)* Spelling ⛈
* *(deps)* Move renovate config
* *(deps)* Remove redundant renovate config
* *(quick actions)* Format
## [0.22.1] - 2024-01-28
### Bug Fixes

View File

@ -2,12 +2,12 @@
[![Build Status](https://drone.kolaente.de/api/badges/vikunja/vikunjaa/status.svg)](https://drone.kolaente.de/vikunja/vikunja)
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](LICENSE)
[![Download](https://img.shields.io/badge/download-v0.22.1-brightgreen.svg)](https://dl.vikunja.io)
[![Download](https://img.shields.io/badge/download-v0.23.0-brightgreen.svg)](https://dl.vikunja.io)
[![Docker Pulls](https://img.shields.io/docker/pulls/vikunja/vikunja.svg)](https://hub.docker.com/r/vikunja/vikunja/)
[![Swagger Docs](https://img.shields.io/badge/swagger-docs-brightgreen.svg)](https://try.vikunja.io/api/v1/docs)
[![Go Report Card](https://goreportcard.com/badge/kolaente.dev/vikunja/vikunja)](https://goreportcard.com/report/kolaente.dev/vikunja/vikunja)
# Vikunja API
# Vikunja
> The Todo-app to organize your life.
@ -43,12 +43,9 @@ All docs can be found on [the Vikunja home page](https://vikunja.io/docs/).
See [the roadmap](https://my.vikunja.cloud/share/QFyzYEmEYfSyQfTOmIRSwLUpkFjboaBqQCnaPmWd/auth) (hosted on Vikunja!) for more!
* [ ] [Mobile apps](https://code.vikunja.io/app) (separate repo) *In Progress*
* [ ] [Webapp](https://code.vikunja.io/frontend) (separate repo) *In Progress*
## Contributing
Fork -> Push -> Pull-Request. Also see the [dev docs](https://vikunja.io/docs/development/) for more info.
Please check out the contribuition guidelines on [the website](https://vikunja.io/docs/development/).
## License

View File

@ -1,5 +1,8 @@
# Changelog
THIS CHANGELOG ONLY EXISTS FOR HISTORICAL REASONS.
Starting with version 0.23.0, all changes are logged in the CHANGELOG.md in the root of this repository since the repos were merged.
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

View File

@ -2,9 +2,8 @@
set -xe
frontend_version=$(sed -n 's/.*"VERSION": "\([^"]*\)".*/\1/p' ./frontend/version.json)
frontend_version=$(git describe --tags --always --abbrev=10)
sed -i "s/\${version}/$frontend_version/g" package.json
sed -i "s/\"version\": \".*\"/\"version\": \"$frontend_version\"/" package.json

View File

@ -70,30 +70,31 @@ This document describes the different errors Vikunja can return.
## Task
| ErrorCode | HTTP Status Code | Description |
|-----------|------------------|-------------|
| 4001 | 400 | The project task text cannot be empty. |
| 4002 | 404 | The project task does not exist. |
| 4003 | 403 | All bulk editing tasks must belong to the same project. |
| 4004 | 403 | Need at least one task when bulk editing tasks. |
| 4005 | 403 | The user does not have the right to see the task. |
| 4006 | 403 | The user tried to set a parent task as the task itself. |
| ErrorCode | HTTP Status Code | Description |
|-----------|------------------|----------------------------------------------------------------------------|
| 4001 | 400 | The project task text cannot be empty. |
| 4002 | 404 | The project task does not exist. |
| 4003 | 403 | All bulk editing tasks must belong to the same project. |
| 4004 | 403 | Need at least one task when bulk editing tasks. |
| 4005 | 403 | The user does not have the right to see the task. |
| 4006 | 403 | The user tried to set a parent task as the task itself. |
| 4007 | 400 | The user tried to create a task relation with an invalid kind of relation. |
| 4008 | 409 | The user tried to create a task relation which already exists. |
| 4009 | 404 | The task relation does not exist. |
| 4010 | 400 | Cannot relate a task with itself. |
| 4011 | 404 | The task attachment does not exist. |
| 4012 | 400 | The task attachment is too large. |
| 4013 | 400 | The task sort param is invalid. |
| 4014 | 400 | The task sort order is invalid. |
| 4015 | 404 | The task comment does not exist. |
| 4016 | 400 | Invalid task field. |
| 4017 | 400 | Invalid task filter comparator. |
| 4018 | 400 | Invalid task filter concatinator. |
| 4019 | 400 | Invalid task filter value. |
| 4020 | 400 | The provided attachment does not belong to that task. |
| 4021 | 400 | This user is already assigned to that task. |
| 4022 | 400 | The task has a relative reminder which does not specify relative to what. |
| 4008 | 409 | The user tried to create a task relation which already exists. |
| 4009 | 404 | The task relation does not exist. |
| 4010 | 400 | Cannot relate a task with itself. |
| 4011 | 404 | The task attachment does not exist. |
| 4012 | 400 | The task attachment is too large. |
| 4013 | 400 | The task sort param is invalid. |
| 4014 | 400 | The task sort order is invalid. |
| 4015 | 404 | The task comment does not exist. |
| 4016 | 400 | Invalid task field. |
| 4017 | 400 | Invalid task filter comparator. |
| 4018 | 400 | Invalid task filter concatinator. |
| 4019 | 400 | Invalid task filter value. |
| 4020 | 400 | The provided attachment does not belong to that task. |
| 4021 | 400 | This user is already assigned to that task. |
| 4022 | 400 | The task has a relative reminder which does not specify relative to what. |
| 4023 | 409 | Tried to create a task relation which would create a cycle. |
## Team

View File

@ -1,5 +1,8 @@
# Changelog
THIS CHANGELOG ONLY EXISTS FOR HISTORICAL REASONS.
Starting with version 0.23.0, all changes are logged in the CHANGELOG.md in the root of this repository since the repos were merged.
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres

View File

@ -172,7 +172,7 @@
"typescript": "5.3.3",
"vite": "5.1.1",
"vite-plugin-inject-preload": "1.3.3",
"vite-plugin-pwa": "0.17.5",
"vite-plugin-pwa": "0.18.0",
"vite-plugin-sentry": "1.4.0",
"vite-svg-loader": "5.1.0",
"vitest": "1.2.2",

View File

@ -376,8 +376,8 @@ devDependencies:
specifier: 1.3.3
version: 1.3.3(vite@5.1.1)
vite-plugin-pwa:
specifier: 0.17.5
version: 0.17.5(vite@5.1.1)(workbox-build@7.0.0)(workbox-window@7.0.0)
specifier: 0.18.0
version: 0.18.0(vite@5.1.1)(workbox-build@7.0.0)(workbox-window@7.0.0)
vite-plugin-sentry:
specifier: 1.4.0
version: 1.4.0(vite@5.1.1)
@ -3709,7 +3709,7 @@ packages:
'@codemirror/state': 6.3.2
'@codemirror/theme-one-dark': 6.1.2
'@codemirror/view': 6.22.1
'@histoire/shared': 0.17.9(vite@5.1.1)
'@histoire/shared': 0.17.10(vite@5.1.1)
'@histoire/vendors': 0.17.8
transitivePeerDependencies:
- vite
@ -11076,8 +11076,8 @@ packages:
vite: 5.1.1(@types/node@20.11.17)(sass@1.70.0)(terser@5.24.0)
dev: true
/vite-plugin-pwa@0.17.5(vite@5.1.1)(workbox-build@7.0.0)(workbox-window@7.0.0):
resolution: {integrity: sha512-UxRNPiJBzh4tqU/vc8G2TxmrUTzT6BqvSzhszLk62uKsf+npXdvLxGDz9C675f4BJi6MbD2tPnJhi5txlMzxbQ==}
/vite-plugin-pwa@0.18.0(vite@5.1.1)(workbox-build@7.0.0)(workbox-window@7.0.0):
resolution: {integrity: sha512-4ReE3KHz3sSXT3o0kpcNHirOYPbbCcnOgJGZX64jFxOvaOmkHXEorm5h1b6XU6/i48f2xzurSGU7w2+4HnziMQ==}
engines: {node: '>=16.0.0'}
peerDependencies:
vite: ^3.1.0 || ^4.0.0 || ^5.0.0

View File

@ -13,8 +13,6 @@
</template>
<script setup lang="ts">
import {defineProps} from 'vue'
defineProps({
value: {
type: Number,

View File

@ -1003,6 +1003,35 @@ func (err ErrReminderRelativeToMissing) HTTPError() web.HTTPError {
}
}
// ErrTaskRelationCycle represents an error where the user tries to create an already existing relation
type ErrTaskRelationCycle struct {
Kind RelationKind
TaskID int64
OtherTaskID int64
}
// IsErrTaskRelationCycle checks if an error is ErrTaskRelationCycle.
func IsErrTaskRelationCycle(err error) bool {
_, ok := err.(ErrTaskRelationCycle)
return ok
}
func (err ErrTaskRelationCycle) Error() string {
return fmt.Sprintf("Task relation cycle detectetd [TaskID: %v, OtherTaskID: %v, Kind: %v]", err.TaskID, err.OtherTaskID, err.Kind)
}
// ErrCodeTaskRelationCycle holds the unique world-error code of this error
const ErrCodeTaskRelationCycle = 4022
// HTTPError holds the http error description
func (err ErrTaskRelationCycle) HTTPError() web.HTTPError {
return web.HTTPError{
HTTPCode: http.StatusConflict,
Code: ErrCodeTaskRelationCycle,
Message: "This task relation would create a cycle.",
}
}
// ============
// Team errors
// ============

View File

@ -19,8 +19,10 @@ package models
import (
"archive/zip"
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
"os"
"strconv"
"time"
@ -219,15 +221,20 @@ func exportTaskAttachments(s *xorm.Session, wr *zip.Writer, taskIDs []int64) (er
return err
}
fs := make(map[int64]io.ReadCloser)
attachmentFiles := make(map[int64]io.ReadCloser)
for _, ta := range tas {
if err := ta.File.LoadFileByID(); err != nil {
err = ta.File.LoadFileByID()
if err != nil {
var pathError *fs.PathError
if errors.As(err, &pathError) {
continue
}
return err
}
fs[ta.FileID] = ta.File.File
attachmentFiles[ta.FileID] = ta.File.File
}
return utils.WriteFilesToZip(fs, wr)
return utils.WriteFilesToZip(attachmentFiles, wr)
}
func exportSavedFilters(s *xorm.Session, u *user.User, wr *zip.Writer) (err error) {
@ -256,7 +263,7 @@ func exportProjectBackgrounds(s *xorm.Session, u *user.User, wr *zip.Writer) (er
return err
}
fs := make(map[int64]io.ReadCloser)
backgroundFiles := make(map[int64]io.ReadCloser)
for _, l := range projects {
if l.BackgroundFileID == 0 {
continue
@ -267,13 +274,17 @@ func exportProjectBackgrounds(s *xorm.Session, u *user.User, wr *zip.Writer) (er
}
err = bgFile.LoadFileByID()
if err != nil {
return
var pathError *fs.PathError
if errors.As(err, &pathError) {
continue
}
return err
}
fs[l.BackgroundFileID] = bgFile.File
backgroundFiles[l.BackgroundFileID] = bgFile.File
}
return utils.WriteFilesToZip(fs, wr)
return utils.WriteFilesToZip(backgroundFiles, wr)
}
func RegisterOldExportCleanupCron() {

View File

@ -747,6 +747,48 @@ func (wl *WebhookListener) Handle(msg *message.Message) (err error) {
return nil
}
// Load event data again so that it is always populated in the webhook payload
var doerID int64
if doer, has := event["doer"]; has {
d := doer.(map[string]interface{})
if rawDoerID, has := d["id"]; has {
doerID = getIDAsInt64(rawDoerID)
fullDoer, err := user.GetUserByID(s, doerID)
if err != nil && !user.IsErrUserDoesNotExist(err) {
return err
}
if err == nil {
event["doer"] = fullDoer
}
}
}
if task, has := event["task"]; has && doerID != 0 {
t := task.(map[string]interface{})
if taskID, has := t["id"]; has {
id := getIDAsInt64(taskID)
fullTask := Task{ID: id}
err = fullTask.ReadOne(s, &user.User{ID: doerID})
if err != nil && !IsErrTaskDoesNotExist(err) {
return err
}
if err == nil {
event["task"] = fullTask
}
}
}
if _, has := event["project"]; has && doerID != 0 {
project := &Project{ID: projectID}
err = project.ReadOne(s, &user.User{ID: doerID})
if err != nil && !IsErrProjectDoesNotExist(err) {
return err
}
if err == nil {
event["project"] = project
}
}
err = webhook.sendWebhookPayload(&WebhookPayload{
EventName: wl.EventName,
Time: time.Now(),

View File

@ -138,6 +138,54 @@ func getInverseRelation(kind RelationKind) RelationKind {
return RelationKindUnknown
}
func checkTaskRelationCycle(s *xorm.Session, relation *TaskRelation, otherTaskIDToCheck int64, visited map[int64]bool, currentPath map[int64]bool) (err error) {
if visited == nil {
visited = make(map[int64]bool)
}
if currentPath == nil {
currentPath = make(map[int64]bool)
}
if visited[relation.TaskID] {
return nil // Node already visited, no cycle detected
}
if relation.TaskID == otherTaskIDToCheck || // This checks for cycles between leaf nodes
currentPath[relation.TaskID] ||
currentPath[otherTaskIDToCheck] {
// Cycle detected
return ErrTaskRelationCycle{
TaskID: relation.TaskID,
OtherTaskID: relation.OtherTaskID,
Kind: relation.RelationKind,
}
}
visited[relation.TaskID] = true
currentPath[relation.TaskID] = true
parenttasks := []*TaskRelation{}
// where child = relation.id
err = s.Where("other_task_id = ? AND relation_kind = ?", relation.TaskID, relation.RelationKind).
Find(&parenttasks)
if err != nil {
return
}
for _, parent := range parenttasks {
err = checkTaskRelationCycle(s, parent, otherTaskIDToCheck, visited, currentPath)
if err != nil {
return err
}
}
// Remove the current node from the currentPath to avoid false positives
delete(currentPath, relation.TaskID)
return nil
}
// Create creates a new task relation
// @Summary Create a new relation between two tasks
// @Description Creates a new relation between two tasks. The user needs to have update rights on the base task and at least read rights on the other task. Both tasks do not need to be on the same project. Take a look at the docs for available task relation kinds.
@ -191,6 +239,14 @@ func (rel *TaskRelation) Create(s *xorm.Session, a web.Auth) error {
RelationKind: getInverseRelation(rel.RelationKind),
}
// If we're creating a subtask relation, check if we're about to create a cycle
if rel.RelationKind == RelationKindSubtask || rel.RelationKind == RelationKindParenttask {
err = checkTaskRelationCycle(s, rel, rel.OtherTaskID, nil, nil)
if err != nil {
return err
}
}
// Finally insert everything
_, err = s.Insert(&[]*TaskRelation{
rel,

View File

@ -96,6 +96,182 @@ func TestTaskRelation_Create(t *testing.T) {
require.Error(t, err)
assert.True(t, IsErrRelationTasksCannotBeTheSame(err))
})
t.Run("cycle with one subtask", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
rel := TaskRelation{
TaskID: 29,
OtherTaskID: 1,
RelationKind: RelationKindSubtask,
}
err := rel.Create(s, &user.User{ID: 1})
require.Error(t, err)
assert.True(t, IsErrTaskRelationCycle(err))
})
t.Run("cycle with multiple subtasks", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
rel1 := TaskRelation{
TaskID: 1,
OtherTaskID: 2,
RelationKind: RelationKindSubtask,
}
err := rel1.Create(s, &user.User{ID: 1})
require.NoError(t, err)
rel2 := TaskRelation{
TaskID: 2,
OtherTaskID: 3,
RelationKind: RelationKindSubtask,
}
err = rel2.Create(s, &user.User{ID: 1})
require.NoError(t, err)
rel3 := TaskRelation{
TaskID: 3,
OtherTaskID: 4,
RelationKind: RelationKindSubtask,
}
err = rel3.Create(s, &user.User{ID: 1})
require.NoError(t, err)
// Cycle happens here
rel4 := TaskRelation{
TaskID: 4,
OtherTaskID: 2,
RelationKind: RelationKindSubtask,
}
err = rel4.Create(s, &user.User{ID: 1})
require.Error(t, err)
assert.True(t, IsErrTaskRelationCycle(err))
})
t.Run("cycle with multiple subtasks tasks and relation back to parent", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
rel1 := TaskRelation{
TaskID: 1,
OtherTaskID: 2,
RelationKind: RelationKindSubtask,
}
err := rel1.Create(s, &user.User{ID: 1})
require.NoError(t, err)
rel2 := TaskRelation{
TaskID: 2,
OtherTaskID: 3,
RelationKind: RelationKindSubtask,
}
err = rel2.Create(s, &user.User{ID: 1})
require.NoError(t, err)
rel3 := TaskRelation{
TaskID: 3,
OtherTaskID: 4,
RelationKind: RelationKindSubtask,
}
err = rel3.Create(s, &user.User{ID: 1})
require.NoError(t, err)
// Cycle happens here
rel4 := TaskRelation{
TaskID: 4,
OtherTaskID: 1,
RelationKind: RelationKindSubtask,
}
err = rel4.Create(s, &user.User{ID: 1})
require.Error(t, err)
assert.True(t, IsErrTaskRelationCycle(err))
})
t.Run("cycle with one parenttask", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
rel := TaskRelation{
TaskID: 1,
OtherTaskID: 29,
RelationKind: RelationKindParenttask,
}
err := rel.Create(s, &user.User{ID: 1})
require.Error(t, err)
assert.True(t, IsErrTaskRelationCycle(err))
})
t.Run("cycle with multiple parenttasks", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
rel1 := TaskRelation{
TaskID: 1,
OtherTaskID: 2,
RelationKind: RelationKindParenttask,
}
err := rel1.Create(s, &user.User{ID: 1})
require.NoError(t, err)
rel2 := TaskRelation{
TaskID: 2,
OtherTaskID: 3,
RelationKind: RelationKindParenttask,
}
err = rel2.Create(s, &user.User{ID: 1})
require.NoError(t, err)
rel3 := TaskRelation{
TaskID: 3,
OtherTaskID: 4,
RelationKind: RelationKindParenttask,
}
err = rel3.Create(s, &user.User{ID: 1})
require.NoError(t, err)
// Cycle happens here
rel4 := TaskRelation{
TaskID: 4,
OtherTaskID: 2,
RelationKind: RelationKindParenttask,
}
err = rel4.Create(s, &user.User{ID: 1})
require.Error(t, err)
assert.True(t, IsErrTaskRelationCycle(err))
})
t.Run("cycle with multiple parenttasks and relation back to parent", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
rel1 := TaskRelation{
TaskID: 1,
OtherTaskID: 2,
RelationKind: RelationKindParenttask,
}
err := rel1.Create(s, &user.User{ID: 1})
require.NoError(t, err)
rel2 := TaskRelation{
TaskID: 2,
OtherTaskID: 3,
RelationKind: RelationKindParenttask,
}
err = rel2.Create(s, &user.User{ID: 1})
require.NoError(t, err)
rel3 := TaskRelation{
TaskID: 3,
OtherTaskID: 4,
RelationKind: RelationKindParenttask,
}
err = rel3.Create(s, &user.User{ID: 1})
require.NoError(t, err)
// Cycle happens here
rel4 := TaskRelation{
TaskID: 4,
OtherTaskID: 1,
RelationKind: RelationKindParenttask,
}
err = rel4.Create(s, &user.User{ID: 1})
require.Error(t, err)
assert.True(t, IsErrTaskRelationCycle(err))
})
}
func TestTaskRelation_Delete(t *testing.T) {