mirror of
https://github.com/mirego/accent.git
synced 2024-10-26 18:39:53 +03:00
Delete operations on project delete
This commit is contained in:
parent
f3954c127a
commit
0d56ab1087
@ -1,5 +1,8 @@
|
||||
defmodule Accent.ProjectDeleter do
|
||||
@moduledoc false
|
||||
import Ecto.Query, only: [from: 2]
|
||||
|
||||
alias Accent.Operation
|
||||
alias Accent.Repo
|
||||
|
||||
def delete(project: project) do
|
||||
@ -7,6 +10,17 @@ defmodule Accent.ProjectDeleter do
|
||||
|> Ecto.assoc(:all_collaborators)
|
||||
|> Repo.delete_all()
|
||||
|
||||
Repo.transaction(fn ->
|
||||
Repo.delete_all(
|
||||
from(operations in Operation,
|
||||
inner_join: revisions in assoc(operations, :revision),
|
||||
where: revisions.project_id == ^project.id
|
||||
)
|
||||
)
|
||||
|
||||
Repo.delete_all(from(operations in Operation, where: operations.project_id == ^project.id))
|
||||
end)
|
||||
|
||||
{:ok, project}
|
||||
end
|
||||
end
|
||||
|
@ -3,14 +3,22 @@ defmodule AccentTest.ProjectDeleter do
|
||||
use Accent.RepoCase, async: true
|
||||
|
||||
alias Accent.Collaborator
|
||||
alias Accent.Language
|
||||
alias Accent.Operation
|
||||
alias Accent.Project
|
||||
alias Accent.ProjectDeleter
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
|
||||
test "create with language and user" do
|
||||
test "delete collaborators and operations" do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "french"})
|
||||
language = Repo.insert!(%Language{slug: "foo", name: "foo"})
|
||||
revision = Repo.insert!(%Revision{language_id: language.id, project_id: project.id})
|
||||
collaborator = Repo.insert!(%Collaborator{project_id: project.id, role: "reviewer"})
|
||||
|
||||
Repo.insert!(%Operation{project_id: project.id, action: "sync"})
|
||||
Repo.insert!(%Operation{revision_id: revision.id, action: "merge"})
|
||||
|
||||
assert project
|
||||
|> Ecto.assoc(:all_collaborators)
|
||||
|> Repo.all()
|
||||
@ -18,6 +26,8 @@ defmodule AccentTest.ProjectDeleter do
|
||||
|
||||
{:ok, project} = ProjectDeleter.delete(project: project)
|
||||
|
||||
assert Repo.all(Ecto.assoc(project, :all_collaborators)) === []
|
||||
assert Repo.aggregate(Ecto.assoc(project, :all_collaborators), :count) === 0
|
||||
assert Repo.aggregate(Ecto.assoc(project, :operations), :count) === 0
|
||||
assert Repo.aggregate(Ecto.assoc(revision, :operations), :count) === 0
|
||||
end
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ interface Args {
|
||||
onSave: ({
|
||||
provider,
|
||||
configKey,
|
||||
usePlatform
|
||||
usePlatform,
|
||||
}: {
|
||||
provider: string;
|
||||
configKey: string | null;
|
||||
@ -100,7 +100,7 @@ export default class ProjectSettingsPromptsConfig extends Component<Args> {
|
||||
await this.args.onSave({
|
||||
provider: this.provider,
|
||||
configKey: this.configKey,
|
||||
usePlatform: this.usePlatform
|
||||
usePlatform: this.usePlatform,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -31,11 +31,7 @@
|
||||
{{/if}}
|
||||
</p>
|
||||
|
||||
<textarea
|
||||
placeholder={{this.configKeyPlaceholder}}
|
||||
local-class='textInput'
|
||||
{{on 'change' (fn this.onConfigKeyChange)}}
|
||||
>{{this.configKey}}</textarea>
|
||||
<textarea placeholder={{this.configKeyPlaceholder}} local-class='textInput' {{on 'change' (fn this.onConfigKeyChange)}}>{{this.configKey}}</textarea>
|
||||
{{/unless}}
|
||||
|
||||
<div local-class='actions'>
|
||||
|
Loading…
Reference in New Issue
Block a user