From d3f4d9948e9ebb213a80adbbdf54144cc7d35da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Cirio?= Date: Mon, 2 Dec 2024 11:36:37 -0300 Subject: [PATCH 1/6] [FEATURE] [MER-3961] Remove Admin `Browse collab spaces` (#5276) https://eliterate.atlassian.net/browse/MER-3961 --- lib/oli_web/live/admin/admin_view.ex | 5 - .../live/collaboration_live/index_view.ex | 87 +++------ lib/oli_web/live/sections/overview_view.ex | 2 +- lib/oli_web/router.ex | 5 +- test/oli_web/live/admin_live_test.exs | 12 -- test/oli_web/live/collaboration_live_test.exs | 166 +----------------- 6 files changed, 36 insertions(+), 241 deletions(-) diff --git a/lib/oli_web/live/admin/admin_view.ex b/lib/oli_web/live/admin/admin_view.ex index 2dc20f5cb32..d56f76b6846 100644 --- a/lib/oli_web/live/admin/admin_view.ex +++ b/lib/oli_web/live/admin/admin_view.ex @@ -81,11 +81,6 @@ defmodule OliWeb.Admin.AdminView do Browse all Course Sections -
  • - - Browse all Collaborative Spaces - -
  • Ingest Project
  • diff --git a/lib/oli_web/live/collaboration_live/index_view.ex b/lib/oli_web/live/collaboration_live/index_view.ex index 2ff5bdf7436..26ca94e6b9f 100644 --- a/lib/oli_web/live/collaboration_live/index_view.ex +++ b/lib/oli_web/live/collaboration_live/index_view.ex @@ -3,10 +3,8 @@ defmodule OliWeb.CollaborationLive.IndexView do use OliWeb.Common.SortableTable.TableHandlers alias Oli.Resources.Collaboration - alias OliWeb.Admin.AdminView alias OliWeb.Common.{Breadcrumb, Filter, Listing, SessionContext} - alias OliWeb.CollaborationLive.{AdminTableModel, InstructorTableModel} - alias OliWeb.Router.Helpers, as: Routes + alias OliWeb.CollaborationLive.InstructorTableModel alias alias OliWeb.Sections.Mount @title "Collaborative Spaces" @@ -18,75 +16,49 @@ defmodule OliWeb.CollaborationLive.IndexView do query_str = String.downcase(query) Enum.filter(socket.assigns.collab_spaces, fn cs -> - String.contains?(String.downcase(cs.page.title), query_str) or - (socket.assigns.live_action == :admin and - String.contains?(String.downcase(cs.project.title), query_str)) + String.contains?(String.downcase(cs.page.title), query_str) end) end - def live_path(%{assigns: %{live_action: :admin}} = socket, params), - do: Routes.collab_spaces_index_path(socket, :admin, params) - def live_path( - %{assigns: %{live_action: :instructor, section_slug: section_slug}} = socket, + %{assigns: %{section_slug: section_slug}} = _socket, params ), - do: Routes.collab_spaces_index_path(socket, :instructor, section_slug, params) + do: ~p"/sections/#{section_slug}/collaborative_spaces?#{params}" - def breadcrumb(:admin, _) do - AdminView.breadcrumb() ++ - [ - Breadcrumb.new(%{ - full_title: @title, - link: Routes.collab_spaces_index_path(OliWeb.Endpoint, :admin) - }) - ] - end - - def breadcrumb(:instructor, section) do + def breadcrumb(section) do OliWeb.Sections.OverviewView.set_breadcrumbs(:instructor, section) ++ [ Breadcrumb.new(%{ full_title: @title, - link: Routes.collab_spaces_index_path(OliWeb.Endpoint, :instructor, section.slug) + link: ~p"/sections/#{section.slug}/collaborative_spaces" }) ] end def mount(params, session, socket) do - live_action = socket.assigns.live_action ctx = SessionContext.init(socket, session) section_slug = params["section_slug"] - do_mount = fn -> - {collab_spaces, table_model} = - get_collab_spaces_and_table_model(live_action, ctx, section_slug) - - {:ok, - assign(socket, - breadcrumbs: breadcrumb(live_action, socket.assigns[:section]), - section_slug: section_slug, - collab_spaces: collab_spaces, - table_model: table_model, - total_count: length(collab_spaces), - limit: 20, - offset: 0, - query: "" - )} - end - - case live_action do - :instructor -> - case Mount.for(section_slug, session) do - {:error, e} -> - Mount.handle_error(socket, {:error, e}) - - {_type, _user, _section} -> - do_mount.() - end - - :admin -> - do_mount.() + case Mount.for(section_slug, session) do + {:error, e} -> + Mount.handle_error(socket, {:error, e}) + + {_type, _user, _section} -> + {collab_spaces, table_model} = + get_collab_spaces_and_table_model(ctx, section_slug) + + {:ok, + assign(socket, + breadcrumbs: breadcrumb(socket.assigns[:section]), + section_slug: section_slug, + collab_spaces: collab_spaces, + table_model: table_model, + total_count: length(collab_spaces), + limit: 20, + offset: 0, + query: "" + )} end end @@ -118,14 +90,7 @@ defmodule OliWeb.CollaborationLive.IndexView do """ end - defp get_collab_spaces_and_table_model(:admin, ctx, _) do - collab_spaces = Collaboration.list_collaborative_spaces() - {:ok, table_model} = AdminTableModel.new(collab_spaces, ctx) - - {collab_spaces, table_model} - end - - defp get_collab_spaces_and_table_model(:instructor, ctx, section_slug) do + defp get_collab_spaces_and_table_model(ctx, section_slug) do {_, collab_spaces} = Collaboration.list_collaborative_spaces_in_section(section_slug) {:ok, table_model} = InstructorTableModel.new(collab_spaces, ctx) diff --git a/lib/oli_web/live/sections/overview_view.ex b/lib/oli_web/live/sections/overview_view.ex index 51f825964d9..44a90071a08 100644 --- a/lib/oli_web/live/sections/overview_view.ex +++ b/lib/oli_web/live/sections/overview_view.ex @@ -252,7 +252,7 @@ defmodule OliWeb.Sections.OverviewView do
  • Browse Collaborative Spaces diff --git a/lib/oli_web/router.ex b/lib/oli_web/router.ex index caec0c2eb48..6f3f3f0159d 100644 --- a/lib/oli_web/router.ex +++ b/lib/oli_web/router.ex @@ -1238,9 +1238,7 @@ defmodule OliWeb.Router do Sections.GatingAndScheduling ) - live("/collaborative_spaces", CollaborationLive.IndexView, :instructor, - as: :collab_spaces_index - ) + live("/collaborative_spaces", CollaborationLive.IndexView, as: :collab_spaces_index) live( "/assessment_settings/:active_tab/:assessment_id", @@ -1358,7 +1356,6 @@ defmodule OliWeb.Router do live("/products", Products.ProductsView) live("/products/:product_id/discounts", Products.Payments.Discounts.ProductsIndexView) - live("/collaborative_spaces", CollaborationLive.IndexView, :admin, as: :collab_spaces_index) live( "/products/:product_id/discounts/new", diff --git a/test/oli_web/live/admin_live_test.exs b/test/oli_web/live/admin_live_test.exs index 591b42aaa4a..6c86f6356ed 100644 --- a/test/oli_web/live/admin_live_test.exs +++ b/test/oli_web/live/admin_live_test.exs @@ -281,12 +281,6 @@ defmodule OliWeb.AdminLiveTest do "Browse all Course Sections" ) - assert has_element?( - view, - "a[href=\"#{~p"/admin/collaborative_spaces"}\"]", - "Browse all Collaborative Spaces" - ) - assert has_element?( view, "a[href=\"#{Routes.live_path(OliWeb.Endpoint, OliWeb.Admin.Ingest)}\"]", @@ -425,12 +419,6 @@ defmodule OliWeb.AdminLiveTest do "Browse all Course Sections" ) - assert has_element?( - view, - "a[href=\"#{~p"/admin/collaborative_spaces"}\"]", - "Browse all Collaborative Spaces" - ) - assert has_element?( view, "a[href=\"#{Routes.live_path(OliWeb.Endpoint, OliWeb.Admin.Ingest)}\"]", diff --git a/test/oli_web/live/collaboration_live_test.exs b/test/oli_web/live/collaboration_live_test.exs index 42b1a5319ec..99dde434ee1 100644 --- a/test/oli_web/live/collaboration_live_test.exs +++ b/test/oli_web/live/collaboration_live_test.exs @@ -19,8 +19,8 @@ defmodule OliWeb.CollaborationLiveTest do do: Routes.page_delivery_path(OliWeb.Endpoint, :page_preview, section_slug, page_revision_slug) - defp live_view_collab_space_index(type, section_slug \\ []), - do: Routes.collab_spaces_index_path(OliWeb.Endpoint, type, section_slug) + defp live_view_collab_space_index(section_slug), + do: ~p"/sections/#{section_slug}/collaborative_spaces" defp live_view_student_page(section_slug, page_revision_slug), do: Routes.page_delivery_path(OliWeb.Endpoint, :page, section_slug, page_revision_slug) @@ -182,21 +182,12 @@ defmodule OliWeb.CollaborationLiveTest do |> html_response(403) end - test "redirects to new session when accessing the admin index view", %{ - conn: conn - } do - assert conn - |> get(live_view_collab_space_index(:admin)) - |> html_response(302) =~ - "You are being redirected" - end - test "redirects to new session when accessing the instructor index view", %{ conn: conn, section: section } do assert conn - |> get(live_view_collab_space_index(:instructor, section.slug)) + |> get(live_view_collab_space_index(section.slug)) |> html_response(302) =~ "You are being redirected" end @@ -241,15 +232,6 @@ defmodule OliWeb.CollaborationLiveTest do "You are being get(live_view_collab_space_index(:admin)) - |> html_response(302) =~ - "You are being redirected" - end - test "redirects to unauthorized when accessing the instructor index view", %{ conn: conn, section: section, @@ -258,7 +240,7 @@ defmodule OliWeb.CollaborationLiveTest do enroll_user_to_section(user, section, :context_learner) assert conn - |> get(live_view_collab_space_index(:instructor, section.slug)) + |> get(live_view_collab_space_index(section.slug)) |> html_response(302) =~ "You are being redirected" end @@ -276,30 +258,6 @@ defmodule OliWeb.CollaborationLiveTest do end end - describe "user cannot access when is logged in as an author but is not a system admin or author of the project" do - setup [:author_conn, :create_project_and_section] - - test "redirects to projects when accessing the admin index view", %{ - conn: conn - } do - assert conn - |> get(live_view_collab_space_index(:admin)) - |> response(403) =~ - "Forbidden" - end - - test "redirects to projects when accessing the author edit page view", %{ - conn: conn, - project: project, - page_revision: page_revision - } do - assert conn - |> get(live_view_author_edit(project.slug, page_revision.slug)) - |> html_response(302) =~ - "You are being redirected" - end - end - describe "user can access when is logged in as an author, is not a system admin but is author of the project" do setup [:create_project_and_section] @@ -698,114 +656,6 @@ defmodule OliWeb.CollaborationLiveTest do end end - describe "admin - index view" do - setup [:admin_conn, :create_project_and_section] - - test "loads correctly", %{ - conn: conn, - page_revision: page_revision, - page_revision_cs: page_revision_cs, - project: project - } do - {:ok, view, _html} = live(conn, live_view_collab_space_index(:admin)) - - assert has_element?(view, "#collaborative-spaces-table") - assert has_element?(view, "td", "#{project.title}") - assert has_element?(view, "td", "#{page_revision_cs.title}") - assert has_element?(view, "td", "2") - assert has_element?(view, "td", "#{page_revision.title}") - end - - test "applies searching", %{ - conn: conn, - page_revision: page_revision, - page_revision_cs: page_revision_cs - } do - {:ok, view, _html} = live(conn, live_view_collab_space_index(:admin)) - - view - |> element("input[phx-blur=\"change_search\"]") - |> render_blur(%{value: "other revision A"}) - - view - |> element("button[phx-click=\"apply_search\"]") - |> render_click() - - refute has_element?(view, "td", "#{page_revision_cs.title}") - assert has_element?(view, "td", "#{page_revision.title}") - - view - |> element("button[phx-click=\"reset_search\"]") - |> render_click() - - assert has_element?(view, "td", "#{page_revision_cs.title}") - assert has_element?(view, "td", "#{page_revision.title}") - end - - test "applies sorting", %{ - conn: conn - } do - {:ok, view, _html} = live(conn, live_view_collab_space_index(:admin)) - - view - |> element("th[phx-click=\"sort\"]:first-of-type") - |> render_click(%{sort_by: "page_title"}) - - assert view - |> element("tr:first-child > td:nth-child(2)") - |> render() =~ - "Other revision A" - - view - |> element("th[phx-click=\"sort\"]:first-of-type") - |> render_click(%{sort_by: "page_title"}) - - assert view - |> element("tr:first-child > td:nth-child(2)") - |> render() =~ - "Other revision B" - end - - test "applies paging", %{ - conn: conn, - project: project, - publication: publication, - author: author - } do - for i <- 0..20 do - create_for_paging(project.id, publication, author, "Page #{i}") - end - - {:ok, view, _html} = live(conn, live_view_collab_space_index(:admin)) - - view - |> element("th[phx-click=sort][phx-value-sort_by=page_title]") - |> render_click() - - assert view - |> element("tr:first-child > td:nth-child(2)") - |> render() =~ - "Other revision A" - - assert view - |> element("tr:nth-child(2) > td:nth-child(2)") - |> render() =~ - "Other revision B" - end - - test "renders datetimes using the local timezone", context = %{second_post: second_post} do - {:ok, conn: conn, ctx: session_context} = set_timezone(context) - - {:ok, view, _html} = live(conn, live_view_collab_space_index(:admin)) - - assert has_element?( - view, - "tr", - OliWeb.Common.Utils.render_date(second_post, :inserted_at, session_context) - ) - end - end - describe "instructor - index view" do setup [:user_conn, :create_project_and_section] @@ -818,7 +668,7 @@ defmodule OliWeb.CollaborationLiveTest do } do enroll_user_to_section(user, section, :context_instructor) - {:ok, view, _html} = live(conn, live_view_collab_space_index(:instructor, section.slug)) + {:ok, view, _html} = live(conn, live_view_collab_space_index(section.slug)) assert has_element?(view, "#collaborative-spaces-table") assert has_element?(view, "td", "#{page_revision_cs.title}") @@ -834,7 +684,7 @@ defmodule OliWeb.CollaborationLiveTest do user: user } do enroll_user_to_section(user, section, :context_instructor) - {:ok, view, _html} = live(conn, live_view_collab_space_index(:instructor, section.slug)) + {:ok, view, _html} = live(conn, live_view_collab_space_index(section.slug)) view |> element("input[phx-blur=\"change_search\"]") @@ -861,7 +711,7 @@ defmodule OliWeb.CollaborationLiveTest do user: user } do enroll_user_to_section(user, section, :context_instructor) - {:ok, view, _html} = live(conn, live_view_collab_space_index(:instructor, section.slug)) + {:ok, view, _html} = live(conn, live_view_collab_space_index(section.slug)) view |> element("th[phx-click=sort][phx-value-sort_by=page_title]") @@ -899,7 +749,7 @@ defmodule OliWeb.CollaborationLiveTest do {:ok, _sr} = Sections.create_section_resources(section, publication) enroll_user_to_section(user, section, :context_instructor) - {:ok, view, _html} = live(conn, live_view_collab_space_index(:instructor, section.slug)) + {:ok, view, _html} = live(conn, live_view_collab_space_index(section.slug)) view |> element("th[phx-click=sort][phx-value-sort_by=page_title]") From c5e86cb768fa49aef850c200e9ab52ff81d5199f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Cirio?= Date: Mon, 2 Dec 2024 16:18:26 -0300 Subject: [PATCH 2/6] [FEATURE] [MER-4016] Add more parameters to assignment launch page (#5277) * add page termos on prologue page * fix spacing between elements to match figma desing * fix warning * consider default scoring strategy * add tests --- .../live/delivery/student/prologue_live.ex | 5 +- .../live/delivery/student/review_live.ex | 2 +- lib/oli_web/live/delivery/student/utils.ex | 218 +++++++++++++++++- .../delivery/student/prologue_live_test.exs | 83 +++++++ .../live/delivery/student/utils_test.exs | 11 + 5 files changed, 315 insertions(+), 4 deletions(-) diff --git a/lib/oli_web/live/delivery/student/prologue_live.ex b/lib/oli_web/live/delivery/student/prologue_live.ex index 7ab38545c4b..72e9ff3d6ef 100644 --- a/lib/oli_web/live/delivery/student/prologue_live.ex +++ b/lib/oli_web/live/delivery/student/prologue_live.ex @@ -2,7 +2,7 @@ defmodule OliWeb.Delivery.Student.PrologueLive do use OliWeb, :live_view import OliWeb.Delivery.Student.Utils, - only: [page_header: 1] + only: [page_header: 1, page_terms: 1] alias Oli.Accounts.User alias Oli.Delivery.Attempts.Core.ResourceAttempt @@ -97,8 +97,9 @@ defmodule OliWeb.Delivery.Student.PrologueLive do index={@current_page["index"]} container_label={Utils.get_container_label(@current_page["id"], @section)} /> -
    +
    + <.page_terms effective_settings={@page_context.effective_settings} ctx={@ctx} /> <.attempts_summary page_context={@page_context} attempt_message={@attempt_message} diff --git a/lib/oli_web/live/delivery/student/review_live.ex b/lib/oli_web/live/delivery/student/review_live.ex index af291494716..40cbc7c72e8 100644 --- a/lib/oli_web/live/delivery/student/review_live.ex +++ b/lib/oli_web/live/delivery/student/review_live.ex @@ -167,7 +167,7 @@ defmodule OliWeb.Delivery.Student.ReviewLive do objectives={@objectives} container_label={Utils.get_container_label(@current_page["id"], @section)} /> -
    +
    <%= raw(@html) %>
    <.link diff --git a/lib/oli_web/live/delivery/student/utils.ex b/lib/oli_web/live/delivery/student/utils.ex index fde7e8d3df3..395a3ba693d 100644 --- a/lib/oli_web/live/delivery/student/utils.ex +++ b/lib/oli_web/live/delivery/student/utils.ex @@ -27,7 +27,7 @@ defmodule OliWeb.Delivery.Student.Utils do def page_header(assigns) do ~H""" -