mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-11-27 18:10:42 +00:00
new endpoints to change folder name and comment
This commit is contained in:
parent
0ac2b76bb6
commit
6e3330c670
|
|
@ -2591,6 +2591,98 @@ final class SeedDMS_RestapiController { /* {{{ */
|
||||||
}
|
}
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the name of an existing folder
|
||||||
|
*
|
||||||
|
* @param <type> $id The user name or numerical identifier
|
||||||
|
*/
|
||||||
|
function changeFolderName($request, $response, $args) { /* {{{ */
|
||||||
|
$dms = $this->container->get('dms');
|
||||||
|
$userobj = $this->container->get('userobj');
|
||||||
|
|
||||||
|
$check = $this->checkIfAdmin($request, $response);
|
||||||
|
if ($check !== true)
|
||||||
|
return $check;
|
||||||
|
|
||||||
|
if (!ctype_digit($args['id'])) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = $request->getParsedBody();
|
||||||
|
/* Setting an empty name is not allowed */
|
||||||
|
if (empty($params['name'])) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a new name', 'data'=>''))->withStatus(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newname = $params['name'];
|
||||||
|
|
||||||
|
$folder = $dms->getFolder($args['id']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Folder not found
|
||||||
|
*/
|
||||||
|
if (!$folder) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($folder->getAccessMode($userobj, 'setName') < M_READWRITE) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on folder', 'data'=>''))->withStatus(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$folder->setName($newname)) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change name.'))->withStatus(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getFolderData($folder)))->withStatus(200);
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the comment of an existing folder
|
||||||
|
*
|
||||||
|
* @param <type> $id The user name or numerical identifier
|
||||||
|
*/
|
||||||
|
function changeFolderComment($request, $response, $args) { /* {{{ */
|
||||||
|
$dms = $this->container->get('dms');
|
||||||
|
$userobj = $this->container->get('userobj');
|
||||||
|
$logger = $this->container->get('logger');
|
||||||
|
|
||||||
|
$logger->log("Change comment of folder", PEAR_LOG_INFO);
|
||||||
|
$check = $this->checkIfAdmin($request, $response);
|
||||||
|
if ($check !== true)
|
||||||
|
return $check;
|
||||||
|
|
||||||
|
if (!ctype_digit($args['id'])) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = $request->getParsedBody();
|
||||||
|
/* Setting an empty comment is allowed. */
|
||||||
|
if ($params['comment']) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a new name', 'data'=>''))->withStatus(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newcomment = $params['comment'];
|
||||||
|
|
||||||
|
$folder = $dms->getFolder($args['id']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Folder not found
|
||||||
|
*/
|
||||||
|
if (!$folder) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($folder->getAccessMode($userobj, 'setName') < M_READWRITE) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on folder', 'data'=>''))->withStatus(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$folder->setComment($newcomment)) {
|
||||||
|
return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change comment.'))->withStatus(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getFolderData($folder)))->withStatus(200);
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
function addUserAccessToFolder($request, $response, $args) { /* {{{ */
|
function addUserAccessToFolder($request, $response, $args) { /* {{{ */
|
||||||
return $this->changeFolderAccess($request, $response, $args, 'add', 'user');
|
return $this->changeFolderAccess($request, $response, $args, 'add', 'user');
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
@ -3261,6 +3353,8 @@ $app->delete('/groups/{id}', \SeedDMS_RestapiController::class.':deleteGroup');
|
||||||
$app->get('/groups/{id}', \SeedDMS_RestapiController::class.':getGroup');
|
$app->get('/groups/{id}', \SeedDMS_RestapiController::class.':getGroup');
|
||||||
$app->put('/groups/{id}/addUser', \SeedDMS_RestapiController::class.':addUserToGroup');
|
$app->put('/groups/{id}/addUser', \SeedDMS_RestapiController::class.':addUserToGroup');
|
||||||
$app->put('/groups/{id}/removeUser', \SeedDMS_RestapiController::class.':removeUserFromGroup');
|
$app->put('/groups/{id}/removeUser', \SeedDMS_RestapiController::class.':removeUserFromGroup');
|
||||||
|
$app->put('/folder/{id}/name', \SeedDMS_RestapiController::class.':changeFolderName');
|
||||||
|
$app->put('/folder/{id}/comment', \SeedDMS_RestapiController::class.':changeFolderComment');
|
||||||
$app->put('/folder/{id}/setInherit', \SeedDMS_RestapiController::class.':setFolderInheritsAccess');
|
$app->put('/folder/{id}/setInherit', \SeedDMS_RestapiController::class.':setFolderInheritsAccess');
|
||||||
$app->put('/folder/{id}/owner/{userid}', \SeedDMS_RestapiController::class.':setFolderOwner');
|
$app->put('/folder/{id}/owner/{userid}', \SeedDMS_RestapiController::class.':setFolderOwner');
|
||||||
$app->put('/folder/{id}/access/group/add', \SeedDMS_RestapiController::class.':addGroupAccessToFolder'); //
|
$app->put('/folder/{id}/access/group/add', \SeedDMS_RestapiController::class.':addGroupAccessToFolder'); //
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user