Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions lib/safira/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1030,24 +1030,6 @@ defmodule Safira.Accounts do
Course.changeset(course, attrs)
end

@doc """
Gets a single credential associated to the given attendee.

## Examples

iex> get_credential_of_attendee(%Attendee{})
%Credential{}

iex> get_credential_of_attendee!(%Attendee{})
nil

"""
def get_credential_of_attendee(%Attendee{} = attendee) do
Credential
|> where([c], c.attendee_id == ^attendee.id)
|> Repo.one()
end

def generate_credentials(count) do
for _ <- 1..count do
{:ok, credential} = create_credential(%{})
Expand Down
1 change: 1 addition & 0 deletions lib/safira/accounts/credential.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Safira.Accounts.Credential do
def changeset(credential, attrs) do
credential
|> cast(attrs, [:attendee_id])
|> unique_constraint(:attendee_id)
|> cast_assoc(:attendee)
end
end
2 changes: 1 addition & 1 deletion lib/safira_web/plugs/user_roles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule SafiraWeb.UserRoles do

defp has_credential?(conn) do
is_nil(conn.assigns.current_user.attendee) or
not is_nil(Accounts.get_credential_of_attendee(conn.assigns.current_user.attendee))
Accounts.attendee_has_credential?(conn.assigns.current_user.attendee.id)
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion priv/repo/migrations/20240919141626_create_credentials.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ defmodule Safira.Repo.Migrations.CreateCredentials do
timestamps(type: :utc_datetime)
end

create index(:credentials, [:attendee_id])
create unique_index(:credentials, [:attendee_id])
end
end
Loading