diff --git a/apps/andi/lib/andi_web/controllers/reports_controller.ex b/apps/andi/lib/andi_web/controllers/reports_controller.ex index 9d57c2289..98bf1f56c 100644 --- a/apps/andi/lib/andi_web/controllers/reports_controller.ex +++ b/apps/andi/lib/andi_web/controllers/reports_controller.ex @@ -18,9 +18,17 @@ defmodule AndiWeb.ReportsController do defp build_csv() do values = get_datasets() - |> Enum.map(fn dataset -> [dataset.id, get_users_for_dataset(dataset.is_public, dataset.access_groups, dataset.org_id)] end) + |> Enum.map(fn dataset -> + [ + dataset.id, + dataset.dataTitle, + dataset.orgTitle, + dataset.systemName, + get_users_for_dataset(dataset.is_public, dataset.access_groups, dataset.org_id) + ] + end) - [["Dataset ID", "Users"] | values] + [["Dataset ID", "Dataset Title", "Organization", "System Name", "Users"] | values] end defp get_users_for_dataset(is_public, access_groups, org_id) do @@ -39,12 +47,20 @@ defmodule AndiWeb.ReportsController do query = from(dataset in Dataset, where: dataset.submission_status != :draft, - preload: [:technical, access_groups: [:users]] + preload: [:business, :technical, access_groups: [:users]] ) Andi.Repo.all(query) |> Enum.map(fn dataset -> - %{id: dataset.id, is_public: not dataset.technical.private, access_groups: dataset.access_groups, org_id: dataset.technical.orgId} + %{ + id: dataset.id, + dataTitle: dataset.business.dataTitle, + orgTitle: dataset.business.orgTitle, + systemName: dataset.technical.systemName, + is_public: not dataset.technical.private, + access_groups: dataset.access_groups, + org_id: dataset.technical.orgId + } end) end diff --git a/apps/andi/mix.exs b/apps/andi/mix.exs index 8208bd0e0..41be0997c 100644 --- a/apps/andi/mix.exs +++ b/apps/andi/mix.exs @@ -4,7 +4,7 @@ defmodule Andi.MixProject do def project do [ app: :andi, - version: "2.6.57", + version: "2.6.58", build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/apps/andi/test/integration/andi_web/controllers/reports_controller_test.exs b/apps/andi/test/integration/andi_web/controllers/reports_controller_test.exs index 53188d2f0..266f0fb3c 100644 --- a/apps/andi/test/integration/andi_web/controllers/reports_controller_test.exs +++ b/apps/andi/test/integration/andi_web/controllers/reports_controller_test.exs @@ -4,6 +4,7 @@ defmodule Andi.ReportsControllerTest do use Placebo use AndiWeb.Test.AuthConnCase.IntegrationCase alias Andi.InputSchemas.Datasets.Dataset + alias Andi.InputSchemas.Datasets.Business alias Andi.InputSchemas.Datasets.Technical alias Andi.InputSchemas.AccessGroup alias Andi.InputSchemas.Organization @@ -11,17 +12,33 @@ defmodule Andi.ReportsControllerTest do describe "download_report" do test "sets dataset users to public when dataset is not private", %{curator_conn: conn} do - dataset1 = %Dataset{id: "12345", technical: %Technical{private: false}} + dataset1 = %Dataset{ + id: "12345", + business: %Business{dataTitle: "Example", orgTitle: "Test"}, + technical: %Technical{private: false, systemName: "Test__Example"} + } allow Andi.Repo.all(any()), seq: [[dataset1]] result = get(conn, "/report") assert result.status == 200 - assert result.resp_body == "Dataset ID,Users\r\n12345,All (public)\r\n" + + assert result.resp_body == + "Dataset ID,Dataset Title,Organization,System Name,Users\r\n12345,Example,Test,Test__Example,All (public)\r\n" end test "adds users to private dataset based on the dataset's org", %{curator_conn: conn} do - dataset1 = %Dataset{id: "12345", technical: %Technical{private: true, orgId: "1122"}, access_groups: []} - dataset2 = %Dataset{id: "6789", technical: %Technical{private: false}} + dataset1 = %Dataset{ + id: "12345", + business: %Business{dataTitle: "Example", orgTitle: "Test"}, + technical: %Technical{private: true, orgId: "1122", systemName: "Test__Example"}, + access_groups: [] + } + + dataset2 = %Dataset{ + id: "6789", + business: %Business{dataTitle: "Example2", orgTitle: "Test2"}, + technical: %Technical{private: false, systemName: "Test2__Example2"} + } user1 = %User{ subject_id: UUID.uuid4(), @@ -40,7 +57,9 @@ defmodule Andi.ReportsControllerTest do allow Andi.Repo.all(any()), seq: [[dataset1, dataset2], [org]] result = get(conn, "/report") assert result.status == 200 - assert result.resp_body == "Dataset ID,Users\r\n12345,\"user1@fakemail.com, user2@fakemail.com\"\r\n6789,All (public)\r\n" + + assert result.resp_body == + "Dataset ID,Dataset Title,Organization,System Name,Users\r\n12345,Example,Test,Test__Example,\"user1@fakemail.com, user2@fakemail.com\"\r\n6789,Example2,Test2,Test2__Example2,All (public)\r\n" end test "adds users to private dataset based on the dataset's org and access groups", %{curator_conn: conn} do @@ -64,8 +83,20 @@ defmodule Andi.ReportsControllerTest do access_group1 = %AccessGroup{users: [user1]} access_group2 = %AccessGroup{users: [user2]} - dataset1 = %Dataset{id: "12345", technical: %Technical{private: true, orgId: "1122"}, access_groups: [access_group1, access_group2]} - dataset2 = %Dataset{id: "6789", technical: %Technical{private: false}} + + dataset1 = %Dataset{ + id: "12345", + business: %Business{dataTitle: "Example", orgTitle: "Test"}, + technical: %Technical{private: true, orgId: "1122", systemName: "Test__Example"}, + access_groups: [access_group1, access_group2] + } + + dataset2 = %Dataset{ + id: "6789", + business: %Business{dataTitle: "Example2", orgTitle: "Test2"}, + technical: %Technical{private: false, systemName: "Test2__Example2"} + } + org = %Organization{id: "1122", users: [user3]} allow Andi.Repo.all(any()), seq: [[dataset1, dataset2], [org]] @@ -73,7 +104,7 @@ defmodule Andi.ReportsControllerTest do assert result.status == 200 assert result.resp_body == - "Dataset ID,Users\r\n12345,\"user1@fakemail.com, user2@fakemail.com, user3@fakemail.com\"\r\n6789,All (public)\r\n" + "Dataset ID,Dataset Title,Organization,System Name,Users\r\n12345,Example,Test,Test__Example,\"user1@fakemail.com, user2@fakemail.com, user3@fakemail.com\"\r\n6789,Example2,Test2,Test2__Example2,All (public)\r\n" end test "filters duplicates", %{curator_conn: conn} do @@ -85,14 +116,28 @@ defmodule Andi.ReportsControllerTest do access_group1 = %AccessGroup{users: [user1]} access_group2 = %AccessGroup{users: [user1]} - dataset1 = %Dataset{id: "12345", technical: %Technical{private: true, orgId: "1122"}, access_groups: [access_group1, access_group2]} - dataset2 = %Dataset{id: "6789", technical: %Technical{private: false}} + + dataset1 = %Dataset{ + id: "12345", + business: %Business{dataTitle: "Example", orgTitle: "Test"}, + technical: %Technical{private: true, orgId: "1122", systemName: "Test__Example"}, + access_groups: [access_group1, access_group2] + } + + dataset2 = %Dataset{ + id: "6789", + business: %Business{dataTitle: "Example2", orgTitle: "Test2"}, + technical: %Technical{private: false, systemName: "Test2__Example2"} + } + org = %Organization{id: "1122", users: [user1]} allow Andi.Repo.all(any()), seq: [[dataset1, dataset2], [org]] result = get(conn, "/report") assert result.status == 200 - assert result.resp_body == "Dataset ID,Users\r\n12345,user1@fakemail.com\r\n6789,All (public)\r\n" + + assert result.resp_body == + "Dataset ID,Dataset Title,Organization,System Name,Users\r\n12345,Example,Test,Test__Example,user1@fakemail.com\r\n6789,Example2,Test2,Test2__Example2,All (public)\r\n" end end end