Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -18,7 +18,9 @@ use InvalidArgumentException;
|
||||
use IPS\Application\Module;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\Content\Item;
|
||||
use IPS\Content\Permissions;
|
||||
use IPS\core\Alerts\Alert;
|
||||
use IPS\core\DataLayer;
|
||||
use IPS\core\Reports\Report;
|
||||
use IPS\core\Warnings\Warning;
|
||||
use IPS\DateTime;
|
||||
@@ -26,6 +28,7 @@ use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Member as FormMember;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Output;
|
||||
@@ -180,10 +183,28 @@ class Conversation extends Item
|
||||
* @param Member $member The member
|
||||
* @param Model|null $container Container (e.g. forum) ID, if appropriate
|
||||
* @param bool $showError If TRUE, rather than returning a boolean value, will display an error
|
||||
* @param Alert|null $alert Is this a reply to an alert?
|
||||
* @return bool
|
||||
*/
|
||||
public static function canCreate( Member $member, ?Model $container=NULL, bool $showError=FALSE ) : bool
|
||||
public static function canCreate( Member $member, ?Model $container=NULL, bool $showError=FALSE, Alert $alert = null ) : bool
|
||||
{
|
||||
/* If this conversation is associated with an alert, skip the rest of the permission checks, the user should be able to reply */
|
||||
if ( ( $alert and $alert instanceof Alert ) or isset( Request::i()->alert ) )
|
||||
{
|
||||
if( isset( Request::i()->alert ) )
|
||||
{
|
||||
$alert = Alert::load( Request::i()->alert );
|
||||
}
|
||||
try
|
||||
{
|
||||
if( $alert->forMember( Member::loggedIn() ) AND $alert->reply == Alert::REPLY_REQUIRED )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
catch ( OutOfRangeException $e ) {}
|
||||
}
|
||||
|
||||
/* Can we access the module? */
|
||||
if ( !parent::canCreate( $member, $container, $showError ) )
|
||||
{
|
||||
@@ -200,22 +221,6 @@ class Conversation extends Item
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If this conversation is associated with an alert, skip the
|
||||
rest of the permission checks, the user should be able to reply */
|
||||
if ( isset( Request::i()->alert ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$alert = Alert::load( Request::i()->alert );
|
||||
|
||||
if( $alert->forMember( Member::loggedIn() ) AND $alert->reply == Alert::REPLY_REQUIRED )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
catch ( OutOfRangeException $e ) {}
|
||||
}
|
||||
|
||||
/* Have we exceeded our limit for the day/minute? */
|
||||
if ( $member->group['g_pm_perday'] !== -1 )
|
||||
@@ -401,8 +406,13 @@ class Conversation extends Item
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Extensions are last because all of the above needs to be honored */
|
||||
if( $permCheck = Permissions::can( 'receive', new static, $member ) )
|
||||
{
|
||||
return ( $permCheck === Permissions::PERM_ALLOW );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -475,6 +485,8 @@ class Conversation extends Item
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Does a member have permission to access?
|
||||
*
|
||||
@@ -485,6 +497,12 @@ class Conversation extends Item
|
||||
{
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
/* Extensions check */
|
||||
if( $permCheck = Permissions::can( 'view', $this, $member ) )
|
||||
{
|
||||
return ( $permCheck === Permissions::PERM_ALLOW );
|
||||
}
|
||||
|
||||
/* Is the user part of the conversation? */
|
||||
foreach ( $this->maps() as $map )
|
||||
{
|
||||
@@ -993,4 +1011,59 @@ class Conversation extends Item
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string|null title Title ( if available )
|
||||
* @apiresponse \IPS\Member author The member that created the item
|
||||
* @apiresponse datetime date Date
|
||||
* @apiresponse string content Content
|
||||
* @apiresponse string url URL
|
||||
* @apiresponse [\IPS\Member] participants Active users in this conversation
|
||||
*/
|
||||
public function apiOutput( Member $authorizedMember = NULL ): array
|
||||
{
|
||||
$return = [
|
||||
'id' => $this->id,
|
||||
'title' => $this->mapped( 'title' ),
|
||||
'author' => $this->author()->apiOutput( $authorizedMember ),
|
||||
'date' => DateTime::ts( $this->mapped('date') )->rfc3339(),
|
||||
'content' => $this->content(),
|
||||
'url' => (string) $this->url(),
|
||||
'participants' => []
|
||||
];
|
||||
|
||||
foreach( $this->maps() as $map )
|
||||
{
|
||||
if( $map['map_user_active'] )
|
||||
{
|
||||
$return['participants'][] = Member::load( $map['map_user_id'] )->apiOutput( $authorizedMember );
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comment|null $comment
|
||||
* @param array $createOrEditValues=[]
|
||||
* @param bool $clearCache=false
|
||||
* @return array
|
||||
*/
|
||||
public function getDataLayerProperties ( ?Comment $comment = null, array $createOrEditValues = [], bool $clearCache=false ): array
|
||||
{
|
||||
$properties = parent::getDataLayerProperties( $comment, $createOrEditValues, $clearCache );
|
||||
if ( isset( $properties['content_area'] ) )
|
||||
{
|
||||
$properties['content_area'] = Lang::load( Lang::defaultLanguage() )->addToStack( 'personal_conversations' );
|
||||
}
|
||||
|
||||
$updates = DataLayer::i()->filterProperties([ 'message_recipient_count' => $this->activeParticipants ]);
|
||||
|
||||
return array_replace( $properties, $updates );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user