Skip to content

Commit

Permalink
Merge branch 'Simon-Initiative:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dtiwarATS authored Dec 20, 2024
2 parents c4cc85f + fe803e6 commit d0f482a
Show file tree
Hide file tree
Showing 30 changed files with 315 additions and 299 deletions.
2 changes: 2 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ if config_env() == :prod do

# General OLI app config
config :oli,
depot_warmer_days_lookback: System.get_env("DEPOT_WARMER_DAYS_LOOKBACK", "5"),
depot_warmer_max_number_of_entries: System.get_env("DEPOT_WARMER_MAX_NUMBER_OF_ENTRIES", "0"),
s3_media_bucket_name: s3_media_bucket_name,
s3_xapi_bucket_name: s3_xapi_bucket_name,
media_url: media_url,
Expand Down
22 changes: 22 additions & 0 deletions lib/oli/delivery/certificates.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Oli.Delivery.Certificates do
@moduledoc """
The Certificates context
"""

alias Oli.Delivery.Sections.Certificate
alias Oli.Repo

@doc """
Creates a certificate.
## Examples
iex> create(%{field: value})
{:ok, %Certificate{}}
iex> create(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create(attrs) do
attrs |> Certificate.changeset() |> Repo.insert()
end
end
3 changes: 2 additions & 1 deletion lib/oli/delivery/sections/blueprint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ defmodule Oli.Delivery.Sections.Blueprint do
cover_image: section.cover_image,
skip_email_verification: section.skip_email_verification,
registration_open: section.registration_open,
requires_enrollment: section.requires_enrollment
requires_enrollment: section.requires_enrollment,
certificate: Oli.Repo.preload(section, :certificate).certificate
},
attrs
)
Expand Down
5 changes: 5 additions & 0 deletions lib/oli/delivery/sections/certificate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ defmodule Oli.Delivery.Sections.Certificate do
import Ecto.Changeset
import Oli.Utils, only: [validate_greater_than_or_equal: 4]

alias Oli.Delivery.Sections.GrantedCertificate
alias Oli.Delivery.Sections.Section

@assessments_options [:all, :custom]

@derive {Jason.Encoder, except: [:id, :section, :granted_certificate, :__meta__]}

schema "certificates" do
field :required_discussion_posts, :integer
field :required_class_notes, :integer
Expand All @@ -32,6 +35,8 @@ defmodule Oli.Delivery.Sections.Certificate do

belongs_to :section, Section

has_one :granted_certificate, GrantedCertificate

timestamps(type: :utc_datetime)
end

Expand Down
4 changes: 4 additions & 0 deletions lib/oli/delivery/sections/granted_certificate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ defmodule Oli.Delivery.Sections.GrantedCertificate do
|> validate_required(@required_fields)
|> assoc_constraint(:certificate)
|> assoc_constraint(:user)
|> unique_constraint([:user_id, :certificate_id],
name: :unique_user_certificate,
message: "has already been granted this type of certificate"
)
end
end
3 changes: 2 additions & 1 deletion lib/oli/delivery/sections/section.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule Oli.Delivery.Sections.Section do
field(:contains_deliberate_practice, :boolean, default: false)

field(:certificate_enabled, :boolean, default: false)
has_one(:certificate, Oli.Delivery.Sections.Certificate)
has_one(:certificate, Oli.Delivery.Sections.Certificate, on_replace: :delete)

belongs_to(:required_survey, Oli.Resources.Resource,
foreign_key: :required_survey_resource_id
Expand Down Expand Up @@ -239,6 +239,7 @@ defmodule Oli.Delivery.Sections.Section do
|> unique_constraint(:context_id, name: :sections_active_context_id_unique_index)
|> Slug.update_never("sections")
|> validate_length(:title, max: 255)
|> cast_assoc(:certificate)
end

def validate_positive_grace_period(changeset) do
Expand Down
5 changes: 4 additions & 1 deletion lib/oli/interop/export.ex
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ defmodule Oli.Interop.Export do
project_id: project.id,
include_archived: false
})
|> Repo.preload(section_project_publications: [:publication])
|> Repo.preload([:certificate, section_project_publications: [:publication]])
|> Enum.filter(&(length(&1.section_project_publications) == 1))

product_ids = products |> Enum.map(& &1.id)
Expand Down Expand Up @@ -450,6 +450,8 @@ defmodule Oli.Interop.Export do

Enum.map(root.children, fn id -> full_hierarchy(revisions_by_resource_id, id) end)

certificate = Jason.encode!(product.certificate)

%{
type: "Product",
id: Integer.to_string(product.id, 10),
Expand All @@ -462,6 +464,7 @@ defmodule Oli.Interop.Export do
payByInstitution: product.pay_by_institution,
gracePeriodDays: product.grace_period_days,
amount: product.amount,
certificate: certificate,
children: Enum.map(root.children, fn id -> full_hierarchy(revisions_by_resource_id, id) end)
}
|> entry("#{product.id}.json")
Expand Down
20 changes: 19 additions & 1 deletion lib/oli/interop/ingest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ defmodule Oli.Interop.Ingest do
"amount" => Map.get(product, "amount")
}

# '|| "null"' ensures a valid value is applied when a certificate is
# NOT present in the project's bundle.
certificate_params = Jason.decode!(Map.get(product, "certificate") || "null")

# Create the blueprint (aka 'product'), with the hierarchy definition that was just built
# to mirror the product JSON.
case Oli.Delivery.Sections.Blueprint.create_blueprint(
Expand All @@ -242,7 +246,21 @@ defmodule Oli.Interop.Ingest do
hierarchy_definition,
new_product_attrs
) do
{:ok, _} -> {:ok, container_map}
{:ok, blueprint} ->
maybe_add_certificate(certificate_params, blueprint, container_map)

e ->
e
end
end

defp maybe_add_certificate(nil, _blueprint, container_map), do: {:ok, container_map}

defp maybe_add_certificate(certificate_params, blueprint, container_map) do
certificate_params = Map.put(certificate_params, "section_id", blueprint.id)

case Oli.Delivery.Certificates.create(certificate_params) do
{:ok, _certificate} -> {:ok, container_map}
e -> e
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/oli/utils/db_seeder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Oli.Seeder do
alias Oli.Delivery.Attempts.PageLifecycle.FinalizationSummary
alias Oli.Utils.Seeder.StudentAttemptSeed
alias Oli.Delivery.Attempts.ActivityLifecycle.Evaluate
alias Oli.AccountsFixtures
alias Oli.Utils.Seeder.AccountsFixtures

def base_project_with_resource(author) do
{:ok, family} =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Oli.AccountsFixtures do
defmodule Oli.Utils.Seeder.AccountsFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Oli.Accounts` context.
Expand Down
2 changes: 1 addition & 1 deletion lib/oli/utils/seeder/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Oli.Utils.Seeder.Project do

alias Oli.Publishing.AuthoringResolver
alias Oli.Repo
alias Oli.AccountsFixtures
alias Oli.Utils.Seeder.AccountsFixtures
alias Oli.Authoring.Authors.{AuthorProject, ProjectRole}
alias Oli.Authoring.Course.{Project, Family}
alias Oli.Publishing.Publications.Publication
Expand Down
18 changes: 14 additions & 4 deletions lib/oli/utils/seeder/session.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
defmodule Oli.Utils.Seeder.Session do
import Oli.Utils.Seeder.Utils

alias Oli.TestHelpers

@doc """
Creates an author session
"""
def login_as_author(%{conn: conn} = seeds, author, _tags \\ []) do
[author] = unpack(seeds, [author])

conn = TestHelpers.log_in_author(conn, author)
token = Oli.Accounts.generate_author_session_token(author)

conn =
conn
|> Phoenix.ConnTest.init_test_session(%{})
|> Plug.Conn.put_session(:author_token, token)
|> Plug.Conn.put_session(:current_author_id, author.id)

%{seeds | conn: conn}
end
Expand All @@ -20,7 +24,13 @@ defmodule Oli.Utils.Seeder.Session do
def login_as_user(%{conn: conn} = seeds, user, _tags \\ []) do
[user] = unpack(seeds, [user])

conn = TestHelpers.log_in_user(conn, user)
token = Oli.Accounts.generate_user_session_token(user)

conn =
conn
|> Phoenix.ConnTest.init_test_session(%{})
|> Plug.Conn.put_session(:user_token, token)
|> Plug.Conn.put_session(:current_user_id, user.id)

%{seeds | conn: conn}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ defmodule OliWeb.Delivery.Student.Lesson.Components.OutlineComponent do

attr :item, :map, required: true
attr :is_container?, :boolean, required: true
attr :expanded_items, :list, required: true
attr :target, :any, required: true
attr :section_slug, :string, required: true
attr :selected_view, :atom, required: true
attr :progress, :float, default: nil
attr :expanded_items, :list, required: true

def outline_item(%{item: %{"numbering" => %{"level" => level}}}) when level > 3, do: nil

Expand Down Expand Up @@ -184,20 +184,21 @@ defmodule OliWeb.Delivery.Student.Lesson.Components.OutlineComponent do
]}
>
<div
phx-click={JS.toggle_class("rotate-90", to: "#icon_#{@item["id"]}") |> JS.push("expand_item")}
phx-click="expand_item"
phx-value-item_id={@item["id"]}
phx-target={@target}
data-bs-toggle="collapse"
data-bs-target={"#collapse_#{@item["id"]}"}
aria-expanded={"#{expanded?}"}
class={[
"w-full grow shrink basis-0 p-2 flex-col justify-start items-start gap-1 inline-flex rounded-lg hover:bg-[#f2f8ff] dark:hover:bg-[#2e2b33] hover:cursor-pointer",
if(@progress, do: "bg-[#f3f4f8] dark:bg-[#1b191f]")
]}
>
<div class="text-[#353740] dark:text-[#eeebf5] self-stretch justify-start items-start gap-1 inline-flex">
<div id={"icon_#{@item["id"]}"} class="transition-transform duration-300">
<Icons.chevron_right width="20" height="20" />
<div>
<%= if expanded? do %>
<Icons.chevron_down width="20" height="20" />
<% else %>
<Icons.chevron_right width="20" height="20" />
<% end %>
</div>
<div class="grow shrink basis-0 text-base font-bold leading-normal" role="title">
Expand All @@ -215,18 +216,17 @@ defmodule OliWeb.Delivery.Student.Lesson.Components.OutlineComponent do
/>
</div>
<div
id={"collapse_#{@item["id"]}"}
class="collapse"
:if={expanded?}
class="grow shrink basis-0 py-1 flex-col justify-start items-start gap-1 inline-flex"
>
<.outline_item
:for={node <- @item["children"]}
item={node}
expanded_items={@expanded_items}
is_container?={node["resource_type_id"] == ResourceType.id_for_container()}
target={@target}
section_slug={@section_slug}
selected_view={@selected_view}
expanded_items={@expanded_items}
/>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions lib/oli_web/live/delivery/student/prologue_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule OliWeb.Delivery.Student.PrologueLive do
use OliWeb, :live_view

import OliWeb.Delivery.Student.Utils,
only: [page_header: 1, page_terms: 1]
only: [page_header: 1, page_terms: 1, is_adaptive_page: 1]

alias Oli.Accounts.User
alias Oli.Delivery.Attempts.Core.ResourceAttempt
Expand Down Expand Up @@ -99,7 +99,11 @@ defmodule OliWeb.Delivery.Student.PrologueLive do
/>
<div class="self-stretch h-[0px] opacity-80 dark:opacity-20 bg-white border border-gray-200 mt-3 mb-10">
</div>
<.page_terms effective_settings={@page_context.effective_settings} ctx={@ctx} />
<.page_terms
effective_settings={@page_context.effective_settings}
ctx={@ctx}
is_adaptive={is_adaptive_page(@page_context.page)}
/>
<.attempts_summary
page_context={@page_context}
attempt_message={@attempt_message}
Expand Down
Loading

0 comments on commit d0f482a

Please sign in to comment.