Skip to content

Commit

Permalink
Merge pull request #263 from fixthestatusquo/revert-262-qol-improvements
Browse files Browse the repository at this point in the history
Revert "Fix compile warnings and format code"
  • Loading branch information
destag authored Jul 21, 2024
2 parents a603926 + b329bbb commit 36e4ede
Show file tree
Hide file tree
Showing 67 changed files with 256 additions and 245 deletions.
2 changes: 1 addition & 1 deletion proca/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# is restricted to this project.

# General application configuration
import Config
use Mix.Config

config :proca,
ecto_repos: [Proca.Repo]
Expand Down
5 changes: 1 addition & 4 deletions proca/config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Config
use Mix.Config

# Configure your database

Expand Down Expand Up @@ -36,9 +36,6 @@ case System.get_env("ORGANISATION") do
config :proca, Proca, org_name: org_name
end

config :proca, Proca,
start_daemon_servers: System.get_env("START_DAEMON_SERVERS", "true") == "true"

# For development, we disable any cache and enable
# debugging and code reloading.
#
Expand Down
2 changes: 1 addition & 1 deletion proca/config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Config
use Mix.Config

# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
Expand Down
2 changes: 1 addition & 1 deletion proca/config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Config
use Mix.Config

# Only in tests, remove the complexity from the password hashing algorithm
config :bcrypt_elixir, :log_rounds, 1
Expand Down
17 changes: 9 additions & 8 deletions proca/lib/mix/tasks/eci.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Mix.Tasks.Eci do

keys = apply_changes(Proca.PublicKey.build_for(org, "ECI initial key"))

{:ok, _k} =
{:ok, k} =
keys
|> change(private: nil)
|> Repo.insert()
Expand All @@ -32,14 +32,15 @@ defmodule Mix.Tasks.Eci do
Proca.Campaign.upsert(org, %{name: org_name, title: campaign_name})
|> Repo.insert()

Proca.Contact.EciDataRules.countries()
|> Enum.map(fn ctr ->
{:ok, ap} =
Proca.ActionPage.upsert(org, camp, %{name: "#{campaign_name}/#{ctr}", locale: ctr})
|> Repo.insert()
pages =
Proca.Contact.EciDataRules.countries()
|> Enum.map(fn ctr ->
{:ok, ap} =
Proca.ActionPage.upsert(org, camp, %{name: "#{campaign_name}/#{ctr}", locale: ctr})
|> Repo.insert()

ap
end)
ap
end)
end)
end
end
6 changes: 3 additions & 3 deletions proca/lib/proca/action_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Proca.ActionPage do
alias Ecto.Multi

alias Proca.Repo
alias Proca.{ActionPage, Campaign, Action, Supporter}
alias Proca.{ActionPage, Campaign, Org, Action, Supporter}

