Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amankan route api penduduk dengan middleware #381

Merged
merged 10 commits into from
May 12, 2022
6 changes: 6 additions & 0 deletions app/Http/Controllers/Api/LaporanApbdesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\LaporanApbdesRequest;
use App\Jobs\LaporanApbdesQueueJob;
use Illuminate\Support\Facades\Auth;

class LaporanApbdesController extends Controller
{
Expand All @@ -45,6 +46,11 @@ class LaporanApbdesController extends Controller
public function __construct()
{
$this->middleware('auth:api');
if (!Auth::guard('api')->user()->hasRole('admin-desa')) {
response()->json(['status' => 'error',
'message' => 'akun tidak punya hak akses terhadap modul Laporan APBDdes'], 404)->send();
die();
}
apidong marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/Api/LaporanPendudukController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\LaporanPendudukRequest;
use App\Jobs\LaporanPendudukQueueJob;
use Illuminate\Support\Facades\Auth;

class LaporanPendudukController extends Controller
{
Expand All @@ -45,6 +46,11 @@ class LaporanPendudukController extends Controller
public function __construct()
{
$this->middleware('auth:api');
if (!Auth::guard('api')->user()->hasRole('admin-desa')) {
response()->json(['status' => 'error',
'message' => 'akun tidak punya hak akses terhadap modul Laporan Penduduk'], 404)->send();
die();
}
apidong marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/Api/PendudukController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use App\Imports\SinkronPenduduk;
use App\Jobs\PendudukQueueJob;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use ZipArchive;
Expand All @@ -50,6 +51,11 @@ class PendudukController extends Controller
public function __construct()
{
$this->middleware('auth:api');
if (!Auth::guard('api')->user()->hasRole('admin-desa')) {
response()->json(['status' => 'error',
'message' => 'akun tidak punya hak akses terhadap modul penduduk'], 404)->send();
die();
}
apidong marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
72 changes: 72 additions & 0 deletions database/migrations/2022_04_19_074746_create_role_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/*
* File ini bagian dari:
*
* OpenDK
*
* Aplikasi dan source code ini dirilis berdasarkan lisensi GPL V3
*
* Hak Cipta 2017 - 2022 Perkumpulan Desa Digital Terbuka (https://opendesa.id)
*
* Dengan ini diberikan izin, secara gratis, kepada siapa pun yang mendapatkan salinan
* dari perangkat lunak ini dan file dokumentasi terkait ("Aplikasi Ini"), untuk diperlakukan
* tanpa batasan, termasuk hak untuk menggunakan, menyalin, mengubah dan/atau mendistribusikan,
* asal tunduk pada syarat berikut:
*
* Pemberitahuan hak cipta di atas dan pemberitahuan izin ini harus disertakan dalam
* setiap salinan atau bagian penting Aplikasi Ini. Barang siapa yang menghapus atau menghilangkan
* pemberitahuan ini melanggar ketentuan lisensi Aplikasi Ini.
*
* PERANGKAT LUNAK INI DISEDIAKAN "SEBAGAIMANA ADANYA", TANPA JAMINAN APA PUN, BAIK TERSURAT MAUPUN
* TERSIRAT. PENULIS ATAU PEMEGANG HAK CIPTA SAMA SEKALI TIDAK BERTANGGUNG JAWAB ATAS KLAIM, KERUSAKAN ATAU
* KEWAJIBAN APAPUN ATAS PENGGUNAAN ATAU LAINNYA TERKAIT APLIKASI INI.
*
* @package OpenDK
* @author Tim Pengembang OpenDesa
* @copyright Hak Cipta 2017 - 2022 Perkumpulan Desa Digital Terbuka (https://opendesa.id)
* @license http://www.gnu.org/licenses/gpl.html GPL V3
* @link https://github.com/OpenSID/opendk
*/

use Illuminate\Database\Migrations\Migration;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class CreateRoleApi extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// create permissions
Permission::create(['name' => 'view', 'guard_name' => 'api']);
Permission::create(['name' => 'create', 'guard_name' => 'api']);
Permission::create(['name' => 'edit', 'guard_name' => 'api']);
Permission::create(['name' => 'delete', 'guard_name' => 'api']);

$role = [
['name' =>'admin-desa', 'guard_name' => 'api'],
['name' =>'admin-kecamatan', 'guard_name' => 'api'],
['name' =>'admin-puskesmas', 'guard_name' => 'api'],
['name' =>'admin-pendidikan', 'guard_name' => 'api'],
['name' =>'admin-komplain', 'guard_name' => 'api'],
['name' =>'administrator-website', 'guard_name' => 'api'],
];
foreach ($role as $value) {
Role::create($value)->givePermissionTo(['view', 'create', 'edit', 'delete']);
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}