Skip to content

Commit

Permalink
Merge pull request #144 from dbarzin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dbarzin authored Oct 1, 2024
2 parents 9365a42 + 8434432 commit 41b4f80
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 43 deletions.
73 changes: 73 additions & 0 deletions app/Http/Controllers/ControlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,79 @@ public function edit(int $id)
->with('users', $users);
}

/**
* Clone a control.
*
* @param int Control id
*
* @return \Illuminate\Http\Response
*/
public function clone(Request $request)
{
// Only for admin and users
abort_if(
(Auth::User()->role !== 1) && (Auth::User()->role !== 2),
Response::HTTP_FORBIDDEN,
'403 Forbidden'
);

// get all clauses
$all_measures = DB::table('measures')
->select('id', 'clause')
->orderBy('id')
->get();

// get all scopes
$scopes = DB::table('controls')
->select('scope')
->whereNotNull('scope')
->where('scope', '<>', '')
->whereIn('status', [0, 1])
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();

// get all attributes
$values = [];
$attributes = DB::table('measures')->select('attributes')->get();
foreach ($attributes as $key) {
foreach (explode(' ', $key->attributes) as $value) {
array_push($values, $value);
}
}
sort($values);
$values = array_unique($values);

$users = User::orderBy('name')->get();

// Get Control
$control = Control::find($request->id);

// Workstation not found
abort_if($control === null, Response::HTTP_NOT_FOUND, '404 Not Found');

$request->merge($control->only(
[
"name","scope", "objective",
"input", "periodicity", "model", "action_plan",
"plan_date"
]
)
);
$request->merge(['measures' => $control->measures()->pluck('id')->toArray()]);
$request->merge(['attributes' => explode(' ', $control->attributes)]);
$request->merge(['owners' => $control->owners()->pluck('id')->toArray()]);
$request->flash();

return view('controls.create')
->with('scopes', $scopes)
->with('all_measures', $all_measures)
->with('attributes', $values)
->with('users', $users);
}

