diff --git a/lib/polar/accounts.ex b/lib/polar/accounts.ex index f216f40..e242e63 100644 --- a/lib/polar/accounts.ex +++ b/lib/polar/accounts.ex @@ -12,10 +12,26 @@ defmodule Polar.Accounts do to: Space.Manager, as: :create + defdelegate change_space(space), + to: Space.Manager, + as: :change + + defdelegate change_space(space, attrs), + to: Space.Manager, + as: :change + defdelegate get_space_credential(query), to: Space.Manager, as: :get_credential + defdelegate change_space_credential(credential), + to: Space.Manager, + as: :change_credential + + defdelegate change_space_credential(credential, attrs), + to: Space.Manager, + as: :change_credential + defdelegate create_space_credential(space, user, params), to: Space.Manager, as: :create_credential diff --git a/lib/polar/accounts/space.ex b/lib/polar/accounts/space.ex index d3accb4..fabd232 100644 --- a/lib/polar/accounts/space.ex +++ b/lib/polar/accounts/space.ex @@ -6,7 +6,6 @@ defmodule Polar.Accounts.Space do schema "spaces" do field :name, :string - field :cdn_host, :string belongs_to :owner, User @@ -16,7 +15,8 @@ defmodule Polar.Accounts.Space do @doc false def changeset(space, attrs) do space - |> cast(attrs, [:name, :cdn_host]) + |> cast(attrs, [:name]) |> validate_required([:name]) + |> unique_constraint(:name, name: :spaces_owner_id_name_index) end end diff --git a/lib/polar/accounts/space/credential.ex b/lib/polar/accounts/space/credential.ex index 52a0753..421022c 100644 --- a/lib/polar/accounts/space/credential.ex +++ b/lib/polar/accounts/space/credential.ex @@ -39,6 +39,8 @@ defmodule Polar.Accounts.Space.Credential do def expires_in_range, do: @expires_in_range + def types, do: ["lxd", "incus"] + @doc false def changeset(credential, attrs) do expires_in_range_values = Enum.map(@expires_in_range, fn r -> r.value end) @@ -47,9 +49,10 @@ defmodule Polar.Accounts.Space.Credential do |> cast(attrs, [:name, :expires_in, :type]) |> generate_token() |> validate_inclusion(:expires_in, expires_in_range_values) - |> validate_inclusion(:type, ["lxd", "incus"]) + |> validate_inclusion(:type, types()) |> maybe_set_expires_at() |> validate_required([:token, :type, :name]) + |> unique_constraint(:name, name: :space_credentials_space_id_name_index) end def scope(:active, queryable) do diff --git a/lib/polar/accounts/space/manager.ex b/lib/polar/accounts/space/manager.ex index a576c8a..2022abf 100644 --- a/lib/polar/accounts/space/manager.ex +++ b/lib/polar/accounts/space/manager.ex @@ -11,11 +11,19 @@ defmodule Polar.Accounts.Space.Manager do |> Repo.insert() end + def change(%Space{} = space, attrs \\ %{}) do + Space.changeset(space, attrs) + end + def get_credential(token: token) do Space.Credential.scope(:active, Space.Credential) |> Repo.get_by(token: token) end + def change_credential(credential_or_changeset, attrs \\ %{}) do + Space.Credential.changeset(credential_or_changeset, attrs) + end + def create_credential(%Accounts.Space{} = space, user, params) do %Space.Credential{space_id: space.id} |> Space.Credential.changeset(params) diff --git a/lib/polar/streams/item/manager.ex b/lib/polar/streams/item/manager.ex index 79c8c37..75af3dd 100644 --- a/lib/polar/streams/item/manager.ex +++ b/lib/polar/streams/item/manager.ex @@ -19,8 +19,10 @@ defmodule Polar.Streams.Item.Manager do |> Repo.insert!() %Item.Access{id: item_access_id} = item_access -> + timestamp = DateTime.utc_now() + from(ia in Item.Access, - update: [inc: [count: 1]], + update: [inc: [count: 1], set: [updated_at: ^timestamp]], where: ia.id == ^item_access_id ) |> Repo.update_all([]) diff --git a/lib/polar_web/components/core_components.ex b/lib/polar_web/components/core_components.ex index 9adc7ce..53309f0 100644 --- a/lib/polar_web/components/core_components.ex +++ b/lib/polar_web/components/core_components.ex @@ -389,6 +389,17 @@ defmodule PolarWeb.CoreComponents do """ end + def input(%{type: "radio"} = assigns) do + assigns = + assign_new(assigns, :checked, fn -> + Phoenix.HTML.Form.normalize_value("checkbox", assigns[:value]) + end) + + ~H""" + + """ + end + # All other inputs text, datetime-local, url, password, etc. are handled here... def input(assigns) do ~H""" diff --git a/lib/polar_web/components/layouts/app.html.heex b/lib/polar_web/components/layouts/app.html.heex index d3dde72..5ed7301 100644 --- a/lib/polar_web/components/layouts/app.html.heex +++ b/lib/polar_web/components/layouts/app.html.heex @@ -21,6 +21,18 @@ > <%= gettext("Home") %> + <.link + navigate={~p"/dashboard"} + class={ + if assigns[:current_path] == ~p"/dashboard", + do: "bg-slate-900 text-white rounded-md px-3 py-2 text-sm font-medium", + else: + "rounded-md px-3 py-2 text-sm font-medium text-slate-300 hover:bg-slate-900 hover:text-white" + } + aria-current="page" + > + <%= gettext("Dashboard") %> + @@ -28,7 +40,7 @@
<%= gettext("404") %>
++ <% gettext("Sorry, we couldn’t find the page you’re looking for.") %> +
++ <%= gettext("to the place I belong. West Virginia.") %> +
++ <%= gettext("Go back to the dashboard.") %> +
+<%= gettext("404") %>
++ <% gettext("Sorry, an error happened, we've logged the error.") %> +
++ <%= gettext("to the place I belong. West Virginia.") %> +
++ <%= gettext("Go back to the dashboard.") %> +
++ <%= gettext("Credentials allow you to control your simplestreams feed.") %> +
++ <%= gettext("Details about the credential and instructions on how to use it.") %> +
++ <%= gettext( + "This credential is only meant for you, please do not share it with external parties." + ) %> +
++ <%= gettext( + "Spaces group all your tokens, it can represent an organization or just a workspace." + ) %> +
++ <%= gettext("Get started by creating a new credential.") %> +
+<%= credential.name %>
++ <%= gettext("Created on") %> + +
+ ++ <%= if credential.expires_at do %> + <%= gettext("Expires at") %> <%= Calendar.strftime( + credential.expires_at, + "%d %b %Y" + ) %> + <% else %> + <%= gettext("Never Expires") %> + <% end %> +
++ <%= gettext("Get started by creating a new space.") %> +
+<%= space.name %>
++ <%= gettext("Created on") %> + +
+ +<%= gettext("Owned by") %> <%= space.owner.email %>
+