mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-11 09:35:00 +00:00
add route /document/{id}/attribute/{attrdefid}
This commit is contained in:
parent
1ec3367695
commit
a5802ad3e8
|
@ -1559,6 +1559,56 @@ class RestapiController { /* {{{ */
|
|||
}
|
||||
} /* }}} */
|
||||
|
||||
function setDocumentAttribute($request, $response, $args) { /* {{{ */
|
||||
$dms = $this->container->dms;
|
||||
$userobj = $this->container->userobj;
|
||||
|
||||
if(!$userobj) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!ctype_digit($args['id']) || $args['id'] == 0) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'No document given', 'data'=>''), 400);
|
||||
return;
|
||||
}
|
||||
if(!ctype_digit($args['attrdefid']) || $args['attrdefid'] == 0) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'No attribute definition id given', 'data'=>''), 400);
|
||||
return;
|
||||
}
|
||||
$attrdef = $dms->getAttributeDefinition($args['attrdefid']);
|
||||
$doc = $dms->getDocument($args['id']);
|
||||
if($doc && $attrdef) {
|
||||
if($attrdef->getObjType() !== SeedDMS_Core_AttributeDefinition::objtype_document) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Attribute definition not suitable for documents', 'data'=>''), 500);
|
||||
}
|
||||
|
||||
$params = $request->getParsedBody();
|
||||
$new = $doc->getAttributeValue($attrdef) ? true : false;
|
||||
if(!$attrdef->validate($params['value'], $doc, $new)) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''), 500);
|
||||
}
|
||||
if($doc->getAccessMode($userobj, 'setDocumentAttribute') > M_READ) {
|
||||
if ($doc->setAttributeValue($attrdef, $params['value'])) {
|
||||
return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201);
|
||||
} else {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Could not set attribute value of document', 'data'=>''), 500);
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'No access on document', 'data'=>''), 403);
|
||||
}
|
||||
} else {
|
||||
if(!$doc)
|
||||
return $response->withJson(array('success'=>false, 'message'=>'No such document', 'data'=>''), 404);
|
||||
if(!$attrdef)
|
||||
return $response->withJson(array('success'=>false, 'message'=>'No such attr definition', 'data'=>''), 404);
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Could not find user or document', 'data'=>''), 500);
|
||||
}
|
||||
|
||||
$data = $this->__getDocumentData($doc);
|
||||
return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200);
|
||||
} /* }}} */
|
||||
|
||||
function getAccount($request, $response) { /* {{{ */
|
||||
$dms = $this->container->dms;
|
||||
$userobj = $this->container->userobj;
|
||||
|
@ -2575,6 +2625,7 @@ $app->delete('/document/{id}/categories', \RestapiController::class.':removeDocu
|
|||
$app->delete('/document/{id}/category/{catid}', \RestapiController::class.':removeDocumentCategory');
|
||||
$app->post('/document/{id}/category/{catid}', \RestapiController::class.':addDocumentCategory');
|
||||
$app->put('/document/{id}/owner/{userid}', \RestapiController::class.':setDocumentOwner');
|
||||
$app->put('/document/{id}/attribute/{attrdefid}', \RestapiController::class.':setDocumentAttribute');
|
||||
$app->put('/account/fullname', \RestapiController::class.':setFullName');
|
||||
$app->put('/account/email', \RestapiController::class.':setEmail');
|
||||
$app->get('/account/documents/locked', \RestapiController::class.':getLockedDocuments');
|
||||
|
|
Loading…
Reference in New Issue
Block a user