Skip to content

Commit

Permalink
Progress report #964
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Oct 2, 2024
1 parent 6fadf01 commit 8f1b913
Show file tree
Hide file tree
Showing 26 changed files with 838 additions and 15 deletions.
1 change: 1 addition & 0 deletions core/frameworks/utility/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Frameworks.Utility.List do
def append_if(list, nil), do: list
def append_if(list, term), do: append(list, term)

def append(list, list2) when is_list(list2), do: list ++ list2
def append(list, closure) when is_function(closure, 0), do: list ++ [closure.()]
def append(list, element), do: list ++ [element]

Expand Down
17 changes: 17 additions & 0 deletions core/lib/core/factories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ defmodule Core.Factories do
})
end

def build(:external_user) do
%ExternalSignIn.User{
external_id: Faker.UUID.v4(),
organisation: Faker.Company.name(),
user: build(:member)
}
end

def build(:admin) do
:member
|> build(%{
Expand Down Expand Up @@ -279,6 +287,10 @@ defmodule Core.Factories do
build(:role_assignment, %{role: :owner, principal_id: GreenLight.Principal.id(user)})
end

def build(:participant, %{user: user}) do
build(:role_assignment, %{role: :participant, principal_id: GreenLight.Principal.id(user)})
end

def build(:auth_node, %{} = attributes) do
%Authorization.Node{}
|> struct!(attributes)
Expand Down Expand Up @@ -527,6 +539,11 @@ defmodule Core.Factories do
|> struct!(attributes)
end

def build(:external_user, %{} = attributes) do
build(:external_user)
|> struct!(attributes)
end

def build(:member, %{} = attributes) do
{password, attributes} = Map.pop(attributes, :password)

Expand Down
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions core/priv/gettext/de/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,31 @@ msgstr[1] ""
#, elixir-autogen, elixir-format
msgid "atom.tag"
msgstr ""

#, elixir-autogen, elixir-format
msgid "export.progress.button"
msgstr ""

#, elixir-autogen, elixir-format
msgid "monitor.description"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.header.consent"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.header.participant"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.no"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.not.applicable"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.yes"
msgstr ""
16 changes: 16 additions & 0 deletions core/priv/gettext/de/LC_MESSAGES/eyra-enums.po
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,19 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "assignment_languages.de"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.accepted"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.completed"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.pending"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.rejected"
msgstr ""
28 changes: 28 additions & 0 deletions core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,31 @@ msgstr[1] "%{count} participants"
#, elixir-autogen, elixir-format
msgid "atom.tag"
msgstr "Assignment"

#, elixir-autogen, elixir-format
msgid "export.progress.button"
msgstr "Progress report"

#, elixir-autogen, elixir-format
msgid "monitor.description"
msgstr "Here comes a description"

#, elixir-autogen, elixir-format
msgid "progress.header.consent"
msgstr "Consent"

#, elixir-autogen, elixir-format
msgid "progress.header.participant"
msgstr "Participant"

#, elixir-autogen, elixir-format
msgid "progress.no"
msgstr "no"

#, elixir-autogen, elixir-format
msgid "progress.not.applicable"
msgstr "n/a"

#, elixir-autogen, elixir-format
msgid "progress.yes"
msgstr "yes"
16 changes: 16 additions & 0 deletions core/priv/gettext/en/LC_MESSAGES/eyra-enums.po
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,19 @@ msgstr "Creator"
#, elixir-autogen, elixir-format, fuzzy
msgid "assignment_languages.de"
msgstr "German"

#, elixir-autogen, elixir-format
msgid "crew_task_status.accepted"
msgstr "accepted"

#, elixir-autogen, elixir-format
msgid "crew_task_status.completed"
msgstr "finished"

#, elixir-autogen, elixir-format
msgid "crew_task_status.pending"
msgstr "started"

#, elixir-autogen, elixir-format
msgid "crew_task_status.rejected"
msgstr "rejected"
28 changes: 28 additions & 0 deletions core/priv/gettext/eyra-assignment.pot
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,31 @@ msgstr[1] ""
#, elixir-autogen, elixir-format
msgid "atom.tag"
msgstr ""

#, elixir-autogen, elixir-format
msgid "export.progress.button"
msgstr ""

#, elixir-autogen, elixir-format
msgid "monitor.description"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.header.consent"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.header.participant"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.no"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.not.applicable"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.yes"
msgstr ""
16 changes: 16 additions & 0 deletions core/priv/gettext/eyra-enums.pot
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,19 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "assignment_languages.de"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.accepted"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.completed"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.pending"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.rejected"
msgstr ""
28 changes: 28 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,31 @@ msgstr[1] ""
#, elixir-autogen, elixir-format
msgid "atom.tag"
msgstr ""

#, elixir-autogen, elixir-format
msgid "export.progress.button"
msgstr ""

#, elixir-autogen, elixir-format
msgid "monitor.description"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.header.consent"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.header.participant"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.no"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.not.applicable"
msgstr ""

#, elixir-autogen, elixir-format
msgid "progress.yes"
msgstr ""
16 changes: 16 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,19 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "assignment_languages.de"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.accepted"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.completed"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.pending"
msgstr ""

#, elixir-autogen, elixir-format
msgid "crew_task_status.rejected"
msgstr ""
19 changes: 16 additions & 3 deletions core/systems/assignment/_private.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ defmodule Systems.Assignment.Private do
def get_template(:questionnaire),
do: %Assignment.TemplateQuestionnaire{id: :questionnaire}

def declined_consent?(assignment, user_ref) do
Monitor.Public.event({assignment, :declined, user_ref})
|> Monitor.Public.exists?()
end

def log_performance_event(
%Assignment.Model{} = assignment,
%Crew.TaskModel{} = crew_task,
Expand Down Expand Up @@ -147,26 +152,34 @@ defmodule Systems.Assignment.Private do
["item=#{item_id}"]
end

def task_identifier(
assignment,
workflow_item,
%Crew.MemberModel{id: member_id}
) do
task_identifier(assignment, workflow_item, member_id)
end

def task_identifier(
%{special: :data_donation},
%Workflow.ItemModel{id: item_id},
%Crew.MemberModel{id: member_id}
member_id
) do
["item=#{item_id}", "member=#{member_id}"]
end

def task_identifier(
%{special: :benchmark_challenge},
%Workflow.ItemModel{id: item_id},
%Crew.MemberModel{id: member_id}
member_id
) do
["item=#{item_id}", "member=#{member_id}"]
end

def task_identifier(
%{special: :questionnaire},
%Workflow.ItemModel{id: item_id},
%Crew.MemberModel{id: member_id}
member_id
) do
["item=#{item_id}", "member=#{member_id}"]
end
Expand Down
26 changes: 26 additions & 0 deletions core/systems/assignment/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,32 @@ defmodule Systems.Assignment.Public do
get!(id) |> cancel(user)
end

@doc """
Lists the participants of the assignment.
Returns a list of maps with the following keys:
* `user_id`
* `public_id`
* `external_id`
* `member_id`
"""
def list_participants(%Assignment.Model{} = assignment) do
participant_query(assignment)
|> Repo.all()
end

def list_signatures(%Assignment.Model{consent_agreement_id: nil}) do
[]
end

def list_signatures(%Assignment.Model{} = assignment) do
signature_query(assignment)
|> Repo.all()
end

def list_tasks(%Assignment.Model{workflow: workflow}) do
Workflow.Public.list_items(workflow)
end

def get_task(tool, identifier) do
%{crew: crew} = Assignment.Public.get_by_tool(tool, [:crew])
Crew.Public.get_task(crew, identifier)
Expand Down
39 changes: 39 additions & 0 deletions core/systems/assignment/_queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ defmodule Systems.Assignment.Queries do
import Frameworks.Utility.Query, only: [build: 3]

alias Systems.Assignment
alias Systems.Crew
alias Systems.Account
alias Systems.Content
alias Systems.Consent
alias Systems.Project

def assignment_query() do
Expand Down Expand Up @@ -58,4 +60,41 @@ defmodule Systems.Assignment.Queries do
|> select([assignment: a], a.id)
|> distinct(true)
end

def participant_query() do
from(Crew.MemberModel, as: :member)
end

def participant_query(%Assignment.Model{crew: %{id: id, auth_node_id: auth_node_id}}) do
build(participant_query(), :member, [crew_id == ^id, user: [id != nil]])
|> join(:left, [user: u], e in ExternalSignIn.User, on: u.id == e.user_id, as: :external_user)
|> join(:inner, [user: u], ra in Core.Authorization.RoleAssignment,
on: ra.principal_id == u.id,
as: :role_assignment
)
|> where([role_assignment: ra], ra.role == :participant)
|> where([role_assignment: ra], ra.node_id == ^auth_node_id)
|> select([member: m, user: u, external_user: e], %{
user_id: u.id,
member_id: m.id,
public_id: m.public_id,
external_id: e.external_id
})
end

def signature_query() do
from(Consent.SignatureModel, as: :signature)
end

def signature_query(%Assignment.Model{consent_agreement_id: consent_agreement_id})
when not is_nil(consent_agreement_id) do
build(signature_query(), :signature,
revision: [
agreement: [
id == ^consent_agreement_id
]
]
)
|> select([signature: a], a.user_id)
end
end
1 change: 1 addition & 0 deletions core/systems/assignment/_routes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Systems.Assignment.Routes do
live("/assignment/:id/content", ContentPage)
get("/assignment/:id/invite", Controller, :invite)
get("/assignment/:id/apply", Controller, :apply)
get("/assignment/:id/export", Controller, :export)
get("/assignment/callback/:item", Controller, :callback)
end

Expand Down
Loading

0 comments on commit 8f1b913

Please sign in to comment.