3
0
mirror of https://github.com/snipe/snipe-it.git synced 2025-10-29 19:31:41 +00:00

made eula api route, formatted table, cleaned up code

This commit is contained in:
Godfrey M 2025-06-04 15:04:59 -07:00
parent 6f4cee6334
commit ee3deb9c63
6 changed files with 39 additions and 25 deletions

View File

@ -6,6 +6,7 @@ use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Requests\SaveUserRequest;
use App\Http\Transformers\AccessoriesTransformer;
use App\Http\Transformers\ActionlogsTransformer;
use App\Http\Transformers\AssetsTransformer;
use App\Http\Transformers\ConsumablesTransformer;
use App\Http\Transformers\LicensesTransformer;
@ -80,7 +81,7 @@ class UsersController extends Controller
'users.autoassign_licenses',
'users.website',
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy', 'managesUsers', 'managedLocations')
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy', 'managesUsers', 'managedLocations', 'eulas')
->withCount([
'assets as assets_count' => function(Builder $query) {
$query->withoutTrashed();
@ -736,6 +737,23 @@ class UsersController extends Controller
return (new UsersTransformer)->transformUser($request->user());
}
/**
* Display the EULAs accepted by the user.
*
* @param \App\Models\User $user
* * @param \App\Http\Transformers\ActionlogsTransformer $transformer
* * @return \Illuminate\Http\JsonResponse
*@since [v8.1.16]
* @author [Godfrey Martinez] [<gmartinez@grokability.com>]
*/
public function eulas(User $user, ActionlogsTransformer $transformer)
{
$eulas = $user->eulas;
return response()->json(
$transformer->transformActionlogs($eulas, $eulas->count())
);
}
/**
* Restore a soft-deleted user.
*

View File

@ -39,7 +39,6 @@ class ViewAssetsController extends Controller
'consumables',
'accessories',
'licenses',
'eulas',
)->find(auth()->id());
$field_array = array();

View File

@ -561,6 +561,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
public function eulas()
{
return $this->hasMany(Actionlog::class, 'target_id')
->with('item')
->where('target_type', self::class)
->where('action_type', 'accepted')
->whereNotNull('filename')

View File

@ -288,6 +288,7 @@ return [
'status' => 'Status',
'accept_eula' => 'Acceptance Agreement',
'eula' => 'EULAs',
'eula_long' => 'End-User License Agreements',
'show_or_hide_eulas' => 'Show/Hide EULAs',
'supplier' => 'Supplier',
'suppliers' => 'Suppliers',

View File

@ -731,41 +731,28 @@
data-sort-order="asc"
data-sort-name="name"
class="table table-striped snipe-table table-hover"
data-url="{{route('api.user.eulas', $user->id)}}"
data-export-options='{
"fileName": "export-eula-{{ str_slug($user->username) }}-{{ date('Y-m-d') }}",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","delete","purchasecost", "icon"]
}'>
<caption id="userConsumableToolbar" class="tableCaption">
{{ trans('general.consumables') }}
<caption id="userEulaToolbar" class="tableCaption">
{{ trans('general.eula_long') }}
</caption>
<thead>
<tr>
<th class="col-md-3">{{ trans('general.name') }}</th>
@can('self.view_purchase_cost')
<th class="col-md-2" data-footer-formatter="sumFormatter" data-fieldname="purchase_cost">{{ trans('general.purchase_cost') }}</th>
@endcan
<th class="col-md-2">{{ trans('general.date') }}</th>
<th class="col-md-5">{{ trans('general.notes') }}</th>
<th data-visible="true" data-field="icon" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter">{{ trans('admin/hardware/table.icon') }}</th>
<th data-visible="true" data-field="item.name">{{ trans('general.item') }}</th>
<th data-visible="true" data-field="created_at" data-sortable="true" data-formatter="dateDisplayFormatter">{{ trans('general.accepted_date') }}</th>
<th data-field="note">{{ trans('general.notes') }}</th>
<th data-field="signature_file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.signature') }}</th>
<th data-field="file" data-formatter="fileUploadFormatter">{{ trans('general.download') }}</th>
</tr>
</thead>
<tbody>
@foreach ($user->consumables as $consumable)
<tr>
<td>{{ $consumable->name }}</td>
@can('self.view_purchase_cost')
<td>
{!! Helper::formatCurrencyOutput($consumable->purchase_cost) !!}
</td>
@endcan
<td>{{ Helper::getFormattedDateObject($consumable->pivot->created_at, 'datetime', false) }}</td>
<td>{{ $consumable->pivot->note }}</td>
</tr>
@endforeach
</tbody>
</table>
</div><!-- /consumables-tab -->
</div><!-- /eulas-tab -->
</div><!-- /.tab-content -->
</div><!-- nav-tabs-custom -->
</div>

View File

@ -1094,6 +1094,14 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'api-throttle:api']], fu
]
)->name('api.users.me');
Route::get('/users/{user}/eulas',
[
Api\UsersController::class,
'eulas'
]
)->name('api.user.eulas');
Route::get('list/{status?}',
[
Api\UsersController::class,