Skip to content

Commit

Permalink
Add the ability to turn off Atlos archival (closes #1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesmcc committed Aug 31, 2024
1 parent d8d9ade commit 70f7d8e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion platform/lib/platform/projects/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Platform.Projects.Project do
field(:description, :string, default: "")
field(:color, :string, default: "#fb923c")
field(:active, :boolean, default: true)
field(:source_material_archival_enabled, :boolean, default: true)

# Integrations
field(:should_sync_with_internet_archive, :boolean, default: false)
Expand All @@ -29,7 +30,7 @@ defmodule Platform.Projects.Project do
@doc false
def changeset(project, attrs) do
project
|> cast(attrs, [:name, :code, :color, :description, :should_sync_with_internet_archive])
|> cast(attrs, [:name, :code, :color, :description, :source_material_archival_enabled, :should_sync_with_internet_archive])
|> cast_embed(:attributes, required: false, sort_param: :position)
|> cast_embed(:attribute_groups, required: false, sort_param: :position)
|> validate_required([:name, :code, :color])
Expand Down
6 changes: 4 additions & 2 deletions platform/lib/platform/workers/archiver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Platform.Workers.Archiver do
alias Platform.Material.MediaVersion
alias Platform.Auditor
alias Platform.Uploads
alias Platform.Projects

require Logger

Expand Down Expand Up @@ -30,10 +31,11 @@ defmodule Platform.Workers.Archiver do

Logger.info("Archiving media version #{id}...")
version = Material.get_media_version!(id)
project = Projects.get_project!(version.project_id)

%MediaVersion{status: status, media_id: media_id} = version

if status == :pending or is_rearchive_request do
if (status == :pending or is_rearchive_request) and not (version.upload_type == :direct and not project.source_material_archival_enabled) do
Logger.info("Archiving media version #{id}... (got media #{media_id})")

hide_version_on_failure = Map.get(args, "hide_version_on_failure", false)
Expand Down Expand Up @@ -293,7 +295,7 @@ defmodule Platform.Workers.Archiver do
result
else
Logger.info(
"Media version #{id} is not pending, and this is not a rearchive request. Skipping."
"Media version #{id} is not pending and this is not a rearchive request, or archival is disabled for this project. Skipping."
)

{:ok, version}
Expand Down
14 changes: 14 additions & 0 deletions platform/lib/platform_web/live/projects_live/edit_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,20 @@ defmodule PlatformWeb.ProjectsLive.EditComponent do
</p>
<%= error_tag(f, :should_sync_with_internet_archive) %>
</div>
<div class="mt-4">
<p class="flex gap-2 items-center mb-1">
<%= checkbox(f, :source_material_archival_enabled,
disabled: not Permissions.can_edit_project_metadata?(@current_user, @project)
) %>
<%= label(f, :source_material_archival_enabled) do %>
Use built-in source material archival
<% end %>
</p>
<p class="support">
If enabled, Atlos will automatically archive source material links added to this project. Disable if you'd like to use a custom archival solution.
</p>
<%= error_tag(f, :source_material_archival_enabled) %>
</div>
</details>
<div class="mt-8">
<div class="flex justify-between gap-4 flex-wrap">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Platform.Repo.Migrations.AddArchivalDisableOption do
use Ecto.Migration

def change do
alter table(:projects) do
add :source_material_archival_enabled, :boolean, default: true
end
end
end

0 comments on commit 70f7d8e

Please sign in to comment.