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

+112 -35
View File
@@ -32,6 +32,7 @@ class _supportrequests extends \IPS\Content\Api\ItemController
* GET /nexus/supportrequests
* Get list of support requests
*
* @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 string authors Comma-delimited list of member IDs - if provided, only support requests belonging to those members (or emails specified by email param) are returned
* @apiparam string email Comma-delimited list of email addresses - if provided, only support requests created by those emails (or members specified by authors param) are returned
* @apiparam string departments Comma-delimited list of department IDs
@@ -43,6 +44,7 @@ class _supportrequests extends \IPS\Content\Api\ItemController
* @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\Request>
*/
public function GETindex()
@@ -98,8 +100,16 @@ class _supportrequests extends \IPS\Content\Api\ItemController
$where[] = array( \IPS\Db::i()->in( 'r_staff', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->staff ) ) ) ) );
}
/* 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 );
}
/**
@@ -109,14 +119,20 @@ class _supportrequests extends \IPS\Content\Api\ItemController
* @param int $id ID Number
* @apiparam int hidden If 1, only posts which are hidden are returned, if 0 only not hidden
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @throws 2X313/1 INVALID_ID The topic ID does not exist
* @throws 2X313/1 INVALID_ID The request does not exist or the authorized user does not have permission to view it
* @return \IPS\nexus\Support\Request
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Support\Request::load( $id )->apiOutput() );
$request = \IPS\nexus\Support\Request::load( $id );
if ( $this->member and !$request->canView( $this->member ) )
{
throw new \OutOfRangeException;
}
return new \IPS\Api\Response( 200, $request->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
{
@@ -132,13 +148,20 @@ class _supportrequests extends \IPS\Content\Api\ItemController
* @apiparam int hidden If 1, only replies which are hidden are returned, if 0 only not hidden
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @throws 2X313/2 INVALID_ID The topic ID does not exist
* @apiparam int perPage Number of results per page - defaults to 25
* @throws 2X313/2 INVALID_ID The request does not exist or the authorized user does not have permission to view it
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Support\Reply>
*/
public function GETitem_replies( $id )
{
try
{
$request = \IPS\nexus\Support\Request::load( $id );
if ( $this->member and !$request->canView( $this->member ) )
{
throw new \OutOfRangeException;
}
return $this->_comments( $id, 'IPS\nexus\Support\Reply', array( array( 'reply_type<>?', \IPS\nexus\Support\Reply::REPLY_PENDING ) ) );
}
catch ( \OutOfRangeException $e )
@@ -149,14 +172,15 @@ class _supportrequests extends \IPS\Content\Api\ItemController
/**
* Create or update topic
* Create or update item
*
* @param \IPS\Content\Item $item The item
* @param string $type add or edit
* @return \IPS\Content\Item
*/
protected function _createOrUpdate( \IPS\Content\Item $item )
protected function _createOrUpdate( \IPS\Content\Item $item, $type='add' )
{
/* Department, statuc, etc */
/* Department, status, etc */
foreach ( array( 'department' => 'IPS\nexus\Support\Department', 'status' => 'IPS\nexus\Support\Status', 'severity' => 'IPS\nexus\Support\Severity', 'purchase' => 'IPS\nexus\Purchase', 'staff' => 'IPS\Member' ) as $key => $class )
{
if ( isset( \IPS\Request::i()->$key ) )
@@ -164,17 +188,45 @@ class _supportrequests extends \IPS\Content\Api\ItemController
try
{
$object = $class::load( \IPS\Request::i()->$key );
if ( $this->member )
{
if ( $key === 'department' and $type == 'edit' )
{
continue;
}
if ( $key === 'severity' and ( !$this->member->cm_no_sev or !in_array( $object, \IPS\nexus\Support\Department::load( \IPS\Request::i()->department )->availableSeverities() ) ) )
{
continue;
}
if ( $key === 'purchase' and ( $type == 'edit' or !$object->canView( $this->member ) ) )
{
continue;
}
if ( $key === 'staff' )
{
continue;
}
if ( $key === 'status' and ( $type == 'add' or !\IPS\Member::loggedIn()->language()->checkKeyExists("nexus_status_{$object->id}_set") ) )
{
continue;
}
}
$item->$key = $object;
}
catch ( \OutOfRangeException $e ) {}
}
}
if ( !isset( \IPS\Request::i()->purchase ) and isset( \IPS\Request::i()->lkey ) )
if ( ( $type == 'add' or !$this->member ) and !isset( \IPS\Request::i()->purchase ) and isset( \IPS\Request::i()->lkey ) )
{
try
{
$licenseKey = \IPS\nexus\Purchase\LicenseKey::load( \IPS\Request::i()->lkey );
$item->purchase = $licenseKey->purchase;
if ( !$this->member or $licenseKey->purchase->canView( $this->member ) )
{
$item->purchase = $licenseKey->purchase;
}
}
catch ( \OutOfRangeException $e ) {}
}
@@ -191,6 +243,12 @@ class _supportrequests extends \IPS\Content\Api\ItemController
$item->severity = \IPS\nexus\Support\Severity::load( TRUE, 'sev_default' );
}
}
/* Cannot edit title */
if ( $this->member and $type == 'edit' )
{
unset( \IPS\Request::i()->title );
}
/* Pass up */
return parent::_createOrUpdate( $item );
@@ -200,22 +258,24 @@ class _supportrequests extends \IPS\Content\Api\ItemController
* POST /nexus/supportrequests
* Create a support request
*
* @note For requests using an OAuth Access Token for a particular member, pay-per-incident departments cannot be used. Any parameters the user doesn't have permission to use are ignored (for example, severities they cannot set).
* @reqapiparam string title The support request title
* @reqapiparam int department Department ID number
* @reqapiparam int account The ID number of the member creating the support request - not required if email is provided
* @reqapiparam string email The email address creating the support request - not required if account is provided
* @reqapiparam string message The content as HTML (e.g. "<p>This is a support request.</p>")
* @apiparam int status Status ID number. If not provided, will use the default.
* @reqapiparam int account The ID number of the member creating the support request - not required if email is provided. For requests using an OAuth Access Token for a particular member, this is ignored and that member will always be the author.
* @reqapiparam string email The email address creating the support request - not required if account is provided. For requests using an OAuth Access Token for a particular member, this is ignored and that member will always be the author.
* @reqapiparam string message The content as HTML (e.g. "<p>This is a support request.</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 int status Status ID number. If not provided, will use the default. Ignored for requests using an OAuth Access Token for a particular member
* @apiparam int severity Severity ID number. If not provided, will use the default.
* @apiparam int purchase Associated purchase ID number.
* @apiparam int purchase Associated purchase ID number.
* @apiparam string lkey License key of associated purchase ID number. (Will be ignored if "purchase" is provided)
* @apiparam int staff Assigned staff ID number.
* @apiparam datetime date The date/time that should be used for the support request date. If not provided, will use the current date/time
* @throws 1X313/3 NO_DEPARTMENT The forum ID does not exist
* @apiparam int staff Assigned staff ID number. Ignored for requests using an OAuth Access Token for a particular member
* @apiparam datetime date The date/time that should be used for the support request date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member
* @throws 1X313/3 NO_DEPARTMENT The department does not exist
* @throws 1X313/6 NO_PERMISSION The request is for an authorizes member and the department does not accept submissions or is pay-per-incident
* @throws 1X313/4 NO_AUTHOR The author ID does not exist
* @throws 1X313/5 NO_TITLE No title was supplied
* @throws 1X313/4 NO_POST No post was supplied
* @return \IPS\forums\Topic
* @return \IPS\nexus\Support\Request
*/
public function POSTindex()
{
@@ -228,19 +288,30 @@ class _supportrequests extends \IPS\Content\Api\ItemController
{
throw new \IPS\Api\Exception( 'NO_DEPARTMENT', '1X313/3', 400 );
}
if ( $this->member and ( !$department->open or $department->ppiCost() ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '1X313/6', 403 );
}
/* Get author */
if ( \IPS\Request::i()->account )
if ( $this->member )
{
$author = \IPS\Member::load( \IPS\Request::i()->account );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X313/4', 400 );
}
$author = $this->member;
}
else
{
$author = new \IPS\Member;
if ( \IPS\Request::i()->account )
{
$author = \IPS\Member::load( \IPS\Request::i()->account );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X313/4', 400 );
}
}
else
{
$author = new \IPS\Member;
}
}
/* Check we have a title and a post */
@@ -257,27 +328,28 @@ class _supportrequests extends \IPS\Content\Api\ItemController
$item = $this->_create( NULL, $author, 'message' );
/* Email */
if ( isset( \IPS\Request::i()->email ) )
if ( !$this->member and isset( \IPS\Request::i()->email ) )
{
$item->email = \IPS\Request::i()->email;
}
/* Do it */
return new \IPS\Api\Response( 201, $item->apiOutput() );
return new \IPS\Api\Response( 201, $item->apiOutput( $this->member ) );
}
/**
* POST /nexus/supportrequests/{id}
* Edit a support request
*
* @apiparam string title The support request title
* @apiparam int department Department ID number
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, severities they cannot set).
* @apiparam string title The support request title. Ignored for requests using an OAuth Access Token for a particular member (users cannot edit request titles after they're created)
* @apiparam int department Department ID number. Ignored for requests using an OAuth Access Token for a particular member (users cannot move requests after they're created)
* @apiparam int status Status ID number. If not provided, will use the default.
* @apiparam int severity Severity ID number. If not provided, will use the default.
* @apiparam int purchase Associated purchase ID number.
* @apiparam string lkey License key of associated purchase ID number. (Will be ignored if "purchase" is provided)
* @apiparam int staff Assigned staff ID number.
* @throws 2X313/7 INVALID_ID The topic ID does not exist
* @apiparam int purchase Associated purchase ID number. Ignored for requests using an OAuth Access Token for a particular member (users cannot change associated purchase of request after its created)
* @apiparam string lkey License key of associated purchase ID number. (Will be ignored if "purchase" is provided). Ignored for requests using an OAuth Access Token for a particular member (users cannot change associated purchase of request after its created)
* @apiparam int staff Assigned staff ID number. Ignored for requests using an OAuth Access Token for a particular member
* @throws 2X313/7 INVALID_ID The topic ID does not exist or the authorized user does not have permission to view it
* @return \IPS\nexus\Support\Request
*/
public function POSTitem( $id )
@@ -285,13 +357,17 @@ class _supportrequests extends \IPS\Content\Api\ItemController
try
{
$request = \IPS\nexus\Support\Request::load( $id );
if ( $this->member and !$request->canView( $this->member ) )
{
throw new \OutOfRangeException;
}
/* Process */
$this->_createOrUpdate( $request );
$this->_createOrUpdate( $request, 'edit' );
/* Save and return */
$request->save();
return new \IPS\Api\Response( 200, $request->apiOutput() );
return new \IPS\Api\Response( 200, $request->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
{
@@ -303,6 +379,7 @@ class _supportrequests extends \IPS\Content\Api\ItemController
* DELETE /nexus/supportrequests/{id}
* Delete a support request
*
* @apiclientonly
* @param int $id ID Number
* @throws 1F294/5 INVALID_ID The topic ID does not exist
* @return void