mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can delete a group's logo
This commit is contained in:
parent
8d6dc6365c
commit
539765d01c
@ -25,4 +25,5 @@ pub mod list_unread_conversations_api;
|
|||||||
pub mod global_search_result_api;
|
pub mod global_search_result_api;
|
||||||
pub mod res_create_group;
|
pub mod res_create_group;
|
||||||
pub mod group_api;
|
pub mod group_api;
|
||||||
pub mod advanced_group_api;
|
pub mod advanced_group_api;
|
||||||
|
pub mod res_change_group_logo;
|
22
src/api_data/res_change_group_logo.rs
Normal file
22
src/api_data/res_change_group_logo.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
//! # Change group logo result
|
||||||
|
//!
|
||||||
|
//! @author Pierre Hubert
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::utils::user_data_utils::user_data_url;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct ResChangeGroupLogo {
|
||||||
|
success: String,
|
||||||
|
url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ResChangeGroupLogo {
|
||||||
|
/// Construct a new instance of this structure
|
||||||
|
pub fn new(path: &str) -> ResChangeGroupLogo {
|
||||||
|
ResChangeGroupLogo {
|
||||||
|
success: "Group logo has been successfully updated!".to_string(),
|
||||||
|
url: user_data_url(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,9 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use crate::api_data::advanced_group_api::AdvancedGroupApi;
|
use crate::api_data::advanced_group_api::AdvancedGroupApi;
|
||||||
use crate::api_data::group_api::GroupApi;
|
use crate::api_data::group_api::GroupApi;
|
||||||
|
use crate::api_data::res_change_group_logo::ResChangeGroupLogo;
|
||||||
use crate::api_data::res_create_group::GroupCreationResult;
|
use crate::api_data::res_create_group::GroupCreationResult;
|
||||||
|
use crate::constants::DEFAULT_GROUP_LOGO;
|
||||||
use crate::controllers::routes::RequestResult;
|
use crate::controllers::routes::RequestResult;
|
||||||
use crate::data::group::{Group, GroupAccessLevel, GroupPostsCreationLevel, GroupRegistrationLevel, GroupVisibilityLevel};
|
use crate::data::group::{Group, GroupAccessLevel, GroupPostsCreationLevel, GroupRegistrationLevel, GroupVisibilityLevel};
|
||||||
use crate::data::group_id::GroupID;
|
use crate::data::group_id::GroupID;
|
||||||
@ -121,5 +123,15 @@ pub fn check_virtual_dir(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
|
|
||||||
/// Change a group's logo
|
/// Change a group's logo
|
||||||
pub fn upload_logo(r: &mut HttpRequestHandler) -> RequestResult {
|
pub fn upload_logo(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
|
// TODO : implement this method
|
||||||
r.success("implement me")
|
r.success("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete a group's logo
|
||||||
|
pub fn delete_logo(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
|
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::ADMIN_ACCESS)?;
|
||||||
|
|
||||||
|
groups_helper::delete_logo(&group_id)?;
|
||||||
|
|
||||||
|
r.set_response(ResChangeGroupLogo::new(DEFAULT_GROUP_LOGO))
|
||||||
}
|
}
|
@ -146,6 +146,8 @@ pub fn get_routes() -> Vec<Route> {
|
|||||||
|
|
||||||
Route::post("/groups/upload_logo", Box::new(groups_controller::upload_logo)),
|
Route::post("/groups/upload_logo", Box::new(groups_controller::upload_logo)),
|
||||||
|
|
||||||
|
Route::post("/groups/delete_logo", Box::new(groups_controller::delete_logo)),
|
||||||
|
|
||||||
|
|
||||||
// Virtual directory controller
|
// Virtual directory controller
|
||||||
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
//!
|
//!
|
||||||
//! Group visibility level
|
//! Group visibility level
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::constants::DEFAULT_GROUP_LOGO;
|
use crate::constants::DEFAULT_GROUP_LOGO;
|
||||||
use crate::data::group_id::GroupID;
|
use crate::data::group_id::GroupID;
|
||||||
use crate::utils::user_data_utils::user_data_url;
|
use crate::utils::user_data_utils::{user_data_path, user_data_url};
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Eq, PartialEq, Hash, Debug)]
|
#[derive(Eq, PartialEq, Hash, Debug)]
|
||||||
@ -125,6 +127,11 @@ pub struct Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Group {
|
impl Group {
|
||||||
|
/// Check out whether current group has a logo or not
|
||||||
|
pub fn has_logo(&self) -> bool {
|
||||||
|
self.logo.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
/// Determine the path of the logo to use for this group
|
/// Determine the path of the logo to use for this group
|
||||||
pub fn get_logo_path(&self) -> &str {
|
pub fn get_logo_path(&self) -> &str {
|
||||||
match &self.logo {
|
match &self.logo {
|
||||||
@ -137,6 +144,15 @@ impl Group {
|
|||||||
pub fn get_logo_url(&self) -> String {
|
pub fn get_logo_url(&self) -> String {
|
||||||
user_data_url(self.get_logo_path())
|
user_data_url(self.get_logo_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get file access to the logo
|
||||||
|
pub fn get_logo_sys_path(&self) -> PathBuf {
|
||||||
|
if !self.has_logo() {
|
||||||
|
panic!("This group has no logo!")
|
||||||
|
}
|
||||||
|
|
||||||
|
user_data_path(self.logo.as_ref().unwrap().as_ref())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -300,6 +300,30 @@ pub fn set_settings(g: &Group) -> ResultBoxError {
|
|||||||
.exec()
|
.exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set a new path for a logo
|
||||||
|
pub fn set_logo_path(g: &GroupID, path: Option<String>) -> ResultBoxError {
|
||||||
|
database::UpdateInfo::new(GROUPS_LIST_TABLE)
|
||||||
|
.cond_group_id("id", g)
|
||||||
|
.set_opt_str("path_logo", path)
|
||||||
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete the logo of a group
|
||||||
|
pub fn delete_logo(g: &GroupID) -> ResultBoxError {
|
||||||
|
let group = get_info(g)?;
|
||||||
|
|
||||||
|
if !group.has_logo() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let logo_path = group.get_logo_sys_path();
|
||||||
|
if logo_path.exists() {
|
||||||
|
std::fs::remove_file(logo_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_logo_path(g, None)
|
||||||
|
}
|
||||||
|
|
||||||
/// Turn a database entry into a group struct
|
/// Turn a database entry into a group struct
|
||||||
fn db_to_group(row: &database::RowResult) -> ResultBoxError<Group> {
|
fn db_to_group(row: &database::RowResult) -> ResultBoxError<Group> {
|
||||||
let group_id = row.get_group_id("id")?;
|
let group_id = row.get_group_id("id")?;
|
||||||
|
Loading…
Reference in New Issue
Block a user