mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-09 13:06:14 +00:00
lots of formatting fixes
This commit is contained in:
parent
1ad8fbcb2a
commit
325a180ff8
|
@ -25,24 +25,21 @@ use Psr\Http\Server\MiddlewareInterface;
|
|||
use DI\ContainerBuilder;
|
||||
use Slim\Factory\AppFactory;
|
||||
|
||||
final class JsonRenderer
|
||||
{
|
||||
final class JsonRenderer { /* {{{ */
|
||||
public function json(
|
||||
ResponseInterface $response,
|
||||
array $data = null
|
||||
): ResponseInterface {
|
||||
$response = $response->withHeader('Content-Type', 'application/json');
|
||||
|
||||
$response->getBody()->write(
|
||||
(string)json_encode(
|
||||
$data,
|
||||
JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR
|
||||
)
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
} /* }}} */
|
||||
|
||||
final class SeedDMS_RestapiController { /* {{{ */
|
||||
protected $container;
|
||||
|
@ -1730,12 +1727,9 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
$dms = $this->container->get('dms');
|
||||
$userobj = $this->container->get('userobj');
|
||||
|
||||
if(!$userobj) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403);
|
||||
}
|
||||
if(!$userobj->isAdmin()) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on document', 'data'=>''))->withStatus(403);
|
||||
}
|
||||
$check = $this->checkIfAdmin($request, $response);
|
||||
if ($check !== true)
|
||||
return $check;
|
||||
|
||||
if(!ctype_digit($args['id']) || $args['id'] == 0) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'No document given', 'data'=>''))->withStatus(400);
|
||||
|
@ -2106,8 +2100,8 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
|
||||
function checkIfAdmin($request, $response) { /* {{{ */
|
||||
$dms = $this->container->get('dms');
|
||||
if(!$this->container->has('userobj'))
|
||||
echo "no user object";
|
||||
// if(!$this->container->has('userobj'))
|
||||
// echo "no user object";
|
||||
|
||||
if(!$this->container->has('userobj') || !($userobj = $this->container->get('userobj'))) {
|
||||
return $this->renderer->json($response, ['success'=>false, 'message'=>'Not logged in', 'data'=>''])->withStatus(403);
|
||||
|
@ -2245,7 +2239,7 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
return $check;
|
||||
|
||||
$params = $request->getParsedBody();
|
||||
if ($params['quota'] == null) {
|
||||
if ($params['quota'] == null || !ctype_digit($params['quota'])) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a new quota', 'data'=>''))->withStatus(400);
|
||||
}
|
||||
|
||||
|
@ -2434,6 +2428,7 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
$check = $this->checkIfAdmin($request, $response);
|
||||
if($check !== true)
|
||||
return $check;
|
||||
|
||||
if(ctype_digit($args['id']))
|
||||
$group = $dms->getGroup($args['id']);
|
||||
else {
|
||||
|
@ -2482,20 +2477,16 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
|
||||
$operationResult = false;
|
||||
|
||||
if ($operationType == 'add')
|
||||
{
|
||||
if ($operationType == 'add') {
|
||||
$operationResult = $group->addUser($user);
|
||||
}
|
||||
if ($operationType == 'remove')
|
||||
{
|
||||
if ($operationType == 'remove') {
|
||||
$operationResult = $group->removeUser($user);
|
||||
}
|
||||
|
||||
if ($operationResult === false)
|
||||
{
|
||||
if ($operationResult === false) {
|
||||
$message = 'Could not add user to the group.';
|
||||
if ($operationType == 'remove')
|
||||
{
|
||||
if ($operationType == 'remove') {
|
||||
$message = 'Could not remove user from group.';
|
||||
}
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'Something went wrong. ' . $message, 'data'=>''))->withStatus(500);
|
||||
|
@ -2524,6 +2515,7 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
$check = $this->checkIfAdmin($request, $response);
|
||||
if ($check !== true)
|
||||
return $check;
|
||||
|
||||
$params = $request->getParsedBody();
|
||||
if (!isset($params['enable']))
|
||||
{
|
||||
|
@ -2560,12 +2552,9 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
$dms = $this->container->get('dms');
|
||||
$userobj = $this->container->get('userobj');
|
||||
|
||||
if(!$userobj) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403);
|
||||
}
|
||||
if(!$userobj->isAdmin()) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on folder', 'data'=>''))->withStatus(403);
|
||||
}
|
||||
$check = $this->checkIfAdmin($request, $response);
|
||||
if ($check !== true)
|
||||
return $check;
|
||||
|
||||
if(!ctype_digit($args['id']) || $args['id'] == 0) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'No folder given', 'data'=>''))->withStatus(400);
|
||||
|
@ -2631,51 +2620,40 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
|
||||
$params = $request->getParsedBody();
|
||||
$userOrGroupIdInput = $params['id'];
|
||||
if ($operationType == 'add')
|
||||
{
|
||||
if ($params['id'] == null)
|
||||
{
|
||||
if ($operationType == 'add') {
|
||||
if ($params['id'] == null) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'Please PUT the user or group Id', 'data'=>''))->withStatus(400);
|
||||
}
|
||||
|
||||
if ($params['mode'] == null)
|
||||
{
|
||||
if ($params['mode'] == null) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'Please PUT the access mode', 'data'=>''))->withStatus(400);
|
||||
}
|
||||
|
||||
$modeInput = $params['mode'];
|
||||
|
||||
$mode = M_NONE;
|
||||
if ($modeInput == 'read')
|
||||
{
|
||||
if ($modeInput == 'read') {
|
||||
$mode = M_READ;
|
||||
}
|
||||
if ($modeInput == 'readwrite')
|
||||
{
|
||||
if ($modeInput == 'readwrite') {
|
||||
$mode = M_READWRITE;
|
||||
}
|
||||
if ($modeInput == 'all')
|
||||
{
|
||||
if ($modeInput == 'all') {
|
||||
$mode = M_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$userOrGroupId = $userOrGroupIdInput;
|
||||
if(!ctype_digit($userOrGroupIdInput) && $userOrGroup == 'user')
|
||||
{
|
||||
if (!ctype_digit($userOrGroupIdInput) && $userOrGroup == 'user') {
|
||||
$userOrGroupObj = $dms->getUserByLogin($userOrGroupIdInput);
|
||||
}
|
||||
if(!ctype_digit($userOrGroupIdInput) && $userOrGroup == 'group')
|
||||
{
|
||||
if (!ctype_digit($userOrGroupIdInput) && $userOrGroup == 'group') {
|
||||
$userOrGroupObj = $dms->getGroupByName($userOrGroupIdInput);
|
||||
}
|
||||
if(ctype_digit($userOrGroupIdInput) && $userOrGroup == 'user')
|
||||
{
|
||||
if (ctype_digit($userOrGroupIdInput) && $userOrGroup == 'user') {
|
||||
$userOrGroupObj = $dms->getUser($userOrGroupIdInput);
|
||||
}
|
||||
if(ctype_digit($userOrGroupIdInput) && $userOrGroup == 'group')
|
||||
{
|
||||
if (ctype_digit($userOrGroupIdInput) && $userOrGroup == 'group') {
|
||||
$userOrGroupObj = $dms->getGroup($userOrGroupIdInput);
|
||||
}
|
||||
if (!$userOrGroupObj) {
|
||||
|
@ -2685,29 +2663,23 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
|
||||
$operationResult = false;
|
||||
|
||||
if ($operationType == 'add' && $userOrGroup == 'user')
|
||||
{
|
||||
if ($operationType == 'add' && $userOrGroup == 'user') {
|
||||
$operationResult = $folder->addAccess($mode, $userOrGroupId, true);
|
||||
}
|
||||
if ($operationType == 'remove' && $userOrGroup == 'user')
|
||||
{
|
||||
if ($operationType == 'remove' && $userOrGroup == 'user') {
|
||||
$operationResult = $folder->removeAccess($userOrGroupId, true);
|
||||
}
|
||||
|
||||
if ($operationType == 'add' && $userOrGroup == 'group')
|
||||
{
|
||||
if ($operationType == 'add' && $userOrGroup == 'group') {
|
||||
$operationResult = $folder->addAccess($mode, $userOrGroupId, false);
|
||||
}
|
||||
if ($operationType == 'remove' && $userOrGroup == 'group')
|
||||
{
|
||||
if ($operationType == 'remove' && $userOrGroup == 'group') {
|
||||
$operationResult = $folder->removeAccess($userOrGroupId, false);
|
||||
}
|
||||
|
||||
if ($operationResult === false)
|
||||
{
|
||||
if ($operationResult === false) {
|
||||
$message = 'Could not add user/group access to this folder.';
|
||||
if ($operationType == 'remove')
|
||||
{
|
||||
if ($operationType == 'remove') {
|
||||
$message = 'Could not remove user/group access from this folder.';
|
||||
}
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'Something went wrong. ' . $message, 'data'=>''))->withStatus(500);
|
||||
|
@ -2724,6 +2696,7 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
if (false === ($categories = $dms->getDocumentCategories())) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not get categories', 'data'=>null))->withStatus(500);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($categories as $category)
|
||||
$data[] = $this->__getCategoryData($category);
|
||||
|
@ -2811,8 +2784,7 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
}
|
||||
|
||||
$params = $request->getParsedBody();
|
||||
if (empty($params['name']))
|
||||
{
|
||||
if (empty($params['name'])) {
|
||||
return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a new name', 'data'=>''))->withStatus(400);
|
||||
}
|
||||
|
||||
|
@ -2895,9 +2867,9 @@ final class SeedDMS_RestapiController { /* {{{ */
|
|||
if ($check !== true)
|
||||
return $check;
|
||||
|
||||
if(ctype_digit($args['id']))
|
||||
if (ctype_digit($args['id'])) {
|
||||
$folder = $dms->getFolder($args['id']);
|
||||
else {
|
||||
} else {
|
||||
$folder = $dms->getFolderByName($args['id']);
|
||||
}
|
||||
if (!$folder) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user