Skip to content

Commit

Permalink
Add check for user initial posting
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Apr 18, 2018
1 parent 4238996 commit 85b8377
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ SLACK_ENDPOINT=https://myconan.net/null/

# ADMIN_FORUM_ID=
# HELP_FORUM_IDS=
# INITIAL_HELP_FORUM_IDS="5 47 85"

# GA_TRACKING_ID=UA-xxx

Expand Down
2 changes: 1 addition & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function render($request, Exception $e)
if ($request->ajax()) {
$response = response(['error' => $this->ajaxMessage($e)]);
} else {
$response = response()->view('layout.error');
$response = response()->view('layout.error', ['exception' => $e]);
}
}

Expand Down
36 changes: 36 additions & 0 deletions app/Libraries/OsuAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,30 @@ public function checkForumPostEdit($user, $post)
return 'ok';
}

public function checkForumPostStore($user, $post)
{
$prefix = 'forum.post.store.';

$this->ensureLoggedIn($user);
$this->ensureCleanRecord($user);

$plays = $user->monthlyPlaycounts()->sum('playcount');
$posts = $user->user_posts;
$forInitialHelpForum = in_array($post->forum_id, config('osu.forum.initial_help_forum_ids'), true);

if ($forInitialHelpForum) {
if ($plays < 10 && $posts > 10) {
return $prefix.'too_many_help_posts';
}
} else {
if ($plays < 200 && $plays < $posts + 1) {
return $prefix.'play_more';
}
}

return 'ok';
}

public function checkForumTopicEdit($user, $topic)
{
return $this->checkForumPostEdit($user, $topic->posts()->first());
Expand Down Expand Up @@ -630,6 +654,12 @@ public function checkForumTopicReply($user, $topic)
return $prefix.'no_forum_access';
}

$postStorePermission = $this->doCheckUser($user, 'ForumPostStore', $topic->posts()->create());

if (!$postStorePermission->can()) {
return $postStorePermission->rawMessage();
}

if (!ForumAuthorize::aclCheck($user, 'f_reply', $topic->forum)) {
return $prefix.'no_permission';
}
Expand Down Expand Up @@ -660,6 +690,12 @@ public function checkForumTopicStore($user, $forum)
return $prefix.'no_forum_access';
}

$postStorePermission = $this->doCheckUser($user, 'ForumPostStore', $forum->topics()->create()->posts()->create());

if (!$postStorePermission->can()) {
return $postStorePermission->rawMessage();
}

if (!$forum->isOpen()) {
return $prefix.'forum_closed';
}
Expand Down
1 change: 1 addition & 0 deletions config/osu.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'forum' => [
'admin_forum_id' => intval(env('ADMIN_FORUM_ID', 28)),
'help_forum_ids' => array_map('intval', explode(' ', env('HELP_FORUM_IDS', '4 5 29 30 101'))),
'initial_help_forum_ids' => array_map('intval', explode(' ', env('INITIAL_HELP_FORUM_IDS', '5 47 85'))),
'double_post_time' => [
'normal' => 72,
'author' => 24,
Expand Down
5 changes: 5 additions & 0 deletions resources/lang/en/authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
'not_owner' => 'Only poster can edit the post.',
'topic_locked' => 'Can not edit post of a locked topic.',
],

'store' => [
'play_more' => 'Try playing the game before posting on the forums, please! If you have a problem with playing, please post to the Help and Support forum.',
'too_many_posts' => 'Please wait for responses of current posts.',
],
],

'topic' => [
Expand Down
22 changes: 12 additions & 10 deletions resources/views/layout/error.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@

@section("content")

<div class="osu-layout__row osu-layout__row--page">
<h1 class="text-center">{{{ trans("layout.errors.$current_action.error") }}}</h1>

@if (Lang::get("layout.errors.$current_action.link") and Lang::get("layout.errors.$current_action.link.href") != "layout.errors.$current_action.link.href")
{!! trans("layout.errors.$current_action.description",
["link" => '<a class="blue_normal" href="' . trans("layout.errors.$current_action.link.href") . '">' . trans("layout.errors.$current_action.link.text") . '</a>']
)!!}
@else
<div class="text-center">{{{ trans("layout.errors.$current_action.description") }}}</div>
<div class="osu-page osu-page--generic text-center">
<h1>{{{ trans("layout.errors.$current_action.error") }}}</h1>

@if (isset($exception))
<p>[{{ $exception->getMessage() }}]</p>
@endif

<p>
{!! trans("layout.errors.$current_action.description", ['link' =>
'<a class="blue_normal" href="'.trans("layout.errors.$current_action.link.href").'">'.trans("layout.errors.$current_action.link.text").'</a>',
]) !!}
</p>

@if (isset($ref))
<h4 class="text-center">{{{ trans("layout.errors.reference") }}}<br><small>{{{ $ref }}}</small> </h4>
<h4>{{ trans('layout.errors.reference') }}<br><small>{{ $ref }}</small></h4>
@endif
</div>

Expand Down

0 comments on commit 85b8377

Please sign in to comment.