-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d033f6
commit 0bfd136
Showing
9 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Content; | ||
use App\Models\Post; | ||
use App\Models\PostContent; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Http\Request; | ||
|
||
class ContentController extends Controller | ||
{ | ||
public function deleteCategoryContent(Content $content) | ||
{ | ||
$content->delete(); | ||
return redirect()->back()->withSuccess(__('This language data has been deleted.')); | ||
} | ||
|
||
public function deletePostContent(PostContent $postContent) | ||
{ | ||
$result = DB::select('select post_id from contents_of_posts where content_id = ?', [$postContent->id]); | ||
if (!empty($result)){ | ||
$result = json_decode(json_encode($result), true); | ||
$post = Post::find($result[0]['post_id']); | ||
|
||
if (!empty($post)){ | ||
if ($post->author_id != auth()->user()->id && !auth()->user()->hasOneOfRoles(['admin', 'mod'])){ | ||
abort(403); | ||
} | ||
} | ||
} | ||
|
||
$postContent->delete(); | ||
return redirect()->back()->withSuccess('This language data has been deleted.'); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const hiddenForm = document.querySelector('.hidden-form'); | ||
const hiddenFormInfo = document.querySelector('.hidden-form-info'); | ||
const hiddenFormInfoButton = document.querySelector('.hidden-form-info button'); | ||
|
||
if (hiddenForm && hiddenFormInfo && hiddenFormInfoButton){ | ||
hiddenFormInfoButton.addEventListener('click', () => { | ||
hiddenForm.classList.remove('d-none'); | ||
hiddenFormInfo.classList.add('d-none'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Admin; | ||
|
||
use App\Models\PostContent; | ||
use App\Models\Content; | ||
use Tests\TestCase; | ||
|
||
class ContentTest extends TestCase | ||
{ | ||
private $admin; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->admin = $this->getAdmin(); | ||
} | ||
|
||
public function testDestroyCategoryContent() | ||
{ | ||
$content = Content::all()->random(); | ||
$response = $this->actingAs($this->admin)->delete(route('admin.content.destroy', $content->id)); | ||
|
||
$response->assertSessionHas('success'); | ||
$response->assertStatus(302); | ||
|
||
$emptyContent = Content::find($content->id); | ||
$this->assertEmpty($emptyContent); | ||
} | ||
|
||
public function testDestroyPostContent() | ||
{ | ||
$content = PostContent::all()->random(); | ||
$response = $this->actingAs($this->admin)->delete(route('admin.post-content.destroy', $content->id)); | ||
|
||
$response->assertSessionHas('success'); | ||
$response->assertStatus(302); | ||
|
||
$emptyContent = PostContent::find($content->id); | ||
$this->assertEmpty($emptyContent); | ||
} | ||
} |