Skip to content

Commit

Permalink
Merge pull request #34 from mostafamaklad/v1.3
Browse files Browse the repository at this point in the history
V1.3.4
  • Loading branch information
mostafamaklad committed Sep 28, 2017
2 parents 3f2ed7e + 2ba0562 commit 48ba138
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@

All Notable changes to `laravel-permission-mongodb` will be documented in this file.

## 1.3.4 - 2017-09-28

### added
- Add the support of `laravel 5.2`

## 1.3.3 - 2017-09-27

### added
Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,7 @@
[![Dependency Status][ico-gemnasium]][link-gemnasium]
[![SensioLabsInsight][ico-sensiolabs]][link-sensiolabs]
[![Total Downloads][ico-downloads]][link-packagist]
[![Laravel 5.3.x][ico-laravel-5.2]][link-laravel-5.2]
[![Laravel 5.3.x][ico-laravel-5.3]][link-laravel-5.3]
[![Laravel 5.4.x][ico-laravel-5.4]][link-laravel-5.4]
[![Laravel 5.5.x][ico-laravel-5.5]][link-laravel-5.5]
Expand Down Expand Up @@ -66,6 +67,8 @@ $user->can('edit articles');

This package can be used in Laravel 5.3 and up.

> Note: use version 1.3.4 and up if you are using Laravel 5.2.x
> Note: use version 1.3.3 and up if you are using Laravel 5.3.x
> Note: use version 1.4.0-alpha if you are using Laravel 5.5.x
Expand Down Expand Up @@ -684,6 +687,8 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/mostafamaklad/laravel-permission-mongodb.svg?style=flat-square

[link-laravel-5.2]: https://laravel.com/docs/5.2
[ico-laravel-5.2]: https://img.shields.io/badge/Laravel-5.2.x-brightgreen.svg?style=flat-square
[link-laravel-5.3]: https://laravel.com/docs/5.3
[ico-laravel-5.3]: https://img.shields.io/badge/Laravel-5.3.x-brightgreen.svg?style=flat-square
[link-laravel-5.4]: https://laravel.com/docs/5.4
Expand Down
12 changes: 6 additions & 6 deletions composer.json
@@ -1,6 +1,6 @@
{
"name": "mostafamaklad/laravel-permission-mongodb",
"description": "Permission handling for Laravel 5.3 and up using mongodb",
"description": "Permission handling for Laravel 5.2 and up using mongodb",
"keywords": [
"laravel",
"security",
Expand Down Expand Up @@ -31,15 +31,15 @@
],
"require": {
"php": ">=7.0",
"illuminate/auth": "~5.3.0|~5.4.0",
"illuminate/container": "~5.3.0|~5.4.0",
"illuminate/contracts": "~5.3.0|~5.4.0",
"jenssegers/mongodb": "3.1.*|3.2.*"
"illuminate/auth": "~5.2.0|~5.3.0|~5.4.0",
"illuminate/container": "~5.2.0|~5.3.0|~5.4.0",
"illuminate/contracts": "~5.2.0|~5.3.0|~5.4.0",
"jenssegers/mongodb": "3.0.*|3.1.*|3.2.*"
},
"require-dev": {
"codeclimate/php-test-reporter": "^0.4.4",
"monolog/monolog": "^1.23",
"orchestra/testbench": "~3.3.0|~3.4.2",
"orchestra/testbench": "~3.2.0|~3.3.0|~3.4.2",
"phpunit/phpunit": "^5.7|^6.3",
"squizlabs/php_codesniffer": "^3.1"
},
Expand Down
5 changes: 2 additions & 3 deletions src/Models/Permission.php
Expand Up @@ -61,9 +61,8 @@ public static function create(array $attributes = [])
throw new PermissionAlreadyExists($helpers->getPermissionAlreadyExistsMessage($name, $guardName));
}

switch (substr(app()::VERSION, 0, 3)) {
case '5.3':
return parent::create($attributes);
if (app()::VERSION < '5.4') {
return parent::create($attributes);
}

return static::query()->create($attributes);
Expand Down
5 changes: 2 additions & 3 deletions src/Models/Role.php
Expand Up @@ -60,9 +60,8 @@ public static function create(array $attributes = [])
throw new RoleAlreadyExists($helpers->getRoleAlreadyExistsMessage($name, $guardName));
}

