mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
Merge branch 'hotfixes/export_all_users' into develop
This commit is contained in:
commit
d24c4b1152
|
@ -14,6 +14,7 @@ use App\Models\Setting;
|
||||||
use App\Models\Statuslabel;
|
use App\Models\Statuslabel;
|
||||||
use App\Http\Requests\SaveUserRequest;
|
use App\Http\Requests\SaveUserRequest;
|
||||||
use App\Http\Requests\UpdateUserRequest;
|
use App\Http\Requests\UpdateUserRequest;
|
||||||
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Ldap;
|
use App\Models\Ldap;
|
||||||
use Auth;
|
use Auth;
|
||||||
|
@ -1278,4 +1279,87 @@ class UsersController extends Controller
|
||||||
$assets = Asset::where('assigned_to', '=', $userId)->with('model')->get();
|
$assets = Asset::where('assigned_to', '=', $userId)->with('model')->get();
|
||||||
return response()->json($assets);
|
return response()->json($assets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exports users to CSV
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v3.5]
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function getExportUserCsv()
|
||||||
|
{
|
||||||
|
|
||||||
|
\Debugbar::disable();
|
||||||
|
|
||||||
|
|
||||||
|
$response = new StreamedResponse(function() {
|
||||||
|
// Open output stream
|
||||||
|
$handle = fopen('php://output', 'w');
|
||||||
|
|
||||||
|
User::with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'groups', 'userloc', 'company','throttle')->orderBy('created_at', 'DESC')->chunk(500, function($users) use($handle) {
|
||||||
|
$headers=[
|
||||||
|
// strtolower to prevent Excel from trying to open it as a SYLK file
|
||||||
|
strtolower(trans('general.id')),
|
||||||
|
trans('general.company'),
|
||||||
|
trans('admin/companies/table.title'),
|
||||||
|
trans('admin/users/table.employee_num'),
|
||||||
|
trans('admin/users/table.name'),
|
||||||
|
trans('admin/users/table.email'),
|
||||||
|
trans('admin/users/table.manager'),
|
||||||
|
trans('admin/users/table.location'),
|
||||||
|
trans('general.assets'),
|
||||||
|
trans('general.licenses'),
|
||||||
|
trans('general.accessories'),
|
||||||
|
trans('general.consumables'),
|
||||||
|
trans('admin/users/table.groups'),
|
||||||
|
trans('general.notes'),
|
||||||
|
trans('admin/users/table.activated'),
|
||||||
|
trans('general.created_at')
|
||||||
|
];
|
||||||
|
|
||||||
|
fputcsv($handle, $headers);
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$user_groups = '';
|
||||||
|
|
||||||
|
foreach ($user->groups as $user_group) {
|
||||||
|
$user_groups .= $user_group->name.', ';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a new row with data
|
||||||
|
$values = [
|
||||||
|
$user->id,
|
||||||
|
($user->company) ? $user->company->name : '',
|
||||||
|
$user->title,
|
||||||
|
$user->employee_num,
|
||||||
|
$user->fullName(),
|
||||||
|
$user->email,
|
||||||
|
($user->manager) ? $user->manager->fullName() : '',
|
||||||
|
($user->location) ? $user->location->name : '',
|
||||||
|
$user->assets->count(),
|
||||||
|
$user->licenses->count(),
|
||||||
|
$user->accessories->count(),
|
||||||
|
$user->consumables->count(),
|
||||||
|
$user_groups,
|
||||||
|
$user->notes,
|
||||||
|
($user->activated=='1') ? trans('general.yes') : trans('general.no'),
|
||||||
|
$user->created_at,
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
fputcsv($handle, $values);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Close the output stream
|
||||||
|
fclose($handle);
|
||||||
|
}, 200, [
|
||||||
|
'Content-Type' => 'text/csv',
|
||||||
|
'Content-Disposition' => 'attachment; filename="users-'.date('Y-m-d-his').'.csv"',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -774,6 +774,7 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function ()
|
||||||
Route::post('create', [ 'uses' => 'UsersController@postCreate', 'middleware' => ['authorize:users.edit'] ]);
|
Route::post('create', [ 'uses' => 'UsersController@postCreate', 'middleware' => ['authorize:users.edit'] ]);
|
||||||
Route::get('import', [ 'as' => 'import/user', 'uses' => 'UsersController@getImport', 'middleware' => ['authorize:users.edit'] ]);
|
Route::get('import', [ 'as' => 'import/user', 'uses' => 'UsersController@getImport', 'middleware' => ['authorize:users.edit'] ]);
|
||||||
Route::post('import', [ 'uses' => 'UsersController@postImport', 'middleware' => ['authorize:users.edit'] ]);
|
Route::post('import', [ 'uses' => 'UsersController@postImport', 'middleware' => ['authorize:users.edit'] ]);
|
||||||
|
Route::get('export', [ 'uses' => 'UsersController@getExportUserCsv', 'middleware' => ['authorize:users.view'] ]);
|
||||||
Route::get('{userId}/edit', [ 'as' => 'update/user', 'uses' => 'UsersController@getEdit', 'middleware' => ['authorize:users.edit'] ]);
|
Route::get('{userId}/edit', [ 'as' => 'update/user', 'uses' => 'UsersController@getEdit', 'middleware' => ['authorize:users.edit'] ]);
|
||||||
Route::post('{userId}/edit', [ 'uses' => 'UsersController@postEdit', 'middleware' => ['authorize:users.edit'] ]);
|
Route::post('{userId}/edit', [ 'uses' => 'UsersController@postEdit', 'middleware' => ['authorize:users.edit'] ]);
|
||||||
Route::get('{userId}/clone', [ 'as' => 'clone/user', 'uses' => 'UsersController@getClone', 'middleware' => ['authorize:users.edit'] ]);
|
Route::get('{userId}/clone', [ 'as' => 'clone/user', 'uses' => 'UsersController@getClone', 'middleware' => ['authorize:users.edit'] ]);
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
@else
|
@else
|
||||||
<a class="btn btn-default pull-right" href="{{ URL::to('admin/users?status=deleted') }}" style="margin-right: 5px;">{{ trans('admin/users/table.show_deleted') }}</a>
|
<a class="btn btn-default pull-right" href="{{ URL::to('admin/users?status=deleted') }}" style="margin-right: 5px;">{{ trans('admin/users/table.show_deleted') }}</a>
|
||||||
@endif
|
@endif
|
||||||
|
@can('users.view')
|
||||||
|
<a class="btn btn-default pull-right" href="{{ URL::to('admin/users/export') }}" style="margin-right: 5px;">Export</a>
|
||||||
|
@endcan
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
|
@ -80,7 +83,7 @@
|
||||||
<th data-switchable="true" data-sortable="true" data-field="employee_num" data-visible="false">{{ trans('admin/users/table.employee_num') }}</th>
|
<th data-switchable="true" data-sortable="true" data-field="employee_num" data-visible="false">{{ trans('admin/users/table.employee_num') }}</th>
|
||||||
<th data-sortable="true" data-field="name">{{ trans('admin/users/table.name') }}</th>
|
<th data-sortable="true" data-field="name">{{ trans('admin/users/table.name') }}</th>
|
||||||
<th data-sortable="true" data-field="email">
|
<th data-sortable="true" data-field="email">
|
||||||
<span class="hidden-md hidden-lg">Email</span>
|
<span class="hidden-md hidden-lg">{{ trans('admin/users/table.email') }}</span>
|
||||||
<span class="hidden-xs"><i class="fa fa-envelope fa-lg"></i></span>
|
<span class="hidden-xs"><i class="fa fa-envelope fa-lg"></i></span>
|
||||||
</th>
|
</th>
|
||||||
<th data-sortable="true" data-field="username">{{ trans('admin/users/table.username') }}</th>
|
<th data-sortable="true" data-field="username">{{ trans('admin/users/table.username') }}</th>
|
||||||
|
|
Loading…
Reference in a new issue