2020-06-01 15:17:18 +00:00
|
|
|
//! # Virtual directory controller
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
|
|
|
|
use crate::data::http_request_handler::HttpRequestHandler;
|
|
|
|
use crate::controllers::routes::RequestResult;
|
2020-06-03 11:28:28 +00:00
|
|
|
use crate::helpers::{user_helper, groups_helper};
|
2020-06-02 11:26:12 +00:00
|
|
|
use crate::api_data::res_find_user_by_virtual_directory::FindUserByVirtualDirectoryAPIResult;
|
2020-06-03 11:28:28 +00:00
|
|
|
use crate::api_data::res_find_virtual_directory::ResultFindVirtualDirectory;
|
2020-06-01 15:17:18 +00:00
|
|
|
|
|
|
|
/// Find a user by its virtual directory
|
|
|
|
pub fn find_user(r: &mut HttpRequestHandler) -> RequestResult {
|
2020-06-02 11:12:54 +00:00
|
|
|
let directory = r.post_virtual_directory("subfolder")?;
|
|
|
|
|
2020-06-02 11:26:12 +00:00
|
|
|
let user = r.ok_or_not_found(
|
|
|
|
user_helper::find_user_by_virtual_directory(&directory),
|
2020-06-02 11:29:10 +00:00
|
|
|
"No user was found with this subfolder!",
|
2020-06-02 11:26:12 +00:00
|
|
|
)?;
|
|
|
|
|
|
|
|
r.set_response(FindUserByVirtualDirectoryAPIResult::new(user.id))
|
2020-06-02 11:29:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Search for user / group with a given virtual directory
|
|
|
|
pub fn find(r: &mut HttpRequestHandler) -> RequestResult {
|
2020-06-03 11:28:28 +00:00
|
|
|
let directory = r.post_virtual_directory("directory")?;
|
|
|
|
|
|
|
|
let user = user_helper::find_user_by_virtual_directory(&directory);
|
|
|
|
let group = groups_helper::find_by_virtual_directory(&directory);
|
|
|
|
|
|
|
|
if user.is_err() && group.is_err() {
|
|
|
|
println!("Find virtual directory errors:\n* User: {}\n* Group: {}",
|
|
|
|
user.unwrap_err(), group.unwrap_err());
|
|
|
|
r.not_found("Specified user / group virtual directory not found !".to_string())
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
r.set_response(ResultFindVirtualDirectory::new(user, group))
|
|
|
|
}
|
2020-06-01 15:17:18 +00:00
|
|
|
}
|