Merge remote-tracking branch 'origin/develop'

Signed-off-by: snipe <snipe@snipe.net>

# Conflicts:
#	public/css/build/app.css
#	public/css/build/overrides.css
#	public/css/dist/all.css
#	public/mix-manifest.json
This commit is contained in:
snipe 2024-03-18 12:32:22 +00:00
commit 7070bad53b
27 changed files with 465 additions and 2317 deletions

View file

@ -8,6 +8,12 @@ use \App\Helpers\Helper;
class CheckLocale
{
private function warn_legacy_locale($language, $source)
{
if ($language != Helper::mapLegacyLocale($language)) {
\Log::warning("$source $language and should be updated to be ".Helper::mapLegacyLocale($language));
}
}
/**
* Handle the locale for the user, default to settings otherwise.
*
@ -22,24 +28,23 @@ class CheckLocale
// Default app settings from config
$language = config('app.locale');
$this->warn_legacy_locale($language, "APP_LOCALE in .env is set to");
if ($settings = Setting::getSettings()) {
// User's preference
if (($request->user()) && ($request->user()->locale)) {
$language = $request->user()->locale;
$this->warn_legacy_locale($language, "username ".$request->user()->username." (".$request->user()->id.") has a language");
// App setting preference
} elseif ($settings->locale != '') {
$language = $settings->locale;
$this->warn_legacy_locale($language, "App Settings is set to");
}
}
if (config('app.locale') != Helper::mapLegacyLocale($language)) {
\Log::warning('Your current APP_LOCALE in your .env is set to "'.config('app.locale').'" and should be updated to be "'.Helper::mapLegacyLocale($language).'" in '.base_path().'/.env. Translations may display unexpectedly until this is updated.');
}
\App::setLocale(Helper::mapLegacyLocale($language));
return $next($request);
}

View file

@ -58,7 +58,6 @@
"league/flysystem-aws-s3-v3": "^1.0",
"league/flysystem-cached-adapter": "^1.1",
"livewire/livewire": "^2.4",
"mediconesystems/livewire-datatables": "^0.5.0",
"neitanod/forceutf8": "^2.0",
"nesbot/carbon": "^2.32",
"nunomaduro/collision": "^5.4",

542
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9cca85cd0074df9154765b1ab52f83fa",
"content-hash": "0536c48de3ba12fdeb01bac07fcd7172",
"packages": [
{
"name": "alek13/slack",
@ -2165,57 +2165,6 @@
},
"time": "2019-12-30T22:54:17+00:00"
},
{
"name": "ezyang/htmlpurifier",
"version": "v4.14.0",
"source": {
"type": "git",
"url": "https://github.com/ezyang/htmlpurifier.git",
"reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/12ab42bd6e742c70c0a52f7b82477fcd44e64b75",
"reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75",
"shasum": ""
},
"require": {
"php": ">=5.2"
},
"type": "library",
"autoload": {
"files": [
"library/HTMLPurifier.composer.php"
],
"psr-0": {
"HTMLPurifier": "library/"
},
"exclude-from-classmap": [
"/library/HTMLPurifier/Language/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1-or-later"
],
"authors": [
{
"name": "Edward Z. Yang",
"email": "admin@htmlpurifier.org",
"homepage": "http://ezyang.com"
}
],
"description": "Standards compliant HTML filter written in PHP",
"homepage": "http://htmlpurifier.org/",
"keywords": [
"html"
],
"support": {
"issues": "https://github.com/ezyang/htmlpurifier/issues",
"source": "https://github.com/ezyang/htmlpurifier/tree/v4.14.0"
},
"time": "2021-12-25T01:21:49+00:00"
},
{
"name": "facade/flare-client-php",
"version": "1.9.1",
@ -5133,268 +5082,6 @@
],
"time": "2022-06-19T02:54:20+00:00"
},
{
"name": "maatwebsite/excel",
"version": "3.1.40",
"source": {
"type": "git",
"url": "https://github.com/SpartnerNL/Laravel-Excel.git",
"reference": "8a54972e3d616c74687c3cbff15765555761885c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/8a54972e3d616c74687c3cbff15765555761885c",
"reference": "8a54972e3d616c74687c3cbff15765555761885c",
"shasum": ""
},
"require": {
"ext-json": "*",
"illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0",
"php": "^7.0|^8.0",
"phpoffice/phpspreadsheet": "^1.18"
},
"require-dev": {
"orchestra/testbench": "^6.0|^7.0",
"predis/predis": "^1.1"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Maatwebsite\\Excel\\ExcelServiceProvider"
],
"aliases": {
"Excel": "Maatwebsite\\Excel\\Facades\\Excel"
}
}
},
"autoload": {
"psr-4": {
"Maatwebsite\\Excel\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Patrick Brouwers",
"email": "patrick@spartner.nl"
}
],
"description": "Supercharged Excel exports and imports in Laravel",
"keywords": [
"PHPExcel",
"batch",
"csv",
"excel",
"export",
"import",
"laravel",
"php",
"phpspreadsheet"
],
"support": {
"issues": "https://github.com/SpartnerNL/Laravel-Excel/issues",
"source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.40"
},
"funding": [
{
"url": "https://laravel-excel.com/commercial-support",
"type": "custom"
},
{
"url": "https://github.com/patrickbrouwers",
"type": "github"
}
],
"time": "2022-05-02T13:50:01+00:00"
},
{
"name": "maennchen/zipstream-php",
"version": "2.2.1",
"source": {
"type": "git",
"url": "https://github.com/maennchen/ZipStream-PHP.git",
"reference": "211e9ba1530ea5260b45d90c9ea252f56ec52729"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/211e9ba1530ea5260b45d90c9ea252f56ec52729",
"reference": "211e9ba1530ea5260b45d90c9ea252f56ec52729",
"shasum": ""
},
"require": {
"myclabs/php-enum": "^1.5",
"php": "^7.4 || ^8.0",
"psr/http-message": "^1.0",
"symfony/polyfill-mbstring": "^1.0"
},
"require-dev": {
"ext-zip": "*",
"guzzlehttp/guzzle": "^6.5.3 || ^7.2.0",
"mikey179/vfsstream": "^1.6",
"php-coveralls/php-coveralls": "^2.4",
"phpunit/phpunit": "^8.5.8 || ^9.4.2",
"vimeo/psalm": "^4.1"
},
"type": "library",
"autoload": {
"psr-4": {
"ZipStream\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paul Duncan",
"email": "pabs@pablotron.org"
},
{
"name": "Jonatan Männchen",
"email": "jonatan@maennchen.ch"
},
{
"name": "Jesse Donat",
"email": "donatj@gmail.com"
},
{
"name": "András Kolesár",
"email": "kolesar@kolesar.hu"
}
],
"description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
"keywords": [
"stream",
"zip"
],
"support": {
"issues": "https://github.com/maennchen/ZipStream-PHP/issues",
"source": "https://github.com/maennchen/ZipStream-PHP/tree/2.2.1"
},
"funding": [
{
"url": "https://github.com/maennchen",
"type": "github"
},
{
"url": "https://opencollective.com/zipstream",
"type": "open_collective"
}
],
"time": "2022-05-18T15:52:06+00:00"
},
{
"name": "markbaker/complex",
"version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/MarkBaker/PHPComplex.git",
"reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/ab8bc271e404909db09ff2d5ffa1e538085c0f22",
"reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"phpcompatibility/php-compatibility": "^9.0",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.3",
"squizlabs/php_codesniffer": "^3.4"
},
"type": "library",
"autoload": {
"psr-4": {
"Complex\\": "classes/src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Baker",
"email": "mark@lange.demon.co.uk"
}
],
"description": "PHP Class for working with complex numbers",
"homepage": "https://github.com/MarkBaker/PHPComplex",
"keywords": [
"complex",
"mathematics"
],
"support": {
"issues": "https://github.com/MarkBaker/PHPComplex/issues",
"source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.1"
},
"time": "2021-06-29T15:32:53+00:00"
},
{
"name": "markbaker/matrix",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/MarkBaker/PHPMatrix.git",
"reference": "c66aefcafb4f6c269510e9ac46b82619a904c576"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/c66aefcafb4f6c269510e9ac46b82619a904c576",
"reference": "c66aefcafb4f6c269510e9ac46b82619a904c576",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"phpcompatibility/php-compatibility": "^9.0",
"phpdocumentor/phpdocumentor": "2.*",
"phploc/phploc": "^4.0",
"phpmd/phpmd": "2.*",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.3",
"sebastian/phpcpd": "^4.0",
"squizlabs/php_codesniffer": "^3.4"
},
"type": "library",
"autoload": {
"psr-4": {
"Matrix\\": "classes/src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Baker",
"email": "mark@demon-angel.eu"
}
],
"description": "PHP Class for working with matrices",
"homepage": "https://github.com/MarkBaker/PHPMatrix",
"keywords": [
"mathematics",
"matrix",
"vector"
],
"support": {
"issues": "https://github.com/MarkBaker/PHPMatrix/issues",
"source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.0"
},
"time": "2021-07-01T19:01:15+00:00"
},
{
"name": "masterminds/html5",
"version": "2.8.1",
@ -5528,69 +5215,6 @@
},
"time": "2021-12-27T18:49:48+00:00"
},
{
"name": "mediconesystems/livewire-datatables",
"version": "v0.5.4",
"source": {
"type": "git",
"url": "https://github.com/MedicOneSystems/livewire-datatables.git",
"reference": "bf6f24d529208e6bdec58276e92792719c73c827"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MedicOneSystems/livewire-datatables/zipball/bf6f24d529208e6bdec58276e92792719c73c827",
"reference": "bf6f24d529208e6bdec58276e92792719c73c827",
"shasum": ""
},
"require": {
"illuminate/support": "^7.0|^8.0",
"livewire/livewire": "^1.2|^2.0",
"maatwebsite/excel": "^3.1",
"php": "^7.2.5|^8.0"
},
"require-dev": {
"laravel/legacy-factories": "^1.0.4",
"orchestra/testbench": "^4.0|5.0|6.0",
"phpunit/phpunit": "^8.0|9.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Mediconesystems\\LivewireDatatables\\LivewireDatatablesServiceProvider"
],
"aliases": {
"LivewireDatatables": "Mediconesystems\\LivewireDatatables\\LivewireDatatablesFacade"
}
}
},
"autoload": {
"psr-4": {
"Mediconesystems\\LivewireDatatables\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Salmon",
"email": "mark.salmon@mediconesystems.com",
"role": "Developer"
}
],
"homepage": "https://github.com/mediconesystems/livewire-datatables",
"keywords": [
"livewire-datatables",
"mediconesystems"
],
"support": {
"issues": "https://github.com/MedicOneSystems/livewire-datatables/issues",
"source": "https://github.com/MedicOneSystems/livewire-datatables/tree/v0.5.4"
},
"time": "2021-08-09T20:37:55+00:00"
},
{
"name": "monolog/monolog",
"version": "2.7.0",
@ -5761,66 +5385,6 @@
},
"time": "2023-08-25T10:54:48+00:00"
},
{
"name": "myclabs/php-enum",
"version": "1.8.3",
"source": {
"type": "git",
"url": "https://github.com/myclabs/php-enum.git",
"reference": "b942d263c641ddb5190929ff840c68f78713e937"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/php-enum/zipball/b942d263c641ddb5190929ff840c68f78713e937",
"reference": "b942d263c641ddb5190929ff840c68f78713e937",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": "^7.3 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "1.*",
"vimeo/psalm": "^4.6.2"
},
"type": "library",
"autoload": {
"psr-4": {
"MyCLabs\\Enum\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP Enum contributors",
"homepage": "https://github.com/myclabs/php-enum/graphs/contributors"
}
],
"description": "PHP Enum implementation",
"homepage": "http://github.com/myclabs/php-enum",
"keywords": [
"enum"
],
"support": {
"issues": "https://github.com/myclabs/php-enum/issues",
"source": "https://github.com/myclabs/php-enum/tree/1.8.3"
},
"funding": [
{
"url": "https://github.com/mnapoli",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/myclabs/php-enum",
"type": "tidelift"
}
],
"time": "2021-07-05T08:18:36+00:00"
},
{
"name": "neitanod/forceutf8",
"version": "v2.0.4",
@ -6960,110 +6524,6 @@
},
"time": "2022-03-15T21:29:03+00:00"
},
{
"name": "phpoffice/phpspreadsheet",
"version": "1.24.1",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
"reference": "69991111e05fca3ff7398e1e7fca9ebed33efec6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/69991111e05fca3ff7398e1e7fca9ebed33efec6",
"reference": "69991111e05fca3ff7398e1e7fca9ebed33efec6",
"shasum": ""
},
"require": {
"ext-ctype": "*",
"ext-dom": "*",
"ext-fileinfo": "*",
"ext-gd": "*",
"ext-iconv": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"ext-xml": "*",
"ext-xmlreader": "*",
"ext-xmlwriter": "*",
"ext-zip": "*",
"ext-zlib": "*",
"ezyang/htmlpurifier": "^4.13",
"maennchen/zipstream-php": "^2.1",
"markbaker/complex": "^3.0",
"markbaker/matrix": "^3.0",
"php": "^7.3 || ^8.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/simple-cache": "^1.0 || ^2.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
"dompdf/dompdf": "^1.0 || ^2.0",
"friendsofphp/php-cs-fixer": "^3.2",
"jpgraph/jpgraph": "^4.0",
"mpdf/mpdf": "8.1.1",
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^8.5 || ^9.0",
"squizlabs/php_codesniffer": "^3.7",
"tecnickcom/tcpdf": "^6.4"
},
"suggest": {
"dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)",
"jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers",
"mpdf/mpdf": "Option for rendering PDF with PDF Writer",
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)"
},
"type": "library",
"autoload": {
"psr-4": {
"PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Maarten Balliauw",
"homepage": "https://blog.maartenballiauw.be"
},
{
"name": "Mark Baker",
"homepage": "https://markbakeruk.net"
},
{
"name": "Franck Lefevre",
"homepage": "https://rootslabs.net"
},
{
"name": "Erik Tilt"
},
{
"name": "Adrien Crivelli"
}
],
"description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine",
"homepage": "https://github.com/PHPOffice/PhpSpreadsheet",
"keywords": [
"OpenXML",
"excel",
"gnumeric",
"ods",
"php",
"spreadsheet",
"xls",
"xlsx"
],
"support": {
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.24.1"
},
"time": "2022-07-18T19:50:48+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.8.1",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,8 @@
{
"/js/build/app.js": "/js/build/app.js?id=6bbc4dd6b643fefe492261fdfe6fae5a",
"/css/dist/skins/skin-blue.css": "/css/dist/skins/skin-blue.css?id=392cc93cfc0be0349bab9697669dd091",
"/css/build/overrides.css": "/css/build/overrides.css?id=6a7f37afafaaf9ccea99a7391cdf02b2",
"/css/build/app.css": "/css/build/app.css?id=ea3875faceb1d09c162d00fbf5b4df57",
"/css/build/overrides.css": "/css/build/overrides.css?id=87c4587df4ab5c64e0e3ee920310ba2a",
"/css/build/app.css": "/css/build/app.css?id=28a7726dc9fa61365d36ed7067461490",
"/css/build/AdminLTE.css": "/css/build/AdminLTE.css?id=f25c77ed07053646a42e9c19923d24fa",
"/css/dist/skins/skin-orange.css": "/css/dist/skins/skin-orange.css?id=268041e902b019730c23ee3875838005",
"/css/dist/skins/skin-orange-dark.css": "/css/dist/skins/skin-orange-dark.css?id=d409d9b1a3b69247df8b98941ba06e33",
@ -18,7 +18,7 @@
"/css/dist/skins/skin-green.css": "/css/dist/skins/skin-green.css?id=b48f4d8af0e1ca5621c161e93951109f",
"/css/dist/skins/skin-contrast.css": "/css/dist/skins/skin-contrast.css?id=f0fbbb0ac729ea092578fb05ca615460",
"/css/dist/skins/skin-red.css": "/css/dist/skins/skin-red.css?id=b9a74ec0cd68f83e7480d5ae39919beb",
"/css/dist/all.css": "/css/dist/all.css?id=2ef1965d45a0a72336dd8e9b93f82d80",
"/css/dist/all.css": "/css/dist/all.css?id=532efb2074799739e7924d4d15cbeb48",
"/css/dist/signature-pad.css": "/css/dist/signature-pad.css?id=6a89d3cd901305e66ced1cf5f13147f7",
"/css/dist/signature-pad.min.css": "/css/dist/signature-pad.min.css?id=6a89d3cd901305e66ced1cf5f13147f7",
"/css/webfonts/fa-brands-400.ttf": "/css/webfonts/fa-brands-400.ttf?id=69e5d8e4e818f05fd882cceb758d1eba",

View file

@ -888,3 +888,6 @@ input[type="radio"]:checked::before {
.separator:not(:empty)::after {
margin-left: .25em;
}
.datepicker.dropdown-menu {
z-index: 1030 !important;
}

View file

@ -521,7 +521,7 @@
@else
------------
@endcan
<td>{{ $license->category->name }}</td>
<td>{{ ($license->category) ? $license->category->name : trans('general.deleted') }}</td>
</tr>
@endforeach
</tbody>

View file

@ -410,12 +410,13 @@
</div>
<div class="col-md-6{{ (($field->format=='URL') && ($asset->{$field->db_column_name()}!='')) ? ' ellipsis': '' }}">
@if (($field->field_encrypted=='1') && ($asset->{$field->db_column_name()}!=''))
<i class="fas fa-lock" data-tooltip="true" data-placement="top" title="{{ trans('admin/custom_fields/general.value_encrypted') }}"></i>
<i class="fas fa-lock" data-tooltip="true" data-placement="top" title="{{ trans('admin/custom_fields/general.value_encrypted') }}" onclick="showHideEncValue(this)" id="text-{{ $field->id }}"></i>
@endif
@if ($field->isFieldDecryptable($asset->{$field->db_column_name()} ))
@can('assets.view.encrypted_custom_fields')
<span class="js-copy-{{ $field->id }}">
<span id="text-{{ $field->id }}-to-hide">********</span>
<span class="js-copy-{{ $field->id }}" id="text-{{ $field->id }}-to-show" style="font-size: 0px;">
@if (($field->format=='URL') && ($asset->{$field->db_column_name()}!=''))
<a href="{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}" target="_new">{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}</a>
@elseif (($field->format=='DATE') && ($asset->{$field->db_column_name()}!=''))
@ -427,7 +428,7 @@
<i class="fa-regular fa-clipboard js-copy-link" data-clipboard-target=".js-copy-{{ $field->id }}" aria-hidden="true" data-tooltip="true" data-placement="top" title="{{ trans('general.copy_to_clipboard') }}">
<span class="sr-only">{{ trans('general.copy_to_clipboard') }}</span>
</i>
@else
@else
{{ strtoupper(trans('admin/custom_fields/general.encrypted')) }}
@endcan

View file

@ -964,8 +964,7 @@
var clickedElement = $(e.trigger);
// Get the target element selector from data attribute
var targetSelector = clickedElement.data('data-clipboard-target');
// Find the target element
var targetEl = $(targetSelector);
// Show the alert that the content was copied
clickedElement.tooltip('hide').attr('data-original-title', '{{ trans('general.copied') }}').tooltip('show');
});
@ -979,6 +978,23 @@
});
function showHideEncValue(e) {
// Use element id to find the text element to hide / show
var targetElement = e.id+"-to-show";
var hiddenElement = e.id+"-to-hide";
if($(e).hasClass('fa-lock')) {
$(e).removeClass('fa-lock').addClass('fa-unlock');
// Show the encrypted custom value and hide the element with asterisks
document.getElementById(targetElement).style.fontSize = "100%";
document.getElementById(hiddenElement).style.display = "none";
} else {
$(e).removeClass('fa-unlock').addClass('fa-lock');
// ClipboardJS can't copy display:none elements so use a trick to hide the value
document.getElementById(targetElement).style.fontSize = "0px";
document.getElementById(hiddenElement).style.display = "";
}
}
$(function () {
// Invoke Bootstrap 3's tooltip

View file

@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Users;
use App\Models\User;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
use Tests\Support\InteractsWithAuthentication;
class UpdateUserApiTest extends TestCase
{
use InteractsWithSettings;
use InteractsWithAuthentication;
public function testApiUsersCanBeActivatedWithNumber()
{
@ -64,5 +61,4 @@ class UpdateUserApiTest extends TestCase
$this->assertEquals(0, $user->refresh()->activated);
}
}

View file

@ -1,96 +0,0 @@
<?php
namespace Tests\Feature\Notifications;
use App\Events\CheckoutableCheckedIn;
use App\Events\CheckoutableCheckedOut;
use App\Models\Accessory;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use App\Notifications\CheckoutAccessoryNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AccessoryWebhookTest extends TestCase
{
use InteractsWithSettings;
public function testAccessoryCheckoutSendsWebhookNotificationWhenSettingEnabled()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckoutAccessoryNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
public function testAccessoryCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled()
{
Notification::fake();
$this->settings->disableWebhook();
event(new CheckoutableCheckedOut(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
}
public function testAccessoryCheckinSendsWebhookNotificationWhenSettingEnabled()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckinAccessoryNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
public function testAccessoryCheckinDoesNotSendWebhookNotificationWhenSettingDisabled()
{
Notification::fake();
$this->settings->disableWebhook();
event(new CheckoutableCheckedIn(
Accessory::factory()->appleBtKeyboard()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
}
}

View file

@ -1,163 +0,0 @@
<?php
namespace Tests\Feature\Notifications;
use App\Events\CheckoutableCheckedIn;
use App\Events\CheckoutableCheckedOut;
use App\Models\Asset;
use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAssetNotification;
use App\Notifications\CheckoutAssetNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetWebhookTest extends TestCase
{
use InteractsWithSettings;
public function targets(): array
{
return [
'Asset checked out to user' => [fn() => User::factory()->create()],
'Asset checked out to asset' => [fn() => $this->createAsset()],
'Asset checked out to location' => [fn() => Location::factory()->create()],
];
}
/** @dataProvider targets */
public function testAssetCheckoutSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut(
$this->createAsset(),
$checkoutTarget(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckoutAssetNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
/** @dataProvider targets */
public function testAssetCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
{
Notification::fake();
$this->settings->disableWebhook();
event(new CheckoutableCheckedOut(
$this->createAsset(),
$checkoutTarget(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class);
}
/** @dataProvider targets */
public function testAssetCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedIn(
$this->createAsset(),
$checkoutTarget(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckinAssetNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
/** @dataProvider targets */
public function testAssetCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
{
Notification::fake();
$this->settings->disableWebhook();
event(new CheckoutableCheckedIn(
$this->createAsset(),
$checkoutTarget(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class);
}
public function testCheckInEmailSentToUserIfSettingEnabled()
{
Notification::fake();
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => true]);
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
Notification::assertSentTo(
[$user],
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
},
);
}
public function testCheckInEmailNotSentToUserIfSettingDisabled()
{
Notification::fake();
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => false]);
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
Notification::assertNotSentTo(
[$user],
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
}
);
}
private function createAsset()
{
return Asset::factory()->laptopMbp()->create();
}
}

View file

@ -1,50 +0,0 @@
<?php
namespace Tests\Feature\Notifications;
use App\Events\CheckoutableCheckedIn;
use App\Events\CheckoutableCheckedOut;
use App\Models\Asset;
use App\Models\Component;
use App\Models\User;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class ComponentWebhookTest extends TestCase
{
use InteractsWithSettings;
public function testComponentCheckoutDoesNotSendWebhookNotification()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut(
Component::factory()->ramCrucial8()->create(),
Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNothingSent();
}
public function testComponentCheckinDoesNotSendWebhookNotification()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedIn(
Component::factory()->ramCrucial8()->create(),
Asset::factory()->laptopMbp()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNothingSent();
}
}

View file

@ -1,56 +0,0 @@
<?php
namespace Tests\Feature\Notifications;
use App\Events\CheckoutableCheckedOut;
use App\Models\Consumable;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckoutConsumableNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class ConsumableWebhookTest extends TestCase
{
use InteractsWithSettings;
public function testConsumableCheckoutSendsWebhookNotificationWhenSettingEnabled()
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckoutConsumableNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
public function testConsumableCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled()
{
Notification::fake();
$this->settings->disableWebhook();
event(new CheckoutableCheckedOut(
Consumable::factory()->cardstock()->create(),
User::factory()->create(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
}
}

View file

@ -0,0 +1,70 @@
<?php
namespace Tests\Feature\Notifications\Email;
use App\Events\CheckoutableCheckedIn;
use App\Models\Asset;
use App\Models\User;
use App\Notifications\CheckinAssetNotification;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
/**
* @group notifications
*/
class EmailNotificationsUponCheckinTest extends TestCase
{
use InteractsWithSettings;
protected function setUp(): void
{
parent::setUp();
Notification::fake();
}
public function testCheckInEmailSentToUserIfSettingEnabled()
{
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => true]);
$this->fireCheckInEvent($asset, $user);
Notification::assertSentTo(
$user,
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
},
);
}
public function testCheckInEmailNotSentToUserIfSettingDisabled()
{
$user = User::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create();
$asset->model->category->update(['checkin_email' => false]);
$this->fireCheckInEvent($asset, $user);
Notification::assertNotSentTo(
$user,
function (CheckinAssetNotification $notification, $channels) {
return in_array('mail', $channels);
}
);
}
private function fireCheckInEvent($asset, $user): void
{
event(new CheckoutableCheckedIn(
$asset,
$user,
User::factory()->checkinAssets()->create(),
''
));
}
}

View file

@ -1,109 +0,0 @@
<?php
namespace Tests\Feature\Notifications;
use App\Events\CheckoutableCheckedIn;
use App\Events\CheckoutableCheckedOut;
use App\Models\Asset;
use App\Models\LicenseSeat;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinLicenseSeatNotification;
use App\Notifications\CheckoutLicenseSeatNotification;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class LicenseWebhookTest extends TestCase
{
use InteractsWithSettings;
public function targets(): array
{
return [
'License checked out to user' => [fn() => User::factory()->create()],
'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
];
}
/** @dataProvider targets */
public function testLicenseCheckoutSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedOut(
LicenseSeat::factory()->create(),
$checkoutTarget(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckoutLicenseSeatNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
/** @dataProvider targets */
public function testLicenseCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
{
Notification::fake();
$this->settings->disableWebhook();
event(new CheckoutableCheckedOut(
LicenseSeat::factory()->create(),
$checkoutTarget(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class);
}
/** @dataProvider targets */
public function testLicenseCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
{
Notification::fake();
$this->settings->enableSlackWebhook();
event(new CheckoutableCheckedIn(
LicenseSeat::factory()->create(),
$checkoutTarget(),
User::factory()->superuser()->create(),
''
));
Notification::assertSentTo(
new AnonymousNotifiable,
CheckinLicenseSeatNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
/** @dataProvider targets */
public function testLicenseCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
{
Notification::fake();
$this->settings->disableWebhook();
event(new CheckoutableCheckedIn(
LicenseSeat::factory()->create(),
$checkoutTarget(),
User::factory()->superuser()->create(),
''
));
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinLicenseSeatNotification::class);
}
}

View file

@ -0,0 +1,148 @@
<?php
namespace Tests\Feature\Notifications\Webhooks;
use App\Events\CheckoutableCheckedIn;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Component;
use App\Models\LicenseSeat;
use App\Models\Location;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use App\Notifications\CheckinAssetNotification;
use App\Notifications\CheckinLicenseSeatNotification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
/**
* @group notifications
*/
class SlackNotificationsUponCheckinTest extends TestCase
{
use InteractsWithSettings;
protected function setUp(): void
{
parent::setUp();
Notification::fake();
}
public function assetCheckInTargets(): array
{
return [
'Asset checked out to user' => [fn() => User::factory()->create()],
'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
'Asset checked out to location' => [fn() => Location::factory()->create()],
];
}
public function licenseCheckInTargets(): array
{
return [
'License checked out to user' => [fn() => User::factory()->create()],
'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
];
}
public function testAccessoryCheckinSendsSlackNotificationWhenSettingEnabled()
{
$this->settings->enableSlackWebhook();
$this->fireCheckInEvent(
Accessory::factory()->create(),
User::factory()->create(),
);
$this->assertSlackNotificationSent(CheckinAccessoryNotification::class);
}
public function testAccessoryCheckinDoesNotSendSlackNotificationWhenSettingDisabled()
{
$this->settings->disableSlackWebhook();
$this->fireCheckInEvent(
Accessory::factory()->create(),
User::factory()->create(),
);
$this->assertNoSlackNotificationSent(CheckinAccessoryNotification::class);
}
/** @dataProvider assetCheckInTargets */
public function testAssetCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
{
$this->settings->enableSlackWebhook();
$this->fireCheckInEvent(
Asset::factory()->create(),
$checkoutTarget(),
);
$this->assertSlackNotificationSent(CheckinAssetNotification::class);
}
/** @dataProvider assetCheckInTargets */
public function testAssetCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
{
$this->settings->disableSlackWebhook();
$this->fireCheckInEvent(
Asset::factory()->create(),
$checkoutTarget(),
);
$this->assertNoSlackNotificationSent(CheckinAssetNotification::class);
}
public function testComponentCheckinDoesNotSendSlackNotification()
{
$this->settings->enableSlackWebhook();
$this->fireCheckInEvent(
Component::factory()->create(),
Asset::factory()->laptopMbp()->create(),
);
Notification::assertNothingSent();
}
/** @dataProvider licenseCheckInTargets */
public function testLicenseCheckinSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
{
$this->settings->enableSlackWebhook();
$this->fireCheckInEvent(
LicenseSeat::factory()->create(),
$checkoutTarget(),
);
$this->assertSlackNotificationSent(CheckinLicenseSeatNotification::class);
}
/** @dataProvider licenseCheckInTargets */
public function testLicenseCheckinDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
{
$this->settings->disableSlackWebhook();
$this->fireCheckInEvent(
LicenseSeat::factory()->create(),
$checkoutTarget(),
);
$this->assertNoSlackNotificationSent(CheckinLicenseSeatNotification::class);
}
private function fireCheckInEvent(Model $checkoutable, Model $target)
{
event(new CheckoutableCheckedIn(
$checkoutable,
$target,
User::factory()->superuser()->create(),
''
));
}
}

View file

@ -0,0 +1,174 @@
<?php
namespace Tests\Feature\Notifications\Webhooks;
use App\Events\CheckoutableCheckedOut;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Component;
use App\Models\Consumable;
use App\Models\LicenseSeat;
use App\Models\Location;
use App\Models\User;
use App\Notifications\CheckoutAccessoryNotification;
use App\Notifications\CheckoutAssetNotification;
use App\Notifications\CheckoutConsumableNotification;
use App\Notifications\CheckoutLicenseSeatNotification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Notification;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
/**
* @group notifications
*/
class SlackNotificationsUponCheckoutTest extends TestCase
{
use InteractsWithSettings;
protected function setUp(): void
{
parent::setUp();
Notification::fake();
}
public function assetCheckoutTargets(): array
{
return [
'Asset checked out to user' => [fn() => User::factory()->create()],
'Asset checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
'Asset checked out to location' => [fn() => Location::factory()->create()],
];
}
public function licenseCheckoutTargets(): array
{
return [
'License checked out to user' => [fn() => User::factory()->create()],
'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
];
}
public function testAccessoryCheckoutSendsSlackNotificationWhenSettingEnabled()
{
$this->settings->enableSlackWebhook();
$this->fireCheckOutEvent(
Accessory::factory()->create(),
User::factory()->create(),
);
$this->assertSlackNotificationSent(CheckoutAccessoryNotification::class);
}
public function testAccessoryCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
{
$this->settings->disableSlackWebhook();
$this->fireCheckOutEvent(
Accessory::factory()->create(),
User::factory()->create(),
);
$this->assertNoSlackNotificationSent(CheckoutAccessoryNotification::class);
}
/** @dataProvider assetCheckoutTargets */
public function testAssetCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
{
$this->settings->enableSlackWebhook();
$this->fireCheckOutEvent(
Asset::factory()->create(),
$checkoutTarget(),
);
$this->assertSlackNotificationSent(CheckoutAssetNotification::class);
}
/** @dataProvider assetCheckoutTargets */
public function testAssetCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
{
$this->settings->disableSlackWebhook();
$this->fireCheckOutEvent(
Asset::factory()->create(),
$checkoutTarget(),
);
$this->assertNoSlackNotificationSent(CheckoutAssetNotification::class);
}
public function testComponentCheckoutDoesNotSendSlackNotification()
{
$this->settings->enableSlackWebhook();
$this->fireCheckOutEvent(
Component::factory()->create(),
Asset::factory()->laptopMbp()->create(),
);
Notification::assertNothingSent();
}
public function testConsumableCheckoutSendsSlackNotificationWhenSettingEnabled()
{
$this->settings->enableSlackWebhook();
$this->fireCheckOutEvent(
Consumable::factory()->create(),
User::factory()->create(),
);
$this->assertSlackNotificationSent(CheckoutConsumableNotification::class);
}
public function testConsumableCheckoutDoesNotSendSlackNotificationWhenSettingDisabled()
{
$this->settings->disableSlackWebhook();
$this->fireCheckOutEvent(
Consumable::factory()->create(),
User::factory()->create(),
);
$this->assertNoSlackNotificationSent(CheckoutConsumableNotification::class);
}
/** @dataProvider licenseCheckoutTargets */
public function testLicenseCheckoutSendsSlackNotificationWhenSettingEnabled($checkoutTarget)
{
$this->settings->enableSlackWebhook();
$this->fireCheckOutEvent(
LicenseSeat::factory()->create(),
$checkoutTarget(),
);
$this->assertSlackNotificationSent(CheckoutLicenseSeatNotification::class);
}
/** @dataProvider licenseCheckoutTargets */
public function testLicenseCheckoutDoesNotSendSlackNotificationWhenSettingDisabled($checkoutTarget)
{
$this->settings->disableSlackWebhook();
$this->fireCheckOutEvent(
LicenseSeat::factory()->create(),
$checkoutTarget(),
);
$this->assertNoSlackNotificationSent(CheckoutLicenseSeatNotification::class);
}
private function fireCheckOutEvent(Model $checkoutable, Model $target)
{
event(new CheckoutableCheckedOut(
$checkoutable,
$target,
User::factory()->superuser()->create(),
'',
));
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Tests\Support;
use App\Models\Setting;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
trait AssertsAgainstSlackNotifications
{
public function assertSlackNotificationSent(string $notificationClass)
{
Notification::assertSentTo(
new AnonymousNotifiable,
$notificationClass,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}
public function assertNoSlackNotificationSent(string $notificationClass)
{
Notification::assertNotSentTo(new AnonymousNotifiable, $notificationClass);
}
}

View file

@ -49,7 +49,7 @@ class Settings
]);
}
public function disableWebhook(): Settings
public function disableSlackWebhook(): Settings
{
return $this->update([
'webhook_selected' => '',

View file

@ -6,12 +6,14 @@ use App\Http\Middleware\SecurityHeaders;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use RuntimeException;
use Tests\Support\AssertsAgainstSlackNotifications;
use Tests\Support\CustomTestMacros;
use Tests\Support\InteractsWithAuthentication;
use Tests\Support\InteractsWithSettings;
abstract class TestCase extends BaseTestCase
{
use AssertsAgainstSlackNotifications;
use CreatesApplication;
use CustomTestMacros;
use InteractsWithAuthentication;

View file

@ -23,6 +23,7 @@ class AssetTest extends TestCase
$this->assertModelExists($b);
}
public function testAutoIncrementCollision()
{
$this->settings->enableAutoIncrement();

View file

@ -60,34 +60,4 @@ class CategoryTest extends TestCase
$this->assertCount(5, $category->models);
$this->assertEquals(10, $category->itemCount());
}
// public function testACategoryCanHaveAccessories()
// {
// $category = Category::factory()->assetDesktopCategory()->create();
// Accessory::factory()->count(5)->appleBtKeyboard()->create(
// [
// 'category_id' => $category->id
// ]
// );
// $this->assertCount(5, $category->accessories);
// $this->assertEquals(5, $category->itemCount());
// }
// public function testACategoryCanHaveConsumables()
// {
// $category = $this->createValidCategory('consumable-paper-category');
// \App\Models\Consumable::factory()->count(5)->cardstock()->create(['category_id' => $category->id]);
// $this->assertCount(5, $category->consumables);
// $this->assertEquals(5, $category->itemCount());
// }
// public function testACategoryCanHaveComponents()
// {
// $category = $this->createValidCategory('component-ram-category');
// \App\Models\Component::factory()->count(5)->ramCrucial4()->create(['category_id' => $category->id]);
// $this->assertCount(5, $category->components);
// $this->assertEquals(5, $category->itemCount());
// }
}

View file

@ -1,739 +0,0 @@
<?php
namespace Tests\Unit;
use App\Importer\AccessoryImporter;
use App\Importer\AssetImporter;
use App\Importer\ConsumableImporter;
use App\Importer\LicenseImporter;
use App\Importer\UserImporter;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\CustomField;
use App\Models\Location;
use App\Models\User;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class ImporterTest extends TestCase
{
// public function testDefaultImportAssetWithCustomFields()
// {
// $this->signIn();
// $csv = <<<'EOT'
// Full Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier,Weight
// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan,35
// EOT;
// $this->initializeCustomFields();
// $this->import(new AssetImporter($csv));
// $this->tester->seeRecord('users', [
// 'first_name' => 'Bonnie',
// 'last_name' => 'Nelson',
// 'email' => 'bnelson0@cdbaby.com',
// ]);
// $this->tester->seeRecord('categories', [
// 'name' => 'quam',
// ]);
// $this->tester->seeRecord('models', [
// 'name' => 'massa id',
// 'model_number' => 6377018600094472,
// ]);
// $this->tester->seeRecord('manufacturers', [
// 'name' => 'Linkbridge',
// ]);
// $this->tester->seeRecord('locations', [
// 'name' => 'Daping',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Alpha',
// ]);
// $this->tester->seeRecord('status_labels', [
// 'name' => 'Undeployable',
// ]);
// $this->tester->seeRecord('suppliers', [
// 'name' => 'Blogspan',
// ]);
// $this->tester->seeRecord('assets', [
// 'name' => 'eget nunc donec quis',
// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147',
// 'asset_tag' => '970882174-8',
// 'notes' => 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.',
// 'purchase_date' => '2016-04-05 00:00:01',
// 'purchase_cost' => 133289.59, 'warranty_months' => 14,
// '_snipeit_weight_2' => 35,
// ]);
// }
// public function testImportCheckoutToLocation()
// {
// $this->signIn();
// // Testing in order:
// // * Asset to user, no checkout type defined (default to user).
// // * Asset to user, explicit user checkout type (Checkout to user)
// // * Asset to location, location does not exist to begin with
// // * Asset to preexisting location.
// $csv = <<<'EOT'
// Full Name,Email,Username,Checkout Location,Checkout Type,item Name,Category,Model name,Manufacturer,Model Number,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier,Weight
// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,,,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan,35
// Mildred Gibson,mgibson2@wiley.com,mgibson2,,user,morbi quis tortor id,nunc nisl duis,convallis tortor risus,Lajo,374622546776765,2837ab20-8f0d-4935-8a52-226392f2b1b0,710141467-2,Shekou,In congue. Etiam justo. Etiam pretium iaculis justo.,2015-08-09,233.57,Konklab,Lost,,,
// ,,,Planet Earth,location,dictumst maecenas ut,sem praesent,accumsan felis,Layo,30052522651756,4751495c-cee0-4961-b788-94a545b5643e,998233705-X,Dante Delgado,,2016-04-16,261.79,,Archived,15,Ntag,
// ,,,Daping,location,viverra diam vitae,semper sapien,dapibus dolor vel,Flashset,3559785746335392,e287bb64-ff4f-434c-88ab-210ad433c77b,927820758-6,Achiaman,,2016-03-05,675.3,,Archived,22,Meevee,
// EOT;
// $this->import(new AssetImporter($csv));
// $user = User::where('username', 'bnelson0')->firstOrFail();
// $this->tester->seeRecord('assets', [
// 'asset_tag' => '970882174-8',
// 'assigned_type' => User::class,
// 'assigned_to' => $user->id,
// ]);
// $user = User::where('username', 'mgibson2')->firstOrFail();
// $this->tester->seeRecord('assets', [
// 'asset_tag' => '710141467-2',
// 'assigned_type' => User::class,
// 'assigned_to' => $user->id,
// ]);
// $location = Location::where('name', 'Planet Earth')->firstOrFail();
// $this->tester->seeRecord('assets', [
// 'asset_tag' => '998233705-X',
// 'assigned_type' => Location::class,
// 'assigned_to' => $location->id,
// ]);
// $location = Location::where('name', 'Daping')->firstOrFail();
// $this->tester->seeRecord('assets', [
// 'asset_tag' => '927820758-6',
// 'assigned_type' => Location::class,
// 'assigned_to' => $location->id,
// ]);
// }
// public function testUpdateAssetIncludingCustomFields()
// {
// $this->signIn();
// $csv = <<<'EOT'
// Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier,weight
// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan,95
// EOT;
// $this->initializeCustomFields();
// $this->import(new AssetImporter($csv));
// $updatedCSV = <<<'EOT'
// item Name,Category,Model name,Manufacturer,Model Number,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier
// A new name,some other category,Another Model,Linkbridge 32,356,67433477,970882174-8,New Location,I have no notes,2018-04-05,25.59,Another Company,Ready To Go,18,Not Creative
// EOT;
// $importer = new AssetImporter($updatedCSV);
// $importer->setUserId(1)
// ->setUpdating(true)
// ->setUsernameFormat('firstname.lastname')
// ->import();
// $this->tester->seeRecord('categories', [
// 'name' => 'some other category',
// ]);
// $this->tester->seeRecord('models', [
// 'name' => 'Another Model',
// 'model_number' => 356,
// ]);
// $this->tester->seeRecord('manufacturers', [
// 'name' => 'Linkbridge 32',
// ]);
// $this->tester->seeRecord('locations', [
// 'name' => 'New Location',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Another Company',
// ]);
// $this->tester->seeRecord('status_labels', [
// 'name' => 'Ready To Go',
// ]);
// $this->tester->seeRecord('suppliers', [
// 'name' => 'Not Creative',
// ]);
// $this->tester->seeRecord('assets', [
// 'name' => 'A new name',
// 'serial' => '67433477',
// 'asset_tag' => '970882174-8',
// 'notes' => 'I have no notes',
// 'purchase_date' => '2018-04-05 00:00:01',
// 'purchase_cost' => 25.59,
// 'warranty_months' => 18,
// '_snipeit_weight_2' => 95,
// ]);
// }
// public function testAssetModelNumber4359()
// {
// // As per bug #4359
// // 1) Create model with blank model # and custom field.
// // 2 ) Update custom fields with a csv not including model #
// // 3 ) Not updated. NULL vs. empty issue.
// $this->signIn();
// $csv = <<<'EOT'
// Name,Email,Username,item Name,Category,Model name,Manufacturer,Serial,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier
// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan
// EOT;
// // Need to do this manually...
// $customField = \App\Models\CustomField::factory()->create(['name' => 'Weight']);
// $customFieldSet = \App\Models\CustomFieldset::factory()->create(['name' => 'Default']);
// $customFieldSet->fields()->attach($customField, [
// 'required' => false,
// 'order' => 'asc', ]);
// \App\Models\Category::factory()->assetLaptopCategory()->create([
// 'name' => 'quam',
// ]);
// \App\Models\Manufacturer::factory()->apple()->create([
// 'name' => 'Linkbridge',
// ]);
// $am = \App\Models\AssetModel::factory()->create([
// 'name' => 'massa id',
// 'fieldset_id' => $customFieldSet->id,
// 'category_id' => 1,
// 'manufacturer_id' => 1,
// 'model_number' => null,
// ]);
// $this->import(new AssetImporter($csv));
// $updatedCSV = <<<'EOT'
// Serial,Asset Tag,weight
// 67433477,970882174-8,115
// EOT;
// $importer = new AssetImporter($updatedCSV);
// $importer->setUserId(1)
// ->setUpdating(true)
// ->setUsernameFormat('firstname.lastname')
// ->import();
// $this->tester->seeRecord('assets', [
// 'asset_tag' => '970882174-8',
// '_snipeit_weight_2' => 115,
// ]);
// }
// public function initializeCustomFields()
// {
// $customField = \App\Models\CustomField::factory()->create(['name' => 'Weight']);
// $customFieldSet = \App\Models\CustomFieldset::factory()->create(['name' => 'Default']);
// $customFieldSet->fields()->attach($customField, [
// 'required' => false,
// 'order' => 'asc', ]);
// $am = \App\Models\AssetModel::factory()->create([
// 'name' => 'massa id',
// 'fieldset_id' => $customFieldSet->id,
// ]);
// }
// public function testCustomMappingImport()
// {
// $this->signIn();
// $csv = <<<'EOT'
// Full Name,Email,Username,object name,Cat,Model name,Manufacturer,Model Number,Serial,Asset,Loc,Some Notes,Purchase Date,Purchase Cost,comp,Status,Warranty,Supplier
// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan
// EOT;
// $customFieldMap = [
// 'asset_tag' => 'Asset',
// 'category' => 'Cat',
// 'company' => 'comp',
// 'item_name' => 'object name',
// 'expiration_date' => 'expiration date',
// 'location' => 'loc',
// 'notes' => 'Some Notes',
// 'asset_model' => 'model name',
// ];
// $this->import(new AssetImporter($csv), $customFieldMap);
// // Did we create a user?
// $this->tester->seeRecord('users', [
// 'first_name' => 'Bonnie',
// 'last_name' => 'Nelson',
// 'email' => 'bnelson0@cdbaby.com',
// ]);
// // Grab the user record for use in asserting assigned_to
// $createdUser = $this->tester->grabRecord('users', [
// 'first_name' => 'Bonnie',
// 'last_name' => 'Nelson',
// 'email' => 'bnelson0@cdbaby.com',
// ]);
// $this->tester->seeRecord('categories', [
// 'name' => 'quam',
// ]);
// $this->tester->seeRecord('models', [
// 'name' => 'massa id',
// 'model_number' => 6377018600094472,
// ]);
// $this->tester->seeRecord('manufacturers', [
// 'name' => 'Linkbridge',
// ]);
// $this->tester->seeRecord('locations', [
// 'name' => 'Daping',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Alpha',
// ]);
// $this->tester->seeRecord('status_labels', [
// 'name' => 'Undeployable',
// ]);
// $this->tester->seeRecord('suppliers', [
// 'name' => 'Blogspan',
// ]);
// $this->tester->seeRecord('assets', [
// 'name' => 'eget nunc donec quis',
// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147',
// 'asset_tag' => '970882174-8',
// 'notes' => 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.',
// 'purchase_date' => '2016-04-05 00:00:01',
// 'purchase_cost' => 133289.59,
// 'warranty_months' => 14,
// 'assigned_to' => $createdUser['id'],
// 'assigned_type' => User::class,
// ]);
// }
// public function testDefaultAccessoryImport()
// {
// $csv = <<<'EOT'
// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity
// Walter Carter,09/01/2006,,metus. Vivamus,Macromedia,J935H60W,Customers,False,278
// EOT;
// $this->import(new AccessoryImporter($csv));
// $this->tester->seeRecord('accessories', [
// 'name' => 'Walter Carter',
// 'purchase_date' => '2006-09-01 00:00:01',
// 'order_number' => 'J935H60W',
// 'requestable' => 0,
// 'qty' => 278,
// ]);
// $this->tester->seeRecord('locations', [
// 'name' => 'metus. Vivamus',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Macromedia',
// ]);
// $this->tester->seeRecord('categories', [
// 'name' => 'Customers',
// ]);
// }
// public function testDefaultAccessoryUpdate()
// {
// $csv = <<<'EOT'
// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity
// Walter Carter,09/01/2006,,metus. Vivamus,Macromedia,J935H60W,Customers,False,278
// EOT;
// $this->import(new AccessoryImporter($csv));
// $this->tester->seeNumRecords(1, 'accessories');
// $updatedCSV = <<<'EOT'
// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity
// Walter Carter,09/01/2015,350,metus. Vivamus,Macromedia,35GGH,Customers,True,12
// EOT;
// $importer = new AccessoryImporter($updatedCSV);
// $importer->setUserId(1)
// ->setUpdating(true)
// ->import();
// // At this point we should still only have one record.
// $this->tester->seeNumRecords(1, 'accessories');
// // But instead these.
// $this->tester->seeRecord('accessories', [
// 'name' => 'Walter Carter',
// 'purchase_date' => '2015-09-01 00:00:01',
// 'order_number' => '35GGH',
// 'requestable' => 1,
// 'qty' => 12,
// ]);
// }
// public function testCustomAccessoryImport()
// {
// $csv = <<<'EOT'
// Name,Pur Date,Cost,Loc,Comp,Order Num,Cat,Request,Quan
// Walter Carter,09/01/2006,,metus. Vivamus,Macromedia,J935H60W,Customers,False,278
// EOT;
// $customFieldMap = [
// 'category' => 'Cat',
// 'company' => 'Comp',
// 'item_name' => 'Name',
// 'location' => 'Loc',
// 'purchase_date' => 'Pur Date',
// 'purchase_cost' => 'Cost',
// 'order_number' => 'Order Num',
// 'requestable' => 'Request',
// 'quantity' => 'Quan',
// ];
// $this->import(new AccessoryImporter($csv), $customFieldMap);
// // dd($this->tester->grabRecord('accessories'));
// $this->tester->seeRecord('accessories', [
// 'name' => 'Walter Carter',
// 'purchase_date' => '2006-09-01 00:00:01',
// 'order_number' => 'J935H60W',
// 'requestable' => 0,
// 'qty' => 278,
// ]);
// $this->tester->seeRecord('locations', [
// 'name' => 'metus. Vivamus',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Macromedia',
// ]);
// $this->tester->seeRecord('categories', [
// 'name' => 'Customers',
// ]);
// }
// public function testDefaultConsumableImport()
// {
// $csv = <<<'EOT'
// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity,Item Number,Model Number
// eget,01/03/2011,$85.91,mauris blandit mattis.,Lycos,T295T06V,Triamterene/Hydrochlorothiazide,No,322,3305,30123
// EOT;
// $this->import(new ConsumableImporter($csv));
// $this->tester->seeRecord('consumables', [
// 'name' => 'eget',
// 'purchase_date' => '2011-01-03 00:00:01',
// 'purchase_cost' => 85.91,
// 'order_number' => 'T295T06V',
// 'requestable' => 0,
// 'qty' => 322,
// 'item_no' => 3305,
// 'model_number' => 30123,
// ]);
// $this->tester->seeRecord('locations', [
// 'name' => 'mauris blandit mattis.',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Lycos',
// ]);
// $this->tester->seeRecord('categories', [
// 'name' => 'Triamterene/Hydrochlorothiazide',
// ]);
// }
// public function testDefaultConsumableUpdate()
// {
// $csv = <<<'EOT'
// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity
// eget,01/03/2011,85.91,mauris blandit mattis.,Lycos,T295T06V,Triamterene/Hydrochlorothiazide,No,322
// EOT;
// $this->import(new ConsumableImporter($csv));
// $this->tester->seeNumRecords(1, 'consumables');
// $updatedCSV = <<<'EOT'
// Item Name,Purchase Date,Purchase Cost,Location,Company,Order Number,Category,Requestable,Quantity
// eget,12/05/2016,35.45,mauris blandit mattis.,Lycos,3666FF,New Cat,Yes,15
// EOT;
// $importer = new ConsumableImporter($updatedCSV);
// $importer->setUserId(1)
// ->setUpdating(true)
// ->import();
// // At this point we should still only have one record.
// $this->tester->seeNumRecords(1, 'consumables');
// // But instead these.
// $this->tester->seeRecord('consumables', [
// 'name' => 'eget',
// 'purchase_date' => '2016-12-05 00:00:01',
// 'purchase_cost' => 35.45,
// 'order_number' => '3666FF',
// 'requestable' => 1,
// 'qty' => 15,
// ]);
// }
// public function testCustomConsumableImport()
// {
// $csv = <<<'EOT'
// Name,pur Date,Pur Cost,Loc,Comp,Order Num,Kat,Request,Quan
// eget,01/03/2011,85.91,mauris blandit mattis.,Lycos,T295T06V,Triamterene/Hydrochlorothiazide,No,322
// EOT;
// $customFieldMap = [
// 'category' => 'Kat',
// 'company' => 'Comp',
// 'item_name' => 'Name',
// 'location' => 'Loc',
// 'purchase_date' => 'Pur date',
// 'purchase_cost' => 'Pur Cost',
// 'order_number' => 'Order Num',
// 'requestable' => 'Request',
// 'quantity' => 'Quan',
// ];
// $this->import(new ConsumableImporter($csv), $customFieldMap);
// $this->tester->seeRecord('consumables', [
// 'name' => 'eget',
// 'purchase_date' => '2011-01-03 00:00:01',
// 'purchase_cost' => 85.91,
// 'order_number' => 'T295T06V',
// 'requestable' => 0,
// 'qty' => 322,
// ]);
// $this->tester->seeRecord('locations', [
// 'name' => 'mauris blandit mattis.',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Lycos',
// ]);
// $this->tester->seeRecord('categories', [
// 'name' => 'Triamterene/Hydrochlorothiazide',
// ]);
// }
// public function testDefaultLicenseImport()
// {
// $this->signIn();
// $csv = <<<'EOT'
// Full Name,Email,Username,Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes,asset tag
// Helen Anderson,cspencer0@privacy.gov.au,cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,cspencer0@gov.uk,01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.,test 1
// EOT;
// // Force create an asset to match the checkout
// $testAsset = $this->createValidAsset(['asset_tag' => 'test 1']);
// $this->import(new LicenseImporter($csv));
// // dd($this->tester->grabRecord('licenses'));
// // Did we create a user?
// $this->tester->seeRecord('users', [
// 'first_name' => 'Helen',
// 'last_name' => 'Anderson',
// 'email' => 'cspencer0@privacy.gov.au',
// ]);
// // Grab the user record for use in asserting assigned_to
// $createdUser = $this->tester->grabRecord('users', [
// 'first_name' => 'Helen',
// 'last_name' => 'Anderson',
// 'email' => 'cspencer0@privacy.gov.au',
// ]);
// $this->tester->seeRecord('licenses', [
// 'name' => 'Argentum Malachite Athletes Foot Relief',
// 'purchase_date' => '2012-07-13 00:00:01',
// 'seats' => 80,
// 'license_email' => 'cspencer0@gov.uk',
// 'order_number' => '386436062-5',
// 'license_name' => 'Cynthia Spencer',
// 'expiration_date' => '2016-01-27',
// 'maintained' => 0,
// 'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.',
// 'purchase_cost' => 79.66,
// 'purchase_order' => '53008',
// 'reassignable' => 0,
// 'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c',
// ]);
// $this->tester->seeRecord('manufacturers', [
// 'name' => 'Beer, Leannon and Lubowitz',
// ]);
// $this->tester->seeRecord('suppliers', [
// 'name' => 'Hegmann, Mohr and Cremin',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Haag, Schmidt and Farrell',
// ]);
// $this->tester->seeRecord('categories', [
// 'name' => 'Graphics Software',
// ]);
// $this->tester->seeNumRecords(80, 'license_seats');
// $this->tester->seeRecord('license_seats', [
// 'assigned_to' => $createdUser['id'],
// 'license_id' => \App\Models\License::where('serial', '1aa5b0eb-79c5-40b2-8943-5472a6893c3c')->first()->id,
// 'asset_id' => $testAsset->id,
// ]);
// }
// public function testDefaultLicenseUpdate()
// {
// $csv = <<<'EOT'
// Name,Email,Username,Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes
// Helen Anderson,cspencer0@privacy.gov.au,cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,cspencer0@gov.uk,01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.
// EOT;
// $this->import(new LicenseImporter($csv));
// $this->tester->seeNumRecords(1, 'licenses');
// $updatedCSV = <<<'EOT'
// Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes
// Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",05/15/2019,$1865.34,63 ar,18334,A Legend,Legendary@gov.uk,04/27/2016,yes,true,64,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.
// EOT;
// $importer = new LicenseImporter($updatedCSV);
// $importer->setUserId(1)
// ->setUpdating(true)
// ->import();
// // At this point we should still only have one record.
// $this->tester->seeNumRecords(1, 'licenses');
// // But instead these.
// \Log::debug($this->tester->grabRecord('licenses'));
// $this->tester->seeRecord('licenses', [
// 'name' => 'Argentum Malachite Athletes Foot Relief',
// 'purchase_date' => '2019-05-15 00:00:01',
// 'seats' => 64,
// 'license_email' => 'Legendary@gov.uk',
// 'order_number' => '18334',
// 'license_name' => 'A Legend',
// 'expiration_date' => '2016-04-27',
// 'maintained' => 1,
// 'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.',
// 'purchase_cost' => 1865.34,
// 'purchase_order' => '63 ar',
// 'reassignable' => 1,
// 'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c',
// ]);
// // License seats are soft deleted
// $this->tester->seeNumRecords(64, 'license_seats', ['deleted_at' => null]);
// }
// public function testCustomLicenseImport()
// {
// $csv = <<<'EOT'
// Name,Email,Username,Object name,serial num,manuf,pur date,pur cost,purc order,order num,Licensed To,Licensed Email,expire date,maint,reass,seat,comp,supplier,category,note
// Helen Anderson,cspencer0@privacy.gov.au,cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,cspencer0@gov.uk,01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Custom Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.
// EOT;
// $customFieldMap = [
// 'company' => 'Comp',
// 'expiration_date' => 'expire date',
// 'item_name' => 'Object Name',
// 'license_email' => 'licensed email',
// 'license_name' => 'licensed to',
// 'maintained' => 'maint',
// 'manufacturer' => 'manuf',
// 'notes' => 'note',
// 'order_number' => 'Order Num',
// 'purchase_cost' => 'Pur Cost',
// 'purchase_date' => 'Pur date',
// 'purchase_order' => 'Purc Order',
// 'quantity' => 'Quan',
// 'reassignable' => 'reass',
// 'requestable' => 'Request',
// 'seats' => 'seat',
// 'serial' => 'serial num',
// 'category' => 'category',
// ];
// $this->import(new LicenseImporter($csv), $customFieldMap);
// $this->tester->seeRecord('licenses', [
// 'name' => 'Argentum Malachite Athletes Foot Relief',
// 'purchase_date' => '2012-07-13 00:00:01',
// 'seats' => 80,
// 'license_email' => 'cspencer0@gov.uk',
// 'order_number' => '386436062-5',
// 'license_name' => 'Cynthia Spencer',
// 'expiration_date' => '2016-01-27',
// 'maintained' => 0,
// 'notes' => 'Sed ante. Vivamus tortor. Duis mattis egestas metus.',
// 'purchase_cost' => 79.66,
// 'purchase_order' => '53008',
// 'reassignable' => 0,
// 'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c',
// ]);
// $this->tester->seeRecord('manufacturers', [
// 'name' => 'Beer, Leannon and Lubowitz',
// ]);
// $this->tester->seeRecord('suppliers', [
// 'name' => 'Hegmann, Mohr and Cremin',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Haag, Schmidt and Farrell',
// ]);
// $this->tester->seeNumRecords(80, 'license_seats');
// }
// public function testDefaultUserImport()
// {
// Notification::fake();
// $this->signIn();
// $csv = <<<'EOT'
// First Name,Last Name,email,Username,Location,Phone Number,Job Title,Employee Number,Company,Department,activated
// Blanche,O'Collopy,bocollopy0@livejournal.com,bocollopy0,Hinapalanan,63-(199)661-2186,Clinical Specialist,7080919053,Morar-Ward,Management,1
// Jessie,Primo,,jprimo1,Korenovsk,7-(885)578-0266,Paralegal,6284292031,Jast-Stiedemann,1
// EOT;
// $user_importer = new UserImporter($csv);
// $user_importer->sendWelcome();
// $this->import($user_importer);
// $this->tester->seeRecord('users', [
// 'first_name' => 'Blanche',
// 'last_name' => "O'Collopy",
// 'email' => 'bocollopy0@livejournal.com',
// 'username' => 'bocollopy0',
// 'phone' => '63-(199)661-2186',
// 'jobtitle' => 'Clinical Specialist',
// 'employee_num' => '7080919053',
// ]);
// $this->tester->seeRecord('companies', [
// 'name' => 'Morar-Ward',
// ]);
// $this->tester->seeRecord('departments', [
// 'name' => 'Management',
// ]);
// Notification::assertSentTo(User::find(2), \App\Notifications\WelcomeNotification::class);
// Notification::assertNotSentTo(User::find(3), \App\Notifications\WelcomeNotification::class);
// }
// private function import($importer, $mappings = null)
// {
// if ($mappings) {
// $importer->setFieldMappings($mappings);
// }
// $importer->setUserId(1)
// ->setUpdating(false)
// ->setUsernameFormat('firstname.lastname')
// ->import();
// }
}

View file

@ -1,510 +0,0 @@
<?php
namespace Tests\Unit;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Component;
use App\Models\Consumable;
use App\Models\License;
use App\Models\User;
use Tests\TestCase;
class PermissionsTest extends TestCase
{
// public function _before()
// {
// parent::_before();
// $this->noHardware = [
// 'assets.view' => false,
// 'assets.create' => false,
// 'assets.edit' => false,
// 'assets.delete' => false,
// ];
// $this->noLicenses = [
// 'licenses.view' => false,
// 'licenses.create' => false,
// 'licenses.edit' => false,
// 'licenses.delete' => false,
// ];
// $this->noAccessories = [
// 'accessories.view' => false,
// 'accessories.create' => false,
// 'accessories.edit' => false,
// 'accessories.delete' => false,
// ];
// $this->noConsumables = [
// 'consumables.view' => false,
// 'consumables.create' => false,
// 'consumables.edit' => false,
// 'consumables.delete' => false,
// ];
// $this->noComponents = [
// 'components.view' => false,
// 'components.create' => false,
// 'components.edit' => false,
// 'components.delete' => false,
// ];
// $this->noUsers = [
// 'users.view' => false,
// 'users.create' => false,
// 'users.edit' => false,
// 'users.delete' => false,
// ];
// }
// private $noHardware;
// private $noLicenses;
// private $noAccessories;
// private $noConsumables;
// private $noComponents;
// private $noUsers;
// // tests
// /**
// * @test
// */
// public function a_user_with_no_permissions_sees_nothing()
// {
// $u = \App\Models\User::factory()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// // $permissions = $this->noHardware;
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_view_asset_permissions_can_view_assets()
// {
// $u = \App\Models\User::factory()->viewAssets()->create();
// $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'assets.view' => true,
// 'assets.create' => false,
// 'assets.edit' => false,
// 'assets.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_create_asset_permissions_can_create_assets()
// {
// $u = \App\Models\User::factory()->createAssets()->create();
// $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'assets.view' => false,
// 'assets.create' => true,
// 'assets.edit' => false,
// 'assets.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_edit_assets_permissions_can_edit_assets()
// {
// $u = \App\Models\User::factory()->editAssets()->create();
// $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'assets.view' => false,
// 'assets.create' => false,
// 'assets.edit' => true,
// 'assets.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_delete_assets_permissions_can_delete_assets()
// {
// $u = \App\Models\User::factory()->deleteAssets()->create();
// $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'assets.view' => false,
// 'assets.create' => false,
// 'assets.edit' => false,
// 'assets.delete' => true,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_view_licenses_permissions_can_view_licenses()
// {
// $u = \App\Models\User::factory()->viewLicenses()->create();
// $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'licenses.view' => true,
// 'licenses.create' => false,
// 'licenses.edit' => false,
// 'licenses.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_create_licenses_permissions_can_create_licenses()
// {
// $u = \App\Models\User::factory()->createLicenses()->create();
// $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'licenses.view' => false,
// 'licenses.create' => true,
// 'licenses.edit' => false,
// 'licenses.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_edit_licenses_permissions_can_edit_licenses()
// {
// $u = \App\Models\User::factory()->editLicenses()->create();
// $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'licenses.view' => false,
// 'licenses.create' => false,
// 'licenses.edit' => true,
// 'licenses.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_delete_licenses_permissions_can_delete_licenses()
// {
// $u = \App\Models\User::factory()->deleteLicenses()->create();
// $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'licenses.view' => false,
// 'licenses.create' => false,
// 'licenses.edit' => false,
// 'licenses.delete' => true,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_view_accessories_permissions_can_view_accessories()
// {
// $u = \App\Models\User::factory()->viewAccessories()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'accessories.view' => true,
// 'accessories.create' => false,
// 'accessories.edit' => false,
// 'accessories.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_create_accessories_permissions_can_create_accessories()
// {
// $u = \App\Models\User::factory()->createAccessories()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'accessories.view' => false,
// 'accessories.create' => true,
// 'accessories.edit' => false,
// 'accessories.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_edit_accessories_permissions_can_edit_accessories()
// {
// $u = \App\Models\User::factory()->editAccessories()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'accessories.view' => false,
// 'accessories.create' => false,
// 'accessories.edit' => true,
// 'accessories.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_delete_accessories_permissions_can_delete_accessories()
// {
// $u = \App\Models\User::factory()->deleteAccessories()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'accessories.view' => false,
// 'accessories.create' => false,
// 'accessories.edit' => false,
// 'accessories.delete' => true,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_view_consumables_permissions_can_view_consumables()
// {
// $u = \App\Models\User::factory()->viewConsumables()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'consumables.view' => true,
// 'consumables.create' => false,
// 'consumables.edit' => false,
// 'consumables.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_create_consumables_permissions_can_create_consumables()
// {
// $u = \App\Models\User::factory()->createConsumables()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'consumables.view' => false,
// 'consumables.create' => true,
// 'consumables.edit' => false,
// 'consumables.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_edit_consumables_permissions_can_edit_consumables()
// {
// $u = \App\Models\User::factory()->editConsumables()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'consumables.view' => false,
// 'consumables.create' => false,
// 'consumables.edit' => true,
// 'consumables.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_delete_consumables_permissions_can_delete_consumables()
// {
// $u = \App\Models\User::factory()->deleteConsumables()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'consumables.view' => false,
// 'consumables.create' => false,
// 'consumables.edit' => false,
// 'consumables.delete' => true,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_view_users_permissions_can_view_users()
// {
// $u = \App\Models\User::factory()->viewUsers()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents;
// $permissions = array_merge($permissions, [
// 'users.view' => true,
// 'users.create' => false,
// 'users.edit' => false,
// 'users.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_create_users_permissions_can_create_users()
// {
// $u = \App\Models\User::factory()->createUsers()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents;
// $permissions = array_merge($permissions, [
// 'users.view' => false,
// 'users.create' => true,
// 'users.edit' => false,
// 'users.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_edit_users_permissions_can_edit_users()
// {
// $u = \App\Models\User::factory()->editUsers()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents;
// $permissions = array_merge($permissions, [
// 'users.view' => false,
// 'users.create' => false,
// 'users.edit' => true,
// 'users.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_delete_users_permissions_can_delete_users()
// {
// $u = \App\Models\User::factory()->deleteUsers()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents;
// $permissions = array_merge($permissions, [
// 'users.view' => false,
// 'users.create' => false,
// 'users.edit' => false,
// 'users.delete' => true,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_view_components_permissions_can_view_components()
// {
// $u = \App\Models\User::factory()->viewComponents()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'components.view' => true,
// 'components.create' => false,
// 'components.edit' => false,
// 'components.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_create_components_permissions_can_create_components()
// {
// $u = \App\Models\User::factory()->createComponents()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'components.view' => false,
// 'components.create' => true,
// 'components.edit' => false,
// 'components.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_edit_components_permissions_can_edit_components()
// {
// $u = \App\Models\User::factory()->editComponents()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'components.view' => false,
// 'components.create' => false,
// 'components.edit' => true,
// 'components.delete' => false,
// ]);
// $this->hitRoutes($permissions, $u);
// }
// /**
// * @test
// */
// public function a_user_with_delete_components_permissions_can_delete_components()
// {
// $u = \App\Models\User::factory()->deleteComponents()->create();
// $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers;
// $permissions = array_merge($permissions, [
// 'components.view' => false,
// 'components.create' => false,
// 'components.edit' => false,
// 'components.delete' => true,
// ]);
// // dd($u);
// $this->hitRoutes($permissions, $u);
// }
// private function hitRoutes(array $routes, User $user)
// {
// foreach ($routes as $route => $expectation) {
// $this->assertEquals($user->hasAccess($route), $expectation);
// }
// }
}