Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -27,11 +27,13 @@ class _invoices extends \IPS\Api\Controller
|
||||
* GET /nexus/invoices
|
||||
* Get list of invoices
|
||||
*
|
||||
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned
|
||||
* @note For requests using an OAuth Access Token for a particular member, only the members own invoices will be included
|
||||
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam string statuses Comma-delimited list of statuses - if provided, only invoices with those statuses are returned - see invoice object for status keys
|
||||
* @apiparam string sortBy What to sort by. Can be 'date', 'paid' (for paid date), 'total', 'title' or do not specify 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\Invoice>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -40,7 +42,11 @@ class _invoices extends \IPS\Api\Controller
|
||||
$where = array();
|
||||
|
||||
/* Customers */
|
||||
if ( isset( \IPS\Request::i()->customers ) )
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( 'i_member=?', $this->member->member_id );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->customers ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'i_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
|
||||
}
|
||||
@@ -68,7 +74,9 @@ class _invoices extends \IPS\Api\Controller
|
||||
\IPS\Db::i()->select( '*', 'nexus_invoices', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
'IPS\nexus\Invoice',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', $where )->first()
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,14 +85,20 @@ class _invoices extends \IPS\Api\Controller
|
||||
* Get information about a specific invoice
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X299/1 INVALID_ID The invoice ID does not exist
|
||||
* @throws 2X299/1 INVALID_ID The invoice ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Invoice
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\nexus\Invoice::load( $id )->apiOutput() );
|
||||
{
|
||||
$object = \IPS\nexus\Invoice::load( $id );
|
||||
if ( $this->member and !$object->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ class _lkey extends \IPS\Api\Controller
|
||||
* Get information about a specific purchase from its license key
|
||||
*
|
||||
* @param string $lkey License key
|
||||
* @throws 2X310/1 INVALID_KEY The license key does not exist
|
||||
* @throws 2X310/1 INVALID_KEY The license key does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Purchase
|
||||
*/
|
||||
public function GETitem( $lkey )
|
||||
@@ -37,8 +37,12 @@ class _lkey extends \IPS\Api\Controller
|
||||
{
|
||||
$licenseKey = \IPS\nexus\Purchase\LicenseKey::load( $lkey );
|
||||
$purchase = $licenseKey->purchase;
|
||||
if ( $this->member and !$purchase->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput() );
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -50,6 +54,7 @@ class _lkey extends \IPS\Api\Controller
|
||||
* POST /nexus/lkey/{key}
|
||||
* Update custom fields for a purchase from its license key
|
||||
*
|
||||
* @apiclientonly
|
||||
* @apiparam object customFields Values for custom fields
|
||||
* @throws 2X310/2 INVALID_KEY The license key does not exist
|
||||
* @return \IPS\nexus\Purchase
|
||||
@@ -78,6 +83,6 @@ class _lkey extends \IPS\Api\Controller
|
||||
|
||||
$purchase->save();
|
||||
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput() );
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,8 @@ class _purchases extends \IPS\Api\Controller
|
||||
* GET /nexus/purchases
|
||||
* Get list of purchases
|
||||
*
|
||||
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned
|
||||
* @note For requests using an OAuth Access Token for a particular member, only the members own purchases will be included
|
||||
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam int active If 1, only active purchases are returned. If 0, only inactive
|
||||
* @apiparam int canceled If 1, only canceled purchases are returned. If 0, only not canceled
|
||||
* @apiparam string itemApp If specified, only purchases with this application key are returned
|
||||
@@ -38,6 +39,7 @@ class _purchases extends \IPS\Api\Controller
|
||||
* @apiparam string sortBy What to sort by. Can be 'start' (for purchase date), 'expire' (for the epiry date) or do not specify 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\Purchase>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -46,7 +48,11 @@ class _purchases extends \IPS\Api\Controller
|
||||
$where = array();
|
||||
|
||||
/* Customers */
|
||||
if ( isset( \IPS\Request::i()->customers ) )
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( 'ps_member=?', $this->member->member_id );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->customers ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'ps_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
|
||||
}
|
||||
@@ -104,7 +110,9 @@ class _purchases extends \IPS\Api\Controller
|
||||
\IPS\Db::i()->select( '*', 'nexus_purchases', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
'IPS\nexus\Purchase',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', $where )->first()
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -113,14 +121,20 @@ class _purchases extends \IPS\Api\Controller
|
||||
* Get information about a specific purchase
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X310/1 INVALID_ID The purchase ID does not exist
|
||||
* @throws 2X310/1 INVALID_ID The purchase ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Purchase
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\nexus\Purchase::load( $id )->apiOutput() );
|
||||
$object = \IPS\nexus\Purchase::load( $id );
|
||||
if ( $this->member and !$object->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -132,8 +146,8 @@ class _purchases extends \IPS\Api\Controller
|
||||
* POST /nexus/purchases/{id}
|
||||
* Update custom fields for a purchase
|
||||
*
|
||||
* @apiclientonly
|
||||
* @apiparam object customFields Values for custom fields
|
||||
* @throws 2X310/2 INVALID_ID The purchase ID does not exist
|
||||
* @return \IPS\nexus\Purchase
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
@@ -159,6 +173,6 @@ class _purchases extends \IPS\Api\Controller
|
||||
|
||||
$purchase->save();
|
||||
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput() );
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,13 @@ class _shipments extends \IPS\Api\Controller
|
||||
* GET /nexus/shipments
|
||||
* Get list of shipments
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only the members own shipments will be included
|
||||
* @apiparam string statuses Comma-delimited list of statuses - if provided, only transactions with those statuses are returned - see order object for status keys
|
||||
* @apiparam string methods Comma-delimited list of shipping method IDs - if provided, only shipments from those methods are returned
|
||||
* @apiparam string sortBy What to sort by. Can be 'date', 'shipped_date' or do not specify 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\Shipping\Order>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -50,7 +52,13 @@ class _shipments extends \IPS\Api\Controller
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'o_method', array_filter( explode( ',', \IPS\Request::i()->methods ) ) ) );
|
||||
}
|
||||
|
||||
|
||||
/* Permission */
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'o_invoice', iterator_to_array( \IPS\Db::i()->select( 'i_id', 'nexus_invoices', array( 'i_member=?', $this->member->member_id ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
if ( isset( \IPS\Request::i()->sortBy ) and in_array( \IPS\Request::i()->sortBy, array( 'date', 'shipped_date' ) ) )
|
||||
{
|
||||
@@ -68,7 +76,9 @@ class _shipments extends \IPS\Api\Controller
|
||||
\IPS\Db::i()->select( '*', 'nexus_ship_orders', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
'IPS\nexus\Shipping\Order',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_ship_orders', $where )->first()
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_ship_orders', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,14 +87,20 @@ class _shipments extends \IPS\Api\Controller
|
||||
* Get information about a specific shipment
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X307/1 INVALID_ID The shipment ID does not exist
|
||||
* @throws 2X307/1 INVALID_ID The shipment ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Shipping\Order
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\nexus\Shipping\Order::load( $id )->apiOutput() );
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( $id );
|
||||
if ( $this->member and !$shipment->invoice->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $shipment->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -27,12 +27,14 @@ class _transactions extends \IPS\Api\Controller
|
||||
* GET /nexus/transactions
|
||||
* Get list of transactions
|
||||
*
|
||||
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only transactions from those customers are returned
|
||||
* @note For requests using an OAuth Access Token for a particular member, only the members own transactions will be included
|
||||
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only transactions from those customers are returned. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam string statuses Comma-delimited list of statuses - if provided, only transactions with those statuses are returned - see transaction object for status keys
|
||||
* @apiparam string gateways Comma-delimited list of gateway IDs - if provided, only transactions from those gateways are returned
|
||||
* @apiparam string sortBy What to sort by. Can be 'date', 'amount' or do not specify 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\Transaction>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -41,7 +43,11 @@ class _transactions extends \IPS\Api\Controller
|
||||
$where = array();
|
||||
|
||||
/* Customers */
|
||||
if ( isset( \IPS\Request::i()->customers ) )
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( 't_member=?', $this->member->member_id );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->customers ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 't_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
|
||||
}
|
||||
@@ -75,7 +81,9 @@ class _transactions extends \IPS\Api\Controller
|
||||
\IPS\Db::i()->select( '*', 'nexus_transactions', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
'IPS\nexus\Transaction',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', $where )->first()
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,14 +92,15 @@ class _transactions extends \IPS\Api\Controller
|
||||
* Get information about a specific transaction
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X307/1 INVALID_ID The transaction ID does not exist
|
||||
* @throws 2X307/1 INVALID_ID The transaction ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Transaction
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\nexus\Transaction::load( $id )->apiOutput() );
|
||||
$object = $this->member ? \IPS\nexus\Transaction::loadAndCheckPerms( $id ) : \IPS\nexus\Transaction::load( $id );
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
|
||||
@@ -24,14 +24,16 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
class _withdrawals extends \IPS\Api\Controller
|
||||
{
|
||||
/**
|
||||
* GET /nexus/shipments
|
||||
* Get list of shipments
|
||||
* GET /nexus/withdrawals
|
||||
* Get list of withdrawal requests
|
||||
*
|
||||
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned
|
||||
* @note For requests using an OAuth Access Token for a particular member, only the members own withdrawal requests will be included
|
||||
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam string statuses Comma-delimited list of statuses - if provided, only transactions with those statuses are returned - see payout object for status keys
|
||||
* @apiparam string sortBy What to sort by. Can be 'date', 'completed' (for the date it was completed), 'amount' or do not specify 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\Shipping\Order>
|
||||
*/
|
||||
public function GETindex()
|
||||
@@ -40,7 +42,11 @@ class _withdrawals extends \IPS\Api\Controller
|
||||
$where = array();
|
||||
|
||||
/* Customers */
|
||||
if ( isset( \IPS\Request::i()->customers ) )
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( 'po_member=?', $this->member->member_id );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->customers ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'po_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
|
||||
}
|
||||
@@ -68,23 +74,31 @@ class _withdrawals extends \IPS\Api\Controller
|
||||
\IPS\Db::i()->select( '*', 'nexus_payouts', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
'IPS\nexus\Payout`',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_payouts', $where )->first()
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_payouts', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /nexus/withdrawals/{id}
|
||||
* Get information about a specific invoice
|
||||
* Get information about a specific withdrawal request
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X307/1 INVALID_ID The withdrawal ID does not exist
|
||||
* @throws 2X307/1 INVALID_ID The withdrawal ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Payout
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Api\Response( 200, \IPS\nexus\Payout::load( $id )->apiOutput() );
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( $id );
|
||||
if ( $this->member and $this->member->member_id != $payout->member->member_id )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $payout->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user