From bc0724c2ad863fdd8c0bcd6350148a8517ae2b95 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 12 Jan 2023 17:11:50 +0100 Subject: [PATCH] fix(tests): task permissions from parents --- pkg/db/fixtures/buckets.yml | 12 +++++++++ pkg/db/fixtures/projects.yml | 6 +++++ pkg/db/fixtures/tasks.yml | 10 ++++---- pkg/integrations/task_comment_test.go | 36 +++++++++++++-------------- pkg/integrations/task_test.go | 36 +++++++++++++-------------- pkg/models/prject_test.go | 4 +-- 6 files changed, 61 insertions(+), 43 deletions(-) diff --git a/pkg/db/fixtures/buckets.yml b/pkg/db/fixtures/buckets.yml index c70e10042..d68466cb0 100644 --- a/pkg/db/fixtures/buckets.yml +++ b/pkg/db/fixtures/buckets.yml @@ -218,3 +218,15 @@ created_by_id: -2 created: 2020-04-18 21:13:52 updated: 2020-04-18 21:13:52 +- id: 36 + title: testbucket36 + project_id: 33 + created_by_id: 6 + created: 2020-04-18 21:13:52 + updated: 2020-04-18 21:13:52 +- id: 37 + title: testbucket37 + project_id: 34 + created_by_id: 6 + created: 2020-04-18 21:13:52 + updated: 2020-04-18 21:13:52 diff --git a/pkg/db/fixtures/projects.yml b/pkg/db/fixtures/projects.yml index cd1f4a7a4..be570e84a 100644 --- a/pkg/db/fixtures/projects.yml +++ b/pkg/db/fixtures/projects.yml @@ -258,35 +258,41 @@ id: 29 title: Test29 owner_id: 6 + position: 2900 updated: 2018-12-02 15:13:12 created: 2018-12-01 15:13:12 - id: 30 title: Test30 owner_id: 6 + position: 3000 updated: 2018-12-02 15:13:12 created: 2018-12-01 15:13:12 - id: 31 title: Test31 owner_id: 6 + position: 3100 updated: 2018-12-02 15:13:12 created: 2018-12-01 15:13:12 - id: 32 title: Test32 owner_id: 6 + position: 3200 updated: 2018-12-02 15:13:12 created: 2018-12-01 15:13:12 - id: 33 title: Test33 owner_id: 6 + position: 3300 updated: 2018-12-02 15:13:12 created: 2018-12-01 15:13:12 - id: 34 title: Test34 owner_id: 6 + position: 3400 updated: 2018-12-02 15:13:12 created: 2018-12-01 15:13:12 diff --git a/pkg/db/fixtures/tasks.yml b/pkg/db/fixtures/tasks.yml index 7812407d6..89bc9f741 100644 --- a/pkg/db/fixtures/tasks.yml +++ b/pkg/db/fixtures/tasks.yml @@ -193,7 +193,7 @@ title: 'task #21' done: false created_by_id: 6 - project_id: 12 + project_id: 32 index: 1 bucket_id: 12 created: 2018-12-01 01:12:04 @@ -202,18 +202,18 @@ title: 'task #22' done: false created_by_id: 6 - project_id: 12 + project_id: 33 index: 1 - bucket_id: 12 + bucket_id: 36 created: 2018-12-01 01:12:04 updated: 2018-12-01 01:12:04 - id: 23 title: 'task #23' done: false created_by_id: 6 - project_id: 12 + project_id: 34 index: 1 - bucket_id: 12 + bucket_id: 37 created: 2018-12-01 01:12:04 updated: 2018-12-01 01:12:04 - id: 24 diff --git a/pkg/integrations/task_comment_test.go b/pkg/integrations/task_comment_test.go index 6d1959e87..4e367faa8 100644 --- a/pkg/integrations/task_comment_test.go +++ b/pkg/integrations/task_comment_test.go @@ -101,33 +101,33 @@ func TestTaskComments(t *testing.T) { assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project Team readonly", func(t *testing.T) { _, err := testHandler.testUpdateWithUser(nil, map[string]string{"task": "21", "commentid": "9"}, `{"comment":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam write", func(t *testing.T) { + t.Run("Shared Via Parent Project Team write", func(t *testing.T) { _, err := testHandler.testUpdateWithUser(nil, map[string]string{"task": "22", "commentid": "10"}, `{"comment":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) { + t.Run("Shared Via Parent Project Team admin", func(t *testing.T) { _, err := testHandler.testUpdateWithUser(nil, map[string]string{"task": "23", "commentid": "11"}, `{"comment":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project User readonly", func(t *testing.T) { _, err := testHandler.testUpdateWithUser(nil, map[string]string{"task": "24", "commentid": "12"}, `{"comment":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser write", func(t *testing.T) { + t.Run("Shared Via Parent Project User write", func(t *testing.T) { _, err := testHandler.testUpdateWithUser(nil, map[string]string{"task": "25", "commentid": "13"}, `{"comment":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser admin", func(t *testing.T) { + t.Run("Shared Via Parent Project User admin", func(t *testing.T) { _, err := testHandler.testUpdateWithUser(nil, map[string]string{"task": "26", "commentid": "14"}, `{"comment":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) @@ -184,33 +184,33 @@ func TestTaskComments(t *testing.T) { assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project Team readonly", func(t *testing.T) { _, err := testHandler.testDeleteWithUser(nil, map[string]string{"task": "21", "commentid": "9"}) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam write", func(t *testing.T) { + t.Run("Shared Via Parent Project Team write", func(t *testing.T) { _, err := testHandler.testDeleteWithUser(nil, map[string]string{"task": "22", "commentid": "10"}) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) { + t.Run("Shared Via Parent Project Team admin", func(t *testing.T) { _, err := testHandler.testDeleteWithUser(nil, map[string]string{"task": "23", "commentid": "11"}) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project User readonly", func(t *testing.T) { _, err := testHandler.testDeleteWithUser(nil, map[string]string{"task": "24", "commentid": "12"}) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser write", func(t *testing.T) { + t.Run("Shared Via Parent Project User write", func(t *testing.T) { _, err := testHandler.testDeleteWithUser(nil, map[string]string{"task": "25", "commentid": "13"}) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser admin", func(t *testing.T) { + t.Run("Shared Via Parent Project User admin", func(t *testing.T) { _, err := testHandler.testDeleteWithUser(nil, map[string]string{"task": "26", "commentid": "14"}) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) @@ -267,33 +267,33 @@ func TestTaskComments(t *testing.T) { assert.Contains(t, rec.Body.String(), `"comment":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceTeam readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project Team readonly", func(t *testing.T) { _, err := testHandler.testCreateWithUser(nil, map[string]string{"task": "21"}, `{"comment":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam write", func(t *testing.T) { + t.Run("Shared Via Parent Project Team write", func(t *testing.T) { rec, err := testHandler.testCreateWithUser(nil, map[string]string{"task": "22"}, `{"comment":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"comment":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) { + t.Run("Shared Via Parent Project Team admin", func(t *testing.T) { rec, err := testHandler.testCreateWithUser(nil, map[string]string{"task": "23"}, `{"comment":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"comment":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceUser readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project User readonly", func(t *testing.T) { _, err := testHandler.testCreateWithUser(nil, map[string]string{"task": "24"}, `{"comment":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser write", func(t *testing.T) { + t.Run("Shared Via Parent Project User write", func(t *testing.T) { rec, err := testHandler.testCreateWithUser(nil, map[string]string{"task": "25"}, `{"comment":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"comment":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceUser admin", func(t *testing.T) { + t.Run("Shared Via Parent Project User admin", func(t *testing.T) { rec, err := testHandler.testCreateWithUser(nil, map[string]string{"task": "26"}, `{"comment":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"comment":"Lorem Ipsum"`) diff --git a/pkg/integrations/task_test.go b/pkg/integrations/task_test.go index dc6c662cf..be841c3cf 100644 --- a/pkg/integrations/task_test.go +++ b/pkg/integrations/task_test.go @@ -254,33 +254,33 @@ func TestTask(t *testing.T) { assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceTeam readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project Team readonly", func(t *testing.T) { _, err := testHandler.testUpdateWithUser(nil, map[string]string{"projecttask": "21"}, `{"title":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam write", func(t *testing.T) { + t.Run("Shared Via Parent Project Team write", func(t *testing.T) { rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"projecttask": "22"}, `{"title":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) { + t.Run("Shared Via Parent Project Team admin", func(t *testing.T) { rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"projecttask": "23"}, `{"title":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceUser readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project User readonly", func(t *testing.T) { _, err := testHandler.testUpdateWithUser(nil, map[string]string{"projecttask": "24"}, `{"title":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser write", func(t *testing.T) { + t.Run("Shared Via Parent Project User write", func(t *testing.T) { rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"projecttask": "25"}, `{"title":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceUser admin", func(t *testing.T) { + t.Run("Shared Via Parent Project User admin", func(t *testing.T) { rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"projecttask": "26"}, `{"title":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) @@ -372,33 +372,33 @@ func TestTask(t *testing.T) { assert.Contains(t, rec.Body.String(), `Successfully deleted.`) }) - t.Run("Shared Via NamespaceTeam readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project Team readonly", func(t *testing.T) { _, err := testHandler.testDeleteWithUser(nil, map[string]string{"projecttask": "21"}) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam write", func(t *testing.T) { + t.Run("Shared Via Parent Project Team write", func(t *testing.T) { rec, err := testHandler.testDeleteWithUser(nil, map[string]string{"projecttask": "22"}) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `Successfully deleted.`) }) - t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) { + t.Run("Shared Via Parent Project Team admin", func(t *testing.T) { rec, err := testHandler.testDeleteWithUser(nil, map[string]string{"projecttask": "23"}) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `Successfully deleted.`) }) - t.Run("Shared Via NamespaceUser readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project User readonly", func(t *testing.T) { _, err := testHandler.testDeleteWithUser(nil, map[string]string{"projecttask": "24"}) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser write", func(t *testing.T) { + t.Run("Shared Via Parent Project User write", func(t *testing.T) { rec, err := testHandler.testDeleteWithUser(nil, map[string]string{"projecttask": "25"}) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `Successfully deleted.`) }) - t.Run("Shared Via NamespaceUser admin", func(t *testing.T) { + t.Run("Shared Via Parent Project User admin", func(t *testing.T) { rec, err := testHandler.testDeleteWithUser(nil, map[string]string{"projecttask": "26"}) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `Successfully deleted.`) @@ -455,33 +455,33 @@ func TestTask(t *testing.T) { assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceTeam readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project Team readonly", func(t *testing.T) { _, err := testHandler.testCreateWithUser(nil, map[string]string{"project": "12"}, `{"title":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceTeam write", func(t *testing.T) { + t.Run("Shared Via Parent Project Team write", func(t *testing.T) { rec, err := testHandler.testCreateWithUser(nil, map[string]string{"project": "13"}, `{"title":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) { + t.Run("Shared Via Parent Project Team admin", func(t *testing.T) { rec, err := testHandler.testCreateWithUser(nil, map[string]string{"project": "14"}, `{"title":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceUser readonly", func(t *testing.T) { + t.Run("Shared Via Parent Project User readonly", func(t *testing.T) { _, err := testHandler.testCreateWithUser(nil, map[string]string{"project": "15"}, `{"title":"Lorem Ipsum"}`) assert.Error(t, err) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) }) - t.Run("Shared Via NamespaceUser write", func(t *testing.T) { + t.Run("Shared Via Parent Project User write", func(t *testing.T) { rec, err := testHandler.testCreateWithUser(nil, map[string]string{"project": "16"}, `{"title":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) }) - t.Run("Shared Via NamespaceUser admin", func(t *testing.T) { + t.Run("Shared Via Parent Project User admin", func(t *testing.T) { rec, err := testHandler.testCreateWithUser(nil, map[string]string{"project": "17"}, `{"title":"Lorem Ipsum"}`) assert.NoError(t, err) assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`) diff --git a/pkg/models/prject_test.go b/pkg/models/prject_test.go index 584a09689..440da048f 100644 --- a/pkg/models/prject_test.go +++ b/pkg/models/prject_test.go @@ -243,7 +243,7 @@ func TestProject_ReadAll(t *testing.T) { projects := []*Project{} _, _, err := getAllProjectsForUser(s, 1, nil, &projectOptions{}, &projects, 0) assert.NoError(t, err) - assert.Equal(t, 12, len(projects)) + assert.Equal(t, 23, len(projects)) _ = s.Close() }) t.Run("only child projects for one project", func(t *testing.T) { @@ -259,7 +259,7 @@ func TestProject_ReadAll(t *testing.T) { assert.NoError(t, err) assert.Equal(t, reflect.TypeOf(projects3).Kind(), reflect.Slice) ls := projects3.([]*Project) - assert.Equal(t, 12, len(ls)) + assert.Equal(t, 23, len(ls)) assert.Equal(t, int64(3), ls[0].ID) // Project 3 has a position of 1 and should be sorted first assert.Equal(t, int64(1), ls[1].ID) assert.Equal(t, int64(6), ls[2].ID)