Skip to content

Commit

Permalink
Formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Oct 24, 2023
1 parent f5aac4e commit 770c72f
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 89 deletions.
2 changes: 1 addition & 1 deletion core/frameworks/signal/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Frameworks.Signal.Public do
"Systems.Pool.Switch",
"Systems.Student.Switch",
"Systems.Campaign.Switch",
"Systems.NextAction.Switch",
"Systems.NextAction.Switch"
]

def dispatch(signal, message) do
Expand Down
3 changes: 2 additions & 1 deletion core/systems/assignment/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ defmodule Systems.Assignment.Public do

def get_by_consent_agreement(consent_agreement, preload \\ [])

def get_by_consent_agreement(%Consent.AgreementModel{id: id}, preload), do: get_by_consent_agreement(id, preload)
def get_by_consent_agreement(%Consent.AgreementModel{id: id}, preload),
do: get_by_consent_agreement(id, preload)

def get_by_consent_agreement(consent_agreement_id, preload) do
from(assignment in Assignment.Model,
Expand Down
11 changes: 9 additions & 2 deletions core/systems/assignment/_switch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ defmodule Systems.Assignment.Switch do
handle(signal, message)
end

def intercept({:consent_agreement, _} = signal, %{consent_agreement: consent_agreement} = message) do
if assignment = Assignment.Public.get_by_consent_agreement(consent_agreement, Assignment.Model.preload_graph(:down)) do
def intercept(
{:consent_agreement, _} = signal,
%{consent_agreement: consent_agreement} = message
) do
if assignment =
Assignment.Public.get_by_consent_agreement(
consent_agreement,
Assignment.Model.preload_graph(:down)
) do
handle(
{:assignment, signal},
Map.merge(message, %{assignment: assignment})
Expand Down
3 changes: 1 addition & 2 deletions core/systems/assignment/crew_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ defmodule Systems.Assignment.CrewPage do

@impl true
def handle_info({:onboarding_continue, _}, %{assigns: %{onboarding: onboarding}} = socket) do

{_, onboarding} = List.pop_at(onboarding, 0) |> dbg()
{_, onboarding} = List.pop_at(onboarding, 0)

{
:noreply,
Expand Down
4 changes: 2 additions & 2 deletions core/systems/assignment/crew_page_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ defmodule Systems.Assignment.CrewPageBuilder do
defp onboarding(assignment, assigns, current_onboarding) do
full_onboarding(assignment, assigns)
|> Enum.filter(fn %{id: id} ->
Enum.find(current_onboarding, & &1.id == id) != nil
end)
Enum.find(current_onboarding, &(&1.id == id)) != nil
end)
end

defp full_onboarding(assignment, assigns) do
Expand Down
2 changes: 0 additions & 2 deletions core/systems/assignment/gdpr_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ defmodule Systems.Assignment.GdprForm do

@impl true
def update(%{id: id, entity: entity}, socket) do

{
:ok,
socket
Expand All @@ -20,7 +19,6 @@ defmodule Systems.Assignment.GdprForm do
end

defp update_consent_agreement(%{assigns: %{entity: entity}} = socket) do

revision = Consent.Public.latest_unlocked_revision_safe(entity)

consent_revision_form = %{
Expand Down
8 changes: 5 additions & 3 deletions core/systems/assignment/onboarding_consent_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule Systems.Assignment.OnboardingConsentView do
def update(%{id: id, revision: revision, user: user}, socket) do
{
:ok,
socket |> assign(
socket
|> assign(
id: id,
revision: revision,
user: user
Expand All @@ -28,7 +29,9 @@ defmodule Systems.Assignment.OnboardingConsentView do
}
end

defp update_clickwrap_view(%{assigns: %{revision: revision, user: user, myself: myself}} = socket) do
defp update_clickwrap_view(
%{assigns: %{revision: revision, user: user, myself: myself}} = socket
) do
clickwrap_view = %{
id: :consent_clickwrap_view,
module: Consent.ClickWrapView,
Expand All @@ -40,7 +43,6 @@ defmodule Systems.Assignment.OnboardingConsentView do
assign(socket, clickwrap_view: clickwrap_view)
end


@impl true
def render(assigns) do
~H"""
Expand Down
17 changes: 11 additions & 6 deletions core/systems/consent/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ defmodule Systems.Consent.Public do
Consent
}


def create_agreement(auth_node) do
prepare_agreement(auth_node)
|> Repo.insert()
Expand Down Expand Up @@ -102,11 +101,12 @@ defmodule Systems.Consent.Public do

def query_unlocked_revisions(agreement, preload \\ []) do
from(revision in query_revisions(agreement, preload),
where: revision.id not in subquery(
from(signature in Consent.SignatureModel,
select: signature.revision_id
where:
revision.id not in subquery(
from(signature in Consent.SignatureModel,
select: signature.revision_id
)
)
)
)
end

Expand All @@ -117,9 +117,11 @@ defmodule Systems.Consent.Public do
end

def query_revisions(agreement, preload \\ [])

def query_revisions(%Consent.AgreementModel{id: agreement_id}, preload) do
query_revisions(agreement_id, preload)
end

def query_revisions(agreement_id, preload) when is_integer(agreement_id) do
from(revision in Consent.RevisionModel,
where: revision.agreement_id == ^agreement_id,
Expand All @@ -128,10 +130,13 @@ defmodule Systems.Consent.Public do
)
end

def update_revision(%Ecto.Changeset{data: %Consent.RevisionModel{id: id, updated_at: updated_at}} = changeset) do
def update_revision(
%Ecto.Changeset{data: %Consent.RevisionModel{id: id, updated_at: updated_at}} = changeset
) do
Multi.new()
|> Multi.run(:validate_timestamp, fn _, _ ->
%{updated_at: stored_updated_at} = Consent.Public.get_revision!(id)

if stored_updated_at == updated_at do
{:ok, :valid}
else
Expand Down
9 changes: 7 additions & 2 deletions core/systems/consent/_switch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ defmodule Systems.Consent.Switch do
}

@impl true
def intercept({:consent_revision, _} = signal, %{consent_revision: %{agreement_id: agreement_id}} = message) do
consent_agreement = Consent.Public.get_agreement!(agreement_id, Consent.AgreementModel.preload_graph(:down))
def intercept(
{:consent_revision, _} = signal,
%{consent_revision: %{agreement_id: agreement_id}} = message
) do
consent_agreement =
Consent.Public.get_agreement!(agreement_id, Consent.AgreementModel.preload_graph(:down))

dispatch!(
{:consent_agreement, signal},
Map.merge(message, %{consent_agreement: consent_agreement})
Expand Down
5 changes: 2 additions & 3 deletions core/systems/consent/agreement_model.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Systems.Consent.AgreementModel do

use Ecto.Schema
use Frameworks.Utility.Schema

Expand All @@ -19,7 +18,8 @@ defmodule Systems.Consent.AgreementModel do
@required_fields ~w()a

def preload_graph(:down), do: preload_graph([:auth_node])
##def preload_graph(:revisions), do: [revisions: Consent.RevisionModel.preload_graph(:down)]
def preload_graph(:up), do: preload_graph([])
def preload_graph(:revisions), do: [revisions: Consent.RevisionModel.preload_graph(:down)]
def preload_graph(:auth_node), do: [auth_node: []]

def changeset(agreement, attrs \\ %{}) do
Expand All @@ -31,5 +31,4 @@ defmodule Systems.Consent.AgreementModel do
changeset
|> validate_required(@required_fields)
end

end
15 changes: 12 additions & 3 deletions core/systems/consent/clickwrap_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ defmodule Systems.Consent.ClickWrapView do

{
:ok,
socket |> assign(
socket
|> assign(
id: id,
revision: revision,
user: user,
Expand All @@ -36,14 +37,22 @@ defmodule Systems.Consent.ClickWrapView do
defp update_continue_button(%{assigns: %{selected?: selected?, myself: myself}} = socket) do
continue_button = %{
action: %{type: :send, event: "continue", target: myself},
face: %{type: :primary, label: dgettext("eyra-assignment", "onboarding.consent.continue.button") },
face: %{
type: :primary,
label: dgettext("eyra-assignment", "onboarding.consent.continue.button")
},
enabled?: selected?
}

assign(socket, continue_button: continue_button)
end

@impl true
def handle_event("toggle", %{"checkbox" => _checkbox}, %{assigns: %{selected?: selected?}} = socket) do
def handle_event(
"toggle",
%{"checkbox" => _checkbox},
%{assigns: %{selected?: selected?}} = socket
) do
{
:noreply,
socket
Expand Down
7 changes: 6 additions & 1 deletion core/systems/consent/revision_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ defmodule Systems.Consent.RevisionForm do
end

@impl true
def handle_event("save", %{"source_input" => source}, %{assigns: %{entity: %{source: old_source} = entity}} = socket) do
def handle_event(
"save",
%{"source_input" => source},
%{assigns: %{entity: %{source: old_source} = entity}} = socket
) do
{
:noreply,
if old_source == source do
Expand All @@ -36,6 +40,7 @@ defmodule Systems.Consent.RevisionForm do

def save(socket, entity, attrs) do
changeset = Consent.RevisionModel.changeset(entity, attrs)

case Core.Persister.save(entity, changeset) do
{:ok, entity} ->
socket
Expand Down
1 change: 0 additions & 1 deletion core/systems/consent/revision_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ defmodule Systems.Consent.RevisionModel do
changeset
|> validate_required(@required_fields)
end

end
3 changes: 1 addition & 2 deletions core/systems/consent/signature_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Systems.Consent.SignatureModel do
def preload_graph(:revision), do: [revision: Consent.RevisionModel.preload_graph(:up)]
def preload_graph(:user), do: [user: []]

def changeset(signature , attrs \\ %{}) do
def changeset(signature, attrs \\ %{}) do
signature
|> cast(attrs, @fields)
end
Expand All @@ -32,5 +32,4 @@ defmodule Systems.Consent.SignatureModel do
changeset
|> validate_required(@required_fields)
end

end
Loading

0 comments on commit 770c72f

Please sign in to comment.