Commit cb431e81 authored by ZeMKI's avatar ZeMKI

New Function Public Url

* installed url shortener.
* new migrations.
* new middleware to check if the token is correct.
* new home layout.
* css optimization.
parent 5b2413b1
......@@ -6,6 +6,7 @@
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Tests\" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/public" />
<excludeFolder url="file://$MODULE_DIR$/vendor/arietimmerman/laravel-url-shortener" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-debugbar" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-dompdf" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-translation-manager" />
......@@ -113,6 +114,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/sensiolabs/security-checker" />
<excludeFolder url="file://$MODULE_DIR$/vendor/slam/php-cs-fixer-extensions" />
<excludeFolder url="file://$MODULE_DIR$/vendor/slevomat/coding-standard" />
<excludeFolder url="file://$MODULE_DIR$/vendor/spatie/laravel-webhook-server" />
<excludeFolder url="file://$MODULE_DIR$/vendor/squizlabs/php_codesniffer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/stichoza/google-translate-php" />
<excludeFolder url="file://$MODULE_DIR$/vendor/swiftmailer/swiftmailer" />
......@@ -151,6 +153,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/tijsverkoyen/css-to-inline-styles" />
<excludeFolder url="file://$MODULE_DIR$/vendor/vlucas/phpdotenv" />
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
<excludeFolder url="file://$MODULE_DIR$/vendor/webpatser/laravel-uuid" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
......
......@@ -157,6 +157,9 @@
<path value="$PROJECT_DIR$/vendor/jasonmccreary/laravel-test-assertions" />
<path value="$PROJECT_DIR$/vendor/parsedown/laravel" />
<path value="$PROJECT_DIR$/vendor/erusev/parsedown" />
<path value="$PROJECT_DIR$/vendor/webpatser/laravel-uuid" />
<path value="$PROJECT_DIR$/vendor/arietimmerman/laravel-url-shortener" />
<path value="$PROJECT_DIR$/vendor/spatie/laravel-webhook-server" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.2" />
......
......@@ -181,4 +181,6 @@ $app/Http/Middleware/Authenticate.php,f/7/f7ec0e145842212dd9c0763d10bb0aaa68d32
<
app/Role.php,5/0/506466bcf9d9bc1f32f19b46aa47d9cf4fbbe185
C
app/Http/Kernel.php,4/0/405f423e61f666bcedb754ae8befdce9e746176e
\ No newline at end of file
app/Http/Kernel.php,4/0/405f423e61f666bcedb754ae8befdce9e746176e
K
app/Policies/UserPolicy.php,7/2/72a6f8426b50f2d6d3c0bdc2da818be7479c8989
\ No newline at end of file
......
......@@ -37,7 +37,7 @@ class InterviewController extends Controller
$data['study'] = $interview->study;
$data['questions'] = $interview->study->questions;
$data['sorting'] = $interview->study->sortings[0];
$data['author'] = User::where('id', $interview->author)->first();
$data['author'] = User::where('id', $interview->author)->first() ?? $interview->author;
Answer::assignAnswersToQuestion($interview, $data);
Sorting::getSortingInfo($interview->study, $data);
Interview::getSortingImages($interview, $data);
......@@ -53,7 +53,8 @@ class InterviewController extends Controller
*/
public function create(Request $request)
{
$this->authorize([Interview::class, $request->input('study')]);
if(auth()->check()) $this->authorize([Interview::class, $request->input('study')]);
/** Extract method FORMATQUESTIONSANSWERS */
$this->FormatQuestionsAndAnswers($request, $returnQuestions);
$data['questions'] = $returnQuestions;
......@@ -121,9 +122,12 @@ class InterviewController extends Controller
public function store(Request $request)
{
$study = Study::where('id', '=', $request->input('study'))->first();
$author = auth()->check() ? Auth::user()->id : 'From public url.';
$interview = new Interview();
$interview->study_id = $study->id;
$interview->author = Auth::user()->id;
$interview->author = $author;
$interview->interviewed = $request->input('interviewed');
$interview->start = $request->input('time_start');
$interview->end = $request->input('time_end');
......@@ -186,4 +190,10 @@ class InterviewController extends Controller
if (!auth()->user()->can('read-studies', $interview->study_id)) abort(403, "You are not authorized to download these data.");
return (new InterviewTokenExport($interview->id))->download($interview->interviewed . ' tokens.xlsx');
}
public function done()
{
return view('interview.done');
}
}
<?php
namespace App\Http\Controllers;
use App\PublicInterviewUrl;
use ArieTimmerman\Laravel\URLShortener\URLShortener;
use Carbon\Carbon;
use Illuminate\Support\Str;
class PublicInterviewUrlController extends Controller
{
public function store()
{
$uuid = Str::uuid();
$PublicInterviewUrl = new PublicInterviewUrl();
$PublicInterviewUrl->id = $uuid;
$PublicInterviewUrl->study_id = request()->study;
$PublicInterviewUrl->created_at = Carbon::now()->toDateTimeString('minutes');
$PublicInterviewUrl->save();
$url = (string)URLShortener::shorten(url('/interviews/new?study='.request()->study.'&t='.$uuid));
$PublicInterviewUrl->short_url_id = Carbon::now()->toDateTimeString('minutes');
return response()->json(['message' => 'Url Created!', 'url' => $url], 200);
}
}
......@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Exports\AllInterviewTokenExport;
use App\Study;
use App\User;
use Illuminate\Support\Facades\DB;
class StudyInterviewController extends Controller
{
......@@ -12,9 +13,12 @@ class StudyInterviewController extends Controller
{
if (!auth()->user()->can('read-studies', $study->id)) abort(403, "You are not authorized to see this content.");
$data['interviews'] = $study->interviews()->get();
$data['publicInterviews'] = collect(DB::select('select study_interview_public_url.id,url,first_opened_at,submitted_at from art_urls inner join study_interview_public_url on art_urls.url like CONCAT(\'%\',study_interview_public_url.id,\'%\') where study_id = :study', ['study' => $study->id]));
$data['study'] = $study;
foreach ($data['interviews'] as $interview) {
$interview['author'] = User::where('id', $interview['author'])->first()->email;
foreach ($data['interviews'] as $interview)
{
$interview['author'] = User::where('id', $interview['author'])->first()->email ?? $interview['author'];
}
return view('interview.index', $data);
}
......
......@@ -62,5 +62,6 @@ class Kernel extends HttpKernel
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'interview' => \App\Http\Middleware\PublicInterviewTokenCheck::class,
];
}
<?php
namespace App\Http\Middleware;
use App\PublicInterviewUrl;
use Carbon\Carbon;
use Closure;
use Spatie\WebhookServer\Exceptions\CouldNotCallWebhook;
use Spatie\WebhookServer\WebhookCall;
class PublicInterviewTokenCheck
{
/**
* @param $request
* @param Closure $next
* @return mixed
* @throws CouldNotCallWebhook
*/
public function handle($request, Closure $next)
{
if (auth()->check())
{
return $next($request);
} else if (!$request->has("t") && request()->isMethod('get'))
{
abort(403);
}
$uuid = request()->t;
$validToken = PublicInterviewUrl::isValid($uuid);
if ($validToken)
{
if (is_null($validToken->first_opened_at))
{
$validToken->first_opened_at = Carbon::now()->toDateTimeString('minutes');
$validToken->save();
}
if(request()->isMethod('post'))
{
$validToken->submitted_at = Carbon::now()->toDateTimeString('minutes');
$validToken->save();
}
return $next($request);
} else
{
WebhookCall::create()
->url('https://chat.zemki.uni-bremen.de/hooks/Jj3dDY2KzSFDS2kxZ/SvbmjdswXTASAXxC2GfgfTpFooK5Eo4kFBGPyDRrtsWmgED3')
->payload(['text' => 'Someone tried to do an interview with a wrong Token on Mesort from ' . request()->ip()])
->useSecret('Jj3dDY2KzSFDS2kxZ/SvbmjdswXTASAXxC2GfgfTpFooK5Eo4kFBGPyDRrtsWmgED3')
->dispatch();
abort(403, "Token not valid, contact your reference person.");
}
}
}
......@@ -2,11 +2,13 @@
namespace App\Policies;
use Auth;
use App\User;
use App\Study;
use App\Interview;
use App\PublicInterviewUrl;
use App\Study;
use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Support\Facades\Log;
class InterviewPolicy
{
......@@ -27,40 +29,36 @@ class InterviewPolicy
/**
* Determine whether the user can view the interview.
*
* @param User $user
* @param User $user
* @param Interview $interview
* @return mixed
*/
public function view(User $user, Interview $interview)
{
if (! $user->can('read-studies', Study::where('id', '=', $interview->study_id)->first()->id)) {
if (!$user->can('read-studies', Study::where('id', '=', $interview->study_id)->first()->id)) {
abort(403, 'You are not allowed to read this study');
}
return true;
}
/**
* Determine whether the user can create interviews.
*
* @param User $user
* @param User $user
* @param Study $study
* @return mixed
*/
public function create(User $user, $study)
{
if (! $user->can('create-interviews', Study::where('id', '=', $study)->first()->id)) {
if (!$user->can('create-interviews', Study::where('id', '=', $study)->first()->id)) {
abort(403, 'You are not allowed to create interviews for this study');
}
return true;
}
/**
* Determine whether the user can update the interview.
*
* @param User $user
* @param User $user
* @param Interview $interview
* @return void
*/
......@@ -70,8 +68,7 @@ class InterviewPolicy
/**
* Determine whether the user can delete the interview.
*
* @param User $user
* @param User $user
* @param Interview $interview
* @return void
*/
......@@ -81,8 +78,7 @@ class InterviewPolicy
/**
* Determine whether the user can restore the interview.
*
* @param User $user
* @param User $user
* @param Interview $interview
* @return void
*/
......@@ -92,8 +88,7 @@ class InterviewPolicy
/**
* Determine whether the user can permanently delete the interview.
*
* @param User $user
* @param User $user
* @param Interview $interview
* @return void
*/
......@@ -101,11 +96,11 @@ class InterviewPolicy
{
}
public function exportall(User $user, $study){
if ( $user->can('read-studies', Study::where('id', '=', $study)->first()->id)) {
public function exportall(User $user, $study)
{
if ($user->can('read-studies', Study::where('id', '=', $study)->first()->id)) {
abort(403, 'You are not allowed to read this study');
}
return true;
}
}
......@@ -2,7 +2,9 @@
namespace App\Providers;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
......@@ -15,9 +17,16 @@ class AppServiceProvider extends ServiceProvider
public function boot()
{
Schema::defaultStringLength(191);
\Illuminate\Support\Facades\View::composer(['telescope::layout'], function ($view) {
$view->with('telescopeScriptVariables', ['path' => strtolower(env('APP_NAME', 'mesort')).'/telescope', 'timezone' => config('app.timezone'), 'recording' => ! cache('telescope:pause-recording')]);
});
if (App::environment('local')) {
// The environment is local
View::composer(['telescope::layout'], function ($view) {
$view->with('telescopeScriptVariables', ['path' => 'telescope', 'timezone' => config('app.timezone'), 'recording' => !cache('telescope:pause-recording')]);
});
}else{
View::composer(['telescope::layout'], function ($view) {
$view->with('telescopeScriptVariables', ['path' => 'mesort/telescope', 'timezone' => config('app.timezone'), 'recording' => !cache('telescope:pause-recording')]);
});
}
}
/**
......
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PublicInterviewUrl extends Model
{
/**
* @var string
*/
protected $table = 'study_interview_public_url';
public $timestamps = false;
public static function isValid($uuid)
{
return PublicInterviewUrl::where('id', '=', $uuid)->whereNull('submitted_at')->first();
}
}
......@@ -4,8 +4,62 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c26023d49f9ad44d7906c5528eec56e5",
"content-hash": "c7835414cb5718c48e0552ddc64f353c",
"packages": [
{
"name": "arietimmerman/laravel-url-shortener",
"version": "v0.1.3",
"source": {
"type": "git",
"url": "https://github.com/arietimmerman/laravel-url-shortener.git",
"reference": "1032600b56fc4b3ba0cced251196b5a472996277"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/arietimmerman/laravel-url-shortener/zipball/1032600b56fc4b3ba0cced251196b5a472996277",
"reference": "1032600b56fc4b3ba0cced251196b5a472996277",
"shasum": ""
},
"require": {
"illuminate/database": "^5.5 || ^6.0 || ^7.0",
"illuminate/queue": "^5.5 || ^6.0 || ^7.0",
"illuminate/support": "^5.5 || ^6.0 || ^7.0",
"php": "^7.0",
"webpatser/laravel-uuid": "^3.0"
},
"require-dev": {
"orchestra/testbench": "~3.0",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"ArieTimmerman\\Laravel\\URLShortener\\ServiceProvider"
],
"aliases": {
"URLShortener": "ArieTimmerman\\Laravel\\URLShortener\\URLShortener"
}
}
},
"autoload": {
"psr-4": {
"ArieTimmerman\\Laravel\\URLShortener\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Arie Timmerman",
"email": "arietimmerman@gmail.com"
}
],
"description": "Laravel Package for shortening urls",
"time": "2020-03-21T13:42:30+00:00"
},
{
"name": "barryvdh/laravel-dompdf",
"version": "v0.8.6",
......@@ -457,6 +511,52 @@
],
"time": "2020-02-13T22:36:52+00:00"
},
{
"name": "erusev/parsedown",
"version": "1.7.4",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
},
"type": "library",
"autoload": {
"psr-0": {
"Parsedown": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"description": "Parser for Markdown.",
"homepage": "http://parsedown.org",
"keywords": [
"markdown",
"parser"
],
"time": "2019-12-30T22:54:17+00:00"
},
{
"name": "facade/flare-client-php",
"version": "1.3.2",
......@@ -1040,6 +1140,7 @@
"email": "jakub.onderka@gmail.com"
}
],
"abandoned": "php-parallel-lint/php-console-color",
"time": "2018-09-29T17:23:10+00:00"
},
{
......@@ -1086,6 +1187,7 @@
}
],
"description": "Highlight PHP code in terminal",
"abandoned": "php-parallel-lint/php-console-highlighter",
"time": "2018-09-29T18:48:56+00:00"
},
{
......@@ -2222,6 +2324,63 @@
],
"time": "2018-07-02T15:55:56+00:00"
},
{
"name": "parsedown/laravel",
"version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/parsedown/laravel.git",
"reference": "c713ffe28c76730754389180e86e93e8e84087e7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/parsedown/laravel/zipball/c713ffe28c76730754389180e86e93e8e84087e7",
"reference": "c713ffe28c76730754389180e86e93e8e84087e7",
"shasum": ""
},
"require": {
"erusev/parsedown": "^1.7",
"php": ">=7.1.3"
},
"require-dev": {
"orchestra/testbench": "^3.8",
"php": ">=7.2",
"phpunit/phpunit": "^8.3"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Parsedown\\Providers\\ParsedownServiceProvider"
]
}
},
"autoload": {
"files": [
"src/Support/helpers.php"
],
"psr-4": {
"Parsedown\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Eduardo Agostini",
"email": "edu.agostini@gmail.com"
}
],
"description": "Official Parsedown's Laravel Wrapper.",
"homepage": "http://parsedown.org",
"keywords": [
"laravel",
"parsedown"
],
"time": "2020-01-07T02:12:55+00:00"
},
{
"name": "phenx/php-font-lib",
"version": "0.5.1",
......@@ -3167,6 +3326,68 @@
],
"time": "2020-03-02T05:59:21+00:00"
},
{
"name": "spatie/laravel-webhook-server",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-webhook-server.git",
"reference": "c8b447f5672bd57143f5353a8be505f114130e6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-webhook-server/zipball/c8b447f5672bd57143f5353a8be505f114130e6a",
"reference": "c8b447f5672bd57143f5353a8be505f114130e6a",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/guzzle": "^6.3",
"illuminate/bus": "^5.8|^6.0",
"illuminate/queue": "^5.8|^6.0",
"illuminate/support": "^5.8|^6.0",
"php": "^7.3"
},
"require-dev": {
"orchestra/testbench": "^3.8|^4.0",
"phpunit/phpunit": "^8.2",
"spatie/test-time": "^1.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\WebhookServer\\WebhookServerServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Spatie\\WebhookServer\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "Send webhooks in Laravel apps",
"homepage": "https://github.com/spatie/laravel-webhook-server",
"keywords": [
"laravel-webhook-server",
"server",
"spatie",
"webhook"
],
"time": "2019-09-05T21:16:12+00:00"
},
{
"name": "stichoza/google-translate-php",
"version": "v4.1.0",
......@@ -4799,6 +5020,60 @@
"environment"
],
"time": "2019-09-10T21:37:39+00:00"
},
{
"name": "webpatser/laravel-uuid",
"version": "3.0.2",
"source": {
"type": "git",
"url": "https://github.com/webpatser/laravel-uuid.git",
"reference": "a7ce65cdabbc9970fc2a87fdf67b48e0b1641d23"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webpatser/laravel-uuid/zipball/a7ce65cdabbc9970fc2a87fdf67b48e0b1641d23",
"reference": "a7ce65cdabbc9970fc2a87fdf67b48e0b1641d23",
"shasum": ""
},
"require": {
"php": "^7.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",