1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #6072 from beganovich/v5-1706-sync-enabled-modules

(v5) Sync enabled modules with admin portal
This commit is contained in:
Benjamin Beganović 2021-06-17 15:58:53 +02:00 committed by GitHub
commit 353fd1cb39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 332 additions and 129 deletions

View File

@ -3,19 +3,13 @@
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\ShowCreditRequest;
use App\Http\Requests\ClientPortal\Credits\ShowCreditRequest;
use App\Http\Requests\ClientPortal\Credits\ShowCreditsRequest;
use App\Models\Credit;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
class CreditController extends Controller
{
/**
* Display listing of client credits.
*
* @return Factory|View
*/
public function index()
public function index(ShowCreditsRequest $request)
{
return $this->render('credits.index');
}

View File

@ -12,8 +12,9 @@
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\ProcessInvoicesInBulkRequest;
use App\Http\Requests\ClientPortal\ShowInvoiceRequest;
use App\Http\Requests\ClientPortal\Invoices\ShowInvoicesRequest;
use App\Http\Requests\ClientPortal\Invoices\ProcessInvoicesInBulkRequest;
use App\Http\Requests\ClientPortal\Invoices\ShowInvoiceRequest;
use App\Models\Invoice;
use App\Utils\Number;
use App\Utils\TempFile;
@ -33,7 +34,7 @@ class InvoiceController extends Controller
*
* @return Factory|View
*/
public function index()
public function index(ShowInvoicesRequest $request)
{
return $this->render('invoices.index');
}

View File

@ -1,11 +1,22 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers\ClientPortal;
use App\Events\Quote\QuoteWasApproved;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\ProcessQuotesInBulkRequest;
use App\Http\Requests\ClientPortal\ShowQuoteRequest;
use App\Http\Requests\ClientPortal\Quotes\ProcessQuotesInBulkRequest;
use App\Http\Requests\ClientPortal\Quotes\ShowQuotesRequest;
use App\Http\Requests\ClientPortal\Quotes\ShowQuoteRequest;
use App\Jobs\Invoice\InjectSignature;
use App\Models\Quote;
use App\Utils\Ninja;
@ -25,7 +36,7 @@ class QuoteController extends Controller
*
* @return Factory|View
*/
public function index()
public function index(ShowQuotesRequest $request)
{
return $this->render('quotes.index');
}

View File

@ -12,7 +12,9 @@
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\ShowRecurringInvoiceRequest;
use App\Http\Requests\ClientPortal\RecurringInvoices\RequestCancellationRequest;
use App\Http\Requests\ClientPortal\RecurringInvoices\ShowRecurringInvoicesRequest;
use App\Http\Requests\ClientPortal\RecurringInvoices\ShowRecurringInvoiceRequest;
use App\Jobs\Mail\NinjaMailer;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
@ -23,7 +25,6 @@ use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\Notifications\UserNotifies;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\Request;
use Illuminate\View\View;
/**
@ -40,7 +41,7 @@ class RecurringInvoiceController extends Controller
*
* @return Factory|View
*/
public function index()
public function index(ShowRecurringInvoicesRequest $request)
{
return $this->render('recurring_invoices.index');
}
@ -59,7 +60,7 @@ class RecurringInvoiceController extends Controller
]);
}
public function requestCancellation(Request $request, RecurringInvoice $recurring_invoice)
public function requestCancellation(RequestCancellationRequest $request, RecurringInvoice $recurring_invoice)
{
if (is_null($recurring_invoice->subscription_id) || optional($recurring_invoice->subscription)->allow_cancellation) {
$nmo = new NinjaMailerObject;

View File

@ -1,7 +1,8 @@
<?php
namespace App\Http\Requests\ClientPortal;
namespace App\Http\Requests\ClientPortal\Credits;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
class ShowCreditRequest extends FormRequest
@ -13,7 +14,8 @@ class ShowCreditRequest extends FormRequest
*/
public function authorize()
{
return !$this->credit->is_deleted;
return !$this->credit->is_deleted
&& auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_CREDITS;
}
/**

View File

@ -0,0 +1,31 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\ClientPortal\Credits;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
class ShowCreditsRequest extends FormRequest
{
public function authorize()
{
return auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_CREDITS;
}
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\ClientPortal\Invoices;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
class ProcessInvoicesInBulkRequest extends FormRequest
{
public function authorize()
{
return auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
}
public function rules()
{
return [
'invoices' => ['array'],
];
}
}

View File

@ -9,9 +9,10 @@
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Requests\ClientPortal;
namespace App\Http\Requests\ClientPortal\Invoices;
use App\Http\Requests\Request;
use App\Http\ViewComposers\PortalComposer;
class ShowInvoiceRequest extends Request
{
@ -22,6 +23,7 @@ class ShowInvoiceRequest extends Request
*/
public function authorize() : bool
{
return auth('contact')->user()->client->id == $this->invoice->client_id;
return auth('contact')->user()->client->id == $this->invoice->client_id
&& auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\ClientPortal\Invoices;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
class ShowInvoicesRequest extends FormRequest
{
public function authorize()
{
return auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
}
public function rules()
{
return [
//
];
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Http\Requests\ClientPortal;
use Illuminate\Foundation\Http\FormRequest;
class ProcessInvoicesInBulkRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true; // TODO.
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'invoices' => ['array'],
];
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Http\Requests\ClientPortal;
use Illuminate\Foundation\Http\FormRequest;
class ProcessQuotesInBulkRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'quotes' => ['array'],
];
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\ClientPortal\Quotes;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
use function auth;
class ProcessQuotesInBulkRequest extends FormRequest
{
public function authorize()
{
return auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
}
public function rules()
{
return [
'quotes' => ['array'],
];
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\ClientPortal\Quotes;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
class ShowQuoteRequest extends FormRequest
{
public function authorize()
{
return auth()->user()->client->id === $this->quote->client_id
&& auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
}
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\ClientPortal\Quotes;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
class ShowQuotesRequest extends FormRequest
{
public function authorize()
{
return auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
}
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Http\Requests\ClientPortal\RecurringInvoices;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
class RequestCancellationRequest extends FormRequest
{
public function authorize()
{
return auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
}
public function rules()
{
return [
//
];
}
}

View File

@ -9,19 +9,23 @@
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Requests\ClientPortal;
namespace App\Http\Requests\ClientPortal\RecurringInvoices;
use App\Http\Requests\Request;
use App\Http\ViewComposers\PortalComposer;
class ShowRecurringInvoiceRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->client->id === $this->recurring_invoice->client_id;
return auth('contact')->user()->client->id === $this->recurring_invoice->client_id
&& auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
}
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\ClientPortal\RecurringInvoices;
use App\Http\ViewComposers\PortalComposer;
use Illuminate\Foundation\Http\FormRequest;
class ShowRecurringInvoicesRequest extends FormRequest
{
public function authorize()
{
return auth('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
}
public function rules()
{
return [
//
];
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace App\Http\Requests\ClientPortal;
use Illuminate\Foundation\Http\FormRequest;
class ShowQuoteRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
// return auth()->user()->client->id === $this->quote->client_id;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -1,5 +1,15 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\ClientPortal\Tasks;
use Illuminate\Foundation\Http\FormRequest;

View File

@ -22,6 +22,22 @@ use Illuminate\View\View;
*/
class PortalComposer
{
public const MODULE_RECURRING_INVOICES = 1;
public const MODULE_CREDITS = 2;
public const MODULE_QUOTES = 4;
public const MODULE_TASKS = 8;
public const MODULE_EXPENSES = 16;
public const MODULE_PROJECTS = 32;
public const MODULE_VENDORS = 64;
public const MODULE_TICKETS = 128;
public const MODULE_PROPOSALS = 256;
public const MODULE_RECURRING_EXPENSES = 512;
public const MODULE_RECURRING_TASKS = 1024;
public const MODULE_RECURRING_QUOTES = 2048;
public const MODULE_INVOICES = 4096;
public const MODULE_PROFORMAL_INVOICES = 8192;
public const MODULE_PURCHASE_ORDERS = 16384;
public $settings;
/**
@ -69,17 +85,31 @@ class PortalComposer
private function sidebarMenu() :array
{
$enabled_modules = auth('contact')->user()->company->enabled_modules;
$data = [];
//@todo wire this back in when we are happy with dashboard.
// if($this->settings->enable_client_portal_dashboard == TRUE)
// TODO: Enable dashboard once it's completed.
// $this->settings->enable_client_portal_dashboard
// $data[] = [ 'title' => ctrans('texts.dashboard'), 'url' => 'client.dashboard', 'icon' => 'activity'];
if (self::MODULE_INVOICES & $enabled_modules) {
$data[] = ['title' => ctrans('texts.invoices'), 'url' => 'client.invoices.index', 'icon' => 'file-text'];
}
if (self::MODULE_RECURRING_INVOICES & $enabled_modules) {
$data[] = ['title' => ctrans('texts.recurring_invoices'), 'url' => 'client.recurring_invoices.index', 'icon' => 'file'];
}
// $data[] = [ 'title' => ctrans('texts.dashboard'), 'url' => 'client.dashboard', 'icon' => 'activity'];
$data[] = ['title' => ctrans('texts.invoices'), 'url' => 'client.invoices.index', 'icon' => 'file-text'];
$data[] = ['title' => ctrans('texts.recurring_invoices'), 'url' => 'client.recurring_invoices.index', 'icon' => 'file'];
$data[] = ['title' => ctrans('texts.payments'), 'url' => 'client.payments.index', 'icon' => 'credit-card'];
$data[] = ['title' => ctrans('texts.quotes'), 'url' => 'client.quotes.index', 'icon' => 'align-left'];
$data[] = ['title' => ctrans('texts.credits'), 'url' => 'client.credits.index', 'icon' => 'credit-card'];
if (self::MODULE_QUOTES & $enabled_modules) {
$data[] = ['title' => ctrans('texts.quotes'), 'url' => 'client.quotes.index', 'icon' => 'align-left'];
}
if (self::MODULE_CREDITS & $enabled_modules) {
$data[] = ['title' => ctrans('texts.credits'), 'url' => 'client.credits.index', 'icon' => 'credit-card'];
}
$data[] = ['title' => ctrans('texts.payment_methods'), 'url' => 'client.payment_methods.index', 'icon' => 'shield'];
$data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download'];
$data[] = ['title' => ctrans('texts.subscriptions'), 'url' => 'client.subscriptions.index', 'icon' => 'calendar'];