switch (substr(app()::VERSION, 0, 3)) {
case '5.3':
return parent::create($attributes);
if (app()::VERSION < '5.4') {
return parent::create($attributes);
}

return static::query()->create($attributes);
Expand Down
4 changes: 4 additions & 0 deletions src/PermissionServiceProvider.php
Expand Up @@ -54,6 +54,7 @@ protected function registerBladeExtensions()
{
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
$bladeCompiler->directive('role', function ($arguments) {
$arguments = preg_replace('(\(|\)| )', '', $arguments);
list($role, $guard) = \explode(',', $arguments . ',');

return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>";
Expand All @@ -63,6 +64,7 @@ protected function registerBladeExtensions()
});

$bladeCompiler->directive('hasrole', function ($arguments) {
$arguments = preg_replace('(\(|\)| )', '', $arguments);
list($role, $guard) = \explode(',', $arguments . ',');

return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>";
Expand All @@ -72,6 +74,7 @@ protected function registerBladeExtensions()
});

$bladeCompiler->directive('hasanyrole', function ($arguments) {
$arguments = preg_replace('(\(|\)| )', '', $arguments);
list($roles, $guard) = \explode(',', $arguments . ',');

return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAnyRole({$roles})): ?>";
Expand All @@ -81,6 +84,7 @@ protected function registerBladeExtensions()
});

$bladeCompiler->directive('hasallroles', function ($arguments) {
$arguments = preg_replace('(\(|\)| )', '', $arguments);
list($roles, $guard) = \explode(',', $arguments . ',');

return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAllRoles({$roles})): ?>";
Expand Down
6 changes: 2 additions & 4 deletions tests/PermissionTest.php
Expand Up @@ -2,11 +2,9 @@

namespace Maklad\Permission\Test;

use Maklad\Permission\Helpers;
use Maklad\Permission\Models\Permission;
use Maklad\Permission\Exceptions\PermissionAlreadyExists;
use Maklad\Permission\Models\Permission;
use Monolog\Logger;
use Symfony\Component\Console\Helper\Helper;

class PermissionTest extends TestCase
{
Expand Down Expand Up @@ -52,7 +50,7 @@ public function it_has_user_models_of_the_right_class()
$this->testUser->givePermissionTo($this->testUserPermission);

$this->assertCount(1, $this->testUserPermission->users);
$this->assertTrue($this->testUserPermission->users->first()->is($this->testUser));
$this->assertEquals(get_class($this->testUser), get_class($this->testUserPermission->users->first()));
$this->assertInstanceOf(User::class, $this->testUserPermission->users->first());

$this->testUser->delete();
Expand Down
2 changes: 1 addition & 1 deletion tests/RoleTest.php
Expand Up @@ -28,7 +28,7 @@ public function it_has_user_models_of_the_right_class()
$this->testUser->assignRole($this->testUserRole);

$this->assertCount(1, $this->testUserRole->users);
$this->assertTrue($this->testUserRole->users->first()->is($this->testUser));
$this->assertEquals(get_class($this->testUser), get_class($this->testUserRole->users->first()));
$this->assertInstanceOf(User::class, $this->testUserRole->users->first());

$this->testUser->delete();
Expand Down
12 changes: 5 additions & 7 deletions tests/TestCase.php
Expand Up @@ -4,12 +4,12 @@

use Jenssegers\Mongodb\MongodbServiceProvider;
use Maklad\Permission\Helpers;
use Monolog\Handler\TestHandler;
use Maklad\Permission\PermissionRegistrar;
use Maklad\Permission\Models\Role;
use Maklad\Permission\Models\Permission;
use Orchestra\Testbench\TestCase as Orchestra;
use Maklad\Permission\Models\Role;
use Maklad\Permission\PermissionRegistrar;
use Maklad\Permission\PermissionServiceProvider;
use Monolog\Handler\TestHandler;
use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
Expand Down Expand Up @@ -156,9 +156,7 @@ protected function clearLogTestHandler()
{
\collect($this->app['log']->getMonolog()->getHandlers())->filter(function ($handler) {
return $handler instanceof TestHandler;
})->first(function (TestHandler $handler) {
$handler->clear();
});
})->first()->clear();
}

protected function assertNotLogged($message, $level)
Expand Down

0 comments on commit 48ba138

Please sign in to comment.