Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Pages Fixed #8242

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/Agent/kb/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct()
// checking authentication
$this->middleware('auth');
// checking roles
$this->middleware('roles');
$this->middleware('role.agent');
SettingsController::language();
}

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Agent/kb/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct()
// checking authentication
$this->middleware('auth');
// checking roles
$this->middleware('roles');
$this->middleware('role.agent');
SettingsController::language();
}

Expand Down Expand Up @@ -150,9 +150,9 @@ public function store(Category $category, CategoryRequest $request)
try {
$category->fill($request->input())->save();

return Redirect::back()->with('success', Lang::get('lang.category_inserted_successfully'));
return redirect('category')->with('success', Lang::get('lang.category_inserted_successfully'));
} catch (Exception $e) {
return Redirect::back()->with('fails', Lang::get('lang.category_not_inserted').'<li>'.$e->getMessage().'</li>');
return redirect('category')->with('fails', Lang::get('lang.category_not_inserted').'<li>'.$e->getMessage().'</li>');
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Agent/kb/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(Page $page)
// checking authentication
$this->middleware('auth');
// checking roles
$this->middleware('roles');
$this->middleware('role.agent');
$this->page = $page;
SettingsController::language();
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public function getData()
/* add column Actions */
/* there are action buttons and modal popup to delete a data column */
->addColumn('Actions', function ($model) {
return '<span data-toggle="modal" data-target="#deletepage'.$model->id.'"><a href="#" ><button class="btn btn-danger btn-xs"></a> '.\Lang::get('lang.delete').'</button></span>&nbsp;<a href=page/'.$model->slug.'/edit class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp;<a href=pages/'.$model->slug.' class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>
return '<span data-toggle="modal" data-target="#deletepage'.$model->id.'"><a href="#" ><button class="btn btn-danger btn-xs"></a> '.\Lang::get('lang.delete').'</button></span>&nbsp;<a href=page/'.$model->id.'/edit class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp;<a href=pages/'.$model->slug.' class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>
<div class="modal fade" id="deletepage'.$model->id.'">
<div class="modal-dialog">
<div class="modal-content">
Expand Down Expand Up @@ -150,7 +150,7 @@ public function store(PageRequest $request)
public function edit($slug)
{
try {
$page = $this->page->where('slug', $slug)->first();
$page = $this->page->where('id', $slug)->first();

return view('themes.default1.agent.kb.pages.edit', compact('page'));
} catch (Exception $e) {
Expand All @@ -169,7 +169,7 @@ public function edit($slug)
public function update($slug, PageRequest $request)
{
// get pages with respect to slug
$pages = $this->page->where('slug', $slug)->first();
$pages = $this->page->where('id', $slug)->first();
$sl = $request->input('name');
$slug = Str::slug($sl, '-');

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Agent/kb/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct()
// checking authentication
$this->middleware('auth');
// checking roles
$this->middleware('roles');
$this->middleware('role.agent');
$this->language();
}

Expand Down
15 changes: 11 additions & 4 deletions app/Http/Controllers/Client/kb/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function show($slug, Article $article, Category $category)
if ($arti) {
return view('themes.default1.client.kb.article-list.show', compact('arti'));
} else {
return redirect('404');
return Redirect::back()->with('fails', Lang::get('lang.sorry_not_processed'));
}
}

Expand All @@ -150,7 +150,6 @@ public function home(Article $article, Category $category, Relationship $relatio
if (Config::get('database.install') == '%0%') {
return redirect('step1');
} else {
//$categorys = $category->get();
$categorys = $category->get();
// $categorys->setPath('home');
/* direct to view with $article_id */
Expand Down Expand Up @@ -235,7 +234,6 @@ public function postComment($slug, Article $article, Request $request, Comment $
{
$request->validate([
'comment' => 'required',

]);

$article = $article->where('slug', $slug)->first();
Expand Down Expand Up @@ -265,7 +263,16 @@ public function postComment($slug, Article $article, Request $request, Comment $

public function getPage($name, Page $page)
{
$page = $page->where('slug', $name)->first();
$page = $page->where('slug', $name);

if (!Auth::check() || \Auth::user()->role == 'user') {
$page = $page
->where(['status' => 1, 'visibility'=>1])
->first();
} else {
$page = $page->where('status', 1)->first();
}

if ($page) {
return view('themes.default1.client.kb.article-list.pages', compact('page'));
} else {
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Requests/kb/ArticleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function authorize()
public function rules()
{
return [
'name' => 'required',
//'slug' => 'required|unique:kb_article',
'name' => 'required|unique:kb_article',
'description' => 'required',
'category_id' => 'required',
];
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Requests/kb/ArticleUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ public function authorize()
*/
public function rules()
{
$id = $this->segments()[1];
//$id = $this->segments()[1];
$segments = $this->segments();

$id = isset($segments[1]) ? $segments[1] : null;

return [
'name' => 'required',
'slug' => 'required|unique:kb_article,slug,'.$id.',id',
'name' => 'required|unique:kb_article,name,'.$id,
'slug' => 'required|unique:kb_article,slug,'.$id,
'description' => 'required',
'category_id' => 'required',
];
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Requests/kb/PageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public function authorize()
*/
public function rules()
{
$slug = $this->segment(2);
$id = $this->segment(2);

return [
'name' => 'required|unique:kb_pages,slug,'.$slug,
'name' => 'required|unique:kb_pages,name,'.$id,
'description' => 'required',
];
}
}
33 changes: 21 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="bootstrap/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">app/</directory>
</include>
</coverage>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="feature">
<directory>tests/Feature</directory>
<testsuite name="all">
<directory>./tests/</directory>
</testsuite>
<testsuite name="unit">
<directory>tests/Unit</directory>
<directory>./tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">app/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<!-- <env name="DB_CONNECTION" value="testing"/>
<env name="DB_DATABASE" value="testing_db"/> -->
<env name="DB_CONNECTION" value="testing"/>
<env name="DB_DATABASE" value="testing_db"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="MAIL_MAILER" value="mail"/>
<env name="APP_URL" value="http://localhost:8000"/>
<env name="DB_DATABASE" value="testing_db"/>
<env name="DB_INSTALL" value="1"/>
</php>
</phpunit>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class="nav-item menu-open"

<div class="form-group col-sm-12 {{ $errors->has('description') ? 'has-error' : '' }}">
{!! Form::label('description',Lang::get('lang.description')) !!}

<span class="text-red"> *</span>
<div class="form-group" style="background-color:white">
{!! Form::textarea('description',null,['class' => 'form-control color','size' => '110x15','id'=>'myNicEditor','placeholder'=>Lang::get('lang.enter_the_description')]) !!}
</div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/themes/default1/agent/kb/pages/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class="nav-item menu-open"

@section('content')

{!! Form::model($page,['url' => 'page/'.$page->slug, 'method' => 'PATCH','files'=>true]) !!}
{!! Form::model($page,['url' => 'page/'.$page->id, 'method' => 'PATCH','files'=>true]) !!}

@if(Session::has('errors'))
<?php //dd($errors); ?>
Expand Down Expand Up @@ -130,7 +130,7 @@ class="nav-item menu-open"
</div>

<div class="card-footer">

{!! Form::submit(Lang::get('lang.publish'),['class'=>'btn btn-primary'])!!}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,22 @@ function submitComment(userId, comment) {
$(".form-group").removeClass("has-error");

// Perform your custom validation here
var name = $("#comment-name").val().trim();
var email = $("#comment-email").val().trim();
var comment = $("#comment-comment").val().trim();
var nameElement = $("#comment-name");
var emailElement = $("#comment-email");
var commentElement = $("#comment-comment");

if (nameElement.length > 0) {
var name = nameElement.val().trim();
}

if (emailElement.length > 0) {
var email = emailElement.val().trim();
}

if (commentElement.length > 0) {
var comment = commentElement.val().trim();
}


// Flag to track if there are any errors
var hasErrors = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@
</ul>
</li>

<?php $pages = App\Model\kb\Page::where('status', '1')->where('visibility', '1')->get();
<?php
if(!Auth::check() || Auth::user()->role == 'user')
$pages = App\Model\kb\Page::where('status', '1')->where('visibility', '1')->get();
else
$pages = App\Model\kb\Page::where('status', '1')->get();
?>
@if(count($pages))
<li @yield('pages') class="nav-item dropdown">
Expand Down
Loading