mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 07:49:27 +00:00
Groups can now have their own virtual directories too.
This commit is contained in:
parent
8e0eba4385
commit
86cdc3d9a8
@ -166,6 +166,20 @@ class GroupsController {
|
||||
Reset_fatal_error(400, "Unrecognized group registration level!");
|
||||
$settings->set_registration_level($levels[$registration_level]);
|
||||
|
||||
//Get and check group virtual directory
|
||||
$virtualDirectory = postString("virtual_directory", 0);
|
||||
if($virtualDirectory != ""){
|
||||
|
||||
$virtualDirectory = getPostVirtualDirectory("virtual_directory");
|
||||
|
||||
//Check virtual directory availability
|
||||
if(!checkVirtualDirectoryAvailability($virtualDirectory, $groupID, TRUE))
|
||||
Rest_fatal_error(401, "The virtual directory seems not to be available!");
|
||||
|
||||
$settings->set_virtual_directory($virtualDirectory);
|
||||
|
||||
}
|
||||
|
||||
//Try to save the new settings of the group
|
||||
if(!components()->groups->set_settings($settings))
|
||||
Rest_fatal_error(500, "An error occured while trying to update group settings!");
|
||||
@ -485,7 +499,7 @@ class GroupsController {
|
||||
*
|
||||
* @url POST /groups/cancel_invitation
|
||||
*/
|
||||
public function canceInvitation() : array {
|
||||
public function cancelInvitation() : array {
|
||||
|
||||
//Get the ID of the target group
|
||||
$groupID = getPostGroupIdWithAccess("groupID", GroupInfo::MODERATOR_ACCESS);
|
||||
@ -571,6 +585,7 @@ class GroupsController {
|
||||
$data["membership"] = self::GROUPS_MEMBERSHIP_LEVELS[$info->get_membership_level()];
|
||||
$data["visibility"] = self::GROUPS_VISIBILITY_LEVELS[$info->get_visibility()];
|
||||
$data["registration_level"] = self::GROUPS_REGISTRATION_LEVELS[$info->get_registration_level()];
|
||||
$data["virtual_directory"] = $info->get_virtual_directory();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class SettingsController {
|
||||
$virtualDirectory = getPostVirtualDirectory("virtualDirectory");
|
||||
|
||||
//Check if the directory is available
|
||||
if(!components()->settings->checkUserDirectoryAvailability($virtualDirectory, userID))
|
||||
if(!checkVirtualDirectoryAvailability($virtualDirectory, userID, FALSE))
|
||||
Rest_fatal_error(401, "The specified directory is not available!");
|
||||
|
||||
}
|
||||
@ -107,7 +107,7 @@ class SettingsController {
|
||||
$userDirectory = getPostVirtualDirectory("directory");
|
||||
|
||||
//Check if the directory is available
|
||||
if(!components()->settings->checkUserDirectoryAvailability($userDirectory, userID))
|
||||
if(!checkVirtualDirectoryAvailability($userDirectory, userID, FALSE))
|
||||
Rest_fatal_error(401, "The specified directory is not available!");
|
||||
|
||||
//Else the directory is available
|
||||
|
@ -111,6 +111,27 @@ class GroupsComponent {
|
||||
return $data[0]["visibility"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a group by its virtual directory
|
||||
*
|
||||
* @param string $directory The directory to search
|
||||
* @return int The ID of the target group / 0 if none found
|
||||
*/
|
||||
public function findByVirtualDirectory(string $directory) : int {
|
||||
|
||||
$data = db()->select(
|
||||
self::GROUPS_LIST_TABLE,
|
||||
"WHERE virtual_directory = ?",
|
||||
array($directory),
|
||||
array("id")
|
||||
);
|
||||
|
||||
if(count($data) == 0)
|
||||
return 0;
|
||||
else
|
||||
return $data[0]["id"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and return information about a group
|
||||
*
|
||||
@ -533,6 +554,25 @@ class GroupsComponent {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a directory is available or not
|
||||
*
|
||||
* @param string $directory The directory to check
|
||||
* @param int $groupID The ID of the target group
|
||||
* @return bool TRUE if the directory is available / FALSE
|
||||
*/
|
||||
public function checkDirectoryAvailability(string $directory, int $groupID) : int {
|
||||
$currID = $this->findByVirtualDirectory($directory);
|
||||
|
||||
//Check if the domain has not been allocated
|
||||
if($currID < 1)
|
||||
return TRUE;
|
||||
|
||||
else
|
||||
//Else check if the directory has been allocated to the current user
|
||||
return $groupID == $currID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a database entry into a GroupInfo object
|
||||
*
|
||||
@ -555,6 +595,9 @@ class GroupsComponent {
|
||||
if($data["path_logo"] != null && $data["path_logo"] != "" && $data["path_logo"] != "null")
|
||||
$info->set_logo($data["path_logo"]);
|
||||
|
||||
if($data["virtual_directory"] != null && $data["virtual_directory"] != "" && $data["virtual_directory"] != "null")
|
||||
$info->set_virtual_directory($data["virtual_directory"]);
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
@ -619,6 +662,9 @@ class GroupsComponent {
|
||||
if($settings->has_registration_level())
|
||||
$data["registration_level"] = $settings->get_registration_level();
|
||||
|
||||
if($settings->has_virtual_directory())
|
||||
$data["virtual_directory"] = $settings->get_virtual_directory();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -566,6 +566,41 @@ function getPostVirtualDirectory(string $name) : string {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check wether a virtual directory is available or not
|
||||
*
|
||||
* @param string $name The virtual directory to check
|
||||
* @param int $id The ID of the target element
|
||||
* @param bool $isPage TRUE if the request is made for a page
|
||||
* @return bool TRUE if the virtual directory is valid / FALSE else
|
||||
*/
|
||||
function checkVirtualDirectoryAvailability(string $name, int $id, bool $isPage) : bool {
|
||||
|
||||
if(!checkVirtualDirectoryValidity($name))
|
||||
return FALSE;
|
||||
|
||||
if(!$isPage){
|
||||
|
||||
if(!components()->settings->checkUserDirectoryAvailability($name, $id))
|
||||
return FALSE;
|
||||
|
||||
if(!components()->groups->checkDirectoryAvailability($name, -1))
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
if(!components()->settings->checkUserDirectoryAvailability($name, -1))
|
||||
return FALSE;
|
||||
|
||||
if(!components()->groups->checkDirectoryAvailability($name, $id))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//The directory seems to be valid
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a POST group ID
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user