Skip to content

Commit

Permalink
Merge pull request #162 from Hyleus/forum-latest-posts-fix
Browse files Browse the repository at this point in the history
Show only topics that are viewable by user
  • Loading branch information
HDVinnie authored Jan 25, 2018
2 parents c601265 + 540b476 commit b57e2d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class Topic extends Model
{
Expand Down Expand Up @@ -46,6 +47,15 @@ public function posts()
return $this->hasMany(\App\Post::class);
}

public function viewable()
{
if (Auth::user()->group->is_modo) {
return true;
}

return $this->forum->getPermission()->read_topic;
}

public function postNumberFromId($searchId)
{
$count = 0;
Expand Down
2 changes: 2 additions & 0 deletions resources/views/blocks/latest_posts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
</thead>
<tbody>
@foreach($posts as $p)
@if ($p->topic->viewable())
<tr class="">
<td><a href="{{ route('forum_topic', array('slug' => $p->topic->slug, 'id' => $p->topic->id)) }}?page={{$p->getPageNumber()}}#post-{{$p->id}}">{{ preg_replace('#\[[^\]]+\]#', '', str_limit($p->content), 75) }}...</a></td>
<td>{{ $p->topic->name }}</td>
<td>{{ $p->user->username }}</td>
<td>{{ $p->updated_at->diffForHumans() }}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
Expand Down
2 changes: 2 additions & 0 deletions resources/views/blocks/latest_topics.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
</thead>
<tbody>
@foreach($topics as $t)
@if ($t->viewable())
<tr class="">
<td><a href="{{ route('forum_topic', array('slug' => $t->slug, 'id' => $t->id)) }}">{{ $t->name }}</a></td>
<td>{{ $t->first_post_user_username }}</td>
<td>{{ $t->created_at->diffForHumans() }}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
Expand Down

0 comments on commit b57e2d5

Please sign in to comment.