Skip to content

Commit

Permalink
Add setting to stop supervisor notifications
Browse files Browse the repository at this point in the history
This is something I couldn’t do as it unfolded without
a deployment.
  • Loading branch information
backspace committed Dec 4, 2023
1 parent c54e8be commit cc65b00
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule AdventureRegistrationsWeb.UnmnemonicDevices.Settings do
field(:compromised, :boolean, default: false)
field(:down, :boolean, default: false)
field(:ending, :boolean, default: false)
field(:notify_supervisor, :boolean, default: true)
field(:override, :string)
field(:vrs_href, :string)
field(:vrs_human, :string)
Expand All @@ -17,6 +18,15 @@ defmodule AdventureRegistrationsWeb.UnmnemonicDevices.Settings do

def changeset(settings, attrs) do
settings
|> cast(attrs, [:override, :begun, :compromised, :ending, :down, :vrs_href, :vrs_human])
|> cast(attrs, [
:override,
:begun,
:compromised,
:ending,
:notify_supervisor,
:down,
:vrs_href,
:vrs_human
])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@

<br>

<%= label f, :notify_supervisor %>
<%= checkbox f, :notify_supervisor %>
<%= error_tag f, :notify_supervisor %>

<br>

<%= label f, :ending %>
<%= checkbox f, :ending %>
<%= error_tag f, :ending %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule AdventureRegistrations.Repo.Migrations.AddUnmnemonicDevicesNotifySupervisorSetting do
use Ecto.Migration

def change do
alter table("settings", prefix: "unmnemonic_devices") do
add(:notify_supervisor, :boolean, default: true)
end
end
end
8 changes: 5 additions & 3 deletions unmnemonic_devices_vrs/src/routes/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub async fn get_root(
.ok();

let settings =
sqlx::query!("SELECT begun, down, ending, override as override_message FROM unmnemonic_devices.settings LIMIT 1")
sqlx::query!("SELECT begun, down, ending, override as override_message, notify_supervisor FROM unmnemonic_devices.settings LIMIT 1")
.fetch_one(&state.db)
.await
.expect("Failed to fetch settings");
Expand All @@ -128,8 +128,10 @@ pub async fn get_root(
let caller_is_supervisor =
params.caller.clone().unwrap_or("NOTHING".to_string()) == supervisor_number;

let notify_supervisor =
settings.begun.unwrap() && !settings.ending.unwrap() && !caller_is_supervisor;
let notify_supervisor = settings.begun.unwrap()
&& !settings.ending.unwrap()
&& !caller_is_supervisor
&& settings.notify_supervisor.unwrap();
let notify_notification = params.caller.is_some()
&& !settings.begun.unwrap()
&& !caller_is_supervisor
Expand Down
4 changes: 3 additions & 1 deletion unmnemonic_devices_vrs/tests/fixtures/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ CREATE TABLE unmnemonic_devices.settings (
day_before boolean DEFAULT false,
degrading boolean DEFAULT false,
vrs_href character varying(255),
vrs_human character varying(255)
vrs_human character varying(255),
notify_supervisor boolean DEFAULT true
);


Expand Down Expand Up @@ -536,3 +537,4 @@ INSERT INTO public."schema_migrations" (version) VALUES (20231110024646);
INSERT INTO public."schema_migrations" (version) VALUES (20231110062026);
INSERT INTO public."schema_migrations" (version) VALUES (20231111171443);
INSERT INTO public."schema_migrations" (version) VALUES (20231112020314);
INSERT INTO public."schema_migrations" (version) VALUES (20231204001556);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
INSERT INTO
unmnemonic_devices.settings (
id,
begun,
notify_supervisor,
inserted_at,
updated_at
)
VALUES
(1, true, false, now(), now());
9 changes: 9 additions & 0 deletions unmnemonic_devices_vrs/tests/voice/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ async fn root_serves_welcome_and_does_not_notify_self_call_when_begun(db: PgPool
assert!(response.status().is_success());
}

#[sqlx::test(fixtures("schema", "settings-no-notify-supervisor"))]
async fn root_serves_welcome_and_does_not_notify_supervisor_with_setting(db: PgPool) {
let response = get(db, "/?Caller=2040000000", false)
.await
.expect("Failed to execute request.");

assert!(response.status().is_success());
}

#[sqlx::test(fixtures("schema", "settings"))]
async fn root_serves_welcome_when_query_param_begin(db: PgPool) {
let response = get(db, "/?begun", false)
Expand Down

0 comments on commit cc65b00

Please sign in to comment.