Commit 29d47897 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Template jwinf: Optionally require field sex in profile, optionally allow 'no...

Template jwinf: Optionally require field sex in profile, optionally allow 'no answer', 'diverse' or 'other', respectively, configurable via config file
parent f78fd65a
Pipeline #842 passed with stages
in 18 minutes and 42 seconds
...@@ -34,6 +34,10 @@ pub struct Config { ...@@ -34,6 +34,10 @@ pub struct Config {
pub enable_password_login: Option<bool>, pub enable_password_login: Option<bool>,
pub server_message: Option<String>, pub server_message: Option<String>,
pub teacher_page: Option<String>, pub teacher_page: Option<String>,
pub require_sex: Option<bool>,
pub allow_sex_na: Option<bool>,
pub allow_sex_diverse: Option<bool>,
pub allow_sex_other: Option<bool>,
} }
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
......
...@@ -918,8 +918,15 @@ pub fn show_groups_results<T: MedalConnection>(conn: &T, contest_id: i32, sessio ...@@ -918,8 +918,15 @@ pub fn show_groups_results<T: MedalConnection>(conn: &T, contest_id: i32, sessio
Ok(("groupresults".into(), data)) Ok(("groupresults".into(), data))
} }
pub struct SexInformation {
pub require_sex: bool,
pub allow_sex_na: bool,
pub allow_sex_diverse: bool,
pub allow_sex_other: bool,
}
pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: Option<i32>, pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: Option<i32>,
query_string: Option<String>) query_string: Option<String>, sex_infos: SexInformation)
-> MedalValueResult -> MedalValueResult
{ {
let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?; let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
...@@ -927,6 +934,11 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: ...@@ -927,6 +934,11 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id:
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
fill_user_data(&session, &mut data); fill_user_data(&session, &mut data);
data.insert("require_sex".to_string(), to_json(&sex_infos.require_sex));
data.insert("allow_sex_na".to_string(), to_json(&sex_infos.allow_sex_na));
data.insert("allow_sex_diverse".to_string(), to_json(&sex_infos.allow_sex_diverse));
data.insert("allow_sex_other".to_string(), to_json(&sex_infos.allow_sex_other));
match user_id { match user_id {
None => { None => {
data.insert("profile_firstname".to_string(), to_json(&session.firstname)); data.insert("profile_firstname".to_string(), to_json(&session.firstname));
......
...@@ -782,7 +782,17 @@ fn profile<C>(req: &mut Request) -> IronResult<Response> ...@@ -782,7 +782,17 @@ fn profile<C>(req: &mut Request) -> IronResult<Response>
let session_token = req.require_session_token()?; let session_token = req.require_session_token()?;
let query_string = req.url.query().map(|s| s.to_string()); let query_string = req.url.query().map(|s| s.to_string());
let (template, data) = with_conn![core::show_profile, C, req, &session_token, None, query_string].aug(req)?; let si = {
let config = req.get::<Read<SharedConfiguration>>().unwrap();
core::SexInformation {
require_sex: config.require_sex.unwrap_or(false),
allow_sex_na: config.allow_sex_na.unwrap_or(true),
allow_sex_diverse: config.allow_sex_diverse.unwrap_or(false),
allow_sex_other: config.allow_sex_other.unwrap_or(true),
}
};
let (template, data) = with_conn![core::show_profile, C, req, &session_token, None, query_string, si].aug(req)?;
let mut resp = Response::new(); let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok); resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
...@@ -827,8 +837,18 @@ fn user<C>(req: &mut Request) -> IronResult<Response> ...@@ -827,8 +837,18 @@ fn user<C>(req: &mut Request) -> IronResult<Response>
let session_token = req.expect_session_token()?; let session_token = req.expect_session_token()?;
let query_string = req.url.query().map(|s| s.to_string()); let query_string = req.url.query().map(|s| s.to_string());
let si = {
let config = req.get::<Read<SharedConfiguration>>().unwrap();
core::SexInformation {
require_sex: config.require_sex.unwrap_or(false),
allow_sex_na: config.allow_sex_na.unwrap_or(true),
allow_sex_diverse: config.allow_sex_diverse.unwrap_or(false),
allow_sex_other: config.allow_sex_other.unwrap_or(true),
}
};
let (template, data) = let (template, data) =
with_conn![core::show_profile, C, req, &session_token, Some(user_id), query_string].aug(req)?; with_conn![core::show_profile, C, req, &session_token, Some(user_id), query_string, si].aug(req)?;
let mut resp = Response::new(); let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok); resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......
...@@ -113,13 +113,14 @@ ...@@ -113,13 +113,14 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Geschlecht (optional):</td><td> <td>Geschlecht{{#if allow_sex_na}} (optional){{/if}}:</td><td>
<select name="sex"> <select name="sex" {{#if require_sex}}required{{/if}}>
<option value="n" {{ sex_None }}></option> <option value=""></option>
<option value="0" {{ sex_0 }}>Keine Angabe</option> {{#if allow_sex_na}}<option value="0" {{ sex_0 }}>Keine Angabe</option>{{/if}}
<option value="2" {{ sex_2 }}>weiblich</option> <option value="2" {{ sex_2 }}>weiblich</option>
<option value="1" {{ sex_1 }}>männlich</option> <option value="1" {{ sex_1 }}>männlich</option>
<option value="4" {{ sex_4 }}>anderes</option> {{#if allow_sex_diverse}}<option value="3" {{ sex_3 }}>divers</option>{{/if}}
{{#if allow_sex_other}}<option value="4" {{ sex_4 }}>anderes</option>{{/if}}
</select> </select>
</td> </td>
</tr> </tr>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment