mirror of
https://github.com/flarum/core.git
synced 2025-10-21 03:36:05 +02:00
went over most of the changed attributes from the other pr
This commit is contained in:
@@ -51,7 +51,7 @@ class CommentPost extends Post
|
||||
{
|
||||
$post = new static;
|
||||
|
||||
$post->time = time();
|
||||
$post->created_at = time();
|
||||
$post->discussion_id = $discussionId;
|
||||
$post->user_id = $userId;
|
||||
$post->type = static::$type;
|
||||
@@ -77,8 +77,8 @@ class CommentPost extends Post
|
||||
if ($this->content !== $content) {
|
||||
$this->content = $content;
|
||||
|
||||
$this->edit_time = time();
|
||||
$this->edit_user_id = $actor->id;
|
||||
$this->edited_at = time();
|
||||
$this->edited_user_id = $actor->id;
|
||||
|
||||
$this->raise(new Revised($this));
|
||||
}
|
||||
@@ -94,9 +94,9 @@ class CommentPost extends Post
|
||||
*/
|
||||
public function hide(User $actor = null)
|
||||
{
|
||||
if (! $this->hide_time) {
|
||||
$this->hide_time = time();
|
||||
$this->hide_user_id = $actor ? $actor->id : null;
|
||||
if (! $this->hidden_at) {
|
||||
$this->hidden_at = time();
|
||||
$this->hidden_user_id = $actor ? $actor->id : null;
|
||||
|
||||
$this->raise(new Hidden($this));
|
||||
}
|
||||
@@ -111,9 +111,9 @@ class CommentPost extends Post
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
if ($this->hide_time !== null) {
|
||||
$this->hide_time = null;
|
||||
$this->hide_user_id = null;
|
||||
if ($this->hidden_at !== null) {
|
||||
$this->hidden_at = null;
|
||||
$this->hidden_user_id = null;
|
||||
|
||||
$this->raise(new Restored($this));
|
||||
}
|
||||
|
@@ -24,14 +24,14 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
* @property int $id
|
||||
* @property int $discussion_id
|
||||
* @property int $number
|
||||
* @property \Carbon\Carbon $time
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property int|null $user_id
|
||||
* @property string|null $type
|
||||
* @property string|null $content
|
||||
* @property \Carbon\Carbon|null $edit_time
|
||||
* @property int|null $edit_user_id
|
||||
* @property \Carbon\Carbon|null $hide_time
|
||||
* @property int|null $hide_user_id
|
||||
* @property \Carbon\Carbon|null $edited_at
|
||||
* @property int|null $edited_user_id
|
||||
* @property \Carbon\Carbon|null $hidden_at
|
||||
* @property int|null $hidden_user_id
|
||||
* @property \Flarum\Discussion\Discussion|null $discussion
|
||||
* @property User|null $user
|
||||
* @property User|null $editUser
|
||||
@@ -51,7 +51,7 @@ class Post extends AbstractModel
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $dates = ['time', 'edit_time', 'hide_time'];
|
||||
protected $dates = ['created_at', 'edited_at', 'hidden_at'];
|
||||
|
||||
/**
|
||||
* Casts properties to a specific type.
|
||||
@@ -93,7 +93,7 @@ class Post extends AbstractModel
|
||||
// discussion.
|
||||
static::creating(function (Post $post) {
|
||||
$post->type = $post::$type;
|
||||
$post->number = ++$post->discussion->number_index;
|
||||
$post->number = ++$post->discussion->post_number_index;
|
||||
$post->discussion->save();
|
||||
});
|
||||
|
||||
@@ -170,7 +170,7 @@ class Post extends AbstractModel
|
||||
*/
|
||||
public function editUser()
|
||||
{
|
||||
return $this->belongsTo('Flarum\User\User', 'edit_user_id');
|
||||
return $this->belongsTo('Flarum\User\User', 'edited_user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +180,7 @@ class Post extends AbstractModel
|
||||
*/
|
||||
public function hideUser()
|
||||
{
|
||||
return $this->belongsTo('Flarum\User\User', 'hide_user_id');
|
||||
return $this->belongsTo('Flarum\User\User', 'hidden_user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -81,7 +81,7 @@ class PostPolicy extends AbstractPolicy
|
||||
// discussion.
|
||||
if (! $actor->hasPermission('discussion.editPosts')) {
|
||||
$query->where(function ($query) use ($actor) {
|
||||
$query->whereNull('posts.hide_time')
|
||||
$query->whereNull('posts.hidden_at')
|
||||
->orWhere('user_id', $actor->id)
|
||||
->orWhereExists(function ($query) use ($actor) {
|
||||
$query->selectRaw('1')
|
||||
@@ -107,12 +107,12 @@ class PostPolicy extends AbstractPolicy
|
||||
// A post is allowed to be edited if the user has permission to moderate
|
||||
// the discussion which it's in, or if they are the author and the post
|
||||
// hasn't been deleted by someone else.
|
||||
if ($post->user_id == $actor->id && (! $post->hide_time || $post->hide_user_id == $actor->id)) {
|
||||
if ($post->user_id == $actor->id && (! $post->hidden_at || $post->hidden_user_id == $actor->id)) {
|
||||
$allowEditing = $this->settings->get('allow_post_editing');
|
||||
|
||||
if ($allowEditing === '-1'
|
||||
|| ($allowEditing === 'reply' && $post->number >= $post->discussion->last_post_number)
|
||||
|| ($post->time->diffInMinutes(new Carbon) < $allowEditing)) {
|
||||
|| ($post->created_at->diffInMinutes(new Carbon) < $allowEditing)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user