schema "action_pages" do
field :locale, :string
Expand All @@ -37,7 +37,7 @@ defmodule Proca.ActionPage do
@doc """
Casts and validates values to change an Action Page.
The name validation is a pattern that allows two styles of action names:
The name validation is a pattern that allows two styles of action names:
1. identifier/path1/path2/path3 - where identifiers and paths are alphanumeric + - _
2. domain.com.pl/some/campaign - url style (very similar but _ is not allowed for domain part)
See test/action_page_test.exs for examples of valid and invalid names
Expand Down Expand Up @@ -83,7 +83,7 @@ defmodule Proca.ActionPage do
{:ok, action_page}

%{live: false} ->
# XXX do the health checks!
# XXX do the health checks!
change(action_page, live: true) |> Repo.update_and_notify()
end
end
Expand Down
4 changes: 2 additions & 2 deletions proca/lib/proca/action_page/status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Proca.ActionPage.Status do
import Ecto.Query
import Proca.Repo, only: [all: 1, one: 1]

alias Proca.Action
alias Proca.{Action, ActionPage}

def start_link(_opts) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
Expand Down Expand Up @@ -61,7 +61,7 @@ defmodule Proca.ActionPage.Status do
def handle_cast(
{:action,
action = %Action{
id: _id,
id: id,
action_page_id: ap_id,
inserted_at: seen_at
}},
Expand Down
2 changes: 1 addition & 1 deletion proca/lib/proca/confirm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule Proca.Confirm do
alias Proca.Repo
alias Proca.{Confirm, Org}
alias Proca.Users.User
alias Proca.Service.{EmailBackend, EmailMerge}
alias Proca.Service.{EmailBackend, EmailMerge, EmailTemplate}

schema "confirms" do
field :operation, ConfirmOperation
Expand Down
2 changes: 1 addition & 1 deletion proca/lib/proca/confirm/add_staffer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Proca.Confirm.AddStaffer do
alias Proca.Confirm
@behaviour Confirm.Operation

alias Proca.{Staffer, Org, Auth, Permission}
alias Proca.{Campaign, ActionPage, Staffer, Org, Auth, Error, Permission}
import Proca.Repo

def changeset(email, role, %Auth{user: user, staffer: %Staffer{org_id: org_id}}, message \\ nil)
Expand Down
12 changes: 6 additions & 6 deletions proca/lib/proca/confirm/join_campaign.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Proca.Confirm.JoinCampaign do
alias Proca.Repo
import Ecto.Query

import ProcaWeb.Helper, only: [cant_msg: 1, msg_ext: 2]
import ProcaWeb.Helper, only: [has_error?: 3, cant_msg: 1, msg_ext: 2]
import Proca.Permission, only: [can?: 2]

def changeset(%Campaign{id: campaign_id}, %Auth{staffer: %Staffer{org_id: org_id}}) do
Expand Down Expand Up @@ -57,13 +57,13 @@ defmodule Proca.Confirm.JoinCampaign do

def email_template(%Confirm{operation: :join_campaign}), do: "join_campaign"

# latest_page = from(a in ActinPage,
# where: a.campaign_id == ^campaign_id and a.org_id ==,
# latest_page = from(a in ActinPage,
# where: a.campaign_id == ^campaign_id and a.org_id ==,
# order_by: [desc: :id]
# ) |> Repo.one
#
# with {:page, page = %ActionPage{}} <- {:page, latest_page},
# true <- st.org_id ==
# true <- can?(st, [:manage_action_pages])
# do
# true <- st.org_id ==
# true <- can?(st, [:manage_action_pages])
# do
end
3 changes: 2 additions & 1 deletion proca/lib/proca/confirm/launch_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ defmodule Proca.Confirm.LaunchPage do

alias Proca.{Campaign, ActionPage, Staffer, Org, Auth}
import Proca.Repo
import Ecto.Query, only: [from: 2]

import ProcaWeb.Helper, only: [cant_msg: 1, msg_ext: 2]
import ProcaWeb.Helper, only: [has_error?: 3, cant_msg: 1, msg_ext: 2]
import Proca.Permission, only: [can?: 2]

import Logger
Expand Down
24 changes: 24 additions & 0 deletions proca/lib/proca/contact/it_regions.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
defmodule Proca.Contact.ItRegions do
# Vativan, San Marino removed (codes colliding with big regions)
@regions_codes %{
"Abruzzo" => ["64", "65", "66", "67"],
"Aosta Valley" => ["11"],
"Apulia" => ["70", "71", "72", "73", "74", "76"],
"Basilicata" => ["75", "85"],
"Calabria" => ["87", "88", "89"],
"Campania" => ["80", "81", "82", "83", "84"],
"Emilia-Romagna" => ["29", "40", "41", "42", "43", "44", "47", "48"],
"Friuli-Venezia Giulia" => ["33", "34"],
"Lazio" => ["00", "01", "02", "03", "04"],
"Liguria" => ["16", "17", "18", "19"],
"Lombardy" => ["20", "21", "22", "23", "24", "25", "26", "27", "46"],
"Marche" => ["60", "61", "62", "63"],
"Molise" => ["86"],
"Piedmont" => ["10", "12", "13", "14", "15", "28"],
"Sardinia" => ["07", "08", "09"],
"Sicily" => ["90", "91", "92", "93", "94", "95", "96", "97", "98"],
"Trentino-Alto Adige/Südtirol" => ["38", "39"],
"Tuscany" => ["50", "51", "52", "53", "54", "55", "56", "57", "58", "59"],
"Umbria" => ["05", "06"],
"Veneto" => ["30", "31", "32", "35", "36", "37", "45"]
}

@codes_regions %{
"00" => "Lazio",
"01" => "Lazio",
Expand Down
11 changes: 1 addition & 10 deletions proca/lib/proca/ecto_enum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ defenum(DonationSchema, stripe_payment_intent: 0)

defenum(DonationFrequencyUnit, one_off: 0, weekly: 1, monthly: 2, daily: 16)

defenum(EmailStatus,
none: 0,
double_opt_in: 1,
bounce: 2,
blocked: 3,
spam: 4,
unsub: 5,
inactive: 6,
active: 7
)
defenum(EmailStatus, none: 0, double_opt_in: 1, bounce: 2, blocked: 3, spam: 4, unsub: 5, inactive: 6, active: 7)

defenum(CampaignStatus, live: 0, closed: 1, ignored: 2)
1 change: 1 addition & 0 deletions proca/lib/proca/mtt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Proca.MTT do
use Proca.Schema, module: __MODULE__
import Ecto.Changeset
import Proca.Validations
alias Proca.ActionPage

schema "mtt" do
field :start_at, :utc_datetime
Expand Down
3 changes: 2 additions & 1 deletion proca/lib/proca/permission.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ defmodule Proca.Permission do
"""

