mirror of
https://github.com/flarum/framework.git
synced 2025-02-02 02:37:16 +08:00
new api tests uncovered more issues, fixed tokens and discussion posts
This commit is contained in:
parent
6619fb0848
commit
523acba2aa
|
@ -118,7 +118,7 @@ class ShowDiscussionController extends AbstractShowController
|
||||||
*/
|
*/
|
||||||
private function loadPostIds(Discussion $discussion, User $actor)
|
private function loadPostIds(Discussion $discussion, User $actor)
|
||||||
{
|
{
|
||||||
return $discussion->posts()->whereVisibleTo($actor)->orderBy('time')->pluck('id')->all();
|
return $discussion->posts()->whereVisibleTo($actor)->orderBy('created_at')->pluck('id')->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,7 +172,7 @@ class ShowDiscussionController extends AbstractShowController
|
||||||
{
|
{
|
||||||
$query = $discussion->posts()->whereVisibleTo($actor);
|
$query = $discussion->posts()->whereVisibleTo($actor);
|
||||||
|
|
||||||
$query->orderBy('time')->skip($offset)->take($limit)->with($include);
|
$query->orderBy('created_at')->skip($offset)->take($limit)->with($include);
|
||||||
|
|
||||||
$posts = $query->get()->all();
|
$posts = $query->get()->all();
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ class TokenController implements ControllerInterface
|
||||||
$token->save();
|
$token->save();
|
||||||
|
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
'token' => $token->id,
|
'token' => $token->token,
|
||||||
'userId' => $user->id
|
'userId' => $user->id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,13 @@ namespace Flarum\Http;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Flarum\Database\AbstractModel;
|
use Flarum\Database\AbstractModel;
|
||||||
|
use Flarum\User\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property string $id
|
* @property string $token
|
||||||
* @property int $user_id
|
* @property int $user_id
|
||||||
* @property int $last_activity
|
* @property int $last_activity_at
|
||||||
* @property int $lifetime
|
* @property int $lifetime_seconds
|
||||||
* @property \Flarum\User\User|null $user
|
* @property \Flarum\User\User|null $user
|
||||||
*/
|
*/
|
||||||
class AccessToken extends AbstractModel
|
class AccessToken extends AbstractModel
|
||||||
|
@ -35,6 +36,10 @@ class AccessToken extends AbstractModel
|
||||||
*/
|
*/
|
||||||
public $incrementing = false;
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $primaryKey = 'token';
|
||||||
|
|
||||||
|
protected $dates = ['last_activity_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an access token for the specified user.
|
* Generate an access token for the specified user.
|
||||||
*
|
*
|
||||||
|
@ -46,17 +51,17 @@ class AccessToken extends AbstractModel
|
||||||
{
|
{
|
||||||
$token = new static;
|
$token = new static;
|
||||||
|
|
||||||
$token->id = str_random(40);
|
$token->token = str_random(40);
|
||||||
$token->user_id = $userId;
|
$token->user_id = $userId;
|
||||||
$token->last_activity = Carbon::now();
|
$token->last_activity_at = Carbon::now();
|
||||||
$token->lifetime = $lifetime;
|
$token->lifetime_seconds = $lifetime;
|
||||||
|
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function touch()
|
public function touch()
|
||||||
{
|
{
|
||||||
$this->last_activity = Carbon::now();
|
$this->last_activity_at = Carbon::now();
|
||||||
|
|
||||||
return $this->save();
|
return $this->save();
|
||||||
}
|
}
|
||||||
|
@ -68,6 +73,6 @@ class AccessToken extends AbstractModel
|
||||||
*/
|
*/
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('Flarum\User\User');
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user