Added function to get all roles of members
This commit is contained in:
@@ -2,13 +2,14 @@ use std::collections::HashMap;
|
||||
|
||||
use axum::{
|
||||
extract::{FromRef, State},
|
||||
http::HeaderMap,
|
||||
Json,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::{
|
||||
auth::{AuthError, Permissions},
|
||||
auth::{get_user_from_header, AuthError},
|
||||
database::model::Member as DbMember,
|
||||
model::{
|
||||
member::{Groups, Name, Roles},
|
||||
@@ -20,10 +21,12 @@ use crate::{
|
||||
|
||||
pub async fn migrate_request<'a>(
|
||||
State(state): State<AppState>,
|
||||
permissions: Permissions<'a>,
|
||||
headers: HeaderMap,
|
||||
body: String,
|
||||
) -> Result<Json<MigrationResponse>, crate::Error> {
|
||||
if !permissions.0.contains("root") {
|
||||
let (roles, _user) = get_user_from_header(&state.pool, &headers).await?;
|
||||
|
||||
if !roles.contains(Roles::ADMIN) {
|
||||
return Err(AuthError::NoPermssions.into());
|
||||
}
|
||||
|
||||
@@ -50,13 +53,8 @@ pub async fn migrate_request<'a>(
|
||||
|
||||
pub async fn migrate_confirm<'a>(
|
||||
State(state): State<AppState>,
|
||||
permissions: Permissions<'a>,
|
||||
body: String,
|
||||
) -> Result<(), crate::Error> {
|
||||
if !permissions.0.contains("root") {
|
||||
return Err(AuthError::NoPermssions.into());
|
||||
}
|
||||
|
||||
tracing::info!("Migration is confirmed");
|
||||
|
||||
let count = match body.trim().parse::<u32>() {
|
||||
|
Reference in New Issue
Block a user