Commit c3cf8ad6 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1037 Added flags to OpenSharedFolderAPI in ASDevice, DeviceManager,

ZPushAdmin and WebserviceDevice. Added constant
DeviceManager::FLD_FLAGS_REPLYASUSER. Renamed private method
DeviceManager->getAdditionalSyncFolder() to
getAdditionalSyncFolderObject() for better readability, modified checks
on ASDevice->EditAdditionalFolder() to allow a flag modification
(maintaining the same name), added SyncFolder->Flag as ignored parameter
and populate it when calling
DeviceManager->GetAdditionalUserSyncFolders().

Released under the Affero GNU General Public License (AGPL) version 3.
parent 6c1f546a
......@@ -854,11 +854,12 @@ class ASDevice extends StateObject {
* @param string $folderid the folder id of the additional folder.
* @param string $name the name of the additional folder (has to be unique for all folders on the device).
* @param string $type AS foldertype of SYNC_FOLDER_TYPE_USER_*
* @param int $flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
public function AddAdditionalFolder($store, $folderid, $name, $type) {
public function AddAdditionalFolder($store, $folderid, $name, $type, $flags) {
// check if type is of a additional user type
if (!in_array($type, array(SYNC_FOLDER_TYPE_USER_CONTACT, SYNC_FOLDER_TYPE_USER_APPOINTMENT, SYNC_FOLDER_TYPE_USER_TASK, SYNC_FOLDER_TYPE_USER_MAIL, SYNC_FOLDER_TYPE_USER_NOTE, SYNC_FOLDER_TYPE_USER_JOURNAL))) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->AddAdditionalFolder(): folder can not be added because the specified type '%s' is not a permitted user type.", $type));
......@@ -900,6 +901,7 @@ class ASDevice extends StateObject {
'folderid' => $folderid,
'name' => $name,
'type' => $type,
'flags' => $flags,
);
$this->additionalfolders = $af;
......@@ -914,11 +916,12 @@ class ASDevice extends StateObject {
*
* @param string $folderid the folder id of the additional folder.
* @param string $name the name of the additional folder (has to be unique for all folders on the device).
* @param int $flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
public function EditAdditionalFolder($folderid, $name) {
public function EditAdditionalFolder($folderid, $name, $flags) {
// check if a folder with this ID is known
if (!isset($this->additionalfolders[$folderid])) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be edited because there is no folder known with this folder id: '%s'. Add the folder first.", $folderid));
......@@ -926,9 +929,9 @@ class ASDevice extends StateObject {
}
// check if a folder with the new name is already in the list
foreach ($this->additionalfolders as $k => $folder) {
if ($folder['name'] == $name) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be added because there is already an additional folder with the same name: '%s'", $name));
foreach ($this->additionalfolders as $existingFolderid => $folder) {
if ($folder['name'] == $name && $folderid !== $existingFolderid) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be edited because there is already an additional folder with the same name: '%s'", $name));
return false;
}
}
......@@ -936,8 +939,8 @@ class ASDevice extends StateObject {
// check if a folder with the new name is already known on the device (regular folder)
foreach($this->GetHierarchyCache()->ExportFolders() as $syncedFolderid => $folder) {
// $folder is a SyncFolder object here
if ($folder->displayname == $name) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be added because there is already a folder with the same name synchronized: '%s'", $folderid));
if ($folder->displayname == $name && $folderid !== $folder->BackendId && $folderid !== $syncedFolderid) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be edited because there is already a folder with the same name synchronized: '%s'", $folderid));
return false;
}
}
......@@ -945,6 +948,7 @@ class ASDevice extends StateObject {
// update the name
$af = $this->additionalfolders;
$af[$folderid]['name'] = $name;
$af[$folderid]['flags'] = $flags;
$this->additionalfolders = $af;
return true;
......
......@@ -60,6 +60,8 @@ class DeviceManager {
const FLD_ORIGIN_SHARED = "S";
const FLD_ORIGIN_GAB = "G";
const FLD_FLAGS_REPLYASUSER = 1;
private $device;
private $deviceHash;
private $saveDevice;
......@@ -493,7 +495,7 @@ class DeviceManager {
public function GetAdditionalUserSyncFolders() {
$folders = array();
foreach($this->device->GetAdditionalFolders() as $df) {
$folder = $this->getAdditionalSyncFolder($df['store'], $df['folderid'], $df['name'], $df['type'], DeviceManager::FLD_ORIGIN_SHARED);
$folder = $this->getAdditionalSyncFolderObject($df['store'], $df['folderid'], $df['name'], $df['type'], $df['flags'], DeviceManager::FLD_ORIGIN_SHARED);
$folders[$folder->BackendId] = $folder;
}
......@@ -501,7 +503,7 @@ class DeviceManager {
if (KOE_CAPABILITY_GAB && $this->IsKoe() && KOE_GAB_STORE != "" && KOE_GAB_NAME != "") {
// if KOE_GAB_FOLDERID is set, use it
if (KOE_GAB_FOLDERID != "") {
$folder = $this->getAdditionalSyncFolder(KOE_GAB_STORE, KOE_GAB_FOLDERID, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT, DeviceManager::FLD_ORIGIN_GAB);
$folder = $this->getAdditionalSyncFolderObject(KOE_GAB_STORE, KOE_GAB_FOLDERID, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT, 0, DeviceManager::FLD_ORIGIN_GAB);
$folders[$folder->BackendId] = $folder;
}
else {
......@@ -518,7 +520,7 @@ class DeviceManager {
}
if ($backendGabId) {
$folders[$backendGabId] = $this->getAdditionalSyncFolder(KOE_GAB_STORE, $backendGabId, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT, DeviceManager::FLD_ORIGIN_GAB);
$folders[$backendGabId] = $this->getAdditionalSyncFolderObject(KOE_GAB_STORE, $backendGabId, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT, 0, DeviceManager::FLD_ORIGIN_GAB);
}
}
}
......@@ -1141,12 +1143,13 @@ class DeviceManager {
* @param string $folderid
* @param string $name
* @param int $type
* @param int $flags
* @param string $folderOrigin
*
* @access private
* @returns SyncFolder
*/
private function getAdditionalSyncFolder($store, $folderid, $name, $type, $folderOrigin) {
private function getAdditionalSyncFolderObject($store, $folderid, $name, $type, $flags, $folderOrigin) {
$folder = new SyncFolder();
$folder->BackendId = $folderid;
$folder->serverid = $this->GetFolderIdForBackendId($folder->BackendId, true, $folderOrigin, $name);
......@@ -1156,6 +1159,7 @@ class DeviceManager {
// save store as custom property which is not streamed directly to the device
$folder->NoBackendFolder = true;
$folder->Store = $store;
$folder->Flags = $flags;
return $folder;
}
......
......@@ -326,6 +326,7 @@ define("SYNC_FOLDERHIERARCHY_VERSION","FolderHierarchy:Version");
define("SYNC_FOLDERHIERARCHY_IGNORE_STORE","FolderHierarchy:IgnoreStore");
define("SYNC_FOLDERHIERARCHY_IGNORE_NOBCKENDFLD","FolderHierarchy:IgnoreNoBackendFolder");
define("SYNC_FOLDERHIERARCHY_IGNORE_BACKENDID","FolderHierarchy:IgnoreBackendId");
define("SYNC_FOLDERHIERARCHY_IGNORE_FLAGS","FolderHierarchy:IgnoreFlags");
// MeetingResponse
define("SYNC_MEETINGRESPONSE_CALENDARID","MeetingResponse:CalendarId");
......
......@@ -54,6 +54,7 @@ class SyncFolder extends SyncObject {
public $Store;
public $NoBackendFolder;
public $BackendId;
public $Flags;
function SyncFolder() {
$mapping = array (
......@@ -79,6 +80,10 @@ class SyncFolder extends SyncObject {
SYNC_FOLDERHIERARCHY_IGNORE_BACKENDID => array ( self::STREAMER_VAR => "BackendId",
self::STREAMER_TYPE => self::STREAMER_TYPE_IGNORE),
SYNC_FOLDERHIERARCHY_IGNORE_FLAGS => array ( self::STREAMER_VAR => "Flags",
self::STREAMER_TYPE => self::STREAMER_TYPE_IGNORE),
);
parent::SyncObject($mapping);
......
......@@ -506,6 +506,7 @@ class ZPushAdmin {
'name' => $so->displayname,
'type' => $so->type,
'origin' => Utils::GetFolderOriginFromId($syncfolderid),
'flags' => 0, // static folders have no flags
);
}
}
......@@ -528,11 +529,12 @@ class ZPushAdmin {
* @param string $add_folderid the folder id of the additional folder.
* @param string $add_name the name of the additional folder (has to be unique for all folders on the device).
* @param string $add_type AS foldertype of SYNC_FOLDER_TYPE_USER_*
* @param int $add_flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
static public function AdditionalFolderAdd($user, $devid, $add_store, $add_folderid, $add_name, $add_type) {
static public function AdditionalFolderAdd($user, $devid, $add_store, $add_folderid, $add_name, $add_type, $add_flags) {
// load device data
$device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
try {
......@@ -549,7 +551,7 @@ class ZPushAdmin {
return false;
}
$status = $device->AddAdditionalFolder($add_store, $add_folderid, $add_name, $add_type);
$status = $device->AddAdditionalFolder($add_store, $add_folderid, $add_name, $add_type, $add_flags);
if ($status)
ZPush::GetStateMachine()->SetState($device->GetData(), $devid, IStateMachine::DEVICEDATA);
......@@ -570,11 +572,12 @@ class ZPushAdmin {
* @param string $devid device id of where the folder should be updated.
* @param string $add_folderid the folder id of the additional folder.
* @param string $add_name the name of the additional folder (has to be unique for all folders on the device).
* @param int $add_flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
static public function AdditionalFolderEdit($user, $devid, $add_folderid, $add_name) {
static public function AdditionalFolderEdit($user, $devid, $add_folderid, $add_name, $add_flags) {
// load device data
$device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
try {
......@@ -597,7 +600,7 @@ class ZPushAdmin {
return false;
}
$status = $device->EditAdditionalFolder($add_folderid, $add_name);
$status = $device->EditAdditionalFolder($add_folderid, $add_name, $add_flags);
if ($status)
ZPush::GetStateMachine()->SetState($device->GetData(), $devid, IStateMachine::DEVICEDATA);
......
......@@ -190,17 +190,19 @@ class WebserviceDevice {
* @param string $add_folderid the folder id of the additional folder.
* @param string $add_name the name of the additional folder (has to be unique for all folders on the device).
* @param string $add_type AS foldertype of SYNC_FOLDER_TYPE_USER_*
* @param int $add_flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
public function AdditionalFolderAdd($deviceId, $add_store, $add_folderid, $add_name, $add_type) {
public function AdditionalFolderAdd($deviceId, $add_store, $add_folderid, $add_name, $add_type, $add_flags) {
$user = Request::GetGETUser();
$deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
$add_folderid = preg_replace("/[^A-Za-z0-9]/", "", $add_folderid);
$add_type = preg_replace("/[^0-9]/", "", $add_type);
$add_flags = preg_replace("/[^0-9]/", "", $add_flags);
$status = ZPushAdmin::AdditionalFolderAdd($user, $deviceId, $add_store, $add_folderid, $add_name, $add_type);
$status = ZPushAdmin::AdditionalFolderAdd($user, $deviceId, $add_store, $add_folderid, $add_name, $add_type, $add_flags);
if (!$status) {
ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
......@@ -217,16 +219,18 @@ class WebserviceDevice {
* @param string $deviceId device id of where the folder should be updated.
* @param string $add_folderid the folder id of the additional folder.
* @param string $add_name the name of the additional folder (has to be unique for all folders on the device).
* @param int $add_flags Additional flags, like DeviceManager::FLD_FLAGS_REPLYASUSER
*
* @access public
* @return boolean
*/
public function AdditionalFolderEdit($deviceId, $add_folderid, $add_name) {
public function AdditionalFolderEdit($deviceId, $add_folderid, $add_name, $add_flags) {
$user = Request::GetGETUser();
$deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
$add_folderid = preg_replace("/[^A-Za-z0-9]/", "", $add_folderid);
$add_flags = preg_replace("/[^0-9]/", "", $add_flags);
$status = ZPushAdmin::AdditionalFolderEdit($user, $deviceId, $add_folderid, $add_name);
$status = ZPushAdmin::AdditionalFolderEdit($user, $deviceId, $add_folderid, $add_name, $add_flags);
if (!$status) {
ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment