Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+70 -19
View File
@@ -32,6 +32,7 @@ class _supportreplies extends \IPS\Content\Api\CommentController
* GET /nexus/supportreplies
* Get list of support replies
*
* @note For requests using an OAuth Access Token for a particular member, only topics the authorized user can view will be included - if the user is a staff member, will use their staff permissions
* @apiparam int staffReplies If 1, only replies by staff will be included. If 0, only replies by non-staff.
* @apiparam string authors Comma-delimited list of member IDs - if provided, only replies by those members are returned
* @apiparam string departments Comma-delimited list of department IDs
@@ -40,6 +41,7 @@ class _supportreplies extends \IPS\Content\Api\CommentController
* @apiparam string sortBy What to sort by. Can be 'date', 'title' or leave unspecified for ID
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @apiparam int perPage Number of results per page - defaults to 25
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Support\Reply>
*/
public function GETindex()
@@ -74,9 +76,17 @@ class _supportreplies extends \IPS\Content\Api\CommentController
{
$where[] = array( \IPS\Db::i()->in( 'r_severity', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
}
/* Are we a staff member? */
$bypassPerms = FALSE;
if ( $this->member and $this->member->isAdmin() and count( \IPS\nexus\Support\Department::departmentsWithPermission( $this->member ) ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_department', array_keys( iterator_to_array( \IPS\nexus\Support\Department::departmentsWithPermission( $this->member ) ) ) ) );
$bypassPerms = TRUE;
}
/* Return */
return $this->_list( $where );
return $this->_list( $where, NULL, $bypassPerms );
}
/**
@@ -84,14 +94,24 @@ class _supportreplies extends \IPS\Content\Api\CommentController
* View information about a specific reply
*
* @param int $id ID Number
* @throws 2X314/1 INVALID_ID The reply ID does not exist
* @throws 2X314/1 INVALID_ID The reply ID does not exist or the authorized user does not have permission to view it
* @return \IPS\nexus\Support\Reply
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Support\Reply::load( $id )->apiOutput() );
$class = $this->class;
if ( $this->member )
{
$object = $class::loadAndCheckPerms( $id, $this->member );
}
else
{
$object = $class::load( $id );
}
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
{
@@ -104,12 +124,12 @@ class _supportreplies extends \IPS\Content\Api\CommentController
* Create a reply
*
* @reqapiparam int request The ID number of the request the reply is for
* @reqapiparam int author The ID number of the member making the post (0 for guest)
* @reqapiparam string message The reply content as HTML (e.g. "<p>This is a post.</p>")
* @apiparam datetime date The date/time that should be used for the topic/post post date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the topic/post. If not provided, will use the IP address from the API request
* @apiparam bool hidden If true will be added as a hidden note
* @throws 2X314/2 NO_REQUEST The forum ID does not exist
* @reqapiparam int author The ID number of the member making the post (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author.
* @reqapiparam string message The reply content as HTML (e.g. "<p>This is a post.</p>"). Will be sanatized for requests using an OAuth Access Token for a particular member; will be saved unaltered for requests made using an API Key or the Client Credentials Grant Type.
* @apiparam datetime date The date/time that should be used for the topic/post post date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member
* @apiparam string ip_address The IP address that should be stored for the topic/post. If not provided, will use the IP address from the API request. Ignored for requests using an OAuth Access Token for a particular member
* @apiparam bool hidden If true will be added as a hidden note. Ignored if authorized member is not staff
* @throws 2X314/2 NO_REQUEST The support request ID does not exist or the authorized user does not have permission to access it
* @throws 1X314/3 NO_AUTHOR The author ID does not exist
* @throws 1X314/4 NO_MESSAGE No message was supplied
* @return \IPS\nexus\Support\Reply
@@ -120,6 +140,21 @@ class _supportreplies extends \IPS\Content\Api\CommentController
try
{
$request = \IPS\nexus\Support\Request::load( \IPS\Request::i()->request );
if ( $this->member )
{
if ( $request->canView( $this->member ) )
{
// Okay
}
elseif ( $this->member->isAdmin() and ( $request->department->staff === '*' or count( array_intersect( explode( ',', $request->department->staff ), Department::staffDepartmentPerms( $this->member ) ) ) ) )
{
// Okay
}
else
{
throw new \OutOfRangeException;
}
}
}
catch ( \OutOfRangeException $e )
{
@@ -127,18 +162,25 @@ class _supportreplies extends \IPS\Content\Api\CommentController
}
/* Get author */
if ( \IPS\Request::i()->author )
if ( $this->member )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X314/3', 403 );
}
$author = $this->member;
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
if ( \IPS\Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X314/3', 403 );
}
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
}
}
/* Check we have a post */
@@ -162,9 +204,16 @@ class _supportreplies extends \IPS\Content\Api\CommentController
protected function _createComment( \IPS\Content\Item $item, \IPS\Member $author, $contentParam='content' )
{
$comment = parent::_createComment( $item, $author, $contentParam );
if ( \IPS\Request::i()->hidden )
if ( $this->member )
{
$comment->type = $comment::REPLY_HIDDEN;
if ( !$item->canView( $this->member ) )
{
$comment->type = $comment::REPLY_STAFF;
if ( \IPS\Request::i()->hidden )
{
$comment->type = $comment::REPLY_HIDDEN;
}
}
}
$comment->save();
return $comment;
@@ -174,6 +223,7 @@ class _supportreplies extends \IPS\Content\Api\CommentController
* POST /nexus/supportreplies/{id}
* Edit a reply
*
* @apiclientonly
* @param int $id ID Number
* @apiparam int author The ID number of the member making the post (0 for guest)
* @apiparam string message The post content as HTML (e.g. "<p>This is a post.</p>")
@@ -208,6 +258,7 @@ class _supportreplies extends \IPS\Content\Api\CommentController
* DELETE /nexus/supportreplies/{id}
* Deletes a reply
*
* @apiclientonly
* @param int $id ID Number
* @throws 2X314/7 INVALID_ID The post ID does not exist
* @throws 1X314/8 CANNOT_DELETE_FIRST_POST You cannot delete the first reply to a request. Delete the request itself instead.