import Bitwise
use Bitwise
alias Proca.Staffer
alias Proca.Users.User
alias Proca.Auth


@bits [
# Admin permissions [in users.perms]
instance_owner: 1 <<< 0,
Expand Down
4 changes: 2 additions & 2 deletions proca/lib/proca/pipes/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Proca.Pipes.Connection do
end

@impl true
def handle_info({:DOWN, _, :process, pid, _reason}, st = %{conn: %{pid: pid}}) do
def handle_info({:DOWN, _, :process, pid, reason}, st = %{conn: %{pid: pid}}) do
do_reconnecting(st, @connection_down_reconnect)
end

Expand All @@ -43,7 +43,7 @@ defmodule Proca.Pipes.Connection do
end

@impl true
def handle_info({:basic_return, _payload, _meta}, st) do
def handle_info({:basic_return, payload, meta}, st) do
{:noreply, st}
end

Expand Down
5 changes: 3 additions & 2 deletions proca/lib/proca/pipes/topology.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Proca.Pipes.Topology do
are sent by the API layer when respective event occurs. They are not sent by
operations on Proca.Org directly.
### Properties:
### Properties:
- 3 exchanges reflect 3 stages of processing (supporter confirms their data, moderator confirms the action, action is delivered)
- Each exchange has build in worker queues attached, *if workers are enabled*. Worker queues are read by Proca workers.
Expand Down Expand Up @@ -69,7 +69,8 @@ defmodule Proca.Pipes.Topology do
alias Proca.Org
alias Proca.Pipes
alias Proca.Stage
alias AMQP.{Queue, Exchange}
alias AMQP.{Channel, Queue, Exchange}
import AMQP.Basic

## API for topology server lifecycle
def start_link(org = %Org{}) do
Expand Down
4 changes: 2 additions & 2 deletions proca/lib/proca/public_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ defmodule Proca.PublicKey do
alias Proca.Repo
alias Proca.{PublicKey, Org}

@derive {Inspect, only: [:id, :name, :org, :active, :expired]}

schema "public_keys" do
field :name, :string
field :public, :binary
Expand All @@ -23,6 +21,8 @@ defmodule Proca.PublicKey do
timestamps()
end

@derive {Inspect, only: [:id, :name, :org, :active, :expired]}

@doc false
def changeset(public_key, attrs) do
public_key
Expand Down
1 change: 1 addition & 0 deletions proca/lib/proca/server/instance.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Proca.Server.Instance do
alias Proca.Server.Instance
alias Proca.Org

## XXX remove this
Expand Down
18 changes: 6 additions & 12 deletions proca/lib/proca/server/mtt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Proca.Server.MTT do
"""
use GenServer

require Logger
import Logger
import Ecto.Query
alias Proca.Repo
alias Proca.Server.MTTWorker
Expand Down Expand Up @@ -83,9 +83,7 @@ defmodule Proca.Server.MTT do
def handle_info({:DOWN, ref, _, _, _reason}, %{workers: workers}) do
workers = List.delete(workers, ref)

Logger.info(
"MTT Worker finished #{inspect(ref)} - remained #{length(workers)} workers running"
)
Logger.info("MTT Worker finished #{inspect(ref)} - remained #{length(workers)} workers running")

if workers == [] do
# all workers done
Expand All @@ -112,17 +110,13 @@ defmodule Proca.Server.MTT do

Enum.map(running_mtts, fn campaign ->
Logger.info("Start MTT worker for #{campaign.name} (waiting for connection pool)")

# We are compeeting for connection pool with the web server here, at one point we must get the connection
task =
Task.async(fn ->
Repo.checkout(
fn ->
Logger.info("Start MTT worker for #{campaign.name} (connection acquired)")
MTTWorker.process_mtt_campaign(campaign)
end,
timeout: :infinity
)
Repo.checkout(fn ->
Logger.info("Start MTT worker for #{campaign.name} (connection acquired)")
MTTWorker.process_mtt_campaign(campaign)
end, timeout: :infinity)
end)

task.ref
Expand Down
Loading

0 comments on commit 36e4ede

Please sign in to comment.