Add subuser support to tasks
Also allow task creation…
This commit is contained in:
parent
9b4a0ed143
commit
9fb0cb420e
5 changed files with 187 additions and 80 deletions
|
@ -71,7 +71,24 @@ class TaskController extends Controller
|
|||
|
||||
public function postNew(Request $request, $uuid)
|
||||
{
|
||||
dd($request->input());
|
||||
$server = Models\Server::getByUUID($uuid);
|
||||
$this->authorize('create-task', $server);
|
||||
|
||||
try {
|
||||
$repo = new Repositories\TaskRepository;
|
||||
$repo->create($server->id, $request->except([
|
||||
'_token'
|
||||
]));
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('server.tasks', $uuid)->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unknown error occured while attempting to create this task.')->flash();
|
||||
}
|
||||
return redirect()->route('server.tasks', $uuid);
|
||||
|
||||
}
|
||||
|
||||
public function getView(Request $request, $uuid, $id)
|
||||
|
|
|
@ -106,12 +106,12 @@ class TaskRepository
|
|||
$validator = Validator::make($data, [
|
||||
'action' => 'string|required',
|
||||
'data' => 'string|required',
|
||||
'year' => 'string|sometimes|required',
|
||||
'day_of_week' => 'string|sometimes|required',
|
||||
'month' => 'string|sometimes|required',
|
||||
'day_of_month' => 'string|sometimes|required',
|
||||
'hour' => 'string|sometimes|required',
|
||||
'minute' => 'string|sometimes|required'
|
||||
'year' => 'string|sometimes',
|
||||
'day_of_week' => 'string|sometimes',
|
||||
'month' => 'string|sometimes',
|
||||
'day_of_month' => 'string|sometimes',
|
||||
'hour' => 'string|sometimes',
|
||||
'minute' => 'string|sometimes'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -124,7 +124,7 @@ class TaskRepository
|
|||
|
||||
$cron = $this->defaults;
|
||||
foreach ($this->defaults as $setting => $value) {
|
||||
if (array_key_exists($setting, $data)) {
|
||||
if (array_key_exists($setting, $data) && !is_null($data[$setting]) && $data[$setting] !== '') {
|
||||
$cron[$setting] = $data[$setting];
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ class TaskRepository
|
|||
$cron['year']
|
||||
));
|
||||
} catch (\Exception $ex) {
|
||||
throw new DisplayException($ex);
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
$task = new Models\Task;
|
||||
|
|
|
@ -40,7 +40,8 @@
|
|||
<tbody>
|
||||
@foreach($tasks as $task)
|
||||
<tr @if($task->active === 0)class="text-disabled"@endif>
|
||||
<td><a href="{{ route('server.tasks.view', [ $server->uuidShort, $task->id ]) }}">{{ $actions[$task->action] }}</a></td>
|
||||
{{-- <td><a href="{{ route('server.tasks.view', [ $server->uuidShort, $task->id ]) }}">{{ $actions[$task->action] }}</a></td> --}}
|
||||
<td>{{ $actions[$task->action] }}</td>
|
||||
<td><code>{{ $task->data }}</code></td>
|
||||
<td>{{ Carbon::parse($task->last_run)->toDayDateTimeString() }} <p class="text-muted"><small>({{ Carbon::parse($task->last_run)->diffForHumans() }})</small></p></td>
|
||||
<td>
|
||||
|
@ -70,6 +71,7 @@ $(document).ready(function () {
|
|||
$('.server-tasks').addClass('active');
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
@can('delete-task', $server)
|
||||
$('[data-action="delete-task"]').click(function (event) {
|
||||
var self = $(this);
|
||||
swal({
|
||||
|
@ -106,7 +108,8 @@ $(document).ready(function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
@endcan
|
||||
@can('toggle-task', $server)
|
||||
$('[data-action="toggle-task"]').click(function (event) {
|
||||
var self = $(this);
|
||||
swal({
|
||||
|
@ -146,6 +149,7 @@ $(document).ready(function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
@endcan
|
||||
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -214,6 +214,49 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 fuelux">
|
||||
<h4>Task Management</h4><hr />
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['list-tasks']))checked="checked"@endif value="list-tasks"> <strong>List Tasks</strong>
|
||||
<p class="text-muted"><small>Allows a user to list all tasks (enabled and disabled) on a server.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['view-task']))checked="checked"@endif value="view-task"> <strong>View Task</strong>
|
||||
<p class="text-muted"><small>Allows a user to view a specific task's details.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['toggle-task']))checked="checked"@endif value="toggle-task"> <strong>Toggle Task</strong>
|
||||
<p class="text-muted"><small>Allows a user to toggle a task on or off.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['queue-task']))checked="checked"@endif value="queue-task"> <strong>Queue Task</strong>
|
||||
<p class="text-muted"><small>Allows a user to queue a task to run on next cycle.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['create-task']))checked="checked"@endif value="create-task"> <strong>Create Task</strong>
|
||||
<p class="text-muted"><small>Allows a user to create new tasks.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($oldInput['delete-task']))checked="checked"@endif value="delete-task"> <strong>Delete Task</strong>
|
||||
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows a user to delete a task.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 fuelux">
|
||||
</div>
|
||||
</div>
|
||||
@can('edit-subuser', $server)
|
||||
<div class="well">
|
||||
<div class="row">
|
||||
|
|
|
@ -203,6 +203,49 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 fuelux">
|
||||
<h4>Task Management</h4><hr />
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['list-tasks']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="list-tasks"> <strong>List Tasks</strong>
|
||||
<p class="text-muted"><small>Allows a user to list all tasks (enabled and disabled) on a server.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['view-task']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="view-task"> <strong>View Task</strong>
|
||||
<p class="text-muted"><small>Allows a user to view a specific task's details.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['toggle-task']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="toggle-task"> <strong>Toggle Task</strong>
|
||||
<p class="text-muted"><small>Allows a user to toggle a task on or off.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['queue-task']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="queue-task"> <strong>Queue Task</strong>
|
||||
<p class="text-muted"><small>Allows a user to queue a task to run on next cycle.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['create-task']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="create-task"> <strong>Create Task</strong>
|
||||
<p class="text-muted"><small>Allows a user to create new tasks.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox highlight">
|
||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||
<input class="sr-only" name="permissions[]" type="checkbox" @if(isset($permissions['delete-task']))checked="checked"@endif @cannot('edit-subuser', $server)disabled="disabled"@endcannot value="delete-task"> <strong>Delete Task</strong>
|
||||
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows a user to delete a task.</small><p>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 fuelux">
|
||||
</div>
|
||||
</div>
|
||||
@can('edit-subuser', $server)
|
||||
<div class="well">
|
||||
<div class="row">
|
||||
|
|
Loading…
Reference in a new issue