Skip to content

Commit

Permalink
School: Remove kind field
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Ceolin committed Jul 14, 2024
1 parent 00a4fca commit 91cea3b
Show file tree
Hide file tree
Showing 37 changed files with 208 additions and 1,484 deletions.
2 changes: 1 addition & 1 deletion lib/layouts/components/app_menu.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule ZoonkWeb.Components.Layouts.AppMenu do
title={gettext("Courses")}
/>
<.menu_item :if={@school && @school.kind != :white_label} navigate={~p"/schools/new"} icon="tabler-rocket" title={gettext("Create school")} />
<.menu_item :if={@school && is_nil(@school.school_id)} navigate={~p"/schools/new"} icon="tabler-rocket" title={gettext("Create school")} />
</ul>
</li>
Expand Down
4 changes: 2 additions & 2 deletions lib/layouts/menu_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ defmodule ZoonkWeb.Layouts.MenuUtils do
def home_page?(_active_page, _course, _last_course_slug), do: false

@spec dashboard_school_menu(School.t()) :: list()
def dashboard_school_menu(%School{kind: kind, school_id: school_id}) do
def dashboard_school_menu(%School{school_id: school_id}) do
[
%{link: ~p"/dashboard", view: [:dashboard_home], title: gettext("Overview"), visible?: true},
%{link: ~p"/dashboard/schools", view: [:dashboard_schoollist, :dashboard_schoolview], title: gettext("Schools"), visible?: kind != :white_label},
%{link: ~p"/dashboard/schools", view: [:dashboard_schoollist, :dashboard_schoolview], title: gettext("Schools"), visible?: is_nil(school_id)},
%{link: ~p"/dashboard/users", view: [:dashboard_schooluserlist, :dashboard_schooluserview], title: dgettext("orgs", "Users"), visible?: true},
%{link: ~p"/dashboard/edit/logo", view: [:dashboard_schooledit_logo], title: gettext("Logo"), visible?: true},
%{link: ~p"/dashboard/edit/icon", view: [:dashboard_schooledit_icon], title: gettext("Icon"), visible?: true},
Expand Down
4 changes: 0 additions & 4 deletions lib/organizations/school_live/school_new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ defmodule ZoonkWeb.Live.SchoolNew do
end
end

defp school_kind_options do
[{dgettext("orgs", "White label"), "white_label"}, {dgettext("orgs", "SaaS"), "saas"}, {dgettext("orgs", "Marketplace"), "marketplace"}]
end

defp redirect_to_dashboard(socket, _new_school, nil), do: redirect(socket, to: ~p"/dashboard")

defp redirect_to_dashboard(socket, %School{} = new_school, %School{} = app), do: redirect(socket, external: "https://#{new_school.slug}.#{app.custom_domain}/dashboard")
Expand Down
1 change: 0 additions & 1 deletion lib/organizations/school_live/school_new.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<.simple_form for={@form} id="school-form" phx-submit="save" phx-change="validate">
<.header icon="tabler-rocket"><%= dgettext("orgs", "Create school") %></.header>

<.input :if={is_nil(@app)} type="select" field={@form[:kind]} label={dgettext("orgs", "App type")} options={school_kind_options()} required />
<.input type="text" field={@form[:name]} label={dgettext("orgs", "School name")} required />
<.input type="email" field={@form[:email]} label={dgettext("orgs", "School email")} required />
<.input type="text" field={@form[:slug]} label={dgettext("orgs", "Nickname")} helper={dgettext("orgs", "Choose a nickname to acess your school profile")} required />
Expand Down
4 changes: 2 additions & 2 deletions lib/organizations/school_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ defmodule ZoonkWeb.Plugs.School do
def check_school_setup(%{request_path: "/schools/new"} = conn, opts), do: check_school_setup(conn, opts, conn.assigns.school)
def check_school_setup(conn, _opts), do: conn

# If the school is already configured, we don't want to show the configuration page.
defp check_school_setup(_conn, _opts, %School{kind: :white_label}), do: raise(ZoonkWeb.PermissionError, code: :school_already_configured)
# We don't want to show the creation page for child schools.
defp check_school_setup(_conn, _opts, %School{} = school) when school.school_id != nil, do: raise(ZoonkWeb.PermissionError, code: :school_already_configured)
defp check_school_setup(conn, _opts, _school), do: conn

@doc """
Expand Down
16 changes: 1 addition & 15 deletions lib/organizations/school_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ defmodule Zoonk.Organizations.School do
field :currency, :string
field :custom_domain, :string
field :email, :string
field :kind, Ecto.Enum, values: [:marketplace, :saas, :white_label], default: :white_label
field :icon, :string
field :logo, :string
field :name, :string
Expand All @@ -44,7 +43,7 @@ defmodule Zoonk.Organizations.School do
@spec create_changeset(Ecto.Schema.t(), map()) :: Ecto.Changeset.t()
def create_changeset(school, attrs) do
school
|> cast(attrs, [:kind | shared_cast_fields()])
|> cast(attrs, shared_cast_fields())
|> default_changeset()
end

Expand All @@ -67,7 +66,6 @@ defmodule Zoonk.Organizations.School do
|> validate_slug(:slug)
|> validate_unique_slug()
|> validate_custom_domain()
|> validate_kind()
|> validate_allow_guests()
end

Expand Down Expand Up @@ -103,18 +101,6 @@ defmodule Zoonk.Organizations.School do
put_change(changeset, :allow_guests?, allow_guests?)
end

# Child schools must have a `white_label` kind. A school has a parent school when `school_id` is not `nil`.
defp validate_kind(changeset) do
kind = get_field(changeset, :kind)
school_id = get_field(changeset, :school_id)

if school_id && kind != :white_label do
add_error(changeset, :kind, dgettext("errors", "must be white_label"))
else
changeset
end
end

# Don't allow to add a subdomain as `custom_domain` if that domain already exists.
defp validate_custom_domain(changeset) do
custom_domain = get_change(changeset, :custom_domain)
Expand Down
35 changes: 20 additions & 15 deletions priv/gettext/courses.pot
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ msgstr ""
msgid "Advanced"
msgstr ""

#: lib/content/course_live/lesson_completed.html.heex:19
#: lib/content/course_live/lesson_completed.html.heex:21
#, elixir-autogen, elixir-format
msgid "Back to the course"
msgstr ""
Expand All @@ -31,7 +31,7 @@ msgstr ""
msgid "Beginner"
msgstr ""

#: lib/content/course_live/lesson_play.html.heex:95
#: lib/content/course_live/lesson_play.html.heex:94
#, elixir-autogen, elixir-format
msgid "Confirming..."
msgstr ""
Expand All @@ -41,7 +41,7 @@ msgstr ""
msgid "Enrolled successfully!"
msgstr ""

#: lib/content/course_live/lesson_completed.ex:27
#: lib/content/course_live/lesson_completed.ex:29
#, elixir-autogen, elixir-format
msgid "Excellent!"
msgstr ""
Expand All @@ -56,12 +56,12 @@ msgstr ""
msgid "Failed to enroll"
msgstr ""

#: lib/content/course_live/lesson_completed.ex:29
#: lib/content/course_live/lesson_completed.ex:31
#, elixir-autogen, elixir-format
msgid "Good!"
msgstr ""

#: lib/content/course_live/lesson_completed.html.heex:4
#: lib/content/course_live/lesson_completed.html.heex:5
#, elixir-autogen, elixir-format
msgid "Illustration of a green alien"
msgstr ""
Expand All @@ -71,17 +71,17 @@ msgstr ""
msgid "Intermediate"
msgstr ""

#: lib/content/course_live/lesson_play.html.heex:99
#: lib/content/course_live/lesson_play.html.heex:98
#, elixir-autogen, elixir-format
msgid "Next step"
msgstr ""

#: lib/content/course_live/lesson_completed.ex:30
#: lib/content/course_live/lesson_completed.ex:32
#, elixir-autogen, elixir-format
msgid "Not bad!"
msgstr ""

#: lib/content/course_live/lesson_completed.ex:26
#: lib/content/course_live/lesson_completed.ex:28
#, elixir-autogen, elixir-format
msgid "Perfect!"
msgstr ""
Expand All @@ -96,22 +96,22 @@ msgstr ""
msgid "That's incorrect."
msgstr ""

#: lib/content/course_live/lesson_completed.ex:31
#: lib/content/course_live/lesson_completed.ex:33
#, elixir-autogen, elixir-format
msgid "There's room for improvement"
msgstr ""

#: lib/content/course_live/lesson_play.ex:93
#: lib/content/course_live/lesson_play.ex:90
#, elixir-autogen, elixir-format
msgid "Unable to complete lesson"
msgstr ""

#: lib/content/course_live/lesson_play.ex:56
#: lib/content/course_live/lesson_play.ex:53
#, elixir-autogen, elixir-format
msgid "Unable to select option"
msgstr ""

#: lib/content/course_live/lesson_completed.ex:28
#: lib/content/course_live/lesson_completed.ex:30
#, elixir-autogen, elixir-format
msgid "Very good!"
msgstr ""
Expand All @@ -121,7 +121,7 @@ msgstr ""
msgid "Well done!"
msgstr ""

#: lib/content/course_live/lesson_completed.html.heex:11
#: lib/content/course_live/lesson_completed.html.heex:13
#, elixir-autogen, elixir-format
msgid "You got %{correct} out of %{total} answers right."
msgstr ""
Expand All @@ -131,7 +131,7 @@ msgstr ""
msgid "Lesson cover"
msgstr ""

#: lib/content/course_live/lesson_play.html.heex:16
#: lib/content/course_live/lesson_play.html.heex:15
#, elixir-autogen, elixir-format
msgid "Your progress in this lesson will be lost. Would you like to quit?"
msgstr ""
Expand All @@ -151,7 +151,12 @@ msgstr ""
msgid "No courses"
msgstr ""

#: lib/content/course_live/lesson_play.ex:79
#: lib/content/course_live/lesson_play.ex:76
#, elixir-autogen, elixir-format
msgid "Unable to send answer"
msgstr ""

#: lib/content/course_live/lesson_completed.html.heex:12
#, elixir-autogen, elixir-format
msgid "You got all the answers correct!"
msgstr ""
35 changes: 20 additions & 15 deletions priv/gettext/de/LC_MESSAGES/courses.po
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ msgstr "Ein Antrag auf Einschreibung wurde an den Kursleiter geschickt."
msgid "Advanced"
msgstr "Erweitert"

#: lib/content/course_live/lesson_completed.html.heex:19
#: lib/content/course_live/lesson_completed.html.heex:21
#, elixir-autogen, elixir-format
msgid "Back to the course"
msgstr "Zurück zum Kurs"
Expand All @@ -31,7 +31,7 @@ msgstr "Zurück zum Kurs"
msgid "Beginner"
msgstr "Anfänger"

#: lib/content/course_live/lesson_play.html.heex:95
#: lib/content/course_live/lesson_play.html.heex:94
#, elixir-autogen, elixir-format
msgid "Confirming..."
msgstr "Bestätigen..."
Expand All @@ -41,7 +41,7 @@ msgstr "Bestätigen..."
msgid "Enrolled successfully!"
msgstr "Erfolgreich eingeschrieben!"

#: lib/content/course_live/lesson_completed.ex:27
#: lib/content/course_live/lesson_completed.ex:29
#, elixir-autogen, elixir-format
msgid "Excellent!"
msgstr "Ausgezeichnet!"
Expand All @@ -56,12 +56,12 @@ msgstr "Experte"
msgid "Failed to enroll"
msgstr "Einschreibung fehlgeschlagen"

#: lib/content/course_live/lesson_completed.ex:29
#: lib/content/course_live/lesson_completed.ex:31
#, elixir-autogen, elixir-format
msgid "Good!"
msgstr "Gut!"

#: lib/content/course_live/lesson_completed.html.heex:4
#: lib/content/course_live/lesson_completed.html.heex:5
#, elixir-autogen, elixir-format
msgid "Illustration of a green alien"
msgstr "Illustration eines grünen Außerirdischen"
Expand All @@ -71,17 +71,17 @@ msgstr "Illustration eines grünen Außerirdischen"
msgid "Intermediate"
msgstr "Zwischenbericht"

#: lib/content/course_live/lesson_play.html.heex:99
#: lib/content/course_live/lesson_play.html.heex:98
#, elixir-autogen, elixir-format
msgid "Next step"
msgstr "Nächster Schritt"

#: lib/content/course_live/lesson_completed.ex:30
#: lib/content/course_live/lesson_completed.ex:32
#, elixir-autogen, elixir-format
msgid "Not bad!"
msgstr "Nicht schlecht!"

#: lib/content/course_live/lesson_completed.ex:26
#: lib/content/course_live/lesson_completed.ex:28
#, elixir-autogen, elixir-format
msgid "Perfect!"
msgstr "Perfekt!"
Expand All @@ -96,22 +96,22 @@ msgstr "Antrag auf Beitritt"
msgid "That's incorrect."
msgstr "Das ist nicht richtig."

#: lib/content/course_live/lesson_completed.ex:31
#: lib/content/course_live/lesson_completed.ex:33
#, elixir-autogen, elixir-format
msgid "There's room for improvement"
msgstr "Es gibt Raum für Verbesserungen"

#: lib/content/course_live/lesson_play.ex:93
#: lib/content/course_live/lesson_play.ex:90
#, elixir-autogen, elixir-format
msgid "Unable to complete lesson"
msgstr "Lektion kann nicht abgeschlossen werden"

#: lib/content/course_live/lesson_play.ex:56
#: lib/content/course_live/lesson_play.ex:53
#, elixir-autogen, elixir-format
msgid "Unable to select option"
msgstr "Option kann nicht ausgewählt werden"

#: lib/content/course_live/lesson_completed.ex:28
#: lib/content/course_live/lesson_completed.ex:30
#, elixir-autogen, elixir-format
msgid "Very good!"
msgstr "Sehr gut!"
Expand All @@ -121,7 +121,7 @@ msgstr "Sehr gut!"
msgid "Well done!"
msgstr "Gut gemacht!"

#: lib/content/course_live/lesson_completed.html.heex:11
#: lib/content/course_live/lesson_completed.html.heex:13
#, elixir-autogen, elixir-format
msgid "You got %{correct} out of %{total} answers right."
msgstr "Du hast %{correct} von %{total} der Antworten richtig."
Expand All @@ -131,7 +131,7 @@ msgstr "Du hast %{correct} von %{total} der Antworten richtig."
msgid "Lesson cover"
msgstr "Lektions Cover"

#: lib/content/course_live/lesson_play.html.heex:16
#: lib/content/course_live/lesson_play.html.heex:15
#, elixir-autogen, elixir-format
msgid "Your progress in this lesson will be lost. Would you like to quit?"
msgstr "Ihr Fortschritt in dieser Lektion wird verloren gehen. Möchten Sie aufhören?"
Expand All @@ -151,7 +151,12 @@ msgstr "Beginnen Sie mit der Teilnahme an einem Kurs."
msgid "No courses"
msgstr "Keine Kurse"

#: lib/content/course_live/lesson_play.ex:79
#: lib/content/course_live/lesson_play.ex:76
#, elixir-autogen, elixir-format
msgid "Unable to send answer"
msgstr "Senden der Antwort fehlgeschlagen"

#: lib/content/course_live/lesson_completed.html.heex:12
#, elixir-autogen, elixir-format
msgid "You got all the answers correct!"
msgstr "Du hast alle Antworten richtig!"
Loading

0 comments on commit 91cea3b

Please sign in to comment.