Skip to content

Commit

Permalink
chore: increase magic link of assign assignment to 1 month
Browse files Browse the repository at this point in the history
  • Loading branch information
cptrodgers committed Aug 15, 2024
1 parent ec36c79 commit edeb8e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 9 additions & 6 deletions graphql_server/src/db/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use uuid::Uuid;

use super::schema::{notification_receivers, notifications};
use crate::db::User;
use crate::helper::generate_document_magic_link;
use crate::helper::{generate_document_magic_link, ONE_MONTH_SECONDS};
use crate::impl_enum_for_db;
use crate::util::get_now_as_secs;
use crate::util::url_util::{format_document_url, format_space_url};
Expand Down Expand Up @@ -187,8 +187,12 @@ Hello there! You've been assigned to a assignment: {assignment_name}. If you hav
}

fn get_url_path(&self, receiver: &User) -> String {
generate_document_magic_link(receiver.id, self.assignment_document_id)
.unwrap_or(format_document_url(self.assignment_document_id))
generate_document_magic_link(
receiver.id,
self.assignment_document_id,
Some(ONE_MONTH_SECONDS),
)
.unwrap_or(format_document_url(self.assignment_document_id))
}
}

Expand Down Expand Up @@ -217,9 +221,8 @@ Attention! A student {student_name} has started their assignment: {assignment_na
)
}

fn get_url_path(&self, receiver: &User) -> String {
generate_document_magic_link(receiver.id, self.submission_document_id)
.unwrap_or(format_document_url(self.submission_document_id))
fn get_url_path(&self, _receiver: &User) -> String {
format_document_url(self.submission_document_id)
}
}

Expand Down
7 changes: 5 additions & 2 deletions graphql_server/src/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,21 @@ pub fn add_space_member(
Ok(new_member)
}

pub const ONE_MONTH_SECONDS: i64 = 2_592_000;

pub fn generate_document_magic_link(
user_id: i32,
document_id: Uuid,
ttl_seconds: Option<i64>,
) -> Result<String, IkigaiError> {
let otp = generate_otp();
Redis::init().set_magic_token(user_id, &otp)?;
Redis::init().set_magic_token(user_id, &otp, ttl_seconds)?;
Ok(format_document_magic_link(document_id, &otp, user_id))
}

pub fn generate_start_space_magic_link(user_id: i32, space_id: i32) -> Result<String, IkigaiError> {
let otp = generate_otp();
Redis::init().set_magic_token(user_id, &otp)?;
Redis::init().set_magic_token(user_id, &otp, Some(600))?;
Ok(format_start_space_magic_link(space_id, &otp, user_id))
}

Expand Down
9 changes: 7 additions & 2 deletions graphql_server/src/service/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ impl Redis {
Ok(())
}

pub fn set_magic_token(&self, user_id: i32, otp: &str) -> RedisResult<()> {
pub fn set_magic_token(
&self,
user_id: i32,
otp: &str,
ttl_seconds: Option<i64>,
) -> RedisResult<()> {
let key = format_magic_token(user_id);
self.set_value(&key, otp, Some(600))?;
self.set_value(&key, otp, ttl_seconds)?;
Ok(())
}

Expand Down

0 comments on commit edeb8e5

Please sign in to comment.