[Draft] Implement Reviewer Notice Link using Login Redirect #40

Merged
ben merged 5 commits from ben/Jobboerse:notice-link-via-login into main 2023-01-28 18:00:15 +01:00
6 changed files with 21 additions and 8 deletions
Showing only changes of commit fd42f77cff - Show all commits

have reviewer notice link redirect via the login page

# Conflicts:
#	Changelog.md
#	src/route/job_offer/create.rs
Bennet Bleßmann 2022-11-30 21:45:00 +01:00 committed by Bennet Bleßmann
Signed by: ben
GPG key ID: 3BE1A1A3CBC3CF99

View file

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- startup errors are more descriptive
- the confirmation link now works after confirmation so that submissions can be deleted early by the submitter
- this changes the on-disk format slightly as the token now has a different scope and was moved accordingly
- reviewe notice link is now indirect via the login page
### Removed

View file

@ -1,4 +1,5 @@
use crate::job_offers::error::EmailError;
use crate::route::RETURN_TO;
use crate::server_config::EmailConfig;
use crate::template;
use handlebars::Handlebars;
@ -68,13 +69,18 @@ pub(crate) async fn send_confirmation_email(
pub(crate) async fn send_reviewer_notice(
hb: &Handlebars<'_>,
email_config: &EmailConfig,
url: Url,
highlight_url: Url,
mut login_url: Url,
) {
// successfully send a confirmation e-mail now send a notice to our-self
login_url
.query_pairs_mut()
.append_pair(RETURN_TO, highlight_url.as_str());
let body = match hb.render(
template::EMAIL_REVIEWER_NOTICE,
&json!({ "highlight_link": url }),
&json!({ "highlight_link": login_url }),
) {
Ok(body) => body,
Err(err) => {

View file

@ -15,7 +15,7 @@ pub(crate) mod form_constants;
mod job_offer;
mod license;
pub(crate) use auth::{LOGIN_ROUTE, LOGOUT_ROUTE};
pub(crate) use auth::{LOGIN_ROUTE, LOGOUT_ROUTE, RETURN_TO};
pub(crate) use job_offer::{
confirmation::JOBOFFER_CONFIRM_ROUTE,
create::JOBOFFER_CREATION_ROUTE,

View file

@ -24,6 +24,7 @@ pub(crate) fn configure(config: &mut ServiceConfig) {
}
pub(crate) const LOGIN_ROUTE: &str = "login";
pub(crate) const RETURN_TO: &str = "return_to";
#[derive(Serialize, Deserialize)]
pub(crate) struct LoginQuery {

View file

@ -24,6 +24,8 @@ use multipart_helper::MultipartFieldError;
use serde_json::json;
use url::Url;
use super::auth::RETURN_TO;
#[derive(Debug, thiserror::Error)]
#[error("Some error occurred while attempting to display an error page")]
pub struct ErrorHandlerResponseError;
@ -226,7 +228,7 @@ fn login_url_with_return(req: &HttpRequest, return_to: &str) -> Result<Url, UrlG
login_url
.query_pairs_mut()
.append_pair("return_to", return_to);
.append_pair(RETURN_TO, return_to);
Ok(login_url)
}

View file

@ -26,7 +26,7 @@ use crate::job_offers::{
use crate::route::form_constants::{self, UploadLimits};
use crate::route::job_offer::confirmation::JOBOFFER_CONFIRM_ROUTE;
use crate::route::job_offer::error::{FormProcessingError, SubmissionResponseError};
use crate::route::HTML_CONTENT;
use crate::route::{HTML_CONTENT, LOGIN_ROUTE};
use crate::server_config::ServerConfig;
use crate::util::{parse_date, parse_datetime, process_links, process_new_attachments};
use crate::{email, template};
@ -248,9 +248,12 @@ pub(crate) async fn create_job_offer<'data, 'config>(
if let Some(email_config) = &config.config.email {
if !is_pre_approved {
match created_offer.highlight_link(req) {
Ok(highlight_url) => {
email::send_reviewer_notice(hb, email_config, highlight_url).await;
match created_offer
.highlight_link(req)
.and_then(|highlight| Ok((highlight, req.url_for_static(LOGIN_ROUTE)?)))
{
Ok((highlight_url, login_url)) => {
email::send_reviewer_notice(hb, &email_config, highlight_url, login_url).await;
}
Err(err) => {
error!("Failed to generate highlight link: {}", err)