diff --git a/core/config/config.exs b/core/config/config.exs index 7dd7a3cb5..a9f87447a 100644 --- a/core/config/config.exs +++ b/core/config/config.exs @@ -15,6 +15,11 @@ config :logger, :console, format: "$time $metadata[$level] $message\n", metadata: [:request_id] +config :plug, :statuses, %{ + 403 => "Access Denied", + 404 => "Page not found" +} + config :core, image_catalog: Core.ImageCatalog.Unsplash, banking_backend: Systems.Banking.Dummy diff --git a/core/config/dev.exs b/core/config/dev.exs index 9db226bf9..dd7d81853 100644 --- a/core/config/dev.exs +++ b/core/config/dev.exs @@ -23,7 +23,7 @@ config :core, Core.Repo, config :core, CoreWeb.Endpoint, reloadable_compilers: [:elixir], force_ssl: false, - debug_errors: true, + debug_errors: false, code_reloader: true, check_origin: false, live_reload: [ diff --git a/core/lib/core/authorization.ex b/core/lib/core/authorization.ex index 431eaf617..6083e2979 100644 --- a/core/lib/core/authorization.ex +++ b/core/lib/core/authorization.ex @@ -59,7 +59,7 @@ defmodule Core.Authorization do grant_access(Systems.Project.OverviewPage, [:researcher]) grant_access(Systems.Project.NodePage, [:researcher, :owner]) grant_access(Systems.Project.ItemContentPage, [:researcher, :owner]) - grant_access(Systems.Benchmark.ToolPage, [:member, :owner]) + grant_access(Systems.Benchmark.ToolPage, [:owner]) grant_access(Systems.Benchmark.LeaderboardPage, [:visitor, :member]) grant_access(CoreWeb.User.Signin, [:visitor]) @@ -198,15 +198,17 @@ defmodule Core.Authorization do can?(principal, permission) end - def can?(principal, entity, permission) when is_binary(permission) do - can?(principal, permission) or - has_required_roles_in_context?(principal, entity, permission) - end + def can_access?(_principal, nil, _module), do: false def can_access?(principal, entity, module) when is_atom(module) do can?(principal, entity, GreenLight.Permissions.access_permission(module)) end + def can?(principal, entity, permission) when is_binary(permission) do + can?(principal, permission) or + has_required_roles_in_context?(principal, entity, permission) + end + def users_with_role(_, _, preload \\ []) def users_with_role(node_id, role, preload) when is_number(node_id) do diff --git a/core/lib/core_web/controllers/error_html.ex b/core/lib/core_web/controllers/error_html.ex index 56f2d2424..c5360f2f5 100644 --- a/core/lib/core_web/controllers/error_html.ex +++ b/core/lib/core_web/controllers/error_html.ex @@ -1,12 +1,67 @@ defmodule CoreWeb.ErrorHTML do use CoreWeb, :html + use CoreWeb.Layouts.Stripped.Component, :error - embed_templates("error_html/*") + defp body("403.html", status), do: dgettext("eyra-error", "403.body", status: status) + defp body("404.html", status), do: dgettext("eyra-error", "404.body", status: status) + defp body("500.html", status), do: dgettext("eyra-error", "500.body", status: status) + defp body("503.html", status), do: dgettext("eyra-error", "503.body", status: status) + defp body(_, status), do: dgettext("eyra-error", "generic.body", status: status) - # By default, Phoenix returns the status message from - # the template name. For example, "404.html" becomes - # "Not Found". - def template_not_found(template, _assigns) do - Phoenix.Controller.status_message_from_template(template) + defp image("403.html"), do: "/images/illustrations/403.svg" + defp image("404.html"), do: "/images/illustrations/404.svg" + defp image("500.html"), do: "/images/illustrations/500.svg" + defp image("503.html"), do: "/images/illustrations/503.svg" + defp image(_), do: nil + + defp status(template), do: Phoenix.Controller.status_message_from_template(template) + + def render(template, assigns) do + status = status(template) + + assigns = + Map.merge(assigns, %{ + menus: build_menus(assigns), + status: status, + body: body(template, status), + image: image(template) + }) + + ~H""" + <.error + title={@status} + menus={@menus} + body={@body} + image={@image} + /> + """ + end + + attr(:title, :string, required: true) + attr(:body, :string, required: true) + attr(:image, :string, default: nil) + attr(:menus, :map, required: true) + + def error(assigns) do + ~H""" + <.stripped title={@title} menus={@menus} > + + +
+
+
<%= dgettext("eyra-error","page.title") %>
+
+
<%= raw(@body) %>
+
+
+ <%= if @image do %> +
+ +
+ <% end %> +
+
+ + """ end end diff --git a/core/lib/core_web/controllers/error_html/403.html.eex b/core/lib/core_web/controllers/error_html/403.html.eex deleted file mode 100644 index 1c87834a0..000000000 --- a/core/lib/core_web/controllers/error_html/403.html.eex +++ /dev/null @@ -1,19 +0,0 @@ -
-
-
<%= dgettext("eyra-error","page.title") %>
-
-
<%= dgettext("eyra-error","403.body") %>
-
-
- - - - - - -
-
-
- -
-
diff --git a/core/lib/core_web/controllers/error_html/404.html.eex b/core/lib/core_web/controllers/error_html/404.html.eex deleted file mode 100644 index 7375c31f8..000000000 --- a/core/lib/core_web/controllers/error_html/404.html.eex +++ /dev/null @@ -1,19 +0,0 @@ -
-
-
<%= dgettext("eyra-error","page.title") %>
-
-
<%= dgettext("eyra-error","404.body") %>
-
-
- - - - - - -
-
-
- -
-
diff --git a/core/lib/core_web/controllers/error_html/500.html.eex b/core/lib/core_web/controllers/error_html/500.html.eex deleted file mode 100644 index 556980ab3..000000000 --- a/core/lib/core_web/controllers/error_html/500.html.eex +++ /dev/null @@ -1,14 +0,0 @@ -
-
-
<%= dgettext("eyra-error","page.title") %>
-
-
<%= dgettext("eyra-error","500.body") %>
-
- - - -
-
- -
-
diff --git a/core/lib/core_web/controllers/error_html/503.html.eex b/core/lib/core_web/controllers/error_html/503.html.eex deleted file mode 100644 index 431ab5224..000000000 --- a/core/lib/core_web/controllers/error_html/503.html.eex +++ /dev/null @@ -1,14 +0,0 @@ -
-
-
<%= dgettext("eyra-error","page.title") %>
-
-
<%= dgettext("eyra-error","503.body") %>
-
- - - -
-
- -
-
diff --git a/core/lib/core_web/controllers/layouts/error.html.eex b/core/lib/core_web/controllers/layouts/error.html.eex deleted file mode 100644 index 02434aaef..000000000 --- a/core/lib/core_web/controllers/layouts/error.html.eex +++ /dev/null @@ -1,72 +0,0 @@ - - - - - <%= Meta.bundle_title() %> - <%= csrf_meta_tag() %> - - - - - - - - - -
-
-
-
- - -
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- - -
-
-
- <%= @inner_content %> -
-
-
- - -
-
-
-
-
- <.content_footer /> -
-
-
-
-
-
-
-
- -
-
-
- - diff --git a/core/lib/core_web/controllers/layouts/error.html.heex b/core/lib/core_web/controllers/layouts/error.html.heex new file mode 100644 index 000000000..b6dc33471 --- /dev/null +++ b/core/lib/core_web/controllers/layouts/error.html.heex @@ -0,0 +1,28 @@ + + + + + <%= Meta.bundle_title() %> + <%= csrf_meta_tag() %> + + + + + + + + + +
+
+
+
+ <%= @inner_content %> +
+
+
+ + diff --git a/core/lib/core_web/controllers/layouts/stripped/component.ex b/core/lib/core_web/controllers/layouts/stripped/component.ex index c3b1333b6..c9cc6c7eb 100644 --- a/core/lib/core_web/controllers/layouts/stripped/component.ex +++ b/core/lib/core_web/controllers/layouts/stripped/component.ex @@ -19,19 +19,21 @@ defmodule CoreWeb.Layouts.Stripped.Component do def builder, do: Application.fetch_env!(:core, :stripped_menu_builder) - def build_menu(socket, type) do - builder().build_menu(socket, type, unquote(active_item)) + def build_menu(assigns, type) do + builder().build_menu(assigns, type, unquote(active_item)) end - def build_menus(socket) do - menus = - Enum.reduce(@menus, %{}, fn menu_id, acc -> - Map.put(acc, menu_id, build_menu(socket, menu_id)) - end) - + def build_menus(%{assigns: assigns} = socket) do + menus = build_menus(assigns) socket |> assign(menus: menus) end + def build_menus(assigns) do + Enum.reduce(@menus, %{}, fn menu_id, acc -> + Map.put(acc, menu_id, build_menu(assigns, menu_id)) + end) + end + def update_menus(socket) do socket |> build_menus() diff --git a/core/lib/core_web/controllers/layouts/website/component.ex b/core/lib/core_web/controllers/layouts/website/component.ex index 9748aa53a..d44bee168 100644 --- a/core/lib/core_web/controllers/layouts/website/component.ex +++ b/core/lib/core_web/controllers/layouts/website/component.ex @@ -20,19 +20,21 @@ defmodule CoreWeb.Layouts.Website.Component do def builder, do: Application.fetch_env!(:core, :website_menu_builder) - def build_menu(socket, type) do - builder().build_menu(socket, type, unquote(active_item)) + def build_menu(assigns, type) do + builder().build_menu(assigns, type, unquote(active_item)) end - def build_menus(socket) do - menus = - Enum.reduce(@menus, %{}, fn menu_id, acc -> - Map.put(acc, menu_id, build_menu(socket, menu_id)) - end) - + def build_menus(%{assigns: assigns} = socket) do + menus = build_menus(assigns) socket |> assign(menus: menus) end + def build_menus(assigns) do + Enum.reduce(@menus, %{}, fn menu_id, acc -> + Map.put(acc, menu_id, build_menu(assigns, menu_id)) + end) + end + def update_menus(socket) do socket |> build_menus() diff --git a/core/lib/core_web/controllers/layouts/workspace/component.ex b/core/lib/core_web/controllers/layouts/workspace/component.ex index 6749d0c11..3b7ddcb07 100644 --- a/core/lib/core_web/controllers/layouts/workspace/component.ex +++ b/core/lib/core_web/controllers/layouts/workspace/component.ex @@ -22,19 +22,21 @@ defmodule CoreWeb.Layouts.Workspace.Component do def builder, do: Application.fetch_env!(:core, :workspace_menu_builder) - def build_menu(socket, type) do - builder().build_menu(socket, type, unquote(active_item)) + def build_menu(assigns, type) do + builder().build_menu(assigns, type, unquote(active_item)) end - def build_menus(socket) do - menus = - Enum.reduce(@menus, %{}, fn menu_id, acc -> - Map.put(acc, menu_id, build_menu(socket, menu_id)) - end) - + def build_menus(%{assigns: assigns} = socket) do + menus = build_menus(assigns) socket |> assign(menus: menus) end + def build_menus(assigns) do + Enum.reduce(@menus, %{}, fn menu_id, acc -> + Map.put(acc, menu_id, build_menu(assigns, menu_id)) + end) + end + def update_menus(socket) do socket |> build_menus() diff --git a/core/lib/core_web/live/menu/builder.ex b/core/lib/core_web/live/menu/builder.ex index ebb51401b..1c8f40ed6 100644 --- a/core/lib/core_web/live/menu/builder.ex +++ b/core/lib/core_web/live/menu/builder.ex @@ -28,7 +28,7 @@ defmodule CoreWeb.Menu.Builder do import CoreWeb.Menu.Helpers @impl true - def build_menu(%{assigns: assigns}, menu_id, active_item) do + def build_menu(assigns, menu_id, active_item) do builder = &build_item(assigns, menu_id, &1, active_item, @item_flags) primary = select_items(menu_id, @primary) diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po b/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po index e823876ca..afff9ba8d 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po @@ -333,3 +333,11 @@ msgstr "Data Donation Study" #, elixir-autogen, elixir-format, fuzzy msgid "project_templates.empty" msgstr "Empty" + +#, elixir-autogen, elixir-format, fuzzy +msgid "project_tools.benchmark" +msgstr "Benchmark" + +#, elixir-autogen, elixir-format, fuzzy +msgid "project_tools.data_donation" +msgstr "Data Donation Study" diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-error.po b/core/priv/gettext/en/LC_MESSAGES/eyra-error.po index fcce6f1dc..a90c24771 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-error.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-error.po @@ -12,20 +12,24 @@ msgstr "" #, elixir-autogen, elixir-format msgid "403.body" -msgstr "Unfortunately, you don't have access to this page. If you think this is an error, we would appreciate it if you report this by sending an email to support@eyra.co." +msgstr "Unfortunately, you don't have access to this page. If you think this is a mistake on our part, we would appreciate it if you report this by sending an email to support@eyra.co." #, elixir-autogen, elixir-format -msgid "404.body" -msgstr "Unfortunately, this page is not available. If you think this is an error, we would appreciate it if you report this at our helpdesk. If not, click \"Home\" to return to the Panl home page." +msgid "page.title" +msgstr "Sorry" -#, elixir-autogen, elixir-format -msgid "500.body" -msgstr "Unfortunately, this page is currently unavailable. If we are aware of this problem, we are doing the best we can to get this page up and running as soon as possible. Please try again later. If this message keeps appearing, let us know. Thanks in advance." +#, elixir-autogen, elixir-format, fuzzy +msgid "404.body" +msgstr "Unfortunately, this page is unavailable. If you think this is a mistake on our part, we would appreciate it if you report this by sending an email to support@eyra.co." -#, elixir-autogen, elixir-format +#, elixir-autogen, elixir-format, fuzzy msgid "503.body" -msgstr "Unfortunately, this page is currently unavailable. If we are aware of this problem, we are doing the best we can to get this page up and running as soon as possible. Please try again later. If this message keeps appearing, let us know. Thanks in advance." +msgstr "Unfortunately, this page is unavailable at this moment. If this is a recurring problem, we would appreciate it if you report this by sending an email to support@eyra.co." + +#, elixir-autogen, elixir-format, fuzzy +msgid "500.body" +msgstr "Unfortunately, this page is unavailable at this moment. If this is a recurring problem, we would appreciate it if you report this by sending an email to support@eyra.co." #, elixir-autogen, elixir-format -msgid "page.title" -msgstr "Sorry" +msgid "generic.body" +msgstr "Unfortunately, something went wrong. If this is a recurring problem, we would appreciate it if you report this by sending an email to support@eyra.co." diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-project.po b/core/priv/gettext/en/LC_MESSAGES/eyra-project.po index d48110e2c..cb8ee9e2b 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-project.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-project.po @@ -135,14 +135,6 @@ msgstr "Add new item" msgid "add.new.item.button.short" msgstr "New item" -#, elixir-autogen, elixir-format, fuzzy -msgid "add.new.node.button" -msgstr "Add new group" - -#, elixir-autogen, elixir-format, fuzzy -msgid "add.new.node.button.short" -msgstr "New group" - #, elixir-autogen, elixir-format msgid "retract.button" msgstr "Retract" @@ -190,3 +182,11 @@ msgstr "Proceed" #, elixir-autogen, elixir-format msgid "create.title" msgstr "Select template" + +#, elixir-autogen, elixir-format, fuzzy +msgid "create.item.button" +msgstr "Retract" + +#, elixir-autogen, elixir-format +msgid "create.item.button.short" +msgstr "" diff --git a/core/priv/gettext/eyra-enums.pot b/core/priv/gettext/eyra-enums.pot index 0cd1f971d..b74a54417 100644 --- a/core/priv/gettext/eyra-enums.pot +++ b/core/priv/gettext/eyra-enums.pot @@ -333,3 +333,11 @@ msgstr "" #, elixir-autogen, elixir-format msgid "project_templates.empty" msgstr "" + +#, elixir-autogen, elixir-format +msgid "project_tools.benchmark" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "project_tools.data_donation" +msgstr "" diff --git a/core/priv/gettext/eyra-error.pot b/core/priv/gettext/eyra-error.pot index 2a2a74f43..a9c7f4a9f 100644 --- a/core/priv/gettext/eyra-error.pot +++ b/core/priv/gettext/eyra-error.pot @@ -15,11 +15,11 @@ msgid "403.body" msgstr "" #, elixir-autogen, elixir-format -msgid "404.body" +msgid "page.title" msgstr "" #, elixir-autogen, elixir-format -msgid "500.body" +msgid "404.body" msgstr "" #, elixir-autogen, elixir-format @@ -27,5 +27,9 @@ msgid "503.body" msgstr "" #, elixir-autogen, elixir-format -msgid "page.title" +msgid "500.body" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "generic.body" msgstr "" diff --git a/core/priv/gettext/eyra-project.pot b/core/priv/gettext/eyra-project.pot index eb7b1c970..06f26afc1 100644 --- a/core/priv/gettext/eyra-project.pot +++ b/core/priv/gettext/eyra-project.pot @@ -135,14 +135,6 @@ msgstr "" msgid "add.new.item.button.short" msgstr "" -#, elixir-autogen, elixir-format -msgid "add.new.node.button" -msgstr "" - -#, elixir-autogen, elixir-format -msgid "add.new.node.button.short" -msgstr "" - #, elixir-autogen, elixir-format msgid "retract.button" msgstr "" @@ -190,3 +182,11 @@ msgstr "" #, elixir-autogen, elixir-format msgid "create.title" msgstr "" + +#, elixir-autogen, elixir-format +msgid "create.item.button" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "create.item.button.short" +msgstr "" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po index 5d5f53a0f..75a753519 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po @@ -333,3 +333,11 @@ msgstr "Data Donatie Studie" #, elixir-autogen, elixir-format, fuzzy msgid "project_templates.empty" msgstr "Leeg" + +#, elixir-autogen, elixir-format, fuzzy +msgid "project_tools.benchmark" +msgstr "Benchmark" + +#, elixir-autogen, elixir-format, fuzzy +msgid "project_tools.data_donation" +msgstr "Data Donatie Studie" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-error.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-error.po index 301ef6480..9d4f4cff4 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-error.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-error.po @@ -12,20 +12,24 @@ msgstr "" #, elixir-autogen, elixir-format msgid "403.body" -msgstr "Je hebt helaas geen toegang tot deze pagina. Is dit volgens jou een fout? Dan horen we dat graag. Stuur een e-mail naar support@eyra.co." +msgstr "Je hebt helaas geen toegang tot deze pagina. Is dit volgens jou een fout? Dan horen we dat graag. Stuur een e-mail naar support@eyra.co." #, elixir-autogen, elixir-format -msgid "404.body" -msgstr "Deze pagina is helaas niet beschikbaar. Is dit volgens jou een fout? Dan horen we dat graag. Laat een melding achter bij onze helpdesk. Zo niet, klik dan op \"Home\" om terug te gaan naar de home pagina van Panl." +msgid "page.title" +msgstr "Sorry" -#, elixir-autogen, elixir-format -msgid "500.body" -msgstr "Deze pagina is op dit moment helaas niet bereikbaar. Als we hiervan op de hoogte zijn dan doen we ons uiterste best om de pagina zo snel mogelijk weer bereikbaar te maken. Probeer het later nog eens. Blijft deze melding verschijnen? Dan horen we het graag. Neem even contact met ons op. Alvast bedankt." +#, elixir-autogen, elixir-format, fuzzy +msgid "404.body" +msgstr "Deze pagina is helaas niet beschikbaar. Is dit volgens jou een fout? Dan horen we dat graag. Stuur een e-mail naar support@eyra.co." -#, elixir-autogen, elixir-format +#, elixir-autogen, elixir-format, fuzzy msgid "503.body" -msgstr "Deze pagina is op dit moment helaas niet bereikbaar. Als we hiervan op de hoogte zijn dan doen we ons uiterste best om de pagina zo snel mogelijk weer bereikbaar te maken. Probeer het later nog eens. Blijft deze melding verschijnen? Dan horen we het graag. Neem even contact met ons op. Alvast bedankt." +msgstr "Deze pagina is op dit moment helaas niet bereikbaar. Blijft dit probleem bestaan dan horen we dat graag. Stuur een e-mail naar support@eyra.co." + +#, elixir-autogen, elixir-format, fuzzy +msgid "500.body" +msgstr "Deze pagina is op dit moment helaas niet bereikbaar. Blijft dit probleem bestaan dan horen we dat graag. Stuur een e-mail naar support@eyra.co." #, elixir-autogen, elixir-format -msgid "page.title" -msgstr "Sorry" +msgid "generic.body" +msgstr "Er is helaas iets misgegaan. Blijft dit probleem bestaan dan horen we dat graag. Stuur een e-mail naar support@eyra.co." diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po index e060eddc2..07a565320 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po @@ -135,14 +135,6 @@ msgstr "Voeg nieuw item toe" msgid "add.new.item.button.short" msgstr "Nieuw item" -#, elixir-autogen, elixir-format, fuzzy -msgid "add.new.node.button" -msgstr "Voeg nieuwe groep toe" - -#, elixir-autogen, elixir-format, fuzzy -msgid "add.new.node.button.short" -msgstr "Nieuwe group" - #, elixir-autogen, elixir-format msgid "retract.button" msgstr "Terugtrekken" @@ -190,3 +182,11 @@ msgstr "Doorgaan" #, elixir-autogen, elixir-format msgid "create.title" msgstr "Selecteer template" + +#, elixir-autogen, elixir-format, fuzzy +msgid "create.item.button" +msgstr "Terugtrekken" + +#, elixir-autogen, elixir-format +msgid "create.item.button.short" +msgstr "" diff --git a/core/systems/benchmark/_public.ex b/core/systems/benchmark/_public.ex index e6a8b97a2..6ddd673ef 100644 --- a/core/systems/benchmark/_public.ex +++ b/core/systems/benchmark/_public.ex @@ -24,6 +24,15 @@ defmodule Systems.Benchmark.Public do |> Repo.get!(id) end + def get_spot_for_tool(tool_id, spot_id, preload \\ []) do + from(spot in Benchmark.SpotModel, + where: spot.id == ^spot_id, + where: spot.tool_id == ^tool_id, + preload: ^preload + ) + |> Repo.one() + end + def get_spot!(id, preload \\ []) do from(spot in Benchmark.SpotModel, preload: ^preload) |> Repo.get!(id) diff --git a/core/systems/benchmark/tool_page.ex b/core/systems/benchmark/tool_page.ex index 71825af8e..35bffe097 100644 --- a/core/systems/benchmark/tool_page.ex +++ b/core/systems/benchmark/tool_page.ex @@ -12,8 +12,10 @@ defmodule Systems.Benchmark.ToolPage do } @impl true - def get_authorization_context(%{"spot" => spot_id}, _session, _socket) do - Benchmark.Public.get_spot!(String.to_integer(spot_id)) + def get_authorization_context(%{"id" => id, "spot" => spot_id}, _session, %{ + assigns: %{current_user: _user} + }) do + Benchmark.Public.get_spot_for_tool(String.to_integer(id), String.to_integer(spot_id)) end @impl true diff --git a/core/test/core/authorization_test.exs b/core/test/core/authorization_test.exs index a39b685ed..d43e6d7fe 100644 --- a/core/test/core/authorization_test.exs +++ b/core/test/core/authorization_test.exs @@ -89,4 +89,20 @@ defmodule Core.AuthorizationTest do {:ok, second_sub_node} = Authorization.create_node(second_node) refute Authorization.roles_intersect?(%User{id: 1}, second_sub_node, [:owner]) end + + test "can_access?/3 fail for entity == nil" do + assert Authorization.can_access?(%User{id: 1}, nil, Systems.Benchmark.ToolPage) == false + end + + test "can_access?/3 fail for entity without roles" do + {:ok, node_id} = Authorization.create_node() + assert Authorization.can_access?(%User{id: 1}, node_id, Systems.Benchmark.ToolPage) == false + end + + test "can_access?/3 succeeds for entity with suffient rights" do + principal = %User{id: 1} + {:ok, node_id} = Authorization.create_node() + Authorization.assign_role(principal, node_id, :owner) + assert Authorization.can_access?(principal, node_id, Systems.Benchmark.ToolPage) == true + end end diff --git a/core/test/systems/project/assembly_test.exs b/core/test/systems/project/assembly_test.exs index 4672489d2..b73a8a98d 100644 --- a/core/test/systems/project/assembly_test.exs +++ b/core/test/systems/project/assembly_test.exs @@ -1,11 +1,11 @@ defmodule Systems.Project.AssemblyTest do use Core.DataCase - alias Systems.{ - Project - } + # alias Systems.{ + # Project + # } test "create_item/2" do - %{root: root} = Factories.insert!(:project, %{name: "AAP"}) + %{root: _root} = Factories.insert!(:project, %{name: "AAP"}) end end