Skip to content

Commit

Permalink
Improve initial user authentication and APNS target change cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Apr 30, 2024
1 parent 51ea85b commit 2a01b42
Show file tree
Hide file tree
Showing 30 changed files with 121 additions and 68 deletions.
52 changes: 26 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion subvt-app-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-app-service"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
52 changes: 36 additions & 16 deletions subvt-app-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,23 @@ async fn add_user_notification_channel(
HttpResponse::NotFound().json(ServiceError::from("Notification channel not found."))
);
}
// delete existing channels with the same code
// validate input
if input.target.is_empty() {
return Ok(
HttpResponse::BadRequest().json(ServiceError::from("Invalid notification target."))
);
}
// if channel exists, just return it
let user_notification_channels = state
.postgres
.get_user_notification_channels(auth.id)
.await?;
for channel in user_notification_channels.iter() {
if channel.channel == input.channel && channel.target == input.target {
return Ok(HttpResponse::Ok().json(input));
}
}
// delete existing channels with the same code, possibly for other users
let deleted_channel_count = state
.postgres
.delete_existing_notification_channels_with_code(
Expand All @@ -148,21 +164,6 @@ async fn add_user_notification_channel(
deleted_channel_count,
input.channel.to_string().as_str(),
);
if state
.postgres
.user_notification_channel_target_exists(&input)
.await?
{
return Ok(
HttpResponse::Conflict().json(ServiceError::from("This target exists for the user."))
);
}
// validate input
if input.target.is_empty() {
return Ok(
HttpResponse::BadRequest().json(ServiceError::from("Invalid notification target."))
);
}
input.id = state
.postgres
.save_user_notification_channel(&input)
Expand Down Expand Up @@ -273,6 +274,25 @@ async fn create_default_user_notification_rules(
) -> ResultResponse {
let mut channel_id_set = HashSet::default();
channel_id_set.insert(input.user_notification_channel_id);
if state.postgres.user_has_created_rules(auth.id).await? {
let rules = state.postgres.get_user_notification_rules(auth.id).await?;
log::info!(
"User {} has already created rules. Add notification channel to {} rules if not added already.",
auth.id,
rules.len()
);
for rule in rules.iter() {
state
.postgres
.add_user_notification_channel_to_rule(
input.user_notification_channel_id as i32,
rule.id as i32,
)
.await?;
}
return Ok(HttpResponse::NoContent().finish());
}
log::info!("Create default notification rules for user {}.", auth.id);
for rule in subvt_types::app::notification::rules::DEFAULT_RULES.iter() {
state
.postgres
Expand Down
2 changes: 1 addition & 1 deletion subvt-block-processor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-block-processor"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-config"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-governance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-governance"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-logging/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-logging"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-metrics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-metrics"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-network-status-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-network-status-server"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-network-status-updater/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-network-status-updater"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-nft/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-nft"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-notification-generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-notification-generator"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-notification-processor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-notification-processor"
version = "0.17.30"
version = "0.17.31"
edition = "2021"
rust-version = "1.67.0"

Expand Down
Loading

0 comments on commit 2a01b42

Please sign in to comment.