/**
* Remove the specified resource from storage.
*
Expand Down
7 changes: 6 additions & 1 deletion app/Http/Controllers/DomainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,17 @@ public function destroy(Domain $domain)
// Has measures ?
if (DB::table('measures')
->where('domain_id', $domain->id)
->join('control_measure','measures.id','control_measure.measure_id')
->exists()) {
return back()
->withErrors(['msg' => 'There are controls associated with this framework !'])
->withErrors(['msg' => 'There are measures associated with this framework !'])
->withInput();
}

// Delete measures
DB::table('measures')->where('domain_id', $domain->id)->delete();

// Delete domain
$domain->delete();

return redirect('/domains');
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function edit(User $user)
// Allow only admin or the owner of the profile to edit
$this->authorizeAdminOrOwner($user);

$controls = Control::select('id', 'clause')->whereNull('realisation_date')->orderBy('clause')->get();
$controls = Control::select('id', 'name')->whereNull('realisation_date')->orderBy('name')->get();

return view('users.edit', compact('user', 'controls'));
}
Expand Down
24 changes: 13 additions & 11 deletions docs/controls.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,29 @@ Cet écran permet de réaliser un contrôle de sécurité.

Cet écran contient :

* Le nom du contrôle
* Le ou les clauses,

* L’objectif
* Le nom du contrôle,

* Les données
* L’objectif,

* La date de réalisation, la date de planification
* Les données,

* Les observation du contrôle
* La date de réalisation, la date de planification,

* Une zone pour sauvegarder les preuves (**CTRL+V** permet de coller un fichier ou une capture d'écran)
* Les observation du contrôle,

* Un lien permettant de télécharger la fiche de contrôles
* Une zone pour sauvegarder les preuves (**CTRL+V** permet de coller un fichier ou une capture d'écran),

* Le modèle de calcul appliqué
* Un lien permettant de télécharger la fiche de contrôles,

* La note
* Le modèle de calcul appliqué,

* Le score
* La note,

* Le plan d’action
* Le score,

* Le plan d’action,

* La date du prochaine contrôle

Expand Down
22 changes: 12 additions & 10 deletions docs/controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,31 @@ This screen allows you to perform a measurement.

This screen contains:

* The name of the measurement
* The clauses,

* The goal
* The name of the measurement,

* Data
* The objective,

* Completion date, planning date
* The input data,

* Completion date, planning date,

* A text area for observations

* A file area for saving evidence (**CTRL+V** can be used to paste a file or screenshot)

* A link to download the measurement sheet
* A link to download the measurement sheet,

* The computation model applied
* The computation model applied,

* The note
* The note,

* The score
* The score,

* The action plan
* The action plan,

* The date of the next check
* The date of the next check,

[![Screenshot](images/c3.png)](images/c3.png)
[![Screenshot](images/c4.png)](images/c4.png)
Expand Down
6 changes: 3 additions & 3 deletions resources/views/controls/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
<select data-role="select" name="attributes[]" multiple>
@foreach($attributes as $attribute)
@if (strlen($attribute)>0)
<option
{{ old("attributes") ? (in_array($attribute, old("attributes")) ? "selected" : "") : ""}}
>{{ $attribute }}</option>
<option {{ in_array($attribute, old("attributes",[])) ? "selected" : "" }}>
{{ $attribute }}
</option>
@endif
@endforeach
</select>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/controls/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
>
<thead>
<tr>
<th class="sortable-column" width="5%">{{ trans("cruds.control.fields.measure") }}</th>
<th class="sortable-column" width="5%">{{ trans("cruds.control.fields.clauses") }}</th>
<th width="40%">{{ trans("cruds.control.fields.name") }}</th>
<th class="sortable-column" width="10%">{{ trans("cruds.control.fields.scope") }}</th>
<th class="sortable-column" width="5%">{{ trans("cruds.control.fields.score") }}</th>
Expand Down
10 changes: 9 additions & 1 deletion resources/views/controls/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,22 @@
</button>
</form>
&nbsp;
<form action="/bob/clone/{{ $control->id }}">
<button class="button yellow">
<span class="mif-plus"></span>
&nbsp;
{{ trans('common.clone') }}
</button>
</form>
&nbsp;
<form action="/bob/delete/{{ $control->id }}" onSubmit="if(!confirm('{{ trans('common.confirm') }}')){return false;}">
<button class="button alert">
<span class="mif-fire"></span>
&nbsp;
{{ trans("common.delete") }}
</button>
</form>
&nbsp;
&nbsp;
@endif
<form action="/bob/index">
<button class="button">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/measures/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</form>
&nbsp;
<form action="/alice/clone/{{ $measure->id }}">
<button class="button primary">
<button class="button yellow">
<span class="mif-plus"></span>
&nbsp;
{{ trans('common.clone') }}
Expand Down
4 changes: 2 additions & 2 deletions resources/views/users/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
@endif

</div>
@if ((Auth::User()->role === 1)||(Auth::User()->role === 2))
@if ((Auth::User()->role === 1)||(Auth::User()->role === 2))
<div class="row">
<div class="cell-2">
<strong>{{ trans('cruds.user.fields.controls') }}</strong>
Expand All @@ -109,7 +109,7 @@
<div class="cell-8">
<select data-role="select" name="controls[]" id="controls" multiple>
@foreach($controls as $control)
<option value="{{ $control->id }}" {{ (in_array($control->id, old('controls', [])) || ($user->controls->contains($control->id))) ? 'selected' : '' }}>{{ $control->clause }}</option>
<option value="{{ $control->id }}" {{ (in_array($control->id, old('controls', [])) || ($user->controls->contains($control->id))) ? 'selected' : '' }}>{{ $control->name }}</option>
@endforeach
</select>

Expand Down
21 changes: 9 additions & 12 deletions resources/views/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
>
<thead>
<tr>
<th class="sortable-column" width="5%">{{ trans("cruds.control.fields.domain") }}</th>
<th class="sortable-column" width="5%">{{ trans("cruds.control.fields.measure") }}</th>
<th class="sortable-column" width="5%">{{ trans("cruds.control.fields.clauses") }}</th>
<th width="50%">{{ trans("cruds.control.fields.name") }}</th>
<th class="sortable-column sort-asc" width="5%">{{ trans("cruds.control.fields.planned") }}</th>
</tr>
Expand All @@ -92,17 +91,15 @@
@foreach($user->lastControls as $control)
<tr>
<td>
<a id="{{ $control->domain->title }}" href="/alice/show/{{ $control->domain_id}}">
{{ $control->domain->title }}
</a>
</td>
<td>
<a id="{{ $control->clause }}" href="/alice/show/{{ $control->measure_id }}">
{{ $control->clause }}
</a>
</td>
@foreach($control->measures as $measure)
<a href="/alice/show/{{ $measure->id }}">{{ $measure->clause }}</a>
@if(!$loop->last)
,
@endif
@endforeach
</td>
<td>
{{ $control->name }}
{{ $control->name }}
</td>
<td>
<a id="{{ $control->plan_date }}" href="/bob/show/{{$control->id}}">
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
Route::get('/bob/make/{id}', 'ControlController@make');
Route::get('/bob/edit/{id}', 'ControlController@edit');
Route::get('/bob/template/{id}', 'ControlController@template');
Route::get('/bob/clone/{id}', 'ControlController@clone');
Route::get('/bob/delete/{id}', 'ControlController@destroy');
Route::post('/bob/make', 'ControlController@doMake');
Route::post('/bob/accept', 'ControlController@accept');
Expand Down

0 comments on commit 41b4f80

Please sign in to comment.