mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-10-30 23:24:42 +00:00 
			
		
		
		
	Save new group settings in the database
This commit is contained in:
		| @@ -102,7 +102,7 @@ pub fn set_settings(r: &mut HttpRequestHandler) -> RequestResult { | ||||
|         url: r.post_url_opt("url", false)?, | ||||
|     }; | ||||
|  | ||||
|     println!("New settings: {:#?}", new_settings); | ||||
|     groups_helper::set_settings(&new_settings)?; | ||||
|  | ||||
|     r.success("complete implementation") | ||||
|     r.success("Group settings have been successfully updated!") | ||||
| } | ||||
| @@ -1,8 +1,9 @@ | ||||
| use core::fmt; | ||||
| use serde::export::Formatter; | ||||
| use std::error; | ||||
| use std::error::Error; | ||||
|  | ||||
| use serde::export::Formatter; | ||||
|  | ||||
| /// Simple rust error | ||||
| /// | ||||
| /// @author Pierre Hubert | ||||
| @@ -10,7 +11,7 @@ use std::error::Error; | ||||
|  | ||||
| /// Simple result type | ||||
| pub type ResultExecError<E> = Result<E, ExecError>; | ||||
| pub type ResultBoxError<E> = Result<E, Box<dyn Error>>; | ||||
| pub type ResultBoxError<E = ()> = Result<E, Box<dyn Error>>; | ||||
|  | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct ExecError(pub String); | ||||
|   | ||||
| @@ -671,6 +671,12 @@ impl UpdateInfo { | ||||
|         self | ||||
|     } | ||||
|  | ||||
|     /// Filter with a group id | ||||
|     pub fn cond_group_id(mut self, name: &str, val: &GroupID) -> UpdateInfo { | ||||
|         self.cond.insert(name.to_string(), Value::UInt(val.id())); | ||||
|         self | ||||
|     } | ||||
|  | ||||
|     /// Filter with an unsigned integer | ||||
|     pub fn cond_u64(mut self, name: &str, val: u64) -> UpdateInfo { | ||||
|         self.cond.insert(name.to_string(), Value::UInt(val)); | ||||
| @@ -727,6 +733,11 @@ impl UpdateInfo { | ||||
|     } | ||||
|  | ||||
|     /// Set a new unsigned number | ||||
|     pub fn set_u32(mut self, name: &str, val: u32) -> UpdateInfo { | ||||
|         self.set.insert(name.to_string(), Value::UInt(val as u64)); | ||||
|         self | ||||
|     } | ||||
|  | ||||
|     pub fn set_u64(mut self, name: &str, val: u64) -> UpdateInfo { | ||||
|         self.set.insert(name.to_string(), Value::UInt(val)); | ||||
|         self | ||||
|   | ||||
| @@ -282,6 +282,24 @@ pub fn check_directory_availability(dir: &str, group_id: Option<GroupID>) -> Res | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// Set new settings to the group, except group logo | ||||
| pub fn set_settings(g: &Group) -> ResultBoxError { | ||||
|     database::UpdateInfo::new(GROUPS_LIST_TABLE) | ||||
|         .cond_group_id("id", &g.id) | ||||
|  | ||||
|         // Updates | ||||
|         .set_str("name", &g.name) | ||||
|         .set_u64("visibility", g.visibility.to_db()) | ||||
|         .set_u32("registration_level", g.registration_level.to_db()) | ||||
|         .set_u32("posts_level", g.posts_creation_level.to_db()) | ||||
|         .set_opt_str("virtual_directory", g.virtual_directory.clone()) | ||||
|         .set_opt_str("description", g.description.clone()) | ||||
|         .set_opt_str("url", g.url.clone()) | ||||
|  | ||||
|  | ||||
|         .exec() | ||||
| } | ||||
|  | ||||
| /// Turn a database entry into a group struct | ||||
| fn db_to_group(row: &database::RowResult) -> ResultBoxError<Group> { | ||||
|     let group_id = row.get_group_id("id")?; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user