mirror of
https://github.com/mirego/accent.git
synced 2024-08-17 06:50:31 +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,11 +13,11 @@ interface Args {
|
||||
onSave: ({
|
||||
provider,
|
||||
configKey,
|
||||
usePlatform
|
||||
usePlatform,
|
||||
}: {
|
||||
provider: string;
|
||||
configKey: string | null;
|
||||
usePlatform: boolean;
|
||||
usePlatform: boolean;
|
||||
}) => Promise<any>;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -77,4 +77,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</li>
|
@ -28,4 +28,4 @@
|
||||
</LinkTo>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
@ -22,21 +22,17 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{{#unless this.usePlatform}}
|
||||
<p local-class='config-key-help'>
|
||||
{{#unless this.usePlatform}}
|
||||
<p local-class='config-key-help'>
|
||||
{{#if @project.promptConfig.useConfigKey}}
|
||||
{{t 'components.project_settings.prompts.config_key_help_present'}}
|
||||
{{else}}
|
||||
{{t 'components.project_settings.prompts.config_key_help_not_present'}}
|
||||
{{/if}}
|
||||
</p>
|
||||
{{t 'components.project_settings.prompts.config_key_help_present'}}
|
||||
{{else}}
|
||||
{{t 'components.project_settings.prompts.config_key_help_not_present'}}
|
||||
{{/if}}
|
||||
</p>
|
||||
|
||||
<textarea
|
||||
placeholder={{this.configKeyPlaceholder}}
|
||||
local-class='textInput'
|
||||
{{on 'change' (fn this.onConfigKeyChange)}}
|
||||
>{{this.configKey}}</textarea>
|
||||
{{/unless}}
|
||||
<textarea placeholder={{this.configKeyPlaceholder}} local-class='textInput' {{on 'change' (fn this.onConfigKeyChange)}}>{{this.configKey}}</textarea>
|
||||
{{/unless}}
|
||||
|
||||
<div local-class='actions'>
|
||||
{{#if @project.promptConfig}}
|
||||
@ -49,4 +45,4 @@
|
||||
{{t 'components.project_settings.integrations.save'}}
|
||||
</AsyncButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user