mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add ability to enable\disable modules
This commit is contained in:
parent
4a94633add
commit
5b80e32fa7
@ -704,9 +704,27 @@ class AccountController extends BaseController
|
||||
return AccountController::saveTaxRates();
|
||||
} elseif ($section === ACCOUNT_PAYMENT_TERMS) {
|
||||
return AccountController::savePaymetTerms();
|
||||
} elseif ($section === ACCOUNT_MANAGEMENT) {
|
||||
return AccountController::saveAccountManagement();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
private function saveAccountManagement()
|
||||
{
|
||||
$account = Auth::user()->account;
|
||||
$modules = Input::get('modules');
|
||||
|
||||
$account->enabled_modules = $modules ? array_sum($modules) : 0;
|
||||
$account->save();
|
||||
|
||||
Session::flash('message', trans('texts.updated_settings'));
|
||||
|
||||
return Redirect::to('settings/'.ACCOUNT_MANAGEMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
|
@ -95,7 +95,7 @@ class ClientController extends BaseController
|
||||
if($user->can('create', ENTITY_TASK)){
|
||||
$actionLinks[] = ['label' => trans('texts.new_task'), 'url' => URL::to('/tasks/create/'.$client->public_id)];
|
||||
}
|
||||
if (Utils::hasFeature(FEATURE_QUOTES) && $user->can('create', ENTITY_INVOICE)) {
|
||||
if (Utils::hasFeature(FEATURE_QUOTES) && $user->can('create', ENTITY_QUOTE)) {
|
||||
$actionLinks[] = ['label' => trans('texts.new_quote'), 'url' => URL::to('/quotes/create/'.$client->public_id)];
|
||||
}
|
||||
|
||||
|
@ -103,18 +103,18 @@ class Account extends Eloquent
|
||||
];
|
||||
|
||||
public static $modules = [
|
||||
1 => ENTITY_RECURRING_INVOICE,
|
||||
2 => ENTITY_CREDIT,
|
||||
4 => ENTITY_QUOTE,
|
||||
8 => ENTITY_TASK,
|
||||
16 => ENTITY_EXPENSE,
|
||||
32 => ENTITY_VENDOR,
|
||||
ENTITY_RECURRING_INVOICE => 1,
|
||||
ENTITY_CREDIT => 2,
|
||||
ENTITY_QUOTE => 4,
|
||||
ENTITY_TASK => 8,
|
||||
ENTITY_EXPENSE => 16,
|
||||
ENTITY_VENDOR => 32,
|
||||
];
|
||||
|
||||
public static $dashboardSections = [
|
||||
1 => 'total_revenue',
|
||||
2 => 'average_invoice',
|
||||
4 => 'outstanding',
|
||||
'total_revenue' => 1,
|
||||
'average_invoice' => 2,
|
||||
'outstanding' => 4,
|
||||
];
|
||||
|
||||
/**
|
||||
@ -1846,6 +1846,20 @@ class Account extends Eloquent
|
||||
public function getFontFolders(){
|
||||
return array_map(function($item){return $item['folder'];}, $this->getFontsData());
|
||||
}
|
||||
|
||||
public function isModuleEnabled($entityType)
|
||||
{
|
||||
if (in_array($entityType, [
|
||||
ENTITY_CLIENT,
|
||||
ENTITY_INVOICE,
|
||||
ENTITY_PRODUCT,
|
||||
ENTITY_PAYMENT,
|
||||
])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->enabled_modules & static::$modules[$entityType];
|
||||
}
|
||||
}
|
||||
|
||||
Account::updated(function ($account)
|
||||
|
@ -93,7 +93,7 @@ class ClientDatatable extends EntityDatatable
|
||||
return URL::to("quotes/create/{$model->public_id}");
|
||||
},
|
||||
function ($model) {
|
||||
return Auth::user()->hasFeature(FEATURE_QUOTES) && Auth::user()->can('create', ENTITY_INVOICE);
|
||||
return Auth::user()->hasFeature(FEATURE_QUOTES) && Auth::user()->can('create', ENTITY_QUOTE);
|
||||
}
|
||||
],
|
||||
[
|
||||
|
@ -16,7 +16,11 @@ class EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
public static function create(User $user, $item) {
|
||||
if ( ! static::checkModuleEnabled($user, $item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->hasPermission('create_all');
|
||||
}
|
||||
|
||||
@ -27,6 +31,10 @@ class EntityPolicy
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit(User $user, $item) {
|
||||
if ( ! static::checkModuleEnabled($user, $item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->hasPermission('edit_all') || $user->owns($item);
|
||||
}
|
||||
|
||||
@ -37,6 +45,10 @@ class EntityPolicy
|
||||
* @return bool
|
||||
*/
|
||||
public static function view(User $user, $item) {
|
||||
if ( ! static::checkModuleEnabled($user, $item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->hasPermission('view_all') || $user->owns($item);
|
||||
}
|
||||
|
||||
@ -57,4 +69,10 @@ class EntityPolicy
|
||||
public static function editByOwner(User $user, $ownerUserId) {
|
||||
return $user->hasPermission('edit_all') || $user->id == $ownerUserId;
|
||||
}
|
||||
|
||||
private static function checkModuleEnabled(User $user, $item)
|
||||
{
|
||||
$entityType = is_string($item) ? $item : $item->getEntityType();
|
||||
return $user->account->isModuleEnabled($entityType);
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ class ExpensePolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
if ( ! parent::create($user)) {
|
||||
public static function create(User $user, $item) {
|
||||
if ( ! parent::create($user, $item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -50,11 +50,26 @@ class GenericEntityPolicy
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function create(User $user, $itemType) {
|
||||
$itemType = Utils::getEntityName($itemType);
|
||||
if (method_exists("App\\Policies\\{$itemType}Policy", 'create')) {
|
||||
return call_user_func(["App\\Policies\\{$itemType}Policy", 'create'], $user);
|
||||
$entityName = Utils::getEntityName($itemType);
|
||||
if (method_exists("App\\Policies\\{$entityName}Policy", 'create')) {
|
||||
return call_user_func(["App\\Policies\\{$entityName}Policy", 'create'], $user, $itemType);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param $itemType
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function view(User $user, $itemType) {
|
||||
$entityName = Utils::getEntityName($itemType);
|
||||
if (method_exists("App\\Policies\\{$entityName}Policy", 'view')) {
|
||||
return call_user_func(["App\\Policies\\{$entityName}Policy", 'view'], $user, $itemType);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -10,8 +10,8 @@ class QuotePolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
if ( ! parent::create($user)) {
|
||||
public static function create(User $user, $item) {
|
||||
if ( ! parent::create($user, $item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@ class TaskPolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
if ( ! parent::create($user)) {
|
||||
public static function create(User $user, $item) {
|
||||
if ( ! parent::create($user, $item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@ class VendorPolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
if ( ! parent::create($user)) {
|
||||
public static function create(User $user, $item) {
|
||||
if ( ! parent::create($user, $item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2173,6 +2173,7 @@ $LANG = array(
|
||||
'white_label_license_key' => 'License Key',
|
||||
'invalid_white_label_license' => 'The white label license is not valid',
|
||||
'created_by' => 'Created by :name',
|
||||
'modules' => 'Modules',
|
||||
|
||||
);
|
||||
|
||||
|
@ -140,6 +140,35 @@
|
||||
@endif
|
||||
{!! Former::close() !!}
|
||||
|
||||
|
||||
{!! Former::open('settings/account_management') !!}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{!! trans('texts.modules') !!}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<label for="modules" class="control-label col-lg-4 col-sm-4"></label>
|
||||
<div class="col-lg-8 col-sm-8">
|
||||
@foreach (\App\Models\Account::$modules as $entityType => $value)
|
||||
<div class="checkbox">
|
||||
<label for="modules_{{ $value}}">
|
||||
<input name="modules[]" id="modules_{{ $value}}" type="checkbox" {{ Auth::user()->account->isModuleEnabled($entityType) ? 'checked="checked"' : '' }} value="{{ $value }}">{{ trans("texts.{$entityType}s") }}
|
||||
</label>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="modules" class="control-label col-lg-4 col-sm-4"></label>
|
||||
<div class="col-lg-8 col-sm-8">
|
||||
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{!! Former::close() !!}
|
||||
|
||||
{!! Former::open('settings/cancel_account')->addClass('cancel-account') !!}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
|
@ -506,6 +506,7 @@
|
||||
'settings',
|
||||
//'self-update'
|
||||
] as $option)
|
||||
@if (in_array($option, ['dashboard', 'settings']) || Auth::user()->can('view', substr($option, 0, -1)))
|
||||
<li class="{{ Request::is("{$option}*") ? 'active' : '' }}">
|
||||
@if ($option == 'settings')
|
||||
<a type="button" class="btn btn-default btn-sm pull-right"
|
||||
@ -530,6 +531,7 @@
|
||||
@endif
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user