--- /dev/null
+# Akkoma Code of Conduct
+
+The Akkoma project aims to be **enjoyable** for anyone to participate in, regardless of their identity or level of expertise. To achieve this, the community must create an environment which is **safe** and **equitable**; the following guidelines have been created with these goals in mind.
+
+1. **Treat individuals with respect.** Differing experiences and viewpoints deserve to be respected, and bigotry and harassment are not tolerated under any circumstances.
+ - Individuals should at all times be treated as equals, regardless of their age, gender, sexuality, race, ethnicity, _or any other characteristic_, intrinsic or otherwise.
+ - Behaviour that is harmful in nature should be addressed and corrected *regardless of intent*.
+ - Respect personal boundaries and ask for clarification whenever they are unclear.
+ - (Obviously, hate does not count as merely a "differing viewpoint", because it is harmful in nature.)
+
+2. **Be understanding of differences in communication.** Not everyone is aware of unspoken social cues, and speech that is not intended to be offensive should not be treated as such simply due to an atypical manner of communication.
+ - Somebody who speaks bluntly is not necessarily rude, and somebody who swears a lot is not necessarily volatile.
+ - Try to confirm your interpretation of their intent rather than assuming bad faith.
+ - Someone may not communicate as, or come across as a picture of "professionalism", but this should not be seen as a reason to dismiss them. This is a **casual** space, and communication styles can reflect that.
+
+3. **"Uncomfortable" does not mean "unsafe".** In an ideal world, the community would be safe, equitable, enjoyable, *and* comfortable for all members at all times. Unfortunately, this is not always possible in reality.
+ - Safety and equity will be prioritized over comfort whenever it is necessary to do so.
+ - Weaponizing one's own discomfort to deflect accountability or censor an individual (e.g. "white fragility") is a form of discriminatory conduct.
+
+4. **Let people grow from their mistakes.** Nobody is perfect; even the most well-meaning individual can do something hurtful. Everyone should be given a fair opportunity to explain themselves and correct their behaviour. Portraying someone as inherently malicious prevents improvement and shifts focus away from the *action* that was problematic.
+ - Avoid bringing up past events that do not accurately reflect an individual's current actions or beliefs. (This is, of course, different from providing evidence of a recurring pattern of behaviour.)
+
+---
+This document was adapted from one created by ~keith as part of punks default repository template, and is licensed under CC-BY-SA 4.0. The original template is here: <https://bytes.keithhacks.cyou/keith/default-template>
config_path =
cond do
opts[:config_path] -> opts[:config_path]
- System.get_env("PLEROMA_CONFIG_PATH") -> System.get_env("PLEROMA_CONFIG_PATH")
System.get_env("AKKOMA_CONFIG_PATH") -> System.get_env("AKKOMA_CONFIG_PATH")
- File.exists?("/etc/akkoma/config.exs") -> "/etc/akkoma/config.exs"
- true -> "/etc/pleroma/config.exs"
+ System.get_env("PLEROMA_CONFIG_PATH") -> System.get_env("PLEROMA_CONFIG_PATH")
+ File.exists?("/etc/pleroma/config.exs") -> "/etc/pleroma/config.exs"
+ true -> "/etc/akkoma/config.exs"
end
with_runtime_config =
warning = [
IO.ANSI.red(),
IO.ANSI.bright(),
- "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file",
+ "!!! Config path is not declared! Please ensure it exists and that AKKOMA_CONFIG_PATH and/or PLEROMA_CONFIG_PATH is unset or points to an existing file",
IO.ANSI.reset()
]
|> Builder.add_param(:query, :query, params)
|> Builder.convert_to_keyword()
end
-
- defp adapter_middlewares(_) do
- if Pleroma.Config.get(:env) == :test do
- # Emulate redirects in test env, which are handled by adapters in other environments
- [Tesla.Middleware.FollowRedirects]
- else
- []
- end
- end
end
end
def create(user, admin_id \\ nil) do
- with :ok <- validate_email_enabled(),
- :ok <- validate_user_email(user),
- :ok <- validate_limit(user, admin_id),
+ with :ok <- validate_limit(user, admin_id),
{:ok, backup} <- user |> new() |> Repo.insert() do
BackupWorker.process(backup, admin_id)
end
end
end
- defp validate_email_enabled do
- if Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled]) do
- :ok
- else
- {:error, dgettext("errors", "Backups require enabled email")}
- end
- end
-
- defp validate_user_email(%User{email: nil}) do
- {:error, dgettext("errors", "Email is required")}
- end
-
- defp validate_user_email(%User{email: email}) when is_binary(email), do: :ok
-
def get_last(user_id) do
__MODULE__
|> where(user_id: ^user_id)
backup_id |> Backup.get() |> Backup.process(),
{:ok, _job} <- schedule_deletion(backup),
:ok <- Backup.remove_outdated(backup),
- {:ok, _} <-
- backup
- |> Pleroma.Emails.UserEmail.backup_is_ready_email(admin_user_id)
- |> Pleroma.Emails.Mailer.deliver() do
+ :ok <- maybe_deliver_email(backup, admin_user_id) do
{:ok, backup}
end
end
nil -> :ok
end
end
+
+ defp has_email?(user) do
+ not is_nil(user.email) and user.email != ""
+ end
+
+ defp maybe_deliver_email(backup, admin_user_id) do
+ has_mailer = Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled])
+ backup = backup |> Pleroma.Repo.preload(:user)
+
+ if has_email?(backup.user) and has_mailer do
+ backup
+ |> Pleroma.Emails.UserEmail.backup_is_ready_email(admin_user_id)
+ |> Pleroma.Emails.Mailer.deliver()
+
+ :ok
+ else
+ :ok
+ end
+ end
end
clear_config([Pleroma.Emails.Mailer, :enabled], true)
end
- test "it requries enabled email" do
+ test "it does not requrie enabled email" do
clear_config([Pleroma.Emails.Mailer, :enabled], false)
user = insert(:user)
- assert {:error, "Backups require enabled email"} == Backup.create(user)
+ assert {:ok, _} = Backup.create(user)
end
- test "it requries user's email" do
+ test "it does not require user's email" do
user = insert(:user, %{email: nil})
- assert {:error, "Email is required"} == Backup.create(user)
+ assert {:ok, _} = Backup.create(user)
end
test "it creates a backup record and an Oban job" do
)
end
+ test "it does not send an email if the user does not have an email" do
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ %{id: user_id} = user = insert(:user, %{email: nil})
+
+ assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id} = args}} = Backup.create(user)
+ assert {:ok, backup} = perform_job(BackupWorker, args)
+ assert backup.file_size > 0
+ assert %Backup{id: ^backup_id, processed: true, user_id: ^user_id} = backup
+
+ assert_no_email_sent()
+ end
+
+ test "it does not send an email if mailer is not on" do
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ %{id: user_id} = user = insert(:user)
+
+ assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id} = args}} = Backup.create(user)
+ assert {:ok, backup} = perform_job(BackupWorker, args)
+ assert backup.file_size > 0
+ assert %Backup{id: ^backup_id, processed: true, user_id: ^user_id} = backup
+
+ assert_no_email_sent()
+ end
+
+ test "it does not send an email if the user has an empty email" do
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ %{id: user_id} = user = insert(:user, %{email: ""})
+
+ assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id} = args}} = Backup.create(user)
+ assert {:ok, backup} = perform_job(BackupWorker, args)
+ assert backup.file_size > 0
+ assert %Backup{id: ^backup_id, processed: true, user_id: ^user_id} = backup
+
+ assert_no_email_sent()
+ end
+
test "it removes outdated backups after creating a fresh one" do
clear_config([Backup, :limit_days], -1)
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
assert not called(
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
- inbox: "https://rejected.com/users/nick1/inbox",
+ inbox: "https://rejected.com/users/nick2/inbox",
actor_id: actor.id,
id: public_note_activity.data["id"]
})
|> post("/api/v1/pleroma/backups")
|> json_response_and_validate_schema(400)
end
+
+ test "Backup without email address" do
+ user = Pleroma.Factory.insert(:user, email: nil)
+ %{conn: conn} = oauth_access(["read:accounts"], user: user)
+
+ assert is_nil(user.email)
+
+ assert [
+ %{
+ "content_type" => "application/zip",
+ "url" => _url,
+ "file_size" => 0,
+ "processed" => false,
+ "inserted_at" => _
+ }
+ ] =
+ conn
+ |> post("/api/v1/pleroma/backups")
+ |> json_response_and_validate_schema(:ok)
+ end
end