dataset publication workflow: editor page

This commit is contained in:
Arno Kaimbacher 2019-04-09 19:05:03 +02:00
parent de80de9d88
commit 246577b0b0
9 changed files with 246 additions and 35 deletions

View File

@ -30,7 +30,7 @@ class WorkflowController extends Controller
$builder = Dataset::query(); $builder = Dataset::query();
$myDatasets = $builder $myDatasets = $builder
->whereIn('server_state', ['inprogress', 'released']) ->whereIn('server_state', ['inprogress', 'released'])
->where('account_id', $user_id) // ->where('account_id', $user_id)
->with('user:id,login') ->with('user:id,login')
->get(); ->get();
return view('workflow.index', [ return view('workflow.index', [
@ -51,7 +51,7 @@ class WorkflowController extends Controller
// $q->where('login', 'admin'); // $q->where('login', 'admin');
// })->pluck('login', 'id'); // })->pluck('login', 'id');
$editors = User::with(['roles' => function ($query) { $editors = User::with(['roles' => function ($query) {
$query->where('name', 'reviewer'); $query->where('name', 'editor');
}]) }])
->pluck('login', 'id'); ->pluck('login', 'id');
//$editors = Role::where('name', 'reviewer')->first()->users; //$editors = Role::where('name', 'reviewer')->first()->users;
@ -105,7 +105,7 @@ class WorkflowController extends Controller
} }
} }
$dataset->delete(); $dataset->delete();
session()->flash('flash_message', 'You have been deleted 1 dataset!'); session()->flash('flash_message', 'You have deleted 1 dataset!');
return redirect()->route('publish.workflow.index'); return redirect()->route('publish.workflow.index');
} }
} }
@ -115,14 +115,43 @@ class WorkflowController extends Controller
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function indexReleased() public function editorIndex()
{ {
$builder = Dataset::query(); $builder = Dataset::query();
$datasets = $builder $datasets = $builder
//->where('server_state', 'inprogress') //->where('server_state', 'inprogress')
->whereIn('server_state', ['released']) ->whereIn('server_state', ['released'])
->get(); ->get();
return view('workflow.review', compact('datasets')); return view('workflow.editor_index', compact('datasets'));
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\View\View
*/
public function accept($id): View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
// $editors = User::whereHas('roles', function ($q) {
// $q->where('login', 'admin');
// })->pluck('login', 'id');
$editors = User::with(['roles' => function ($query) {
$query->where('name', 'editor');
}])
->pluck('login', 'id');
//$editors = Role::where('name', 'reviewer')->first()->users;
return view('workflow.accept', [
'dataset' => $dataset,
'editors' => $editors,
]);
}
public function acceptUpdate(Request $request, $id)
{
$dataset = Dataset::findOrFail($id);
} }
// public function release() // public function release()

View File

@ -63,6 +63,7 @@ class Kernel extends HttpKernel
// 'role' => \Zizaco\Entrust\Middleware\EntrustRole::class, // 'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class, 'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class, 'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,
'isUserDatasetAdmin' => \App\Http\Middleware\WebAuthorizeDataset::class,
]; ];
} }

View File

