This commit is contained in:
snipe 2019-03-18 11:59:48 -07:00
commit dec77890bd
12 changed files with 167 additions and 34 deletions

View file

@ -25,7 +25,7 @@ class ImportController extends Controller
*/ */
public function index() public function index()
{ {
// $this->authorize('import');
$imports = Import::latest()->get(); $imports = Import::latest()->get();
return (new ImportsTransformer)->transformImports($imports); return (new ImportsTransformer)->transformImports($imports);
@ -39,10 +39,8 @@ class ImportController extends Controller
*/ */
public function store() public function store()
{ {
// $this->authorize('import');
if (!Company::isCurrentUserAuthorized()) { if (!config('app.lock_passwords')) {
return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions'));
} elseif (!config('app.lock_passwords')) {
$files = Input::file('files'); $files = Input::file('files');
$path = config('app.private_uploads').'/imports'; $path = config('app.private_uploads').'/imports';
$results = []; $results = [];
@ -119,7 +117,7 @@ class ImportController extends Controller
*/ */
public function process(ItemImportRequest $request, $import_id) public function process(ItemImportRequest $request, $import_id)
{ {
$this->authorize('create', Asset::class); $this->authorize('import');
// Run a backup immediately before processing // Run a backup immediately before processing
Artisan::call('backup:run'); Artisan::call('backup:run');
$errors = $request->import(Import::find($import_id)); $errors = $request->import(Import::find($import_id));
@ -162,7 +160,7 @@ class ImportController extends Controller
*/ */
public function destroy($import_id) public function destroy($import_id)
{ {
$this->authorize('create', Asset::class); $this->authorize('import');
$import = Import::find($import_id); $import = Import::find($import_id);
try { try {
unlink(config('app.private_uploads').'/imports/'.$import->file_path); unlink(config('app.private_uploads').'/imports/'.$import->file_path);

View file

@ -52,6 +52,7 @@ class UsersController extends Controller
'users.phone', 'users.phone',
'users.state', 'users.state',
'users.two_factor_enrolled', 'users.two_factor_enrolled',
'users.two_factor_optin',
'users.updated_at', 'users.updated_at',
'users.username', 'users.username',
'users.zip', 'users.zip',

View file

@ -12,7 +12,7 @@ class ImportsController extends Controller
{ {
public function index() public function index()
{ {
$this->authorize('create', Asset::class); $this->authorize('import');
$imports = Import::latest()->get(); $imports = Import::latest()->get();
$imports = (new ImportsTransformer)->transformImports($imports); $imports = (new ImportsTransformer)->transformImports($imports);
return view('importer/import')->with('imports', $imports); return view('importer/import')->with('imports', $imports);

View file

@ -53,6 +53,8 @@ class UsersTransformer
'permissions' => $user->decodePermissions(), 'permissions' => $user->decodePermissions(),
'activated' => ($user->activated =='1') ? true : false, 'activated' => ($user->activated =='1') ? true : false,
'two_factor_activated' => ($user->two_factor_active()) ? true : false, 'two_factor_activated' => ($user->two_factor_active()) ? true : false,
'two_factor_enrolled' => ($user->two_factor_active_and_enrolled()) ? true : false,
'assets_count' => (int) $user->assets_count, 'assets_count' => (int) $user->assets_count,
'licenses_count' => (int) $user->licenses_count, 'licenses_count' => (int) $user->licenses_count,
'accessories_count' => (int) $user->accessories_count, 'accessories_count' => (int) $user->accessories_count,

View file

@ -389,7 +389,11 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
} }
/** /**
* Check whether two-factor authorization is required and the user has activated it * Check whether two-factor authorization is requiredfor this user
*
* 0 = 2FA disabled
* 1 = 2FA optional
* 2 = 2FA universally required
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0] * @since [v4.0]
@ -398,10 +402,45 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
*/ */
public function two_factor_active () { public function two_factor_active () {
if (Setting::getSettings()->two_factor_enabled !='0') { // If the 2FA is optional and the user has opted in
if (($this->two_factor_optin =='1') && ($this->two_factor_enrolled)) { if ((Setting::getSettings()->two_factor_enabled =='1') && ($this->two_factor_optin =='1'))
{
return true; return true;
} }
// If the 2FA is required for everyone so is implicitly active
elseif (Setting::getSettings()->two_factor_enabled =='2')
{
return true;
}
return false;
}
/**
* Check whether two-factor authorization is required and the user has activated it
* and enrolled a device
*
* 0 = 2FA disabled
* 1 = 2FA optional
* 2 = 2FA universally required
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.6.14]
*
* @return bool
*/
public function two_factor_active_and_enrolled () {
// If the 2FA is optional and the user has opted in and is enrolled
if ((Setting::getSettings()->two_factor_enabled =='1') && ($this->two_factor_optin =='1') && ($this->two_factor_enrolled =='1'))
{
return true;
}
// If the 2FA is required for everyone and the user has enrolled
elseif ((Setting::getSettings()->two_factor_enabled =='2') && ($this->two_factor_enrolled))
{
return true;
} }
return false; return false;

View file

@ -53,7 +53,7 @@ abstract class SnipePermissionsPolicy
/** /**
* Determine whether the user can view the accessory. * Determine whether the user can view the accessory.
* *
* @param \App\User $user * @param \App\Models\User $user
* @return mixed * @return mixed
*/ */
public function view(User $user, $item = null) public function view(User $user, $item = null)
@ -64,7 +64,7 @@ abstract class SnipePermissionsPolicy
/** /**
* Determine whether the user can create accessories. * Determine whether the user can create accessories.
* *
* @param \App\User $user * @param \App\Models\User $user
* @return mixed * @return mixed
*/ */
public function create(User $user) public function create(User $user)
@ -75,7 +75,7 @@ abstract class SnipePermissionsPolicy
/** /**
* Determine whether the user can update the accessory. * Determine whether the user can update the accessory.
* *
* @param \App\User $user * @param \App\Models\User $user
* @return mixed * @return mixed
*/ */
public function update(User $user, $item = null) public function update(User $user, $item = null)
@ -86,7 +86,7 @@ abstract class SnipePermissionsPolicy
/** /**
* Determine whether the user can delete the accessory. * Determine whether the user can delete the accessory.
* *
* @param \App\User $user * @param \App\Models\User $user
* @return mixed * @return mixed
*/ */
public function delete(User $user, $item = null) public function delete(User $user, $item = null)
@ -97,11 +97,13 @@ abstract class SnipePermissionsPolicy
/** /**
* Determine whether the user can manage the accessory. * Determine whether the user can manage the accessory.
* *
* @param \App\User $user * @param \App\Models\User $user
* @return mixed * @return mixed
*/ */
public function manage(User $user, $item = null) public function manage(User $user, $item = null)
{ {
return $user->hasAccess($this->columnName().'.edit'); return $user->hasAccess($this->columnName().'.edit');
} }
} }

View file

@ -226,14 +226,14 @@ class UserPresenter extends Presenter
[ [
"field" => "two_factor_enrolled", "field" => "two_factor_enrolled",
"searchable" => false, "searchable" => false,
"sortable" => false, "sortable" => true,
"switchable" => true, "switchable" => true,
"title" => trans('admin/users/general.two_factor_enrolled'), "title" => trans('admin/users/general.two_factor_enrolled'),
"visible" => false, "visible" => false,
'formatter' => 'trueFalseFormatter' 'formatter' => 'trueFalseFormatter'
], ],
[ [
"field" => "two_factor_active", "field" => "two_factor_activated",
"searchable" => false, "searchable" => false,
"sortable" => false, "sortable" => false,
"switchable" => true, "switchable" => true,
@ -246,7 +246,7 @@ class UserPresenter extends Presenter
"searchable" => false, "searchable" => false,
"sortable" => true, "sortable" => true,
"switchable" => true, "switchable" => true,
"title" => trans('general.activated'), "title" => trans('general.login_enabled'),
"visible" => true, "visible" => true,
'formatter' => 'trueFalseFormatter' 'formatter' => 'trueFalseFormatter'
], ],

View file

@ -113,6 +113,14 @@ class AuthServiceProvider extends ServiceProvider
}); });
// Can the user import CSVs?
Gate::define('import', function ($user) {
if ($user->hasAccess('import') ) {
return true;
}
});
# ----------------------------------------- # -----------------------------------------
# Reports # Reports
# ----------------------------------------- # -----------------------------------------

View file

@ -27,6 +27,15 @@ return array(
) )
), ),
'CSV Import' => array(
array(
'permission' => 'import',
'label' => '',
'note' => 'This will allow users to import even if access to users, assets, etc is denied elsewhere.',
'display' => true,
)
),
'Reports' => array( 'Reports' => array(
array( array(
'permission' => 'reports.view', 'permission' => 'reports.view',

View file

@ -221,4 +221,5 @@
'zip' => 'Zip', 'zip' => 'Zip',
'noimage' => 'No image uploaded or image not found.', 'noimage' => 'No image uploaded or image not found.',
'token_expired' => 'Your form session has expired. Please try again.', 'token_expired' => 'Your form session has expired. Please try again.',
'login_enabled' => 'Login Enabled',
]; ];

View file

@ -520,7 +520,7 @@
</a> </a>
</li> </li>
@endcan @endcan
@can('create', \App\Models\Asset::class) @can('import')
<li{!! (Request::is('import/*') ? ' class="active"' : '') !!}> <li{!! (Request::is('import/*') ? ' class="active"' : '') !!}>
<a href="{{ route('imports.index') }}"> <a href="{{ route('imports.index') }}">
<i class="fa fa-cloud-download"></i> <i class="fa fa-cloud-download"></i>

View file

@ -127,22 +127,22 @@
<table class="table table-striped"> <table class="table table-striped">
@if (!is_null($user->company)) @if (!is_null($user->company))
<tr> <tr>
<td>{{ trans('general.company') }}</td> <td class="text-nowrap">{{ trans('general.company') }}</td>
<td>{{ $user->company->name }}</td> <td>{{ $user->company->name }}</td>
</tr> </tr>
@endif @endif
<tr> <tr>
<td>{{ trans('admin/users/table.name') }}</td> <td class="text-nowrap">{{ trans('admin/users/table.name') }}</td>
<td>{{ $user->present()->fullName() }}</td> <td>{{ $user->present()->fullName() }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ trans('admin/users/table.username') }}</td> <td class="text-nowrap">{{ trans('admin/users/table.username') }}</td>
<td>{{ $user->username }}</td> <td>{{ $user->username }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ trans('general.groups') }}</td> <td class="text-nowrap">{{ trans('general.groups') }}</td>
<td> <td>
@if ($user->groups->count() > 0) @if ($user->groups->count() > 0)
@foreach ($user->groups as $group) @foreach ($user->groups as $group)
@ -164,21 +164,21 @@
@if ($user->jobtitle) @if ($user->jobtitle)
<tr> <tr>
<td>{{ trans('admin/users/table.job') }}</td> <td class="text-nowrap">{{ trans('admin/users/table.job') }}</td>
<td>{{ $user->jobtitle }}</td> <td>{{ $user->jobtitle }}</td>
</tr> </tr>
@endif @endif
@if ($user->employee_num) @if ($user->employee_num)
<tr> <tr>
<td>{{ trans('admin/users/table.employee_num') }}</td> <td class="text-nowrap">{{ trans('admin/users/table.employee_num') }}</td>
<td>{{ $user->employee_num }}</td> <td>{{ $user->employee_num }}</td>
</tr> </tr>
@endif @endif
@if ($user->manager) @if ($user->manager)
<tr> <tr>
<td>{{ trans('admin/users/table.manager') }}</td> <td class="text-nowrap">{{ trans('admin/users/table.manager') }}</td>
<td> <td>
<a href="{{ route('users.show', $user->manager->id) }}">{{ $user->manager->getFullNameAttribute() }}</a> <a href="{{ route('users.show', $user->manager->id) }}">{{ $user->manager->getFullNameAttribute() }}</a>
@ -188,21 +188,21 @@
@if ($user->email) @if ($user->email)
<tr> <tr>
<td>{{ trans('admin/users/table.email') }}</td> <td class="text-nowrap">{{ trans('admin/users/table.email') }}</td>
<td><a href="mailto:{{ $user->email }}">{{ $user->email }}</a></td> <td><a href="mailto:{{ $user->email }}">{{ $user->email }}</a></td>
</tr> </tr>
@endif @endif
@if ($user->phone) @if ($user->phone)
<tr> <tr>
<td>{{ trans('admin/users/table.phone') }}</td> <td class="text-nowrap">{{ trans('admin/users/table.phone') }}</td>
<td><a href="tel:{{ $user->phone }}">{{ $user->phone }}</a></td> <td><a href="tel:{{ $user->phone }}">{{ $user->phone }}</a></td>
</tr> </tr>
@endif @endif
@if ($user->userloc) @if ($user->userloc)
<tr> <tr>
<td>{{ trans('admin/users/table.location') }}</td> <td class="text-nowrap">{{ trans('admin/users/table.location') }}</td>
<td>{{ link_to_route('locations.show', $user->userloc->name, [$user->userloc->id]) }}</td> <td>{{ link_to_route('locations.show', $user->userloc->name, [$user->userloc->id]) }}</td>
@ -210,14 +210,14 @@
@endif @endif
@if ($user->last_login) @if ($user->last_login)
<tr> <tr>
<td>{{ trans('general.last_login') }}</td> <td class="text-nowrap">{{ trans('general.last_login') }}</td>
<td>{{ \App\Helpers\Helper::getFormattedDateObject($user->last_login, 'datetime', false) }}</td> <td>{{ \App\Helpers\Helper::getFormattedDateObject($user->last_login, 'datetime', false) }}</td>
</tr> </tr>
@endif @endif
@if (!is_null($user->department)) @if (!is_null($user->department))
<tr> <tr>
<td>{{ trans('general.department') }}</td> <td class="text-nowrap">{{ trans('general.department') }}</td>
<td><a href="{{ route('departments.show', $user->department) }}">{{ $user->department->name }}</a></td> <td><a href="{{ route('departments.show', $user->department) }}">{{ $user->department->name }}</a></td>
</tr> </tr>
@endif @endif
@ -227,6 +227,45 @@
<td>{{ $user->created_at->format('F j, Y h:iA') }}</td> <td>{{ $user->created_at->format('F j, Y h:iA') }}</td>
</tr> </tr>
@endif @endif
<tr>
<td class="text-nowrap">{{ trans('general.login_enabled') }}</td>
<td>{{ ($user->activated=='1') ? trans('general.yes') : trans('general.no') }}</td>
</tr>
@if ($user->activated=='1')
<tr>
<td class="text-nowrap">{{ trans('admin/users/general.two_factor_active') }}</td>
<td>{{ ($user->two_factor_active()) ? trans('general.yes') : trans('general.no') }}</td>
</tr>
<tr>
<td class="text-nowrap">{{ trans('admin/users/general.two_factor_enrolled') }}</td>
<td class="two_factor_resetrow">
<div class="row">
<div class="col-md-1" id="two_factor_reset_toggle">
{{ ($user->two_factor_active_and_enrolled()) ? trans('general.yes') : trans('general.no') }}
</div>
@if ((Auth::user()->isSuperUser()) && ($snipeSettings->two_factor_enabled!='0'))
<div class="col-md-11">
<a class="btn btn-default btn-sm pull-left" id="two_factor_reset" style="margin-right: 10px;"> {{ trans('admin/settings/general.two_factor_reset') }}</a>
<span id="two_factor_reseticon">
</span>
<span id="two_factor_resetresult">
</span>
<span id="two_factor_resetstatus">
</span>
<br><br><p class="help-block">{{ trans('admin/settings/general.two_factor_reset_help') }}</p>
</div>
</div>
@endif
</td>
</tr>
@endif
</table> </table>
</div> </div>
</div> <!--/col-md-8--> </div> <!--/col-md-8-->
@ -542,6 +581,40 @@
@include ('partials.bootstrap-table', ['simple_view' => true]) @include ('partials.bootstrap-table', ['simple_view' => true])
<script nonce="{{ csrf_token() }}"> <script nonce="{{ csrf_token() }}">
$(function () { $(function () {
$("#two_factor_reset").click(function(){
$("#two_factor_resetrow").removeClass('success');
$("#two_factor_resetrow").removeClass('danger');
$("#two_factor_resetstatus").html('');
$("#two_factor_reseticon").html('<i class="fa fa-spinner spin"></i>');
$.ajax({
url: '{{ route('api.users.two_factor_reset', ['id'=> $user->id]) }}',
type: 'POST',
data: {},
headers: {
"X-Requested-With": 'XMLHttpRequest',
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
},
dataType: 'json',
success: function (data) {
$("#two_factor_reset_toggle").html('').html('{{ trans('general.no') }}');
$("#two_factor_reseticon").html('');
$("#two_factor_resetstatus").html('<i class="fa fa-check text-success"></i>' + data.message);
},
error: function (data) {
$("#two_factor_reseticon").html('');
$("#two_factor_reseticon").html('<i class="fa fa-exclamation-triangle text-danger"></i>');
$('#two_factor_resetstatus').text(data.message);
}
});
});
//binds to onchange event of your input field //binds to onchange event of your input field
var uploadedFileSize = 0; var uploadedFileSize = 0;
$('#fileupload').bind('change', function() { $('#fileupload').bind('change', function() {