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

+24 -15
View File
@@ -29,9 +29,12 @@ class _calendars extends \IPS\Node\Api\NodeController
protected $class = 'IPS\calendar\Calendar';
/**
* GET /calendar/calendar
* GET /calendar/calendars
* Get list of calendars
*
* @apiparam int page Page number
* @apiparam int perPage Number of results per page - defaults to 25
* @note For requests using an OAuth Access Token for a particular member, only calendars the authorized user can view will be included
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Calendar>
*/
public function GETindex()
@@ -41,23 +44,30 @@ class _calendars extends \IPS\Node\Api\NodeController
}
/**
* GET /calendar/calendar/{id}
* GET /calendar/calendars/{id}
* Get specific calendar
*
* @param int $id ID Number
*
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Calendar>
* @throws 1L364/1 INVALID_ID The calendar does not exist or the authorized user does not have permission to view it
* @return \IPS\calendar\Calendar
*/
public function GETitem( $id )
{
/* Return */
return $this->_view( $id );
try
{
return $this->_view( $id );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1L364/1', 404 );
}
}
/**
* POST /calendar/calendar
* POST /calendar/calendars
* Create a calendar
*
* @apiclientonly
* @reqapiparam string title The calendar title
* @apiparam string color The calendar color (Hexadecimal)
* @apiparam int approve_events 0|1 Events must be approved?
@@ -65,18 +75,18 @@ class _calendars extends \IPS\Node\Api\NodeController
* @apiparam int approve_comments 0|1 Comments must be approved
* @apiparam int allow_reviews 0|1 Allow reviews
* @apiparam int approve_reviews 0|1 Reviews must be approved
*
* @return \IPS\calendar\Calendar
*/
public function POSTindex()
{
return $this->_create();
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
}
/**
* POST /calendar/calendar/{id}
* POST /calendar/calendars/{id}
* Edit a calendar
*
* @apiclientonly
* @reqapiparam string title The calendar title
* @apiparam string color The calendar color (Hexadecimal)
* @apiparam int approve_events 0|1 Events must be approved?
@@ -84,22 +94,21 @@ class _calendars extends \IPS\Node\Api\NodeController
* @apiparam int approve_comments 0|1 Comments must be approved
* @apiparam int allow_reviews 0|1 Allow reviews
* @apiparam int approve_reviews 0|1 Reviews must be approved
*
* @return \IPS\calendar\Calendar
*/
public function POSTitem( $id )
{
$class = static::$class;
$class = $this->class;
$calendar = $class::load( $id );
$calendar = $this->_createOrUpdate( $calendar );
return $calendar;
return new \IPS\Api\Response( 201, $this->_createOrUpdate( $calendar )->apiOutput( $this->member ) );
}
/**
* DELETE /calendar/calendar/{id}
* DELETE /calendar/calendars/{id}
* Delete a calendar
*
* @apiclientonly
* @param int $id ID Number
* @return void
*/
+60 -18
View File
@@ -32,6 +32,7 @@ class _comments extends \IPS\Content\Api\CommentController
* GET /calendar/comments
* Get list of comments
*
* @note For requests using an OAuth Access Token for a particular member, only comments the authorized user can view will be included
* @apiparam string calendars Comma-delimited list of calendar IDs
* @apiparam string authors Comma-delimited list of member IDs - if provided, only topics started by those members are returned
* @apiparam int locked If 1, only comments from events which are locked are returned, if 0 only unlocked
@@ -40,6 +41,7 @@ class _comments 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\calendar\Event\Comment>
*/
public function GETindex()
@@ -52,14 +54,24 @@ class _comments extends \IPS\Content\Api\CommentController
* View information about a specific comment
*
* @param int $id ID Number
* @throws 2L297/1 INVALID_ID The comment ID does not exist
* @throws 2L297/1 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
* @return \IPS\calendar\Event\Comment
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\calendar\Event\Comment::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 )
{
@@ -71,21 +83,23 @@ class _comments extends \IPS\Content\Api\CommentController
* POST /calendar/comments
* Create a comment
*
* @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, hidden will only be honoured if the authentictaed user has permission to hide content).
* @reqapiparam int event The ID number of the event the comment is for
* @reqapiparam int author The ID number of the member making the comment (0 for guest)
* @reqapiparam int author The ID number of the member making the comment (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
* @apiparam string author_name If author is 0, the guest name that should be used
* @reqapiparam string content The comment content as HTML (e.g. "<p>This is a comment.</p>")
* @apiparam datetime date The date/time that should be used for the comment date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the comment. If not provided, will use the IP address from the API request
* @reqapiparam string content The comment content as HTML (e.g. "<p>This is a comment.</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 comment 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 comment. 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 int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @throws 2L297/3 INVALID_ID The comment ID does not exist
* @throws 1L297/4 NO_AUTHOR The author ID does not exist
* @throws 1L297/5 NO_CONTENT No content was supplied
* @throws 2L297/8 NO_PERMISSION The authorized user does not have permission to comment on that event
* @return \IPS\calendar\Event\Comment
*/
public function POSTindex()
{
/* Get topic */
/* Get event */
try
{
$event = \IPS\calendar\Event::load( \IPS\Request::i()->event );
@@ -96,18 +110,29 @@ class _comments 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 )
if ( !$event->canComment( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1L297/4', 404 );
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L297/8', 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', '1L297/4', 404 );
}
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
}
}
/* Check we have a post */
@@ -124,13 +149,15 @@ class _comments extends \IPS\Content\Api\CommentController
* POST /calendar/comments/{id}
* Edit a comment
*
* @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, hidden will only be honoured if the authentictaed user has permission to hide content).
* @param int $id ID Number
* @apiparam int author The ID number of the member making the comment (0 for guest)
* @apiparam int author The ID number of the member making the comment (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam string author_name If author is 0, the guest name that should be used
* @apiparam string content The comment content as HTML (e.g. "<p>This is a comment.</p>")
* @apiparam string content The comment content as HTML (e.g. "<p>This is a comment.</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 hidden 1/0 indicating if the topic should be hidden
* @throws 2L297/6 INVALID_ID The comment ID does not exist
* @throws 2L297/6 INVALID_ID The comment ID does not exist or the authorized user does not have permission to view it
* @throws 1L297/7 NO_AUTHOR The author ID does not exist
* @throws 2L297/9 NO_PERMISSION The authorized user does not have permission to edit the comment
* @return \IPS\calendar\Event\Comment
*/
public function POSTitem( $id )
@@ -139,6 +166,14 @@ class _comments extends \IPS\Content\Api\CommentController
{
/* Load */
$comment = \IPS\calendar\Event\Comment::load( $id );
if ( $this->member and !$comment->canView( $this->member ) )
{
throw new \OutOfRangeException;
}
if ( $this->member and !$comment->canEdit( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L297/9', 403 );
}
/* Do it */
try
@@ -161,14 +196,21 @@ class _comments extends \IPS\Content\Api\CommentController
* Deletes a comment
*
* @param int $id ID Number
* @throws 2L297/2 INVALID_ID The comment ID does not exist
* @throws 2L297/2 INVALID_ID The comment ID does not exist
* @throws 2L297/A NO_PERMISSION The authorized user does not have permission to delete the comment
* @return void
*/
public function DELETEitem( $id )
{
try
{
\IPS\calendar\Event\Comment::load( $id )->delete();
$class = $this->class;
$object = $class::load( $id );
if ( $this->member and !$object->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L297/A', 403 );
}
$object->delete();
return new \IPS\Api\Response( 200, NULL );
}
+95 -32
View File
@@ -32,6 +32,7 @@ class _events extends \IPS\Content\Api\ItemController
* GET /calendar/events
* Get list of events
*
* @note For requests using an OAuth Access Token for a particular member, only events the authorized user can view will be included
* @apiparam string calendars Comma-delimited list of calendar IDs
* @apiparam string authors Comma-delimited list of member IDs - if provided, only events started by those members are returned
* @apiparam int locked If 1, only events which are locked are returned, if 0 only unlocked
@@ -40,6 +41,7 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam string sortBy What to sort by. Can be 'date' for creation 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\calendar\Event>
*/
public function GETindex()
@@ -56,7 +58,7 @@ class _events extends \IPS\Content\Api\ItemController
* View information about a specific event
*
* @param int $id ID Number
* @throws 1F294/1 INVALID_ID The event ID does not exist
* @throws 1F294/1 INVALID_ID The event ID does not exist or the authorized user does not have permission to view it
* @return \IPS\calendar\Event
*/
public function GETitem( $id )
@@ -75,10 +77,11 @@ class _events extends \IPS\Content\Api\ItemController
* POST /calendar/events
* Create an event
*
* @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, locked will only be honoured if the authentictaed user has permission to lock events).
* @reqapiparam int calendar The ID number of the calendar the event should be created in
* @reqapiparam int author The ID number of the member creating the event (0 for guest)
* @apiparam int author The ID number of the member creating the event (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 title The event title
* @reqapiparam string description The description as HTML (e.g. "<p>This is an event.</p>")
* @reqapiparam string description The description as HTML (e.g. "<p>This is an event.</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.
* @reqapiparam datetime start The event start date/time
* @apiparam datetime end The event end date/time
* @apiparam string recurrence If this event recurs, the ICS recurrence definition
@@ -87,8 +90,8 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam \IPS\GeoLocation location The location where the event is taking place
* @apiparam string prefix Prefix tag
* @apiparam string tags Comma-separated list of tags (do not include prefix)
* @apiparam datetime date The date/time that should be used for the event/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 event/post. If not provided, will use the IP address from the API request
* @apiparam datetime date The date/time that should be used for the event/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 event/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 int locked 1/0 indicating if the event should be locked
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @apiparam int featured 1/0 indicating if the event should be featured
@@ -98,6 +101,7 @@ class _events extends \IPS\Content\Api\ItemController
* @throws 1L296/9 NO_DESC No description was supplied
* @throws 1L296/A INVALID_START The start date is invalid
* @throws 1L296/B INVALID_END The end date is invalid
* @throws 2L296/C NO_PERMISSION The authorized user does not have permission to create an event in that calendar
* @return \IPS\calendar\Event
*/
public function POSTindex()
@@ -113,17 +117,28 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Get author */
if ( \IPS\Request::i()->author )
if ( $this->member )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
if ( !$calendar->can( 'add', $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1L296/7', 400 );
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L296/C', 403 );
}
$author = $this->member;
}
else
{
$author = new \IPS\Member;
if ( \IPS\Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1L296/7', 400 );
}
}
else
{
$author = new \IPS\Member;
}
}
/* Check we have a title and a description */
@@ -158,17 +173,18 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Do it */
return new \IPS\Api\Response( 201, $this->_create( $calendar, $author )->apiOutput() );
return new \IPS\Api\Response( 201, $this->_create( $calendar, $author )->apiOutput( $this->member ) );
}
/**
* POST /calendar/events/{id}
* Edit an event
*
* @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, locked will only be honoured if the authentictaed user has permission to lock topics).
* @reqapiparam int calendar The ID number of the calendar the event should be created in
* @reqapiparam int author The ID number of the member creating the event (0 for guest)
* @reqapiparam int author The ID number of the member creating the event (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
* @reqapiparam string title The event title
* @reqapiparam string description The description as HTML (e.g. "<p>This is an event.</p>")
* @reqapiparam string description The description as HTML (e.g. "<p>This is an event.</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.
* @reqapiparam datetime start The event start date/time
* @apiparam datetime end The event end date/time
* @apiparam string recurrence If this event recurs, the ICS recurrence definition
@@ -177,16 +193,17 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam \IPS\GeoLocation location The location where the event is taking place
* @apiparam string prefix Prefix tag
* @apiparam string tags Comma-separated list of tags (do not include prefix)
* @apiparam datetime date The date/time that should be used for the event/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 event/post. If not provided, will use the IP address from the API request
* @apiparam datetime date The date/time that should be used for the event/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 event/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 int locked 1/0 indicating if the event should be locked
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @apiparam int featured 1/0 indicating if the event should be featured
* @throws 1L296/I INVALID_ID The event ID is invalid
* @throws 1L296/D NO_CALENDAR The calendar ID does not exist
* @throws 1L296/I INVALID_ID The event ID is invalid or the authorized user does not have permission to view it
* @throws 1L296/D NO_CALENDAR The calendar ID does not exist or the authorized user does not have permission to post in it
* @throws 1L296/E NO_AUTHOR The author ID does not exist
* @throws 1L296/G INVALID_START The start date is invalid
* @throws 1L296/H INVALID_END The end date is invalid
* @throws 2L296/D NO_PERMISSION The authorized user does not have permission to edit the topic
* @return \IPS\calendar\Event
*/
public function POSTitem( $id )
@@ -194,13 +211,26 @@ class _events extends \IPS\Content\Api\ItemController
try
{
$event = \IPS\calendar\Event::load( $id );
if ( $this->member and !$event->can( 'read', $this->member ) )
{
throw new \OutOfRangeException;
}
if ( $this->member and !$event->canEdit( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L296/D', 403 );
}
/* New calendar */
if ( isset( \IPS\Request::i()->calendar ) and \IPS\Request::i()->calendar != $event->forum_id )
if ( isset( \IPS\Request::i()->calendar ) and \IPS\Request::i()->calendar != $event->calendar_id and ( !$this->member or $event->canMove( $this->member ) ) )
{
try
{
$newCalendar = \IPS\calendar\Calendar::load( \IPS\Request::i()->calendar );
if ( $this->member and !$newCalendar->can( 'add', $this->member ) )
{
throw new \OutOfRangeException;
}
$event->move( $newCalendar );
}
catch ( \OutOfRangeException $e )
@@ -210,7 +240,7 @@ class _events extends \IPS\Content\Api\ItemController
}
/* New author */
if ( isset( \IPS\Request::i()->author ) )
if ( !$this->member and isset( \IPS\Request::i()->author ) )
{
try
{
@@ -253,11 +283,11 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Everything else */
$this->_createOrUpdate( $event );
$this->_createOrUpdate( $event, 'edit' );
/* Save and return */
$event->save();
return new \IPS\Api\Response( 200, $event->apiOutput() );
return new \IPS\Api\Response( 200, $event->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
{
@@ -273,7 +303,8 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam int hidden If 1, only comments 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 2L296/2 INVALID_ID The event ID does not exist
* @apiparam int perPage Number of results per page - defaults to 25
* @throws 2L296/2 INVALID_ID The event ID does not exist or the authorized user does not have permission to view it
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Event\Comment>
*/
public function GETitem_comments( $id )
@@ -296,7 +327,8 @@ class _events extends \IPS\Content\Api\ItemController
* @apiparam int hidden If 1, only comments 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 2L296/3 INVALID_ID The event ID does not exist
* @apiparam int perPage Number of results per page - defaults to 25
* @throws 2L296/3 INVALID_ID The event ID does not exist or the authorized user does not have permission to view it
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Event\Review>
*/
public function GETitem_reviews( $id )
@@ -316,7 +348,7 @@ class _events extends \IPS\Content\Api\ItemController
* Get RSVPs on an event
*
* @param int $id ID Number
* @throws 2L296/3 INVALID_ID The event ID does not exist
* @throws 2L296/3 INVALID_ID The event ID does not exist or the authorized user does not have permission to view it
* @return array
* @apiresponse [\IPS\Member] attending Members that have confirmed they are attending the event
* @apiresponse [\IPS\Member] notAttending Members that have confirmed they are not attending the event
@@ -327,16 +359,21 @@ class _events extends \IPS\Content\Api\ItemController
try
{
$event = \IPS\calendar\Event::load( $id );
if ( $this->member and !$event->can( 'read', $this->member ) )
{
throw new \OutOfRangeException;
}
$attendees = $event->attendees();
return new \IPS\Api\Response( 200, array(
'attending' => array_values( array_map( function( $member ) {
return $member->apiOutput();
return $member->apiOutput( $this->member );
}, $attendees[1] ) ),
'notAttending' => array_values( array_map( function( $member ) {
return $member->apiOutput();
return $member->apiOutput( $this->member );
}, $attendees[0] ) ),
'maybeAttending' => array_values( array_map( function( $member ) {
return $member->apiOutput();
return $member->apiOutput( $this->member );
}, $attendees[2] ) ),
) );
}
@@ -350,10 +387,12 @@ class _events extends \IPS\Content\Api\ItemController
* PUT /calendar/events/{id}/rsvps/{member_id}
* RSVP a member to an event
*
* @note For requests using an OAuth Access Token for a particular member, the member ID must be the authorized member's ID
* @reqapiparam int response 0 = Not attending; 1 = attending; 2 = maybe attending
* @param int $id Event ID NUmber
* @param int $memberId Member ID NUmber
* @throws 2L296/J INVALID_ID The event ID does not exist
* @throws 2L296/K INVALID_MEMBER The member ID was not valid
* @return void
*/
public function PUTitem_rsvps( $id, $memberId )
@@ -363,6 +402,11 @@ class _events extends \IPS\Content\Api\ItemController
throw new \IPS\Api\Exception( 'INVALID_RESPONSE', '1L296/L', 400 );
}
if ( $this->member and $memberId != $this->member->member_id )
{
throw new \IPS\Api\Exception( 'INVALID_MEMBER', '2L296/K', 404 );
}
try
{
$event = \IPS\calendar\Event::load( $id );
@@ -401,12 +445,19 @@ class _events extends \IPS\Content\Api\ItemController
* DELETE /calendar/events/{id}/rsvps/{member_id}
* Remove a member from RSVP list
*
* @note For requests using an OAuth Access Token for a particular member, the member ID must be the authorized member's ID
* @param int $id Event ID NUmber
* @param int $memberId Member ID NUmber
* @return void
* @throws 2L296/K INVALID_MEMBER The member ID was not valid
*/
public function DELETEitem_rsvps( $id, $memberId )
{
if ( $this->member and $memberId != $this->member->member_id )
{
throw new \IPS\Api\Exception( 'INVALID_MEMBER', '2L296/K', 404 );
}
\IPS\Db::i()->delete( 'calendar_event_rsvp', array( 'rsvp_event_id=? AND rsvp_member_id=?', intval( $id ), intval( $memberId ) ) );
return new \IPS\Api\Response( 200, NULL );
}
@@ -415,9 +466,10 @@ class _events extends \IPS\Content\Api\ItemController
* Create or update event
*
* @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' )
{
/* Start/End date */
$startDate = new \IPS\DateTime( \IPS\Request::i()->start );
@@ -440,10 +492,15 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Description */
$item->content = \IPS\Request::i()->description;
$descriptionContents = \IPS\Request::i()->description;
if ( $this->member )
{
$descriptionContents = \IPS\Text\Parser::parseStatic( $descriptionContents, TRUE, NULL, $this->member, 'calendar_Calendar' );
}
$item->content = $descriptionContents;
/* RSVP */
if ( isset( \IPS\Request::i()->rsvp ) )
if ( isset( \IPS\Request::i()->rsvp ) and ( !$this->member or $item->container()->can( 'askrsvp', $this->member ) ) )
{
$item->rsvp = intval( \IPS\Request::i()->rsvp );
if ( $item->rsvp and isset( \IPS\Request::i()->rsvpLimit ) and \IPS\Request::i()->rsvpLimit )
@@ -475,7 +532,7 @@ class _events extends \IPS\Content\Api\ItemController
}
/* Pass up */
return parent::_createOrUpdate( $item );
return parent::_createOrUpdate( $item, $type );
}
/**
@@ -490,7 +547,13 @@ class _events extends \IPS\Content\Api\ItemController
{
try
{
\IPS\calendar\Event::load( $id )->delete();
$item = \IPS\calendar\Event::load( $id );
if ( $this->member and !$item->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2F294/B', 404 );
}
$item->delete();
return new \IPS\Api\Response( 200, NULL );
}
+60 -18
View File
@@ -32,6 +32,7 @@ class _reviews extends \IPS\Content\Api\CommentController
* GET /calendar/reviews
* Get list of reviews
*
* @note For requests using an OAuth Access Token for a particular member, only reviews the authorized user can view will be included
* @apiparam string calendars Comma-delimited list of calendar IDs
* @apiparam string authors Comma-delimited list of member IDs - if provided, only topics started by those members are returned
* @apiparam int locked If 1, only reviews from events which are locked are returned, if 0 only unlocked
@@ -40,6 +41,7 @@ class _reviews 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\calendar\Event\Review>
*/
public function GETindex()
@@ -52,14 +54,24 @@ class _reviews extends \IPS\Content\Api\CommentController
* View information about a specific review
*
* @param int $id ID Number
* @throws 2L298/1 INVALID_ID The review ID does not exist
* @throws 2L298/1 INVALID_ID The review ID does not exist or the authorized user does not have permission to view it
* @return \IPS\calendar\Event\Review
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\calendar\Event\Review::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 )
{
@@ -71,23 +83,25 @@ class _reviews extends \IPS\Content\Api\CommentController
* POST /calendar/reviews
* Create a review
*
* @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, hidden will only be honoured if the authentictaed user has permission to hide content).
* @reqapiparam int event The ID number of the event the review is for
* @reqapiparam int author The ID number of the member making the review (0 for guest)
* @reqapiparam int author The ID number of the member making the review (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
* @apiparam string author_name If author is 0, the guest name that should be used
* @reqapiparam string content The review content as HTML (e.g. "<p>This is a review.</p>")
* @apiparam datetime date The date/time that should be used for the review date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the review. If not provided, will use the IP address from the API request
* @reqapiparam string content The review content as HTML (e.g. "<p>This is a review.</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 review 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 review. 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 int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @reqapiparam int rating Star rating
* @throws 2L298/2 INVALID_ID The forum ID does not exist
* @throws 1L298/3 NO_AUTHOR The author ID does not exist
* @throws 1L298/4 NO_CONTENT No content was supplied
* @throws 1L298/8 INVALID_RATING The rating is not a valid number up to the maximum rating
* @throws 2L298/A NO_PERMISSION The authorized user does not have permission to review that event
* @return \IPS\calendar\Event\Review
*/
public function POSTindex()
{
/* Get topic */
/* Get event */
try
{
$event = \IPS\calendar\Event::load( \IPS\Request::i()->event );
@@ -98,18 +112,29 @@ class _reviews 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 )
if ( !$event->canReview( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1L298/3', 404 );
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L298/A', 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', '1L298/3', 404 );
}
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
}
}
/* Check we have a post */
@@ -132,15 +157,17 @@ class _reviews extends \IPS\Content\Api\CommentController
* POST /calendar/reviews/{id}
* Edit a review
*
* @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, hidden will only be honoured if the authentictaed user has permission to hide content).
* @param int $id ID Number
* @apiparam int author The ID number of the member making the review (0 for guest)
* @apiparam int author The ID number of the member making the review (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam string author_name If author is 0, the guest name that should be used
* @apiparam string content The review content as HTML (e.g. "<p>This is a review.</p>")
* @apiparam string content The review content as HTML (e.g. "<p>This is a review.</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 hidden 1/0 indicating if the topic should be hidden
* @apiparam int rating Star rating
* @throws 2L298/5 INVALID_ID The review ID does not exist
* @throws 2L298/5 INVALID_ID The review ID does not exist or the authorized user does not have permission to view it
* @throws 1L298/6 NO_AUTHOR The author ID does not exist
* @throws 1L298/9 INVALID_RATING The rating is not a valid number up to the maximum rating
* @throws 2L298/B NO_PERMISSION The authorized user does not have permission to edit the review
* @return \IPS\calendar\Event\Review
*/
public function POSTitem( $id )
@@ -149,6 +176,14 @@ class _reviews extends \IPS\Content\Api\CommentController
{
/* Load */
$comment = \IPS\calendar\Event\Review::load( $id );
if ( $this->member and !$comment->canView( $this->member ) )
{
throw new \OutOfRangeException;
}
if ( $this->member and !$comment->canEdit( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L298/B', 403 );
}
/* Check */
if ( isset( \IPS\Request::i()->rating ) and !in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
@@ -176,14 +211,21 @@ class _reviews extends \IPS\Content\Api\CommentController
* Deletes a review
*
* @param int $id ID Number
* @throws 2L298/7 INVALID_ID The review ID does not exist
* @throws 2L298/7 INVALID_ID The review ID does not exist
* @throws 2L298/C NO_PERMISSION The authorized user does not have permission to delete the comment
* @return void
*/
public function DELETEitem( $id )
{
try
{
\IPS\calendar\Event\Review::load( $id )->delete();
$class = $this->class;
$object = $class::load( $id );
if ( $this->member and !$object->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'NO_PERMISSION', '2L298/C', 403 );
}
$object->delete();
return new \IPS\Api\Response( 200, NULL );
}