Added timezone support
This commit is contained in:
parent
e1ed350e91
commit
35e785bdc2
|
@ -248,12 +248,34 @@ version = "0.4.19"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"num-integer",
|
||||
"num-traits 0.2.14",
|
||||
"serde 1.0.125",
|
||||
"time 0.1.43",
|
||||
"winapi 0.3.9",
|
||||
"libc",
|
||||
"num-integer",
|
||||
"num-traits 0.2.14",
|
||||
"serde 1.0.125",
|
||||
"time 0.1.43",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chrono-tz"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"chrono-tz-build",
|
||||
"phf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chrono-tz-build"
|
||||
version = "0.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069"
|
||||
dependencies = [
|
||||
"parse-zoneinfo",
|
||||
"phf",
|
||||
"phf_codegen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -262,7 +284,7 @@ version = "0.2.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801"
|
||||
dependencies = [
|
||||
"generic-array 0.14.4",
|
||||
"generic-array 0.14.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -521,18 +543,19 @@ dependencies = [
|
|||
name = "errms"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"chrono",
|
||||
"config",
|
||||
"diesel",
|
||||
"diesel_geometry",
|
||||
"email-address-parser",
|
||||
"env_logger",
|
||||
"iban_validate",
|
||||
"log",
|
||||
"rand",
|
||||
"rocket",
|
||||
"rocket_dyn_templates",
|
||||
"base64",
|
||||
"chrono",
|
||||
"chrono-tz",
|
||||
"config",
|
||||
"diesel",
|
||||
"diesel_geometry",
|
||||
"email-address-parser",
|
||||
"env_logger",
|
||||
"iban_validate",
|
||||
"log",
|
||||
"rand",
|
||||
"rocket",
|
||||
"rocket_dyn_templates",
|
||||
"rust-argon2",
|
||||
"serde 1.0.125",
|
||||
"serde_derive",
|
||||
|
@ -1281,12 +1304,21 @@ version = "0.8.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"instant",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"winapi 0.3.9",
|
||||
"cfg-if 1.0.0",
|
||||
"instant",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parse-zoneinfo"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41"
|
||||
dependencies = [
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1295,9 +1327,9 @@ version = "0.2.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702"
|
||||
dependencies = [
|
||||
"inlinable_string",
|
||||
"pear_codegen",
|
||||
"yansi",
|
||||
"inlinable_string",
|
||||
"pear_codegen",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1356,9 +1388,48 @@ version = "2.1.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d"
|
||||
dependencies = [
|
||||
"maplit",
|
||||
"pest",
|
||||
"sha-1",
|
||||
"maplit",
|
||||
"pest",
|
||||
"sha-1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_codegen"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_generator"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
"uncased",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1813,9 +1884,15 @@ version = "1.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a86232ab60fa71287d7f2ddae4a7073f6b7aac33631c3015abb556f08c6d0a3e"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.3"
|
||||
|
|
|
@ -17,7 +17,8 @@ diesel = { version = "1.4.6", features = ["postgres", "uuidv07", "chrono", "serd
|
|||
diesel_geometry = "1.4.0"
|
||||
uuid = { version = "0.8.2", features = ["serde", "v4"] }
|
||||
rust-argon2 = "0.8.3"
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
chrono-tz = "0.6"
|
||||
rand = "0.8.3"
|
||||
iban_validate = "4.0.0"
|
||||
base64 = "0.13.0"
|
||||
|
|
|
@ -18,6 +18,7 @@ login_lock_duration = 1800
|
|||
reset_password_token_valid_duration = 3600
|
||||
user_support_email = "support@einsatz.online"
|
||||
new_member_default_role = "member"
|
||||
default_timezone = "Etc/UTC"
|
||||
|
||||
[mail]
|
||||
from = "No Reply <noreply@localhost>"
|
||||
|
|
|
@ -18,6 +18,7 @@ login_lock_duration = 1800
|
|||
reset_password_token_valid_duration = 3600
|
||||
user_support_email = "support@einsatz.online"
|
||||
new_member_default_role = "member"
|
||||
default_timezone = "Europe/Berlin"
|
||||
|
||||
[mail]
|
||||
from = "No Reply <noreply@localhost>"
|
||||
|
|
|
@ -1 +1 @@
|
|||
v0.2-71-g4b9ea4a
|
||||
v0.2-74-gfa2436e
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use diesel::{BoolExpressionMethods, ExpressionMethods, JoinOnDsl, PgTextExpressionMethods, RunQueryDsl, sql_query};
|
||||
use diesel::{BoolExpressionMethods, ExpressionMethods, PgTextExpressionMethods, RunQueryDsl, sql_query};
|
||||
use diesel::dsl::any;
|
||||
use diesel::pg::types::sql_types::Uuid;
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::connector::establish_connection;
|
||||
use crate::database::controller::events::instances::instances::RawEventUnitInstance;
|
||||
use crate::database::controller::events::templates::vehicle_positions::get_eu_vehicle_positions_for_template;
|
||||
use crate::database::model::events::{Event, EventType, EventUnitInstance, EventUnitInstancePosition, EventUnitInstanceVehiclePosition, EventUnitPosition, EventUnitTemplate, EventUnitVehiclePosition};
|
||||
use crate::database::model::events::{Event, EventType, EventUnitInstancePosition, EventUnitInstanceVehiclePosition, EventUnitPosition, EventUnitTemplate, EventUnitVehiclePosition};
|
||||
use crate::diesel::QueryDsl;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::schema::eu_positions_templates;
|
||||
|
||||
pub mod templates;
|
||||
pub mod instances;
|
||||
|
||||
//TODO: migrate to multiple files to improve readability
|
||||
|
||||
|
@ -376,11 +378,11 @@ pub fn update_eu_template(settings: &State<Settings>, template: EventUnitTemplat
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_instance(settings: &State<Settings>, instance: EventUnitInstance) -> Result<EventUnitInstance, diesel::result::Error>{
|
||||
pub fn add_instance(settings: &State<Settings>, instance: RawEventUnitInstance) -> Result<RawEventUnitInstance, diesel::result::Error> {
|
||||
use crate::schema::eu_instances::dsl::*;
|
||||
|
||||
let connection = establish_connection(settings);
|
||||
match diesel::insert_into(eu_instances).values(instance).get_result(&connection){
|
||||
match diesel::insert_into(eu_instances).values(instance).get_result(&connection) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(e) => {
|
||||
error!("Couldn't create event unit instance: {}", e);
|
||||
|
@ -423,19 +425,6 @@ pub fn add_position_instances_for_instance(settings: &State<Settings>, instance_
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_instances(settings: &State<Settings>, event: uuid::Uuid) -> Result<Vec<EventUnitInstance>, diesel::result::Error>{
|
||||
use crate::schema::eu_instances::dsl::*;
|
||||
|
||||
let connection = establish_connection(settings);
|
||||
match eu_instances.filter(event_id.eq(event)).get_results(&connection){
|
||||
Ok(instances) => Ok(instances),
|
||||
Err(e) => {
|
||||
error!("Couldn't get event unit instances: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_instance_positions(settings: &State<Settings>, instance_id2: uuid::Uuid) -> Result<Vec<EventUnitInstancePosition>, diesel::result::Error>{
|
||||
|
||||
let connection = establish_connection(settings);
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
use chrono::Utc;
|
||||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::connector::establish_connection;
|
||||
use crate::schema::eu_instances;
|
||||
use crate::Settings;
|
||||
|
||||
#[derive(Queryable, Clone, Deserialize, Serialize, AsChangeset, Insertable)]
|
||||
#[table_name = "eu_instances"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[primary_key(entity_id)]
|
||||
pub struct RawEventUnitInstance {
|
||||
pub(crate) instance_id: uuid::Uuid,
|
||||
pub(crate) template_id: uuid::Uuid,
|
||||
pub(crate) name: String,
|
||||
pub(crate) event_id: uuid::Uuid,
|
||||
pub(crate) planned_start_time: Option<chrono::DateTime<Utc>>,
|
||||
pub(crate) planned_end_time: Option<chrono::DateTime<Utc>>,
|
||||
pub(crate) real_start_time: Option<chrono::DateTime<Utc>>,
|
||||
pub(crate) real_end_time: Option<chrono::DateTime<Utc>>,
|
||||
pub(crate) billing_rate_id: Option<uuid::Uuid>,
|
||||
pub(crate) billing_state_id: Option<String>,
|
||||
}
|
||||
|
||||
pub fn get_instances(settings: &State<Settings>, event: uuid::Uuid) -> Result<Vec<RawEventUnitInstance>, diesel::result::Error> {
|
||||
use crate::schema::eu_instances::dsl::*;
|
||||
|
||||
let connection = establish_connection(settings);
|
||||
match eu_instances.filter(event_id.eq(event)).get_results(&connection) {
|
||||
Ok(instances) => Ok(instances),
|
||||
Err(e) => {
|
||||
error!("Couldn't get event unit instances: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
pub mod instance_positions;
|
||||
pub mod instances;
|
|
@ -1,14 +1,15 @@
|
|||
use diesel::ExpressionMethods;
|
||||
use diesel::result::Error;
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::connector::establish_connection;
|
||||
use crate::database::model::users::User;
|
||||
use crate::diesel::prelude::*;
|
||||
use crate::diesel::QueryDsl;
|
||||
use crate::helper::settings::Settings;
|
||||
use diesel::ExpressionMethods;
|
||||
use rocket::State;
|
||||
use crate::schema::members::columns::entity_id;
|
||||
use diesel::result::Error;
|
||||
use crate::schema::users::dsl::users;
|
||||
use crate::schema::members::dsl::members;
|
||||
use crate::schema::users::dsl::users;
|
||||
|
||||
pub fn get_user_by_email(email: String, settings: &State<Settings>) -> Option<User> {
|
||||
use crate::schema::users::dsl::email as email1;
|
||||
|
@ -42,7 +43,7 @@ pub fn get_user_by_member(settings: &State<Settings>, member_uuid: uuid::Uuid) -
|
|||
|
||||
let connection = establish_connection(settings);
|
||||
|
||||
let user : Result<User, diesel::result::Error> = members.inner_join(crate::schema::users::table).filter(entity_id.eq(member_uuid)).select((id, password, email, username)).first(&connection);
|
||||
let user: Result<User, diesel::result::Error> = members.inner_join(crate::schema::users::table).filter(entity_id.eq(member_uuid)).select((id, password, email, username, timezone)).first(&connection);
|
||||
match user{
|
||||
Ok(user) => Ok(Some(user)),
|
||||
Err(e) => {
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use crate::schema::events;
|
||||
use crate::schema::event_types;
|
||||
use diesel::sql_types::{Jsonb, Nullable, SmallInt, Text, Timestamp, Uuid};
|
||||
|
||||
use crate::schema::eu_instances;
|
||||
use crate::schema::eu_positions;
|
||||
use crate::schema::eu_templates;
|
||||
use crate::schema::eu_instances;
|
||||
use crate::schema::eu_vehicle_positions;
|
||||
use diesel::sql_types::{Uuid, Text, Nullable, Jsonb, Timestamp, SmallInt};
|
||||
use crate::schema::event_types;
|
||||
use crate::schema::events;
|
||||
|
||||
#[derive(Queryable, Clone, Deserialize, Serialize, AsChangeset, Insertable, QueryableByName)]
|
||||
#[table_name = "events"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[primary_key(entity_id)]
|
||||
pub struct Event{
|
||||
pub struct Event {
|
||||
#[sql_type = "Uuid"]
|
||||
pub(crate) entity_id: uuid::Uuid,
|
||||
#[sql_type = "Text"]
|
||||
|
@ -80,7 +81,8 @@ pub struct EventUnitTemplate{
|
|||
#[table_name = "eu_instances"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[primary_key(entity_id)]
|
||||
pub struct EventUnitInstance{
|
||||
#[deprecated]
|
||||
pub struct EventUnitInstanceDeprecated {
|
||||
pub(crate) instance_id: uuid::Uuid,
|
||||
pub(crate) template_id: uuid::Uuid,
|
||||
pub(crate) name: String,
|
||||
|
|
|
@ -4,4 +4,5 @@ pub struct User {
|
|||
pub(crate) password: Option<String>,
|
||||
pub(crate) email: String,
|
||||
pub(crate) username: Option<String>,
|
||||
pub(crate) timezone: Option<String>,
|
||||
}
|
||||
|
|
|
@ -14,4 +14,5 @@ pub mod user_request_guard;
|
|||
pub mod mail_queue;
|
||||
pub mod mail_templates;
|
||||
pub mod permission;
|
||||
pub mod order_enum;
|
||||
pub mod order_enum;
|
||||
pub mod time;
|
|
@ -1,15 +1,17 @@
|
|||
use core::fmt;
|
||||
use std::{error, iter};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::RwLock;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use rand::{Rng, thread_rng};
|
||||
use rand::distributions::Alphanumeric;
|
||||
|
||||
use crate::database::model::users::User;
|
||||
use crate::helper::session_cookies::model::{
|
||||
SessionCookie, SessionCookieError, SessionCookieStorage,
|
||||
};
|
||||
use crate::modules::member_management::model::member::Member;
|
||||
use chrono::{DateTime, Utc};
|
||||
use core::fmt;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::collections::HashMap;
|
||||
use std::{error, iter};
|
||||
use std::sync::RwLock;
|
||||
|
||||
impl SessionCookieStorage {
|
||||
/// Generates random alphanumerical id
|
||||
|
@ -122,10 +124,11 @@ impl error::Error for SessionCookieError {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use chrono::NaiveDate;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
pub fn test_add() {
|
||||
let storage = SessionCookieStorage::new();
|
||||
|
@ -136,7 +139,8 @@ mod tests {
|
|||
id: uuid,
|
||||
password: None,
|
||||
email: "test@test.de".to_string(),
|
||||
username: None
|
||||
username: None,
|
||||
timezone: None,
|
||||
};
|
||||
|
||||
let inserted_cookie = storage.add(
|
||||
|
@ -162,7 +166,8 @@ mod tests {
|
|||
id: uuid,
|
||||
password: None,
|
||||
email: "test@test.de".to_string(),
|
||||
username: None
|
||||
username: None,
|
||||
timezone: None,
|
||||
};
|
||||
|
||||
let inserted_cookie = storage.add(
|
||||
|
@ -189,7 +194,8 @@ mod tests {
|
|||
id: uuid,
|
||||
password: None,
|
||||
email: "test@test.de".to_string(),
|
||||
username: None
|
||||
username: None,
|
||||
timezone: None,
|
||||
};
|
||||
|
||||
let inserted_cookie = storage.add(
|
||||
|
@ -213,7 +219,8 @@ mod tests {
|
|||
id: uuid,
|
||||
password: None,
|
||||
email: "test@test.de".to_string(),
|
||||
username: None
|
||||
username: None,
|
||||
timezone: None,
|
||||
};
|
||||
|
||||
storage.add(
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
use config::{Config, ConfigError, Environment, File};
|
||||
use std::env;
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
use config::{Config, ConfigError, Environment, File};
|
||||
|
||||
#[derive(Debug, Deserialize, Default, Clone)]
|
||||
pub struct Database {
|
||||
pub connection_string: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
#[derive(Debug, Deserialize, Default, Clone)]
|
||||
pub struct Application {
|
||||
pub url: String,
|
||||
pub default_language: String,
|
||||
|
@ -20,26 +21,33 @@ pub struct Application {
|
|||
pub reset_password_token_valid_duration: i64,
|
||||
pub user_support_email: String,
|
||||
pub new_member_default_role: String,
|
||||
pub default_timezone: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
#[derive(Debug, Deserialize, Default, Clone)]
|
||||
pub struct Mail{
|
||||
pub from : String,
|
||||
pub reply_to : String,
|
||||
pub from: String,
|
||||
pub reply_to: String,
|
||||
pub communication_email_type_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
pub struct Api{
|
||||
#[derive(Debug, Deserialize, Default, Clone)]
|
||||
pub struct Api {
|
||||
pub default_pagination_limit: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
#[derive(Debug, Deserialize, Default, Clone)]
|
||||
pub struct Billing {
|
||||
pub member_responsible_overwrites_permissions: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default, Clone)]
|
||||
pub struct Settings {
|
||||
pub database: Database,
|
||||
pub application: Application,
|
||||
pub mail: Mail,
|
||||
pub api: Api,
|
||||
pub billing: Billing,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
use chrono::{DateTime, NaiveDateTime, ParseError, TimeZone, Utc};
|
||||
use chrono_tz::Tz;
|
||||
use rocket::State;
|
||||
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::Settings;
|
||||
|
||||
pub fn get_timezone(settings: &State<Settings>, cookie: &SessionCookie) -> Tz {
|
||||
let default_tz: Tz = match settings.application.default_timezone.parse() {
|
||||
Ok(tz) => tz,
|
||||
Err(e) => {
|
||||
panic!("Invalid configuration! Couldn't parse default_timezone: {}", e);
|
||||
}
|
||||
};
|
||||
match cookie.user.timezone.clone() {
|
||||
Some(tz) => match tz.parse() {
|
||||
Ok(tz) => tz,
|
||||
Err(e) => {
|
||||
warn!("Unparsable timezone for user: {}, falling back to default timezone. Error is {}", cookie.user.id, e);
|
||||
default_tz
|
||||
}
|
||||
},
|
||||
None => default_tz
|
||||
}
|
||||
}
|
||||
|
||||
pub fn datetime_str_to_utc(settings: &State<Settings>, cookie: &SessionCookie, user_datetime: &str) -> Result<DateTime<Utc>, ParseError> {
|
||||
let tz = get_timezone(settings, cookie);
|
||||
|
||||
let naive = NaiveDateTime::parse_from_str(user_datetime, "%Y-%m-%dT%H:%M")?;
|
||||
let local_datetime = tz.from_local_datetime(&naive).unwrap();
|
||||
Ok(local_datetime.with_timezone(&Utc))
|
||||
}
|
||||
|
||||
pub fn utc_to_local_user_time(settings: &State<Settings>, cookie: &SessionCookie, utc: DateTime<Utc>) -> String {
|
||||
let tz = get_timezone(settings, cookie);
|
||||
let local_time = utc.with_timezone(&tz);
|
||||
local_time.format("%Y-%m-%dT%H:%M").to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::{DateTime, Local, TimeZone, Utc};
|
||||
use rocket::{Build, Rocket};
|
||||
|
||||
use crate::database::model::users::User;
|
||||
use crate::helper::settings::Application;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn get_test_settings() -> Settings {
|
||||
Settings {
|
||||
database: Default::default(),
|
||||
application: Application {
|
||||
url: "".to_string(),
|
||||
default_language: "".to_string(),
|
||||
fallback_language: "".to_string(),
|
||||
loglevel: "".to_string(),
|
||||
session_timeout: 0,
|
||||
upload_path: "".to_string(),
|
||||
max_login_attempts: 0,
|
||||
login_lock_duration: 0,
|
||||
name: "".to_string(),
|
||||
reset_password_token_valid_duration: 0,
|
||||
user_support_email: "".to_string(),
|
||||
new_member_default_role: "".to_string(),
|
||||
default_timezone: "Europe/Berlin".to_string(),
|
||||
},
|
||||
mail: Default::default(),
|
||||
api: Default::default(),
|
||||
billing: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_test_cookies() -> SessionCookie {
|
||||
SessionCookie {
|
||||
id: "".to_string(),
|
||||
expires: Utc::now(),
|
||||
user: User {
|
||||
id: Default::default(),
|
||||
password: None,
|
||||
email: "".to_string(),
|
||||
username: None,
|
||||
timezone: None,
|
||||
},
|
||||
member: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_utc_to_local_user_time() {
|
||||
let utcdate: DateTime<Utc> = Utc.ymd(2022, 1, 23).and_hms(12, 0, 0);
|
||||
|
||||
let rocket = rocket::build().manage(get_test_settings());
|
||||
let res = utc_to_local_user_time(State::get(&rocket).unwrap(), &get_test_cookies(), utcdate);
|
||||
|
||||
assert_eq!(res, "2022-01-23T13:00");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_datetime_str_to_utc_error() {
|
||||
let rocket = rocket::build().manage(get_test_settings());
|
||||
assert!(datetime_str_to_utc(State::get(&rocket).unwrap(), &get_test_cookies(), "2022-01-23").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_datetime_str_to_utc_error2() {
|
||||
let rocket = rocket::build().manage(get_test_settings());
|
||||
assert!(datetime_str_to_utc(State::get(&rocket).unwrap(), &get_test_cookies(), "2022-01-23T").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_datetime_str_to_utc_error3() {
|
||||
let rocket = rocket::build().manage(get_test_settings());
|
||||
assert!(datetime_str_to_utc(State::get(&rocket).unwrap(), &get_test_cookies(), "2022-01-23T15:00:00").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_datetime_str_to_utc_error4() {
|
||||
let rocket = rocket::build().manage(get_test_settings());
|
||||
assert!(datetime_str_to_utc(State::get(&rocket).unwrap(), &get_test_cookies(), "2022-01-23T15").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_datetime_str_to_utc_error5() {
|
||||
let rocket = rocket::build().manage(get_test_settings());
|
||||
assert!(datetime_str_to_utc(State::get(&rocket).unwrap(), &get_test_cookies(), "Black Mamba").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_datetime_str_to_utc_correct() {
|
||||
let rocket = rocket::build().manage(get_test_settings());
|
||||
let utcdate: DateTime<Utc> = Utc.ymd(2022, 1, 23).and_hms(12, 0, 0);
|
||||
assert_eq!(datetime_str_to_utc(State::get(&rocket).unwrap(), &get_test_cookies(), "2022-01-23T13:00").unwrap(), utcdate);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_timezone() {
|
||||
let utcdate: DateTime<Utc> = Utc.ymd(2022, 1, 23).and_hms(12, 0, 0);
|
||||
let tz: Tz = "Europe/Berlin".parse().unwrap();
|
||||
let localdate1 = utcdate.with_timezone(&tz);
|
||||
|
||||
let localdate2: DateTime<Local> = Local.ymd(2022, 1, 23).and_hms(13, 0, 0);
|
||||
|
||||
print!("{}:{}", localdate1.to_string(), localdate2.to_string());
|
||||
assert_eq!(localdate1, localdate2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_timezone_to_utc() {
|
||||
let tz: Tz = "Europe/Berlin".parse().unwrap();
|
||||
let naive = NaiveDateTime::parse_from_str("2022-01-23T13:00", "%Y-%m-%dT%H:%M").unwrap();
|
||||
let local_datetime = tz.from_local_datetime(&naive).unwrap();
|
||||
let converted_to_utc: DateTime<Utc> = local_datetime.with_timezone(&Utc);
|
||||
let native_utc: DateTime<Utc> = Utc.ymd(2022, 1, 23).and_hms(12, 0, 0);
|
||||
|
||||
print!("{}:{}", converted_to_utc.to_string(), native_utc.to_string());
|
||||
assert_eq!(converted_to_utc, native_utc);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
extern crate argon2;
|
||||
extern crate base64;
|
||||
extern crate chrono;
|
||||
extern crate chrono_tz;
|
||||
extern crate config;
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use rocket::State;
|
||||
use crate::helper::settings::Settings;
|
||||
|
||||
use rocket::http::Status;
|
||||
use crate::helper::sitebuilder::model::sidebar::Sidebar;
|
||||
use crate::helper::sitebuilder::model::general::{Header, Stylesheet, Footer, Script};
|
||||
use rocket::State;
|
||||
use rocket_dyn_templates::Template;
|
||||
use crate::database::model::roles::Role;
|
||||
|
||||
use crate::database::controller::roles::get_roles;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::sitebuilder::model::general::{Footer, Header, Script, Stylesheet};
|
||||
use crate::helper::sitebuilder::model::sidebar::Sidebar;
|
||||
use crate::modules::admin_settings::permissions::SettingsModule;
|
||||
|
||||
#[get("/portal/settings/roles")]
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use diesel::result::Error;
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn put_position_in_template(
|
|||
|
||||
let data = put_position_in_template_data.into_inner();
|
||||
|
||||
if (data.template_id != template_id || data.position_entity_id != position_id) {
|
||||
if data.template_id != template_id || data.position_entity_id != position_id {
|
||||
return Err(Json(
|
||||
ApiError::new(400, "template_id or position_entity_id in URI doesn't match POST data!".to_string()).to_wrapper(),
|
||||
));
|
||||
|
|
|
@ -3,7 +3,7 @@ use rocket::State;
|
|||
|
||||
use crate::database::controller::events::{EventUnitTemplatePosition, get_event_unit_positions_for_template, get_event_unit_templates, get_event_unit_templates_count};
|
||||
use crate::database::controller::events::templates::vehicle_positions::get_eu_vehicle_positions_for_template;
|
||||
use crate::database::model::events::{EventUnitPosition, EventUnitTemplate, EventUnitVehiclePosition};
|
||||
use crate::database::model::events::{EventUnitTemplate, EventUnitVehiclePosition};
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
|
|
|
@ -1,20 +1,27 @@
|
|||
use rocket::State;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use chrono::{DateTime, FixedOffset, NaiveDateTime};
|
||||
use chrono_tz::Tz;
|
||||
use diesel::result::Error;
|
||||
use rocket::serde::json::Json;
|
||||
use crate::database::model::events::EventUnitInstance;
|
||||
use crate::modules::api::model::api_outcome::{ApiErrorWrapper, ApiError};
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::entities::generate_entity;
|
||||
use crate::database::controller::events::{add_instance, add_position_instances_for_instance};
|
||||
use crate::database::controller::events::instances::instances::RawEventUnitInstance;
|
||||
use crate::database::model::events::EventUnitInstanceDeprecated;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::time::datetime_str_to_utc;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use diesel::result::Error;
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use crate::modules::api::model::api_outcome::{ApiError, ApiErrorWrapper};
|
||||
|
||||
#[derive(Queryable, Clone, Deserialize, Serialize)]
|
||||
pub struct CreateInstanceData{
|
||||
pub struct CreateInstanceData {
|
||||
pub template_id: String,
|
||||
pub name: String,
|
||||
pub event_id: String,
|
||||
pub planned_start_time: Option<String>,
|
||||
pub planned_end_time: Option<String>,
|
||||
}
|
||||
|
||||
#[post("/api/events/<event_id>/instances", format = "json", data = "<create_instance_data>")]
|
||||
|
@ -23,8 +30,8 @@ pub fn create_instance(
|
|||
cookie: SessionCookie,
|
||||
create_instance_data: Json<CreateInstanceData>,
|
||||
event_id: String,
|
||||
) -> Result<Json<EventUnitInstance>, Json<ApiErrorWrapper>> {
|
||||
let caller = parse_member_cookie(cookie.member)?;
|
||||
) -> Result<Json<RawEventUnitInstance>, Json<ApiErrorWrapper>> {
|
||||
let caller = parse_member_cookie(cookie.member.clone())?;
|
||||
if !caller.has_permission(crate::permissions::modules::event_management::events::EDIT.to_string()) {
|
||||
return Err(Json(
|
||||
ApiError::new(403, "Keine Berechtigung Einsätze zu bearbeiten!".to_string()).to_wrapper(),
|
||||
|
@ -32,21 +39,55 @@ pub fn create_instance(
|
|||
}
|
||||
let cid = create_instance_data.into_inner();
|
||||
|
||||
if event_id != cid.event_id{
|
||||
if event_id != cid.event_id {
|
||||
return Err(Json(
|
||||
ApiError::new(400, "Two different event_ids in body and parameter!".to_string()).to_wrapper(),
|
||||
))
|
||||
}
|
||||
let entity_id = match generate_entity(settings){
|
||||
let entity_id = match generate_entity(settings) {
|
||||
Ok(entity) => entity,
|
||||
Err(_e) => return Err(Json(ApiError::new(500, "Konnte keine neue Entität anlegen.".to_string()).to_wrapper())),
|
||||
};
|
||||
|
||||
let instance = EventUnitInstance{
|
||||
|
||||
let planned_start_time = match cid.planned_start_time {
|
||||
Some(dt) => match datetime_str_to_utc(settings, &cookie, &dt) {
|
||||
Ok(dt) => Some(dt),
|
||||
Err(e) => {
|
||||
warn!("Couldn't parse planned start time as DateTime: {}",e);
|
||||
return Err(Json(
|
||||
ApiError::new(400, "Couldn't parse planned start time!".to_string()).to_wrapper(),
|
||||
))
|
||||
}
|
||||
},
|
||||
None => None
|
||||
};
|
||||
|
||||
let planned_end_time = match cid.planned_end_time {
|
||||
Some(dt) => match datetime_str_to_utc(settings, &cookie, &dt) {
|
||||
Ok(dt) => Some(dt),
|
||||
Err(e) => {
|
||||
warn!("Couldn't parse planned end time as DateTime: {}",e);
|
||||
return Err(Json(
|
||||
ApiError::new(400, "Couldn't parse planned end time!".to_string()).to_wrapper(),
|
||||
))
|
||||
}
|
||||
},
|
||||
None => None
|
||||
};
|
||||
|
||||
|
||||
let instance = RawEventUnitInstance {
|
||||
instance_id: entity_id,
|
||||
template_id: parse_uuid_string(cid.template_id)?,
|
||||
name: cid.name,
|
||||
event_id: parse_uuid_string(event_id)?
|
||||
event_id: parse_uuid_string(event_id)?,
|
||||
planned_start_time,
|
||||
planned_end_time,
|
||||
real_start_time: None,
|
||||
real_end_time: None,
|
||||
billing_rate_id: None,
|
||||
billing_state_id: None,
|
||||
};
|
||||
|
||||
match add_position_instances_for_instance(settings, instance.instance_id, instance.template_id){
|
||||
|
|
|
@ -1,12 +1,65 @@
|
|||
use crate::helper::settings::Settings;
|
||||
use rocket::State;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::database::model::events::{EventUnitInstance, EventUnitInstancePosition, EventUnitInstanceVehiclePosition};
|
||||
use rocket::serde::json::Json;
|
||||
use crate::modules::api::model::api_outcome::{ApiErrorWrapper, ApiError};
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use crate::database::controller::events::{get_instances, get_instance_positions, get_instance_vehicle_positions};
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::events::{get_instance_positions, get_instance_vehicle_positions};
|
||||
use crate::database::controller::events::instances::instances::{get_instances, RawEventUnitInstance};
|
||||
use crate::database::model::events::{EventUnitInstanceDeprecated, EventUnitInstancePosition, EventUnitInstanceVehiclePosition};
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::time::utc_to_local_user_time;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use crate::modules::api::model::api_outcome::{ApiError, ApiErrorWrapper};
|
||||
|
||||
/// This struct contains RawEventUnitInstance data but converts all UTC DateTimes to local time
|
||||
#[derive(Queryable, Clone, Deserialize, Serialize, )]
|
||||
pub struct EventUnitInstance {
|
||||
pub instance_id: uuid::Uuid,
|
||||
pub template_id: uuid::Uuid,
|
||||
pub name: String,
|
||||
pub event_id: uuid::Uuid,
|
||||
pub planned_start_time: Option<String>,
|
||||
pub planned_end_time: Option<String>,
|
||||
pub real_start_time: Option<String>,
|
||||
pub real_end_time: Option<String>,
|
||||
pub billing_rate_id: Option<uuid::Uuid>,
|
||||
pub billing_state_id: Option<String>,
|
||||
}
|
||||
|
||||
impl EventUnitInstance {
|
||||
/// Convert RawEventUnitInstance to EventUnitInstance by converting Utc DateTimes to timestamps with user specified timezone
|
||||
pub fn from_raw(raw: RawEventUnitInstance, settings: &State<Settings>, cookie: &SessionCookie) -> EventUnitInstance {
|
||||
let planned_start_time = match raw.planned_start_time {
|
||||
Some(dt) => Some(utc_to_local_user_time(settings, cookie, dt)),
|
||||
None => None
|
||||
};
|
||||
let planned_end_time = match raw.planned_end_time {
|
||||
Some(dt) => Some(utc_to_local_user_time(settings, cookie, dt)),
|
||||
None => None
|
||||
};
|
||||
let real_start_time = match raw.real_start_time {
|
||||
Some(dt) => Some(utc_to_local_user_time(settings, cookie, dt)),
|
||||
None => None
|
||||
};
|
||||
let real_end_time = match raw.real_end_time {
|
||||
Some(dt) => Some(utc_to_local_user_time(settings, cookie, dt)),
|
||||
None => None
|
||||
};
|
||||
|
||||
EventUnitInstance {
|
||||
instance_id: raw.instance_id,
|
||||
template_id: raw.template_id,
|
||||
name: raw.name,
|
||||
event_id: raw.event_id,
|
||||
planned_start_time,
|
||||
planned_end_time,
|
||||
real_start_time,
|
||||
real_end_time,
|
||||
billing_rate_id: raw.billing_rate_id,
|
||||
billing_state_id: raw.billing_state_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/api/events/<event_id>/instances", format = "json", rank = 1)]
|
||||
pub fn read_instances(
|
||||
|
@ -14,17 +67,24 @@ pub fn read_instances(
|
|||
cookie: SessionCookie,
|
||||
event_id: String,
|
||||
) -> Result<Json<Vec<EventUnitInstance>>, Json<ApiErrorWrapper>> {
|
||||
let caller = parse_member_cookie(cookie.member)?;
|
||||
let caller = parse_member_cookie(cookie.member.clone())?;
|
||||
if !caller.has_permission(crate::permissions::modules::event_management::events::VIEW.to_string()) {
|
||||
return Err(Json(
|
||||
ApiError::new(403, "Keine Berechtigung Einsätze abzurufen!".to_string()).to_wrapper(),
|
||||
));
|
||||
}
|
||||
|
||||
match get_instances(settings, parse_uuid_string(event_id)?){
|
||||
Ok(pos) => Ok(Json(pos)),
|
||||
let pos = match get_instances(settings, parse_uuid_string(event_id)?) {
|
||||
Ok(pos) => pos,
|
||||
Err(e) => return Err(translate_diesel(e))
|
||||
};
|
||||
|
||||
let mut res: Vec<EventUnitInstance> = vec![];
|
||||
for instance in pos {
|
||||
res.push(EventUnitInstance::from_raw(instance, &settings, &cookie));
|
||||
}
|
||||
|
||||
Ok(Json(res))
|
||||
}
|
||||
|
||||
#[get("/api/events/instances/<instance_id>/positions", format = "json", rank = 1)]
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
use rocket::State;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use chrono::{Duration, Local, NaiveDateTime};
|
||||
use rocket::serde::json::Json;
|
||||
use crate::modules::api::model::api_outcome::{ApiErrorWrapper, ApiError};
|
||||
use crate::database::model::events::Event;
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string, parse_uuid};
|
||||
use chrono::{NaiveDateTime, Local, Duration};
|
||||
use crate::database::controller::events::{get_events, get_event_count, get_event, get_events_for_member_in_future, get_instances, get_instance_positions};
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use uuid::Uuid;
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::events::{get_event, get_event_count, get_events, get_events_for_member_in_future, get_instance_positions};
|
||||
use crate::database::controller::events::instances::instances::get_instances;
|
||||
use crate::database::model::events::Event;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid, parse_uuid_string};
|
||||
use crate::modules::api::model::api_outcome::{ApiError, ApiErrorWrapper};
|
||||
|
||||
#[derive(Queryable, Clone, Deserialize, Serialize)]
|
||||
pub struct EventList{
|
||||
pub struct EventList {
|
||||
pub(crate) events: Vec<Event>,
|
||||
pub(crate) total_event_count: i64,
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::groups::{get_group, get_group_entity_states, get_raw_groups, GroupEntityState};
|
||||
use crate::database::controller::groups_permissions::get_group_role_permissions;
|
||||
use crate::database::controller::members::check_access_to_resource;
|
||||
|
@ -8,12 +11,8 @@ use crate::helper::settings::Settings;
|
|||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::modules::api::groups::create::GroupRolePermission;
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use crate::modules::api::members::get_member::MemberSearchResult;
|
||||
use crate::modules::api::model::api_outcome::{ApiError, ApiErrorWrapper};
|
||||
|
||||
use rocket::State;
|
||||
use rocket::serde::json::Json;
|
||||
|
||||
#[derive(Serialize, Deserialize, Queryable, Clone)]
|
||||
pub struct CallerGroupPermissions {
|
||||
pub(crate) permission_groups_core_edit: bool,
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
use rocket::State;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::modules::api::model::api_outcome::{ApiErrorWrapper, ApiError};
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use rocket::serde::json::Json;
|
||||
use crate::database::controller::members_groups::{add_member_to_group, add_member_to_state};
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::database::controller::members::check_access_to_resource;
|
||||
use crate::modules::member_management::model::groups::{GroupUpdateData};
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::groups::update_group_core_data;
|
||||
use crate::database::controller::members::check_access_to_resource;
|
||||
use crate::database::controller::members_groups::{add_member_to_group, add_member_to_state};
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use crate::modules::api::model::api_outcome::{ApiError, ApiErrorWrapper};
|
||||
use crate::modules::member_management::model::groups::GroupUpdateData;
|
||||
|
||||
#[put("/api/groups/<group_id>/members/<member_id>", format = "json")]
|
||||
pub fn put_member_in_group(settings: &State<Settings>, cookie: SessionCookie, group_id: String, member_id: String) -> Result<(), Json<ApiErrorWrapper>>{
|
||||
pub fn put_member_in_group(settings: &State<Settings>, cookie: SessionCookie, group_id: String, member_id: String) -> Result<(), Json<ApiErrorWrapper>> {
|
||||
let caller = parse_member_cookie(cookie.member)?;
|
||||
let member_id = parse_uuid_string(member_id)?;
|
||||
let group_id = parse_uuid_string(group_id)?;
|
||||
|
||||
if !check_access_to_resource(settings, caller.entity_id, group_id, crate::permissions::modules::member_management::groups::members::EDIT){
|
||||
if !check_access_to_resource(settings, caller.entity_id, group_id, crate::permissions::modules::member_management::groups::members::EDIT) {
|
||||
return Err(Json(ApiError::new(403, "Keine Berechtigung Gruppenmitglieder zu ändern!".to_string()).to_wrapper()))
|
||||
}
|
||||
|
||||
|
@ -51,9 +52,9 @@ pub fn put_member_in_state(settings: &State<Settings>, cookie: SessionCookie, gr
|
|||
let caller = parse_member_cookie(cookie.member)?;
|
||||
let member_id = parse_uuid_string(member_id)?;
|
||||
let group_id = parse_uuid_string(group_id)?;
|
||||
let state_id = if(state_id == "null"){
|
||||
let state_id = if state_id == "null" {
|
||||
None
|
||||
}else{
|
||||
} else {
|
||||
Some(parse_uuid_string(state_id)?)
|
||||
};
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use rocket::State;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use rocket::serde::json::Json;
|
||||
use crate::modules::api::model::api_outcome::{ApiErrorWrapper, ApiError};
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::members::check_access_to_resource;
|
||||
use crate::database::controller::permissions::{get_permission, get_role_permission_id, get_role_permission_context};
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::database::controller::permissions::{get_role_permission_context, get_role_permission_id};
|
||||
use crate::database::controller::roles::get_roles_for_member;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use crate::modules::api::model::api_outcome::ApiErrorWrapper;
|
||||
|
||||
/// Check if caller has permission
|
||||
///
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
use crate::database::controller::api_members::{get_member_search_result, get_member_search_result_by_name, get_member_list, get_member_list_count, MemberListEntry, MemberListEntryWithPermissions};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
|
||||
use crate::database::controller::api_members::{get_member_list, get_member_list_count, get_member_search_result, get_member_search_result_by_name, MemberListEntryWithPermissions};
|
||||
use crate::database::controller::api_members::MemberListOrder;
|
||||
use crate::database::controller::groups::GroupMembership;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
||||
use crate::modules::api::model::api_outcome::{ApiError, ApiErrorWrapper};
|
||||
use rocket::State;
|
||||
use rocket::serde::json::Json;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::database::controller::api_members::MemberListOrder;
|
||||
use std::convert::TryFrom;
|
||||
use crate::database::controller::groups::GroupMembership;
|
||||
|
||||
#[derive(Serialize, Deserialize, Queryable, Clone)]
|
||||
pub struct MemberSearchResult {
|
||||
|
@ -132,7 +134,7 @@ pub fn api_member_list(
|
|||
let mut groups_res: Vec<uuid::Uuid> = vec![];
|
||||
|
||||
for group in groups{
|
||||
if(group != "") {
|
||||
if group != "" {
|
||||
match uuid::Uuid::parse_str(group) {
|
||||
Ok(uuidres) => {
|
||||
groups_res.push(uuidres);
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
use rocket::serde::json::Json;
|
||||
use rocket::{State, request, Request, Response, response};
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::database::controller::users::get_user_by_username;
|
||||
use crate::database::controller::login_protection::{login_attempts_exceeded, login_attempts_usernames_exceeded, add_login_attempt, add_login_attempt_username};
|
||||
use crate::database::controller::members::get_members_by_user_uuid;
|
||||
use base64::decode;
|
||||
use rocket::{request, Request, Response, response, State};
|
||||
use rocket::http::Status;
|
||||
use rocket::request::{FromRequest, Outcome};
|
||||
use rocket::http::{Status, ContentType, Header};
|
||||
use std::str::{FromStr, Utf8Error};
|
||||
use rocket::http::uncased::Uncased;
|
||||
use std::borrow::Cow;
|
||||
use rocket::response::Responder;
|
||||
use base64::{decode, DecodeError};
|
||||
use rocket::serde::json::Json;
|
||||
|
||||
use crate::database::controller::login_protection::{add_login_attempt_username, login_attempts_usernames_exceeded};
|
||||
use crate::database::controller::members::get_members_by_user_uuid;
|
||||
use crate::database::controller::users::get_user_by_username;
|
||||
use crate::helper::settings::Settings;
|
||||
|
||||
#[derive(Queryable, Clone, Deserialize, Serialize)]
|
||||
pub struct MatrixAuthRequest {
|
||||
|
@ -107,22 +105,25 @@ pub fn matrix_check_credentials(
|
|||
Some(pw) => pw
|
||||
};
|
||||
if argon2::verify_encoded(&password_hash, auth.user.password.as_ref()).unwrap() {
|
||||
let member = match get_members_by_user_uuid(user.id, &settings).first(){
|
||||
match get_members_by_user_uuid(user.id, &settings).first() {
|
||||
Some(member) => {
|
||||
return Json(MatrixAuthResponse {auth: Auth{
|
||||
success: true,
|
||||
mxid: Some(format!("@{}:drk.digital", id)),
|
||||
profile: Some(Profile{
|
||||
display_name: format!("{} {}", member.firstname, member.lastname)
|
||||
})
|
||||
}})
|
||||
return Json(MatrixAuthResponse {
|
||||
auth: Auth {
|
||||
success: true,
|
||||
mxid: Some(format!("@{}:drk.digital", id)),
|
||||
profile: Some(Profile {
|
||||
display_name: format!("{} {}", member.firstname, member.lastname)
|
||||
}),
|
||||
}
|
||||
})
|
||||
},
|
||||
None => return Json(MatrixAuthResponse {auth: Auth {
|
||||
None => return Json(MatrixAuthResponse {
|
||||
auth: Auth {
|
||||
success: false,
|
||||
mxid: None,
|
||||
profile: None
|
||||
}})
|
||||
};
|
||||
}
|
||||
} else {
|
||||
add_login_attempt_username(settings, id);
|
||||
return Json(MatrixAuthResponse {auth: Auth{
|
||||
|
|
|
@ -7,4 +7,5 @@ pub mod resource_management;
|
|||
pub mod welcome;
|
||||
pub mod communicator;
|
||||
pub mod event_management;
|
||||
pub mod print;
|
||||
pub mod print;
|
||||
pub mod event_billing;
|
|
@ -541,6 +541,7 @@ table! {
|
|||
password -> Nullable<Text>,
|
||||
email -> Text,
|
||||
username -> Nullable<Text>,
|
||||
timezone -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue