Browse Source
Merge pull request #50 from nafiesl/49_system_admins
Merge pull request #50 from nafiesl/49_system_admins
Admin for Managing All Users and DB Backup Managerpull/60/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 196 additions and 24 deletions
-
1.env.example
-
12app/Helpers/functions.php
-
1app/Http/Kernel.php
-
24app/Http/Middleware/AdminOnly.php
-
2app/Policies/CouplePolicy.php
-
4app/Policies/UserPolicy.php
-
12config/app.php
-
11resources/lang/en/birthday.php
-
11resources/lang/id/birthday.php
-
2resources/views/birthdays/index.blade.php
-
4resources/views/layouts/partials/nav.blade.php
-
15routes/web.php
-
44tests/Unit/Helpers/IsSystemAdminHelperTest.php
-
30tests/Unit/Policies/CouplePolicyTest.php
-
47tests/Unit/Policies/UserPolicyTest.php
@ -0,0 +1,24 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Middleware; |
||||
|
|
||||
|
use Closure; |
||||
|
|
||||
|
class AdminOnly |
||||
|
{ |
||||
|
/** |
||||
|
* Handle an incoming request. |
||||
|
* |
||||
|
* @param \Illuminate\Http\Request $request |
||||
|
* @param \Closure $next |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function handle($request, Closure $next) |
||||
|
{ |
||||
|
if (!is_system_admin($request->user())) { |
||||
|
abort(403); |
||||
|
} |
||||
|
|
||||
|
return $next($request); |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,10 @@ |
|||||
<?php |
<?php |
||||
|
|
||||
return [ |
return [ |
||||
'birthday' => 'Birhtday', |
|
||||
'upcoming' => 'Upcoming birthdays', |
|
||||
'remaining' => ':count days', |
|
||||
'age_years' => ':age years', |
|
||||
'days' => 'days', |
|
||||
|
'birthday' => 'Birthday', |
||||
|
'upcoming' => 'Upcoming birthdays', |
||||
|
'no_upcoming' => 'No upcoming birthdays in the next :days days.', |
||||
|
'remaining' => ':count days', |
||||
|
'age_years' => ':age years', |
||||
|
'days' => 'days', |
||||
]; |
]; |
||||
@ -1,9 +1,10 @@ |
|||||
<?php |
<?php |
||||
|
|
||||
return [ |
return [ |
||||
'birthday' => 'Ulang Tahun', |
|
||||
'upcoming' => 'Ulang tahun akan datang', |
|
||||
'remaining' => ':count hari', |
|
||||
'age_years' => ':age tahun', |
|
||||
'days' => 'Hari', |
|
||||
|
'birthday' => 'Ulang Tahun', |
||||
|
'upcoming' => 'Ulang tahun akan datang', |
||||
|
'no_upcoming' => 'Belum ada ulang tahun dalam :days hari kedepan.', |
||||
|
'remaining' => ':count hari', |
||||
|
'age_years' => ':age tahun', |
||||
|
'days' => 'Hari', |
||||
]; |
]; |
||||
@ -0,0 +1,44 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Unit\Helpers; |
||||
|
|
||||
|
use App\User; |
||||
|
use Tests\TestCase; |
||||
|
|
||||
|
class IsSystemAdminHelperTest extends TestCase |
||||
|
{ |
||||
|
/** @test */ |
||||
|
public function user_is_an_admin() |
||||
|
{ |
||||
|
$adminEmail1 = 'admin1@example.net'; |
||||
|
$adminEmail2 = 'admin2@example.net'; |
||||
|
config(['app.system_admin_emails' => $adminEmail1.';'.$adminEmail2]); |
||||
|
|
||||
|
$admin1 = factory(User::class)->make(['email' => $adminEmail1]); |
||||
|
$admin2 = factory(User::class)->make(['email' => $adminEmail2]); |
||||
|
$userWithEmail = factory(User::class)->make(['email' => 'user@example.net']); |
||||
|
$userWithNoEmail = factory(User::class)->make(['email' => null]); |
||||
|
|
||||
|
$this->assertTrue(is_system_admin($admin1)); |
||||
|
$this->assertTrue(is_system_admin($admin2)); |
||||
|
$this->assertFalse(is_system_admin($userWithEmail)); |
||||
|
$this->assertFalse(is_system_admin($userWithNoEmail)); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function if_config_is_null() |
||||
|
{ |
||||
|
$adminEmail1 = 'admin1@example.net'; |
||||
|
$adminEmail2 = 'admin2@example.net'; |
||||
|
|
||||
|
$admin1 = factory(User::class)->make(['email' => $adminEmail1]); |
||||
|
$admin2 = factory(User::class)->make(['email' => $adminEmail2]); |
||||
|
$userWithEmail = factory(User::class)->make(['email' => 'user@example.net']); |
||||
|
$userWithNoEmail = factory(User::class)->make(['email' => null]); |
||||
|
|
||||
|
$this->assertFalse(is_system_admin($admin1)); |
||||
|
$this->assertFalse(is_system_admin($admin2)); |
||||
|
$this->assertFalse(is_system_admin($userWithEmail)); |
||||
|
$this->assertFalse(is_system_admin($userWithNoEmail)); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue