fix visibility issues with multiple users
This commit is contained in:
@ -22,16 +22,16 @@ defmodule Memex.Contexts do
|
||||
@spec list_contexts(search :: String.t() | nil, User.t()) :: [Context.t()]
|
||||
def list_contexts(search \\ nil, user)
|
||||
|
||||
def list_contexts(search, %{id: user_id}) when search in [nil, ""] do
|
||||
Repo.all(from c in Context, where: c.user_id == ^user_id, order_by: c.slug)
|
||||
def list_contexts(search, %{id: user_id}) when user_id |> is_binary() and search in [nil, ""] do
|
||||
Repo.all(from c in Context, order_by: c.slug)
|
||||
end
|
||||
|
||||
def list_contexts(search, %{id: user_id}) when search |> is_binary() do
|
||||
def list_contexts(search, %{id: user_id})
|
||||
when user_id |> is_binary() and search |> is_binary() do
|
||||
trimmed_search = String.trim(search)
|
||||
|
||||
Repo.all(
|
||||
from c in Context,
|
||||
where: c.user_id == ^user_id,
|
||||
where:
|
||||
fragment(
|
||||
"search @@ websearch_to_tsquery('english', ?)",
|
||||
@ -103,12 +103,8 @@ defmodule Memex.Contexts do
|
||||
|
||||
"""
|
||||
@spec get_context!(Context.id(), User.t()) :: Context.t()
|
||||
def get_context!(id, %{id: user_id}) do
|
||||
Repo.one!(
|
||||
from c in Context,
|
||||
where: c.id == ^id,
|
||||
where: c.user_id == ^user_id or c.visibility in [:public, :unlisted]
|
||||
)
|
||||
def get_context!(id, %{id: user_id}) when user_id |> is_binary() do
|
||||
Repo.one!(from c in Context, where: c.id == ^id)
|
||||
end
|
||||
|
||||
def get_context!(id, _invalid_user) do
|
||||
@ -134,12 +130,8 @@ defmodule Memex.Contexts do
|
||||
|
||||
"""
|
||||
@spec get_context_by_slug(Context.slug(), User.t()) :: Context.t() | nil
|
||||
def get_context_by_slug(slug, %{id: user_id}) do
|
||||
Repo.one(
|
||||
from c in Context,
|
||||
where: c.slug == ^slug,
|
||||
where: c.user_id == ^user_id or c.visibility in [:public, :unlisted]
|
||||
)
|
||||
def get_context_by_slug(slug, %{id: user_id}) when user_id |> is_binary() do
|
||||
Repo.one(from c in Context, where: c.slug == ^slug)
|
||||
end
|
||||
|
||||
def get_context_by_slug(slug, _invalid_user) do
|
||||
@ -194,23 +186,16 @@ defmodule Memex.Contexts do
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_context(%Context{user_id: 123}, %User{id: 123})
|
||||
{:ok, %Context{}}
|
||||
|
||||
iex> delete_context(%Context{user_id: 123}, %User{role: :admin})
|
||||
{:ok, %Context{}}
|
||||
|
||||
iex> delete_context(%Context{}, %User{id: 123})
|
||||
{:ok, %Context{}}
|
||||
|
||||
iex> delete_context(%Context{}, nil)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec delete_context(Context.t(), User.t()) ::
|
||||
{:ok, Context.t()} | {:error, Context.changeset()}
|
||||
def delete_context(%Context{user_id: user_id} = context, %{id: user_id}) do
|
||||
context |> Repo.delete()
|
||||
end
|
||||
|
||||
def delete_context(%Context{} = context, %{role: :admin}) do
|
||||
def delete_context(%Context{} = context, %{id: user_id}) when user_id |> is_binary() do
|
||||
context |> Repo.delete()
|
||||
end
|
||||
|
||||
@ -228,13 +213,4 @@ defmodule Memex.Contexts do
|
||||
def change_context(%Context{} = context, attrs \\ %{}, user) do
|
||||
context |> Context.update_changeset(attrs, user)
|
||||
end
|
||||
|
||||
@spec owner_or_admin?(Context.t(), User.t()) :: boolean()
|
||||
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
|
||||
def owner_or_admin?(_context, %{role: :admin}), do: true
|
||||
def owner_or_admin?(_context, _other_user), do: false
|
||||
|
||||
@spec owner?(Context.t(), User.t()) :: boolean()
|
||||
def owner?(%{user_id: user_id}, %{id: user_id}), do: true
|
||||
def owner?(_context, _other_user), do: false
|
||||
end
|
||||
|
@ -63,8 +63,9 @@ defmodule Memex.Contexts.Context do
|
||||
end
|
||||
|
||||
@spec update_changeset(t(), attrs :: map(), User.t()) :: changeset()
|
||||
def update_changeset(%{user_id: user_id} = note, attrs, %User{id: user_id}) do
|
||||
note
|
||||
def update_changeset(%__MODULE__{} = context, attrs, %User{id: user_id})
|
||||
when user_id |> is_binary() do
|
||||
context
|
||||
|> cast(attrs, [:slug, :content, :tags, :visibility])
|
||||
|> cast_tags_string(attrs)
|
||||
|> validate_format(:slug, ~r/^[\p{L}\p{N}\-]+$/,
|
||||
|
@ -31,7 +31,6 @@ defmodule Memex.Notes do
|
||||
|
||||
Repo.all(
|
||||
from n in Note,
|
||||
where: n.user_id == ^user_id,
|
||||
where:
|
||||
fragment(
|
||||
"search @@ websearch_to_tsquery('english', ?)",
|
||||
@ -102,12 +101,8 @@ defmodule Memex.Notes do
|
||||
|
||||
"""
|
||||
@spec get_note!(Note.id(), User.t()) :: Note.t()
|
||||
def get_note!(id, %{id: user_id}) do
|
||||
Repo.one!(
|
||||
from n in Note,
|
||||
where: n.id == ^id,
|
||||
where: n.user_id == ^user_id or n.visibility in [:public, :unlisted]
|
||||
)
|
||||
def get_note!(id, %{id: user_id}) when user_id |> is_binary() do
|
||||
Repo.one!(from n in Note, where: n.id == ^id)
|
||||
end
|
||||
|
||||
def get_note!(id, _invalid_user) do
|
||||
@ -133,12 +128,8 @@ defmodule Memex.Notes do
|
||||
|
||||
"""
|
||||
@spec get_note_by_slug(Note.slug(), User.t()) :: Note.t() | nil
|
||||
def get_note_by_slug(slug, %{id: user_id}) do
|
||||
Repo.one(
|
||||
from n in Note,
|
||||
where: n.slug == ^slug,
|
||||
where: n.user_id == ^user_id or n.visibility in [:public, :unlisted]
|
||||
)
|
||||
def get_note_by_slug(slug, %{id: user_id}) when user_id |> is_binary() do
|
||||
Repo.one(from n in Note, where: n.slug == ^slug)
|
||||
end
|
||||
|
||||
def get_note_by_slug(slug, _invalid_user) do
|
||||
@ -192,22 +183,15 @@ defmodule Memex.Notes do
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_note(%Note{user_id: 123}, %User{id: 123})
|
||||
{:ok, %Note{}}
|
||||
|
||||
iex> delete_note(%Note{}, %User{role: :admin})
|
||||
{:ok, %Note{}}
|
||||
|
||||
iex> delete_note(%Note{}, %User{id: 123})
|
||||
{:ok, %Note{}}
|
||||
|
||||
iex> delete_note(%Note{}, nil)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec delete_note(Note.t(), User.t()) :: {:ok, Note.t()} | {:error, Note.changeset()}
|
||||
def delete_note(%Note{user_id: user_id} = note, %{id: user_id}) do
|
||||
note |> Repo.delete()
|
||||
end
|
||||
|
||||
def delete_note(%Note{} = note, %{role: :admin}) do
|
||||
def delete_note(%Note{} = note, %{id: user_id}) when user_id |> is_binary() do
|
||||
note |> Repo.delete()
|
||||
end
|
||||
|
||||
@ -228,13 +212,4 @@ defmodule Memex.Notes do
|
||||
def change_note(%Note{} = note, attrs \\ %{}, user) do
|
||||
note |> Note.update_changeset(attrs, user)
|
||||
end
|
||||
|
||||
@spec owner_or_admin?(Note.t(), User.t()) :: boolean()
|
||||
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
|
||||
def owner_or_admin?(_context, %{role: :admin}), do: true
|
||||
def owner_or_admin?(_context, _other_user), do: false
|
||||
|
||||
@spec owner?(Note.t(), User.t()) :: boolean()
|
||||
def owner?(%{user_id: user_id}, %{id: user_id}), do: true
|
||||
def owner?(_context, _other_user), do: false
|
||||
end
|
||||
|
@ -62,7 +62,8 @@ defmodule Memex.Notes.Note do
|
||||
end
|
||||
|
||||
@spec update_changeset(t(), attrs :: map(), User.t()) :: changeset()
|
||||
def update_changeset(%{user_id: user_id} = note, attrs, %User{id: user_id}) do
|
||||
def update_changeset(%__MODULE__{} = note, attrs, %User{id: user_id})
|
||||
when user_id |> is_binary() do
|
||||
note
|
||||
|> cast(attrs, [:slug, :content, :tags, :visibility])
|
||||
|> cast_tags_string(attrs)
|
||||
|
@ -22,16 +22,17 @@ defmodule Memex.Pipelines do
|
||||
@spec list_pipelines(search :: String.t() | nil, User.t()) :: [Pipeline.t()]
|
||||
def list_pipelines(search \\ nil, user)
|
||||
|
||||
def list_pipelines(search, %{id: user_id}) when search in [nil, ""] do
|
||||
Repo.all(from p in Pipeline, where: p.user_id == ^user_id, order_by: p.slug)
|
||||
def list_pipelines(search, %{id: user_id})
|
||||
when user_id |> is_binary() and search in [nil, ""] do
|
||||
Repo.all(from p in Pipeline, order_by: p.slug)
|
||||
end
|
||||
|
||||
def list_pipelines(search, %{id: user_id}) when search |> is_binary() do
|
||||
def list_pipelines(search, %{id: user_id})
|
||||
when user_id |> is_binary() and search |> is_binary() do
|
||||
trimmed_search = String.trim(search)
|
||||
|
||||
Repo.all(
|
||||
from p in Pipeline,
|
||||
where: p.user_id == ^user_id,
|
||||
where:
|
||||
fragment(
|
||||
"search @@ websearch_to_tsquery('english', ?)",
|
||||
@ -102,12 +103,8 @@ defmodule Memex.Pipelines do
|
||||
|
||||
"""
|
||||
@spec get_pipeline!(Pipeline.id(), User.t()) :: Pipeline.t()
|
||||
def get_pipeline!(id, %{id: user_id}) do
|
||||
Repo.one!(
|
||||
from p in Pipeline,
|
||||
where: p.id == ^id,
|
||||
where: p.user_id == ^user_id or p.visibility in [:public, :unlisted]
|
||||
)
|
||||
def get_pipeline!(id, %{id: user_id}) when user_id |> is_binary() do
|
||||
Repo.one!(from p in Pipeline, where: p.id == ^id)
|
||||
end
|
||||
|
||||
def get_pipeline!(id, _invalid_user) do
|
||||
@ -133,12 +130,8 @@ defmodule Memex.Pipelines do
|
||||
|
||||
"""
|
||||
@spec get_pipeline_by_slug(Pipeline.slug(), User.t()) :: Pipeline.t() | nil
|
||||
def get_pipeline_by_slug(slug, %{id: user_id}) do
|
||||
Repo.one(
|
||||
from p in Pipeline,
|
||||
where: p.slug == ^slug,
|
||||
where: p.user_id == ^user_id or p.visibility in [:public, :unlisted]
|
||||
)
|
||||
def get_pipeline_by_slug(slug, %{id: user_id}) when user_id |> is_binary() do
|
||||
Repo.one(from p in Pipeline, where: p.slug == ^slug)
|
||||
end
|
||||
|
||||
def get_pipeline_by_slug(slug, _invalid_user) do
|
||||
@ -193,23 +186,16 @@ defmodule Memex.Pipelines do
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_pipeline(%Pipeline{user_id: 123}, %User{id: 123})
|
||||
{:ok, %Pipeline{}}
|
||||
|
||||
iex> delete_pipeline(%Pipeline{}, %User{role: :admin})
|
||||
{:ok, %Pipeline{}}
|
||||
|
||||
iex> delete_pipeline(%Pipeline{}, %User{id: 123})
|
||||
{:ok, %Pipeline{}}
|
||||
|
||||
iex> delete_pipeline(%Pipeline{}, nil)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec delete_pipeline(Pipeline.t(), User.t()) ::
|
||||
{:ok, Pipeline.t()} | {:error, Pipeline.changeset()}
|
||||
def delete_pipeline(%Pipeline{user_id: user_id} = pipeline, %{id: user_id}) do
|
||||
pipeline |> Repo.delete()
|
||||
end
|
||||
|
||||
def delete_pipeline(%Pipeline{} = pipeline, %{role: :admin}) do
|
||||
def delete_pipeline(%Pipeline{} = pipeline, %{id: user_id}) when user_id |> is_binary() do
|
||||
pipeline |> Repo.delete()
|
||||
end
|
||||
|
||||
@ -230,13 +216,4 @@ defmodule Memex.Pipelines do
|
||||
def change_pipeline(%Pipeline{} = pipeline, attrs \\ %{}, user) do
|
||||
pipeline |> Pipeline.update_changeset(attrs, user)
|
||||
end
|
||||
|
||||
@spec owner_or_admin?(Pipeline.t(), User.t()) :: boolean()
|
||||
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
|
||||
def owner_or_admin?(_context, %{role: :admin}), do: true
|
||||
def owner_or_admin?(_context, _other_user), do: false
|
||||
|
||||
@spec owner?(Pipeline.t(), User.t()) :: boolean()
|
||||
def owner?(%{user_id: user_id}, %{id: user_id}), do: true
|
||||
def owner?(_context, _other_user), do: false
|
||||
end
|
||||
|
@ -65,7 +65,8 @@ defmodule Memex.Pipelines.Pipeline do
|
||||
end
|
||||
|
||||
@spec update_changeset(t(), attrs :: map(), User.t()) :: changeset()
|
||||
def update_changeset(%{user_id: user_id} = pipeline, attrs, %User{id: user_id}) do
|
||||
def update_changeset(%__MODULE__{} = pipeline, attrs, %User{id: user_id})
|
||||
when user_id |> is_binary() do
|
||||
pipeline
|
||||
|> cast(attrs, [:slug, :description, :tags, :visibility])
|
||||
|> cast_tags_string(attrs)
|
||||
|
@ -44,9 +44,12 @@ defmodule Memex.Pipelines.Steps.Step do
|
||||
@doc false
|
||||
@spec create_changeset(attrs :: map(), position :: non_neg_integer(), Pipeline.t(), User.t()) ::
|
||||
changeset()
|
||||
def create_changeset(attrs, position, %Pipeline{id: pipeline_id, user_id: user_id}, %User{
|
||||
id: user_id
|
||||
}) do
|
||||
def create_changeset(
|
||||
attrs,
|
||||
position,
|
||||
%Pipeline{id: pipeline_id, user_id: user_id},
|
||||
%User{id: user_id}
|
||||
) do
|
||||
%__MODULE__{}
|
||||
|> cast(attrs, [:title, :content])
|
||||
|> change(pipeline_id: pipeline_id, user_id: user_id, position: position)
|
||||
@ -55,22 +58,16 @@ defmodule Memex.Pipelines.Steps.Step do
|
||||
|
||||
@spec update_changeset(t(), attrs :: map(), User.t()) ::
|
||||
changeset()
|
||||
def update_changeset(
|
||||
%{user_id: user_id} = step,
|
||||
attrs,
|
||||
%User{id: user_id}
|
||||
) do
|
||||
def update_changeset(%__MODULE__{} = step, attrs, %User{id: user_id})
|
||||
when user_id |> is_binary() do
|
||||
step
|
||||
|> cast(attrs, [:title, :content])
|
||||
|> validate_required([:title, :user_id, :position])
|
||||
end
|
||||
|
||||
@spec position_changeset(t(), position :: non_neg_integer(), User.t()) :: changeset()
|
||||
def position_changeset(
|
||||
%{user_id: user_id} = step,
|
||||
position,
|
||||
%User{id: user_id}
|
||||
) do
|
||||
def position_changeset(%__MODULE__{} = step, position, %User{id: user_id})
|
||||
when user_id |> is_binary() do
|
||||
step
|
||||
|> change(position: position)
|
||||
|> validate_required([:title, :user_id, :position])
|
||||
|
@ -21,11 +21,10 @@ defmodule Memex.Pipelines.Steps do
|
||||
|
||||
"""
|
||||
@spec list_steps(Pipeline.t(), User.t()) :: [Step.t()]
|
||||
def list_steps(%{id: pipeline_id}, %{id: user_id}) do
|
||||
def list_steps(%{id: pipeline_id}, %{id: user_id}) when user_id |> is_binary() do
|
||||
Repo.all(
|
||||
from s in Step,
|
||||
where: s.pipeline_id == ^pipeline_id,
|
||||
where: s.user_id == ^user_id,
|
||||
order_by: s.position
|
||||
)
|
||||
end
|
||||
@ -62,8 +61,8 @@ defmodule Memex.Pipelines.Steps do
|
||||
|
||||
"""
|
||||
@spec get_step!(Step.id(), User.t()) :: Step.t()
|
||||
def get_step!(id, %{id: user_id}) do
|
||||
Repo.one!(from n in Step, where: n.id == ^id, where: n.user_id == ^user_id)
|
||||
def get_step!(id, %{id: user_id}) when user_id |> is_binary() do
|
||||
Repo.one!(from n in Step, where: n.id == ^id)
|
||||
end
|
||||
|
||||
def get_step!(id, _invalid_user) do
|
||||
@ -119,22 +118,15 @@ defmodule Memex.Pipelines.Steps do
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_step(%Step{user_id: 123}, %User{id: 123})
|
||||
{:ok, %Step{}}
|
||||
|
||||
iex> delete_step(%Step{}, %User{role: :admin})
|
||||
{:ok, %Step{}}
|
||||
|
||||
iex> delete_step(%Step{}, %User{id: 123})
|
||||
{:ok, %Step{}}
|
||||
|
||||
iex> delete_step(%Step{}, nil)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec delete_step(Step.t(), User.t()) :: {:ok, Step.t()} | {:error, Step.changeset()}
|
||||
def delete_step(%Step{user_id: user_id} = step, %{id: user_id}) do
|
||||
delete_step(step)
|
||||
end
|
||||
|
||||
def delete_step(%Step{} = step, %{role: :admin}) do
|
||||
def delete_step(%Step{} = step, %{id: user_id}) when user_id |> is_binary() do
|
||||
delete_step(step)
|
||||
end
|
||||
|
||||
@ -181,10 +173,11 @@ defmodule Memex.Pipelines.Steps do
|
||||
def reorder_step(%Step{position: 0} = step, :up, _user), do: {:error, step}
|
||||
|
||||
def reorder_step(
|
||||
%Step{position: position, pipeline_id: pipeline_id, user_id: user_id} = step,
|
||||
%Step{position: position, pipeline_id: pipeline_id} = step,
|
||||
:up,
|
||||
%{id: user_id} = user
|
||||
) do
|
||||
)
|
||||
when user_id |> is_binary() do
|
||||
Multi.new()
|
||||
|> Multi.update_all(
|
||||
:reorder_steps,
|
||||
@ -207,10 +200,11 @@ defmodule Memex.Pipelines.Steps do
|
||||
end
|
||||
|
||||
def reorder_step(
|
||||
%Step{pipeline_id: pipeline_id, position: position, user_id: user_id} = step,
|
||||
%Step{pipeline_id: pipeline_id, position: position} = step,
|
||||
:down,
|
||||
%{id: user_id} = user
|
||||
) do
|
||||
)
|
||||
when user_id |> is_binary() do
|
||||
Multi.new()
|
||||
|> Multi.one(
|
||||
:step_count,
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="mx-auto flex flex-col justify-center items-start space-y-4 max-w-3xl">
|
||||
<div class="flex flex-col justify-center items-start mx-auto space-y-4 max-w-3xl">
|
||||
<h1 class="text-xl">
|
||||
<%= gettext("contexts") %>
|
||||
</h1>
|
||||
@ -9,7 +9,7 @@
|
||||
as={:search}
|
||||
phx-change="search"
|
||||
phx-submit="search"
|
||||
class="self-stretch flex flex-col items-stretch"
|
||||
class="flex flex-col items-stretch self-stretch"
|
||||
>
|
||||
<%= text_input(f, :search_term,
|
||||
class: "input input-primary",
|
||||
@ -33,14 +33,14 @@
|
||||
>
|
||||
<:actions :let={context}>
|
||||
<.link
|
||||
:if={Contexts.owner?(context, @current_user)}
|
||||
:if={@current_user}
|
||||
patch={~p"/contexts/#{context}/edit"}
|
||||
aria-label={dgettext("actions", "edit %{context_slug}", context_slug: context.slug)}
|
||||
>
|
||||
<%= dgettext("actions", "edit") %>
|
||||
</.link>
|
||||
<.link
|
||||
:if={Contexts.owner_or_admin?(context, @current_user)}
|
||||
:if={@current_user}
|
||||
href="#"
|
||||
phx-click="delete"
|
||||
phx-value-id={context.id}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="mx-auto flex flex-col justify-center items-stretch space-y-4 max-w-3xl">
|
||||
<div class="flex flex-col justify-center items-stretch mx-auto space-y-4 max-w-3xl">
|
||||
<h1 class="text-xl">
|
||||
<%= @context.slug %>
|
||||
</h1>
|
||||
@ -15,16 +15,12 @@
|
||||
<%= gettext("Visibility: %{visibility}", visibility: @context.visibility) %>
|
||||
</p>
|
||||
|
||||
<div class="self-end flex space-x-4">
|
||||
<.link
|
||||
:if={Contexts.owner?(@context, @current_user)}
|
||||
class="btn btn-primary"
|
||||
patch={~p"/context/#{@context}/edit"}
|
||||
>
|
||||
<div class="flex self-end space-x-4">
|
||||
<.link :if={@current_user} class="btn btn-primary" patch={~p"/context/#{@context}/edit"}>
|
||||
<%= dgettext("actions", "edit") %>
|
||||
</.link>
|
||||
<button
|
||||
:if={Contexts.owner_or_admin?(@context, @current_user)}
|
||||
:if={@current_user}
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
phx-click="delete"
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="mx-auto flex flex-col justify-center items-start space-y-4 max-w-3xl">
|
||||
<div class="flex flex-col justify-center items-start mx-auto space-y-4 max-w-3xl">
|
||||
<h1 class="text-xl">
|
||||
<%= gettext("notes") %>
|
||||
</h1>
|
||||
@ -9,7 +9,7 @@
|
||||
as={:search}
|
||||
phx-change="search"
|
||||
phx-submit="search"
|
||||
class="self-stretch flex flex-col items-stretch"
|
||||
class="flex flex-col items-stretch self-stretch"
|
||||
>
|
||||
<%= text_input(f, :search_term,
|
||||
class: "input input-primary",
|
||||
@ -33,14 +33,14 @@
|
||||
>
|
||||
<:actions :let={note}>
|
||||
<.link
|
||||
:if={Notes.owner?(note, @current_user)}
|
||||
:if={@current_user}
|
||||
patch={~p"/notes/#{note}/edit"}
|
||||
aria-label={dgettext("actions", "edit %{note_slug}", note_slug: note.slug)}
|
||||
>
|
||||
<%= dgettext("actions", "edit") %>
|
||||
</.link>
|
||||
<.link
|
||||
:if={Notes.owner_or_admin?(note, @current_user)}
|
||||
:if={@current_user}
|
||||
href="#"
|
||||
phx-click="delete"
|
||||
phx-value-id={note.id}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="mx-auto flex flex-col justify-center items-stretch space-y-4 max-w-3xl">
|
||||
<div class="flex flex-col justify-center items-stretch mx-auto space-y-4 max-w-3xl">
|
||||
<h1 class="text-xl">
|
||||
<%= @note.slug %>
|
||||
</h1>
|
||||
@ -15,16 +15,12 @@
|
||||
<%= gettext("Visibility: %{visibility}", visibility: @note.visibility) %>
|
||||
</p>
|
||||
|
||||
<div class="self-end flex space-x-4">
|
||||
<.link
|
||||
:if={Notes.owner?(@note, @current_user)}
|
||||
class="btn btn-primary"
|
||||
patch={~p"/note/#{@note}/edit"}
|
||||
>
|
||||
<div class="flex self-end space-x-4">
|
||||
<.link :if={@current_user} class="btn btn-primary" patch={~p"/note/#{@note}/edit"}>
|
||||
<%= dgettext("actions", "edit") %>
|
||||
</.link>
|
||||
<button
|
||||
:if={Notes.owner_or_admin?(@note, @current_user)}
|
||||
:if={@current_user}
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
phx-click="delete"
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="mx-auto flex flex-col justify-center items-start space-y-4 max-w-3xl">
|
||||
<div class="flex flex-col justify-center items-start mx-auto space-y-4 max-w-3xl">
|
||||
<h1 class="text-xl">
|
||||
<%= gettext("pipelines") %>
|
||||
</h1>
|
||||
@ -9,7 +9,7 @@
|
||||
as={:search}
|
||||
phx-change="search"
|
||||
phx-submit="search"
|
||||
class="self-stretch flex flex-col items-stretch"
|
||||
class="flex flex-col items-stretch self-stretch"
|
||||
>
|
||||
<%= text_input(f, :search_term,
|
||||
class: "input input-primary",
|
||||
@ -33,14 +33,14 @@
|
||||
>
|
||||
<:actions :let={pipeline}>
|
||||
<.link
|
||||
:if={Pipelines.owner?(pipeline, @current_user)}
|
||||
:if={@current_user}
|
||||
patch={~p"/pipelines/#{pipeline}/edit"}
|
||||
aria-label={dgettext("actions", "edit %{pipeline_slug}", pipeline_slug: pipeline.slug)}
|
||||
>
|
||||
<%= dgettext("actions", "edit") %>
|
||||
</.link>
|
||||
<.link
|
||||
:if={Pipelines.owner_or_admin?(pipeline, @current_user)}
|
||||
:if={@current_user}
|
||||
href="#"
|
||||
phx-click="delete"
|
||||
phx-value-id={pipeline.id}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="mx-auto flex flex-col justify-center items-stretch space-y-4 max-w-3xl">
|
||||
<div class="flex flex-col justify-center items-stretch mx-auto space-y-4 max-w-3xl">
|
||||
<h1 class="text-xl">
|
||||
<%= @pipeline.slug %>
|
||||
</h1>
|
||||
@ -15,16 +15,12 @@
|
||||
<%= gettext("Visibility: %{visibility}", visibility: @pipeline.visibility) %>
|
||||
</p>
|
||||
|
||||
<div class="pb-4 self-end flex space-x-4">
|
||||
<.link
|
||||
:if={Pipelines.owner?(@pipeline, @current_user)}
|
||||
class="btn btn-primary"
|
||||
patch={~p"/pipeline/#{@pipeline}/edit"}
|
||||
>
|
||||
<div class="flex self-end pb-4 space-x-4">
|
||||
<.link :if={@current_user} class="btn btn-primary" patch={~p"/pipeline/#{@pipeline}/edit"}>
|
||||
<%= dgettext("actions", "edit") %>
|
||||
</.link>
|
||||
<button
|
||||
:if={Pipelines.owner_or_admin?(@pipeline, @current_user)}
|
||||
:if={@current_user}
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
phx-click="delete"
|
||||
@ -37,7 +33,7 @@
|
||||
|
||||
<hr class="hr" />
|
||||
|
||||
<h2 class="pt-2 self-center text-lg">
|
||||
<h2 class="self-center pt-2 text-lg">
|
||||
<%= gettext("steps:") %>
|
||||
</h2>
|
||||
|
||||
@ -52,29 +48,29 @@
|
||||
<%= gettext("%{position}. %{title}", position: position + 1, title: title) %>
|
||||
</h3>
|
||||
|
||||
<%= if Pipelines.owner?(@pipeline, @current_user) do %>
|
||||
<%= if @current_user do %>
|
||||
<div class="flex justify-between items-center space-x-4">
|
||||
<%= if position <= 0 do %>
|
||||
<i class="fas text-xl fa-chevron-up cursor-not-allowed opacity-25"></i>
|
||||
<i class="text-xl opacity-25 cursor-not-allowed fas fa-chevron-up"></i>
|
||||
<% else %>
|
||||
<button
|
||||
type="button"
|
||||
class="cursor-pointer flex justify-center items-center"
|
||||
class="flex justify-center items-center cursor-pointer"
|
||||
phx-click="reorder_step"
|
||||
phx-value-direction="up"
|
||||
phx-value-step-id={step_id}
|
||||
aria-label={dgettext("actions", "move %{step_title} up", step_title: step.title)}
|
||||
>
|
||||
<i class="fas text-xl fa-chevron-up"></i>
|
||||
<i class="text-xl fas fa-chevron-up"></i>
|
||||
</button>
|
||||
<% end %>
|
||||
|
||||
<%= if position >= length(@steps) - 1 do %>
|
||||
<i class="fas text-xl fa-chevron-down cursor-not-allowed opacity-25"></i>
|
||||
<i class="text-xl opacity-25 cursor-not-allowed fas fa-chevron-down"></i>
|
||||
<% else %>
|
||||
<button
|
||||
type="button"
|
||||
class="cursor-pointer flex justify-center items-center"
|
||||
class="flex justify-center items-center cursor-pointer"
|
||||
phx-click="reorder_step"
|
||||
phx-value-direction="down"
|
||||
phx-value-step-id={step_id}
|
||||
@ -82,7 +78,7 @@
|
||||
dgettext("actions", "move %{step_title} down", step_title: step.title)
|
||||
}
|
||||
>
|
||||
<i class="fas text-xl fa-chevron-down"></i>
|
||||
<i class="text-xl fas fa-chevron-down"></i>
|
||||
</button>
|
||||
<% end %>
|
||||
|
||||
@ -113,7 +109,7 @@
|
||||
<% end %>
|
||||
|
||||
<.link
|
||||
:if={Pipelines.owner?(@pipeline, @current_user)}
|
||||
:if={@current_user}
|
||||
class="self-end btn btn-primary"
|
||||
patch={~p"/pipeline/#{@pipeline}/add_step"}
|
||||
>
|
||||
|
Reference in New Issue
Block a user