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 committed May 3, 2024
2 parents c7dd19d + fdd823d commit 722d342
Show file tree
Hide file tree
Showing 30 changed files with 1,484 additions and 1,560 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
name: Elixir build and test
runs-on: ubuntu-latest

environment: ci-build-test

env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -24,9 +26,7 @@ jobs:
- name: 🔧 Configure
run: |
cp postgres.example.env postgres.env
cat > oli.env <<EOL
${{ secrets.CI_OLI_ENV }}
EOL
cp oli.example.env oli.env
- name: 🗄 Start test database
run: docker-compose up -d postgres
Expand Down
6 changes: 5 additions & 1 deletion assets/src/phoenix/activity_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ function makeRequest(
.then((result) => continuation(result))
.catch((error) => continuation(undefined, error));
}

const saveTransform = (result: any) => {
return result.error ? Promise.reject({ message: result.message }) : Promise.resolve(result);
};
const nothingTransform = (result: any) => Promise.resolve(result);
const submissionTransform = (key: string, result: any) => {
return result.error
Expand All @@ -47,6 +49,7 @@ export const initActivityBridge = (elementId: string) => {
'PATCH',
{ partInputs: e.detail.payload },
e.detail.continuation,
saveTransform,
);
},
false,
Expand Down Expand Up @@ -94,6 +97,7 @@ export const initActivityBridge = (elementId: string) => {
'PATCH',
{ response: e.detail.payload },
e.detail.continuation,
saveTransform,
);
},
false,
Expand Down
4 changes: 3 additions & 1 deletion lib/oli/authoring/course/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defmodule Oli.Authoring.Course.Project do
field(:latest_datashop_snapshot_url, :string)
field(:latest_datashop_snapshot_timestamp, :utc_datetime)
field(:analytics_version, Ecto.Enum, values: [:v1, :v2], default: :v1)
field(:allow_transfer_payment_codes, :boolean, default: false)

embeds_one(:customizations, CustomLabels, on_replace: :delete)
embeds_one(:attributes, ProjectAttributes, on_replace: :delete)
Expand Down Expand Up @@ -81,7 +82,8 @@ defmodule Oli.Authoring.Course.Project do
:latest_analytics_snapshot_url,
:latest_analytics_snapshot_timestamp,
:latest_datashop_snapshot_url,
:latest_datashop_snapshot_timestamp
:latest_datashop_snapshot_timestamp,
:allow_transfer_payment_codes
])
|> cast_embed(:attributes, required: false)
|> cast_embed(:customizations, required: false)
Expand Down
14 changes: 12 additions & 2 deletions lib/oli/delivery/attempts/activity_lifecycle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule Oli.Delivery.Attempts.ActivityLifecycle do
alias Oli.Delivery.Evaluation.{Explanation, ExplanationContext}

import Oli.Delivery.Attempts.Core
require Logger

@doc """
Retrieve a hint for an attempt.
Expand Down Expand Up @@ -343,10 +344,19 @@ defmodule Oli.Delivery.Attempts.ActivityLifecycle do
VALUES
#{part_input_values}
) AS batch_values (attempt_guid, response)
WHERE part_attempts.attempt_guid = batch_values.attempt_guid
WHERE part_attempts.attempt_guid = batch_values.attempt_guid and lifecycle_state = 'active'
"""

Ecto.Adapters.SQL.query(Oli.Repo, sql, params)
case Ecto.Adapters.SQL.query(Oli.Repo, sql, params) do
{:ok, %Postgrex.Result{num_rows: n}} when n > 0 ->
{:ok, %{num_rows: n}}

{:ok, %Postgrex.Result{num_rows: 0}} ->
{:error, :already_submitted}

{:error, _} ->
{:error, "Failed to save student input"}
end
end

@doc """
Expand Down
29 changes: 29 additions & 0 deletions lib/oli/delivery/paywall.ex
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,24 @@ defmodule Oli.Delivery.Paywall do
end
end

@spec has_payment_codes?(integer()) :: boolean()
@doc """
Return if a product has any payment codes.
"""
def has_payment_codes?(product_id) do
count =
Repo.one(
from(p in Payment,
join: s in Section,
on: s.id == p.section_id,
where: s.id == ^product_id,
select: count(p.id)
)
)

if count > 0, do: true, else: false
end

@doc """
Get the last X(quantity) payment codes for the given product.
"""
Expand Down Expand Up @@ -504,6 +522,17 @@ defmodule Oli.Delivery.Paywall do
|> Repo.update_all(set: [enrollment_id: target_enrollment_id, section_id: target_section_id])
end

@doc """
Transfers payment codes from one product to another. This updates all payment codes for the current product.
"""
def transfer_payment_codes(current_section_id, target_section_id) do
from(
p in Payment,
where: p.section_id == ^current_section_id
)
|> Repo.update_all(set: [section_id: target_section_id])
end

# ------------------------------------------
# Discounts

Expand Down
22 changes: 22 additions & 0 deletions lib/oli/host/host_identifier.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Oli.Host.HostIdentifier do
use Ecto.Schema
import Ecto.Changeset

@primary_key false
schema "host_identifier" do
field :id, :integer, default: 1
field :hostname, :string

timestamps(type: :utc_datetime)
end

@required_fields [:id, :hostname]

def changeset(host_identifier, attrs \\ %{}) do
host_identifier
|> cast(attrs, @required_fields)
|> validate_required(@required_fields)
|> check_constraint(:id, name: :one_row, message: "must be 1")
|> unique_constraint(:id, name: :host_identifier_id_index)
end
end
Loading

0 comments on commit 722d342

Please sign in to comment.