parent
08646ba971
commit
c9615390f4
@ -3,7 +3,8 @@ use sqlx::PgPool;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
endpoints::IdPath,
|
endpoints::IdPath,
|
||||||
models::{Role, User}, utils::ApplicationError,
|
models::{Role, User},
|
||||||
|
utils::ApplicationError,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[actix_web::delete("/users/{id}")]
|
#[actix_web::delete("/users/{id}")]
|
||||||
@ -20,7 +21,9 @@ pub async fn delete(
|
|||||||
return Ok(HttpResponse::NotFound().finish());
|
return Ok(HttpResponse::NotFound().finish());
|
||||||
};
|
};
|
||||||
|
|
||||||
if user.role == Role::AreaManager && user.area_id != user_in_db.area_id {
|
if user.role == Role::AreaManager
|
||||||
|
&& (user.area_id != user_in_db.area_id || user_in_db.role == Role::Admin)
|
||||||
|
{
|
||||||
return Err(ApplicationError::Unauthorized);
|
return Err(ApplicationError::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,12 @@ pub async fn get_edit(
|
|||||||
return Ok(HttpResponse::NotFound().finish());
|
return Ok(HttpResponse::NotFound().finish());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if user.role == Role::AreaManager
|
||||||
|
&& (user.area_id != user_in_db.area_id || user_in_db.role == Role::Admin)
|
||||||
|
{
|
||||||
|
return Err(ApplicationError::Unauthorized);
|
||||||
|
}
|
||||||
|
|
||||||
let template = NewOrEditUserTemplate {
|
let template = NewOrEditUserTemplate {
|
||||||
user: user.into_inner(),
|
user: user.into_inner(),
|
||||||
id: Some(user_in_db.id),
|
id: Some(user_in_db.id),
|
||||||
|
@ -14,6 +14,7 @@ pub struct UsersTemplate {
|
|||||||
user: User,
|
user: User,
|
||||||
area: Option<Area>,
|
area: Option<Area>,
|
||||||
users: Vec<User>,
|
users: Vec<User>,
|
||||||
|
is_oob: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::get("/users")]
|
#[actix_web::get("/users")]
|
||||||
@ -43,6 +44,7 @@ pub async fn get_overview(
|
|||||||
user: user.into_inner(),
|
user: user.into_inner(),
|
||||||
area,
|
area,
|
||||||
users,
|
users,
|
||||||
|
is_oob: false
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(template.to_response()?)
|
Ok(template.to_response()?)
|
||||||
|
@ -27,7 +27,8 @@ pub async fn post_edit(
|
|||||||
return Ok(HttpResponse::NotFound().finish());
|
return Ok(HttpResponse::NotFound().finish());
|
||||||
};
|
};
|
||||||
|
|
||||||
if user.role == Role::AreaManager && user.area_id != user_in_db.area_id {
|
let role = form.role.try_into()?;
|
||||||
|
if user.role == Role::AreaManager && (user.area_id != user_in_db.area_id || role == Role::Admin) {
|
||||||
return Err(ApplicationError::Unauthorized);
|
return Err(ApplicationError::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ pub async fn post_edit(
|
|||||||
let changeset = UserChangeset {
|
let changeset = UserChangeset {
|
||||||
name: form.name.clone(),
|
name: form.name.clone(),
|
||||||
email: form.email.clone(),
|
email: form.email.clone(),
|
||||||
role: form.role.try_into()?,
|
role,
|
||||||
functions,
|
functions,
|
||||||
area_id,
|
area_id,
|
||||||
};
|
};
|
||||||
|
@ -27,6 +27,10 @@ pub async fn post_new(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let role = Role::try_from(form.role)?;
|
let role = Role::try_from(form.role)?;
|
||||||
|
if role == Role::Admin && user.role != Role::Admin {
|
||||||
|
return Err(ApplicationError::Unauthorized);
|
||||||
|
}
|
||||||
|
|
||||||
let mut functions = Vec::with_capacity(3);
|
let mut functions = Vec::with_capacity(3);
|
||||||
|
|
||||||
if form.is_posten.unwrap_or(false) {
|
if form.is_posten.unwrap_or(false) {
|
||||||
|
@ -24,7 +24,9 @@ pub async fn post(
|
|||||||
return Ok(HttpResponse::NotFound().finish());
|
return Ok(HttpResponse::NotFound().finish());
|
||||||
};
|
};
|
||||||
|
|
||||||
if user.role == Role::AreaManager && user.area_id != user_in_db.area_id {
|
if user.role == Role::AreaManager
|
||||||
|
&& (user.area_id != user_in_db.area_id || user_in_db.role == Role::Admin)
|
||||||
|
{
|
||||||
return Err(ApplicationError::Unauthorized);
|
return Err(ApplicationError::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,9 @@
|
|||||||
<option value="1" {{ role|is_some_and_eq(1|ref)|ref|cond_show("selected") }}>Personal</option>
|
<option value="1" {{ role|is_some_and_eq(1|ref)|ref|cond_show("selected") }}>Personal</option>
|
||||||
<option value="10" {{ role|is_some_and_eq(10|ref)|ref|cond_show("selected") }}>Bereichsleiter
|
<option value="10" {{ role|is_some_and_eq(10|ref)|ref|cond_show("selected") }}>Bereichsleiter
|
||||||
</option>
|
</option>
|
||||||
|
{% if user.role == Role::Admin %}
|
||||||
<option value="100" {{ role|is_some_and_eq(100|ref)|ref|cond_show("selected") }}>Admin</option>
|
<option value="100" {{ role|is_some_and_eq(100|ref)|ref|cond_show("selected") }}>Admin</option>
|
||||||
|
{% endif %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user