@ -0,0 +1,57 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use App\Models\Dataset;
use App\Models\User;
class WebAuthorizeDataset
{
const DELIMITER = '|';
protected $auth;
/**
* Creates a new instance of the middleware.
*
* @param Guard $auth
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(\Illuminate\Http\Request $request, Closure $next, bool $requiresDatasetAdministrator)
{
// if ($this->auth->guest() || !$request->user()->can("Administrator")) {
// abort(403);
// }
$userId = $this->auth->user()->id;
$datasetId = $request->route('id');
if ($this->auth->guest() || !$this->isUserDatasetAdmin($userId, $datasetId)) {
abort(403, "You are not allowed to do this action!");
}
return $next($request);
}
private function isUserDatasetAdmin($userId, $datasetId)
{
$dataset = Dataset::with('user:id,login')->findOrFail($datasetId);
$user = User::findOrFail($userId);
if ($dataset->user->id == $user->id) { //} || $user->can("administrator")) {
return true;
} else {
return false;
}
}
}

View File

@ -5,7 +5,9 @@
<div class='col-lg-4 col-lg-offset-4'> <div class='col-lg-4 col-lg-offset-4'>
<h1><center>403<br> <h1><center>403<br>
ACCESS DENIED</center></h1> ACCESS DENIED</center></h1>
<a href="{{ URL::previous() }}" class="btn btn-default">Back</a>
<h2>{{ $exception->getMessage() }}</h2> <h2>{{ $exception->getMessage() }}</h2>
</div> </div>
@endsection @endsection

View File

@ -65,7 +65,7 @@
<li class="pure-menu-item"><a class="pure-menu-link" href="{{ route('settings.collection.index') }}">COLLECTION</a></li> <li class="pure-menu-item"><a class="pure-menu-link" href="{{ route('settings.collection.index') }}">COLLECTION</a></li>
<li class="pure-menu-item"><a class="pure-menu-link" href="{{ route('settings.project') }}">PROJECT</a></li> <li class="pure-menu-item"><a class="pure-menu-link" href="{{ route('settings.project') }}">PROJECT</a></li>
<!-- <li><a href="{{ route('settings.shelf') }}" class="marvel">SHELF</a></li>-->
<li class="pure-menu-item"><a href="{{ route('settings.license') }}" class="pure-menu-link">LICENSES</a></li> <li class="pure-menu-item"><a href="{{ route('settings.license') }}" class="pure-menu-link">LICENSES</a></li>

View File

@ -88,7 +88,7 @@
</li> </li>
@endpermission @endpermission
@permission('review') @role(array('administrator', 'editor', 'reviewer'))
<li class="treeview"> <li class="treeview">
<h2 class="pure-menu-heading">Publish</h2> <h2 class="pure-menu-heading">Publish</h2>
<ul class="pure-menu-list"> <ul class="pure-menu-list">
@ -98,8 +98,8 @@
<li class="pure-menu-item {{ Route::is('publish.workflow.index') ? 'active' : '' }}"> <li class="pure-menu-item {{ Route::is('publish.workflow.index') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('publish.workflow.index') }}"><i class="fa fa-upload"></i> All my datasets</a> <a class="pure-menu-link" href="{{ URL::route('publish.workflow.index') }}"><i class="fa fa-upload"></i> All my datasets</a>
</li> </li>
<li class="pure-menu-item {{ Route::is('publish.workflow.indexreleased') ? 'active' : '' }}"> <li class="pure-menu-item {{ Route::is('publish.workflow.editorIndex') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('publish.workflow.indexReleased') }}"><i class="fa fa-upload"></i> All released datasets</a> <a class="pure-menu-link" href="{{ URL::route('publish.workflow.editorIndex') }}"><i class="fa fa-upload"></i> EDITOR PAGE: Released datasets</a>
</li> </li>
{{-- <li class="pure-menu-item {{ Route::is('publish.workflow.release') ? 'active' : '' }}"> {{-- <li class="pure-menu-item {{ Route::is('publish.workflow.release') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('publish.workflow.release') }}"><i class="fa fa-upload"></i> Release pending datasets</a> <a class="pure-menu-link" href="{{ URL::route('publish.workflow.release') }}"><i class="fa fa-upload"></i> Release pending datasets</a>
@ -109,7 +109,7 @@
</li> --}} </li> --}}
</ul> </ul>
</li> </li>
@endpermission @endrole

View File

@ -0,0 +1,89 @@
@extends('settings.layouts.app')
@section('content')
<div class="header">
<h3 class="header-title">
<i class="fa fa-share"></i> Accept released dataset
</h3>
</div>
<div class="header">
<h3 class="header-title">
Release your dataset for Editor
</h3>
</div>
<div class="pure-g box-content">
<div class="pure-u-1 pure-u-md-1">
<div>
<a href="{{ route('publish.workflow.editorIndex') }}" class="pure-button button-small">
<i class="fa fa-chevron-left"></i>
<span>BACK</span>
</a>
</div>
<div id="app1">
@php
//if userid changed from last iteration, store new userid and change color
// $lastid = $detail->payment->userid;
if ($dataset->editor->id == Auth::user()->id) {
$userIsDesiredEditor = true;
} else {
$userIsDesiredEditor = false;
$message = 'you are not the desired editor, but you can still accept the dataset';
}
@endphp
{!! Form::model($dataset, [ 'method' => 'POST', 'id' => 'acceptForm',
'class' => 'pure-form', 'enctype' => 'multipart/form-data', 'v-on:submit.prevent' => 'checkForm']) !!}
<fieldset id="fieldset-General">
<legend>General</legend>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-1 pure-div">
{!! Form::label('editor_id', 'preferred editor:') !!}
{!! $dataset->editor->login !!}
@if($userIsDesiredEditor == false)
<span class="help is-danger"> {!! $message !!}</span>
@endif
{{-- <span class="help is-danger" v-if="errors.has('editor_id')" v-text="errors.first('editor_id')"></span> --}}
</div>
<div class="pure-u-1 pure-u-md-1-1 pure-div">
{!! Form::label('owner', 'dataset owner:') !!}
{!! $dataset->user->login !!}
{{-- <span class="help is-danger" v-if="errors.has('editor_id')" v-text="errors.first('editor_id')"></span> --}}
</div>
<div class="pure-u-1 pure-u-md-1-1 pure-div">
{!! Form::label('title', 'dataset title:') !!}
@if ($dataset->titles()->first())
{{ $dataset->titles()->first()->value }}
@endif
</div>
</div>
</fieldset>
<br />
<div class="pure-controls">
<button :disabled="errors.any()" type="submit" class="pure-button">
<i class="fa fa-share"></i>
<span>Accept</span>
</button>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
@stop
@section('after-scripts') {{--
<script type="text/javascript" src="{{ asset('js/lib.js') }}"></script> --}} {{--
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>--}} {{--
<script type="text/javascript" src="{{ resource_path('assets\js\datasetPublish.js') }}"></script> --}}
<script type="text/javascript" src="{{ asset('backend/publish/releaseDataset.js') }}"></script>
@stop

View File

@ -2,7 +2,7 @@
@section('content') @section('content')
<div class="header"> <div class="header">
<h3 class="header-title"> <h3 class="header-title">
<i class="fa fa-file"></i> Review unpblished datasets <i class="fa fa-file"></i>EDITOR PAGE: Approve released datasets
</h3> </h3>
</div> </div>
@ -14,6 +14,7 @@
<th>Dataset Title</th> <th>Dataset Title</th>
<th>ID</th> <th>ID</th>
<th>Server State</th> <th>Server State</th>
<th>Preferred Editor</th>
<th></th> <th></th>
</thead> </thead>
@ -33,13 +34,25 @@
<td> <td>
{{ $dataset->server_state }} {{ $dataset->server_state }}
</td> </td>
<td> {{ optional($dataset->editor)->login }} </td>
<td> <td>
@if ($dataset->server_state == "unpublished") @if ($dataset->server_state == "released")
<a href="{{ URL::route('publish.review.changestate',['id' => $dataset->id, 'targetState' => 'published']) }}" class="pure-button button-small is-success">Publish</a> <a href="{{ URL::route('publish.workflow.accept', $dataset->id) }}" class="pure-button">
{{-- <a href="" class="pure-button button-small is-success">Restrict</a> --}} <i class="fa fa-share"></i>
<span>Accept editor task</span>
</a>
{{-- <a href="{{ URL::route('publish.workflow.delete', $dataset->id) }}" class="pure-button">
<i class="fa fa-trash"></i>
<span>Reject</span>
</a> --}}
@endif @endif
</td> </td>
{{-- <td>
@if ($dataset->server_state == "unpublished")
<a href="{{ URL::route('publish.review.changestate',['id' => $dataset->id, 'targetState' => 'published']) }}" class="pure-button button-small is-success">Publish</a>
@endif
</td> --}}
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>

View File

@ -21,7 +21,7 @@ Route::get(
'setlocale/{lang}', 'setlocale/{lang}',
[ [
'as' => 'setlocale', //name() 'as' => 'setlocale', //name()
'uses' => 'Frontend\LocalizationController@setLocale' 'uses' => 'Frontend\LocalizationController@setLocale',
] ]
); );
@ -29,42 +29,63 @@ Route::get(
Route::group( Route::group(
[ [
'namespace' => 'Publish', 'namespace' => 'Publish',
'middleware' => ['permission:review'], // 'middleware' => ['permission:publish'],
// 'middleware' => ['role:administrator|reviewer|editor'],
'prefix' => 'publish', 'prefix' => 'publish',
'as' => 'publish.' 'as' => 'publish.',
], ],
function () { function () {
Route::get('dataset', [ Route::get('dataset', [
'as' => 'dataset.index', 'uses' => 'IndexController@index', 'as' => 'dataset.index', 'uses' => 'IndexController@index',
]); ]);
Route::get('dataset/create-step1', ['as' => 'dataset.create', 'uses' => 'IndexController@createStep1']); Route::get('dataset/create-step1', [
'middleware' => ['permission:dataset-create'],
'as' => 'dataset.create',
'uses' => 'IndexController@createStep1',
]);
// Route::post('dataset/store-step1', ['as' => 'dataset.store1', 'uses' => 'IndexController@storeStep1']); // Route::post('dataset/store-step1', ['as' => 'dataset.store1', 'uses' => 'IndexController@storeStep1']);
// Route::get('dataset/create-step2', ['as' => 'dataset.create2', 'uses' => 'IndexController@createStep2']); // Route::get('dataset/create-step2', ['as' => 'dataset.create2', 'uses' => 'IndexController@createStep2']);
// Route::post('dataset/store-step2', ['as' => 'dataset.store2', 'uses' => 'IndexController@storeStep2']); // Route::post('dataset/store-step2', ['as' => 'dataset.store2', 'uses' => 'IndexController@storeStep2']);
// Route::get('dataset/create-step3', ['as' => 'dataset.create3', 'uses' => 'IndexController@createStep3']); // Route::get('dataset/create-step3', ['as' => 'dataset.create3', 'uses' => 'IndexController@createStep3']);
Route::post('dataset/store', ['as' => 'dataset.store', 'uses' => 'IndexController@store']); Route::post('dataset/store', [
'middleware' => ['permission:dataset-create'],
'as' => 'dataset.store',
'uses' => 'IndexController@store',
]);
Route::get('workflow/index', [ Route::get('workflow/index', [
'middleware' => ['permission:dataset-list'],
'as' => 'workflow.index', 'uses' => 'WorkflowController@index', 'as' => 'workflow.index', 'uses' => 'WorkflowController@index',
]); ]);
Route::get('workflow/release/{id}', [ Route::get('workflow/release/{id}', [
'middleware' => ['permission:dataset-create', 'isUserDatasetAdmin:true'],
'as' => 'workflow.release', 'uses' => 'WorkflowController@release', 'as' => 'workflow.release', 'uses' => 'WorkflowController@release',
]); ]);
Route::post('workflow/release/{id}', [ Route::post('workflow/release/{id}', [
'middleware' => ['permission:dataset-create', 'isUserDatasetAdmin:true'],
'as' => 'workflow.releaseUpdate', 'uses' => 'WorkflowController@releaseUpdate', 'as' => 'workflow.releaseUpdate', 'uses' => 'WorkflowController@releaseUpdate',
]); ]);
Route::get('workflow/delete/{id}', [ Route::get('workflow/delete/{id}', [
'middleware' => ['isUserDatasetAdmin:true'],
'as' => 'workflow.delete', 'uses' => 'WorkflowController@delete', 'as' => 'workflow.delete', 'uses' => 'WorkflowController@delete',
]); ]);
Route::get('workflow/release/{id}', [ // Route::get('workflow/release/{id}', [
'as' => 'workflow.release', 'uses' => 'WorkflowController@release', // 'as' => 'workflow.release', 'uses' => 'WorkflowController@release',
// ]);
Route::get('workflow/editor_index', [
'middleware' => ['permission:dataset-released-list'],
'as' => 'workflow.editorIndex', 'uses' => 'WorkflowController@editorIndex',
]); ]);
Route::get('workflow/accept/{id}', [
'middleware' => ['permission:dataset-accept'],
Route::get('workflow/indexreleased', [ 'as' => 'workflow.accept', 'uses' => 'WorkflowController@accept',
'as' => 'workflow.indexReleased', 'uses' => 'WorkflowController@indexReleased', ]);
Route::post('workflow/accept/{id}', [
'middleware' => ['permission:dataset-accept'],
'as' => 'workflow.acceptUpdate', 'uses' => 'WorkflowController@acceptUpdate',
]); ]);
Route::get('workflow/changestate/{id}/changestate/{targetState}', [ Route::get('workflow/changestate/{id}/changestate/{targetState}', [
@ -79,7 +100,7 @@ Route::group(
'namespace' => 'Settings\Access', 'namespace' => 'Settings\Access',
'middleware' => ['permission:settings'], 'middleware' => ['permission:settings'],
'prefix' => 'settings/access', 'prefix' => 'settings/access',
'as' => 'access.' 'as' => 'access.',
], ],
function () { function () {
//Route::resource('users','UserController'); //Route::resource('users','UserController');
@ -102,7 +123,7 @@ Route::group(
'as' => 'user.destroy', 'uses' => 'UserController@destroy', 'as' => 'user.destroy', 'uses' => 'UserController@destroy',
]); ]);
//Route::resource('users','RoleController'); //Route::resource('users','RoleController');
Route::get('role', [ Route::get('role', [
'as' => 'role.index', 'uses' => 'RoleController@index', 'as' => 'role.index', 'uses' => 'RoleController@index',
]); ]);
@ -129,7 +150,7 @@ Route::group(
'middleware' => ['permission:settings'], 'middleware' => ['permission:settings'],
'namespace' => 'Settings', 'namespace' => 'Settings',
'prefix' => 'settings', 'prefix' => 'settings',
'as' => 'settings.' 'as' => 'settings.',
], ],
function () { function () {
//Route::resource('page', 'PageController', ['except' => ['show', 'update']]); //Route::resource('page', 'PageController', ['except' => ['show', 'update']]);
@ -147,7 +168,6 @@ Route::group(
} }
); );
//=================================================setting home - dashboard======================================= //=================================================setting home - dashboard=======================================
Route::get('settings/', [ Route::get('settings/', [
'as' => 'settings.dashboard', 'uses' => 'Settings\DashboardController@index', 'as' => 'settings.dashboard', 'uses' => 'Settings\DashboardController@index',
@ -178,7 +198,7 @@ Route::group(['middleware' => ['permission:settings']], function () {
'as' => 'settings.file.download', 'uses' => 'Settings\FileController@download', 'as' => 'settings.file.download', 'uses' => 'Settings\FileController@download',
]); ]);
//=================================================setting mimetype============================================= //=================================================setting mimetype=============================================
Route::get('/settings/mimetype', [ Route::get('/settings/mimetype', [
'as' => 'settings.mimetype.index', 'uses' => 'Settings\MimetypeController@index', 'as' => 'settings.mimetype.index', 'uses' => 'Settings\MimetypeController@index',
]); ]);
@ -341,7 +361,7 @@ Route::group(['namespace' => 'Frontend', 'as' => 'frontend.'], function () {
//=================================================Crawlers==================================================== //=================================================Crawlers====================================================
Route::get('sitelinks', [ Route::get('sitelinks', [
'as' => 'sitelinks.index', 'uses' => 'SitelinkController@index', 'as' => 'sitelinks.index', 'uses' => 'SitelinkController@index',
]); ]);
Route::get('sitelinks/list/{year}', 'SitelinkController@listDocs')->name('sitelinks.list'); Route::get('sitelinks/list/{year}', 'SitelinkController@listDocs')->name('sitelinks.list');
@ -353,8 +373,8 @@ Route::group(['namespace' => 'Frontend', 'as' => 'frontend.'], function () {
]); ]);
/* /*
* Show pages * Show pages
*/ */
Route::get('pages/{slug}', 'HomeController@showPage')->name('pages.show'); Route::get('pages/{slug}', 'HomeController@showPage')->name('pages.show');
//=================================================solr search==================================================== //=================================================solr search====================================================