Fix export being outputted in the wrong directory in release mode
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
ed7e6e4d4b
commit
377b83e02d
@ -329,6 +329,7 @@ config :mobilizon, Mobilizon.Service.Notifier.Email, enabled: true
|
|||||||
config :mobilizon, Mobilizon.Service.Notifier.Push, enabled: true
|
config :mobilizon, Mobilizon.Service.Notifier.Push, enabled: true
|
||||||
|
|
||||||
config :mobilizon, :exports,
|
config :mobilizon, :exports,
|
||||||
|
path: "/var/lib/mobilizon/uploads/exports",
|
||||||
formats: [
|
formats: [
|
||||||
Mobilizon.Service.Export.Participants.CSV
|
Mobilizon.Service.Export.Participants.CSV
|
||||||
]
|
]
|
||||||
|
@ -94,6 +94,8 @@ config :mobilizon, Mobilizon.Web.Auth.Guardian,
|
|||||||
|
|
||||||
config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "uploads"
|
config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "uploads"
|
||||||
|
|
||||||
|
config :mobilizon, :exports, path: "uploads/exports"
|
||||||
|
|
||||||
config :tz_world, data_dir: "_build/dev/lib/tz_world/priv"
|
config :tz_world, data_dir: "_build/dev/lib/tz_world/priv"
|
||||||
|
|
||||||
config :mobilizon, :anonymous,
|
config :mobilizon, :anonymous,
|
||||||
|
@ -60,6 +60,8 @@ config :mobilizon, Mobilizon.Web.Upload, filters: [], link_name: false
|
|||||||
|
|
||||||
config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "test/uploads"
|
config :mobilizon, Mobilizon.Web.Upload.Uploader.Local, uploads: "test/uploads"
|
||||||
|
|
||||||
|
config :mobilizon, :exports, path: "test/uploads/exports"
|
||||||
|
|
||||||
config :tz_world, data_dir: "_build/test/lib/tz_world/priv"
|
config :tz_world, data_dir: "_build/test/lib/tz_world/priv"
|
||||||
|
|
||||||
config :tesla, Mobilizon.Service.HTTP.ActivityPub,
|
config :tesla, Mobilizon.Service.HTTP.ActivityPub,
|
||||||
|
@ -4,9 +4,9 @@ defmodule Mobilizon.Service.Export.Participants.Common do
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
|
alias Mobilizon.{Config, Export}
|
||||||
alias Mobilizon.Events.Participant
|
alias Mobilizon.Events.Participant
|
||||||
alias Mobilizon.Events.Participant.Metadata
|
alias Mobilizon.Events.Participant.Metadata
|
||||||
alias Mobilizon.Export
|
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
import Mobilizon.Web.Gettext, only: [gettext: 1]
|
import Mobilizon.Web.Gettext, only: [gettext: 1]
|
||||||
|
|
||||||
@ -117,4 +117,13 @@ defmodule Mobilizon.Service.Export.Participants.Common do
|
|||||||
formats = Keyword.get(export_config, :formats, [])
|
formats = Keyword.get(export_config, :formats, [])
|
||||||
type in formats
|
type in formats
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@default_upload_path "uploads/exports/"
|
||||||
|
|
||||||
|
@spec export_path(String.t()) :: String.t()
|
||||||
|
def export_path(extension) do
|
||||||
|
[:exports, :path]
|
||||||
|
|> Config.get(@default_upload_path)
|
||||||
|
|> Path.join(extension)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,17 +3,21 @@ defmodule Mobilizon.Service.Export.Participants.CSV do
|
|||||||
Export a list of participants to CSV
|
Export a list of participants to CSV
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.{Events, Export}
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Export
|
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
alias Mobilizon.Web.Gettext
|
alias Mobilizon.Web.Gettext
|
||||||
import Mobilizon.Web.Gettext, only: [gettext: 2]
|
import Mobilizon.Web.Gettext, only: [gettext: 2]
|
||||||
|
|
||||||
import Mobilizon.Service.Export.Participants.Common,
|
import Mobilizon.Service.Export.Participants.Common,
|
||||||
only: [save_upload: 5, columns: 0, to_list: 1, clean_exports: 2, export_enabled?: 1]
|
only: [
|
||||||
|
save_upload: 5,
|
||||||
@upload_path "uploads/exports/csv/"
|
columns: 0,
|
||||||
|
to_list: 1,
|
||||||
|
clean_exports: 2,
|
||||||
|
export_enabled?: 1,
|
||||||
|
export_path: 1
|
||||||
|
]
|
||||||
|
|
||||||
@extension "csv"
|
@extension "csv"
|
||||||
|
|
||||||
@ -26,7 +30,7 @@ defmodule Mobilizon.Service.Export.Participants.CSV do
|
|||||||
def export(%Event{id: event_id} = event, options \\ []) do
|
def export(%Event{id: event_id} = event, options \\ []) do
|
||||||
if ready?() do
|
if ready?() do
|
||||||
filename = "#{ShortUUID.encode!(Ecto.UUID.generate())}.csv"
|
filename = "#{ShortUUID.encode!(Ecto.UUID.generate())}.csv"
|
||||||
full_path = @upload_path <> filename
|
full_path = Path.join([export_path(@extension), filename])
|
||||||
|
|
||||||
file = File.open!(full_path, [:write, :utf8])
|
file = File.open!(full_path, [:write, :utf8])
|
||||||
|
|
||||||
@ -80,7 +84,7 @@ defmodule Mobilizon.Service.Export.Participants.CSV do
|
|||||||
"""
|
"""
|
||||||
@spec clean_exports :: :ok
|
@spec clean_exports :: :ok
|
||||||
def clean_exports do
|
def clean_exports do
|
||||||
clean_exports("csv", @upload_path)
|
clean_exports("csv", export_path(@extension))
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec dependencies_ok? :: boolean
|
@spec dependencies_ok? :: boolean
|
||||||
|
@ -10,9 +10,14 @@ defmodule Mobilizon.Service.Export.Participants.ODS do
|
|||||||
import Mobilizon.Web.Gettext, only: [gettext: 2]
|
import Mobilizon.Web.Gettext, only: [gettext: 2]
|
||||||
|
|
||||||
import Mobilizon.Service.Export.Participants.Common,
|
import Mobilizon.Service.Export.Participants.Common,
|
||||||
only: [save_upload: 5, to_list: 1, clean_exports: 2, columns: 0, export_enabled?: 1]
|
only: [
|
||||||
|
save_upload: 5,
|
||||||
@upload_path "uploads/exports/ods/"
|
to_list: 1,
|
||||||
|
clean_exports: 2,
|
||||||
|
columns: 0,
|
||||||
|
export_enabled?: 1,
|
||||||
|
export_path: 1
|
||||||
|
]
|
||||||
|
|
||||||
@extension "ods"
|
@extension "ods"
|
||||||
|
|
||||||
@ -25,7 +30,7 @@ defmodule Mobilizon.Service.Export.Participants.ODS do
|
|||||||
def export(%Event{id: event_id} = event, options \\ []) do
|
def export(%Event{id: event_id} = event, options \\ []) do
|
||||||
if ready?() do
|
if ready?() do
|
||||||
filename = "#{ShortUUID.encode!(Ecto.UUID.generate())}.ods"
|
filename = "#{ShortUUID.encode!(Ecto.UUID.generate())}.ods"
|
||||||
full_path = @upload_path <> filename
|
full_path = Path.join([export_path(@extension), filename])
|
||||||
|
|
||||||
case Repo.transaction(
|
case Repo.transaction(
|
||||||
fn ->
|
fn ->
|
||||||
@ -84,7 +89,7 @@ defmodule Mobilizon.Service.Export.Participants.ODS do
|
|||||||
"""
|
"""
|
||||||
@spec clean_exports :: :ok
|
@spec clean_exports :: :ok
|
||||||
def clean_exports do
|
def clean_exports do
|
||||||
clean_exports("ods", @upload_path)
|
clean_exports(@extension, export_path(@extension))
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec dependencies_ok? :: boolean
|
@spec dependencies_ok? :: boolean
|
||||||
|
@ -12,9 +12,14 @@ defmodule Mobilizon.Service.Export.Participants.PDF do
|
|||||||
import Mobilizon.Web.Gettext, only: [gettext: 2]
|
import Mobilizon.Web.Gettext, only: [gettext: 2]
|
||||||
|
|
||||||
import Mobilizon.Service.Export.Participants.Common,
|
import Mobilizon.Service.Export.Participants.Common,
|
||||||
only: [save_upload: 5, columns: 0, to_list: 1, clean_exports: 2, export_enabled?: 1]
|
only: [
|
||||||
|
save_upload: 5,
|
||||||
@upload_path "uploads/exports/pdf/"
|
columns: 0,
|
||||||
|
to_list: 1,
|
||||||
|
clean_exports: 2,
|
||||||
|
export_enabled?: 1,
|
||||||
|
export_path: 1
|
||||||
|
]
|
||||||
|
|
||||||
@extension "pdf"
|
@extension "pdf"
|
||||||
|
|
||||||
@ -27,7 +32,7 @@ defmodule Mobilizon.Service.Export.Participants.PDF do
|
|||||||
def export(%Event{id: event_id} = event, options \\ []) do
|
def export(%Event{id: event_id} = event, options \\ []) do
|
||||||
if ready?() do
|
if ready?() do
|
||||||
filename = "#{ShortUUID.encode!(Ecto.UUID.generate())}.pdf"
|
filename = "#{ShortUUID.encode!(Ecto.UUID.generate())}.pdf"
|
||||||
full_path = @upload_path <> filename
|
full_path = Path.join([export_path(@extension), filename])
|
||||||
|
|
||||||
case Repo.transaction(
|
case Repo.transaction(
|
||||||
fn ->
|
fn ->
|
||||||
@ -98,7 +103,7 @@ defmodule Mobilizon.Service.Export.Participants.PDF do
|
|||||||
"""
|
"""
|
||||||
@spec clean_exports :: :ok
|
@spec clean_exports :: :ok
|
||||||
def clean_exports do
|
def clean_exports do
|
||||||
clean_exports("pdf", @upload_path)
|
clean_exports(@extension, export_path(@extension))
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec dependencies_ok? :: boolean
|
@spec dependencies_ok? :: boolean
|
||||||
|
@ -6,7 +6,7 @@ defmodule Mobilizon.Web.ExportController do
|
|||||||
plug(:put_layout, false)
|
plug(:put_layout, false)
|
||||||
action_fallback(Mobilizon.Web.FallbackController)
|
action_fallback(Mobilizon.Web.FallbackController)
|
||||||
alias Mobilizon.Export
|
alias Mobilizon.Export
|
||||||
import Mobilizon.Service.Export.Participants.Common, only: [enabled_formats: 0]
|
import Mobilizon.Service.Export.Participants.Common, only: [enabled_formats: 0, export_path: 1]
|
||||||
import Mobilizon.Web.Gettext, only: [dgettext: 3]
|
import Mobilizon.Web.Gettext, only: [dgettext: 3]
|
||||||
|
|
||||||
# sobelow_skip ["Traversal.SendDownload"]
|
# sobelow_skip ["Traversal.SendDownload"]
|
||||||
@ -15,7 +15,7 @@ defmodule Mobilizon.Web.ExportController do
|
|||||||
if format in enabled_formats() do
|
if format in enabled_formats() do
|
||||||
case Export.get_export(file, "event_participants", format) do
|
case Export.get_export(file, "event_participants", format) do
|
||||||
%Export{file_name: file_name, file_path: file_path} ->
|
%Export{file_name: file_name, file_path: file_path} ->
|
||||||
local_path = "uploads/exports/#{format}/#{file_path}"
|
local_path = Path.join(export_path(format), file_path)
|
||||||
# We're using encode: false to disable escaping the filename with URI.encode_www_form/1
|
# We're using encode: false to disable escaping the filename with URI.encode_www_form/1
|
||||||
# but it may introduce an security issue if the event title wasn't properly sanitized
|
# but it may introduce an security issue if the event title wasn't properly sanitized
|
||||||
# https://github.com/phoenixframework/phoenix/pull/3344
|
# https://github.com/phoenixframework/phoenix/pull/3344
|
||||||
|
Loading…
Reference in New Issue
Block a user