Compare commits
4 Commits
54ba249f52
...
5822224c67
Author | SHA1 | Date |
---|---|---|
|
5822224c67 | |
|
e36bb52245 | |
|
784c620012 | |
|
01bbae8d54 |
app/Http/Controllers
resources/views
tests
|
@ -77,7 +77,6 @@ class GiteaApiController extends Controller
|
||||||
header('Content-Type: text/csv');
|
header('Content-Type: text/csv');
|
||||||
// tell the browser we want to save it instead of displaying it
|
// tell the browser we want to save it instead of displaying it
|
||||||
header('Content-Disposition: attachment; filename="' . $file_name . '.csv";');
|
header('Content-Disposition: attachment; filename="' . $file_name . '.csv";');
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function date_to_datetime(string $date)
|
private function date_to_datetime(string $date)
|
||||||
|
@ -103,13 +102,12 @@ class GiteaApiController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($data) > 0 && $data[0]['Chiuso_il'] != '') {
|
if (count($data) > 0) {
|
||||||
$file_name = date('Y_F', strtotime(explode(' ', $data[0]['Chiuso_il'])[0]));
|
$file_name = $issues_params['state']."_issues_from_".$from_date."_to_".$to_date;
|
||||||
$this->create_csv($file_name, $data);
|
$this->create_csv($file_name, $data);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export_closed_issues(Request $req)
|
public function export_closed_issues(Request $req)
|
||||||
|
@ -119,9 +117,10 @@ class GiteaApiController extends Controller
|
||||||
}
|
}
|
||||||
$from = $req->input('from_year') . '-' . $req->input('from_month') . '-01';
|
$from = $req->input('from_year') . '-' . $req->input('from_month') . '-01';
|
||||||
$to = $req->input('to_year') . '-' . $req->input('to_month') . '-31';
|
$to = $req->input('to_year') . '-' . $req->input('to_month') . '-31';
|
||||||
$this->export_issues($from, $to, ['state' => 'closed']);
|
$res = $this->export_issues($from, $to, ['state' => $req->input('issues_type')]);
|
||||||
return view('backend', [
|
return view('backend', [
|
||||||
'token' => getenv('GITEA_TOKEN')
|
'token' => getenv('GITEA_TOKEN'),
|
||||||
|
'download' => $res
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,14 @@
|
||||||
<form name="search-form" action="{{ url('export') }}" method="POST">
|
<form name="search-form" action="{{ url('export') }}" method="POST">
|
||||||
<input type="hidden" name="token" value="{{ $token }}">
|
<input type="hidden" name="token" value="{{ $token }}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="col-xs-12 mb-3">
|
||||||
|
<label for="issues_type" class="form-label">{{__('Select issues:')}}</label>
|
||||||
|
<select class="form-control" name="issues_type" id="issues_type">
|
||||||
|
<option value="closed">{{__('Closed')}}</option>
|
||||||
|
<option value="open">{{__('Open')}}</option>
|
||||||
|
<option value="all">{{__('All')}}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<p>{{__('From:')}}</p>
|
<p>{{__('From:')}}</p>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
|
|
@ -44,4 +44,15 @@ class PagesTest extends TestCase
|
||||||
__('File exporter'), $this->response->getContent()
|
__('File exporter'), $this->response->getContent()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_export_endpoint_is_not_reachable_for_guests_and_redirect_to_login()
|
||||||
|
{
|
||||||
|
$home = $this->get('/');
|
||||||
|
$res = $this->get('/export');
|
||||||
|
|
||||||
|
$res->assertResponseStatus(302);
|
||||||
|
$res->assertEquals(
|
||||||
|
$home->response->getContent(), $this->response->getContent()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
use App\Http\Controllers\GiteaApiController;
|
||||||
|
use Laravel\Lumen\Testing\DatabaseMigrations;
|
||||||
|
use Laravel\Lumen\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class UnitTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_export_endpoint_works_for_logged_in_users()
|
||||||
|
{
|
||||||
|
$res = $this->post('/export', array(
|
||||||
|
'token' => getenv('GITEA_TOKEN'),
|
||||||
|
'from_month' => '10',
|
||||||
|
'from_year' => '2023',
|
||||||
|
'to_month' => '12',
|
||||||
|
'to_year' => '2023'
|
||||||
|
));
|
||||||
|
|
||||||
|
$res->assertResponseOk();
|
||||||
|
//dd($res);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue