Remove entrust package.

This commit is contained in:
James Cole 2016-02-12 05:49:53 +01:00
parent c63a2ad39d
commit 46856c9394
4 changed files with 80 additions and 43 deletions

View File

@ -1,21 +0,0 @@
<?php
declare(strict_types = 1);
namespace FireflyIII\Models;
use Zizaco\Entrust\EntrustPermission;
/**
* FireflyIII\Models\Permission
*
* @property integer $id
* @property string $name
* @property string $display_name
* @property string $description
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|Role[] $roles
*/
class Permission extends EntrustPermission
{
}

View File

@ -3,21 +3,19 @@ declare(strict_types = 1);
namespace FireflyIII\Models; namespace FireflyIII\Models;
use Zizaco\Entrust\EntrustRole; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
/**
* FireflyIII\Models\Role class Role extends Model
*
* @property integer $id
* @property string $name
* @property string $display_name
* @property string $description
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\User[] $users
* @property-read \Illuminate\Database\Eloquent\Collection|Permission[] $perms
*/
class Role extends EntrustRole
{ {
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function users(): BelongsToMany
{
return $this->belongsToMany('FireflyIII\User');
}
} }

View File

@ -3,10 +3,10 @@ declare(strict_types = 1);
namespace FireflyIII; namespace FireflyIII;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
/** /**
* Class User * Class User
@ -32,11 +32,10 @@ use Zizaco\Entrust\Traits\EntrustUserTrait;
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Role[] $roles * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Role[] $roles
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\RuleGroup[] $ruleGroups * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\RuleGroup[] $ruleGroups
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Rule[] $rules * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Rule[] $rules
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\ExportJob[] $exportjobs * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\ExportJob[] $exportjobs
*/ */
class User extends Authenticatable class User extends Authenticatable
{ {
use EntrustUserTrait;
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
@ -44,16 +43,12 @@ class User extends Authenticatable
* @var array * @var array
*/ */
protected $fillable = ['email', 'password', 'blocked', 'blocked_code']; protected $fillable = ['email', 'password', 'blocked', 'blocked_code'];
/** /**
* The attributes excluded from the model's JSON form. * The attributes excluded from the model's JSON form.
* *
* @var array * @var array
*/ */
protected $hidden = ['password', 'remember_token']; protected $hidden = ['password', 'remember_token'];
/** /**
* The database table used by the model. * The database table used by the model.
* *
@ -69,6 +64,26 @@ class User extends Authenticatable
return $this->hasMany('FireflyIII\Models\Account'); return $this->hasMany('FireflyIII\Models\Account');
} }
/**
* Alias to eloquent many-to-many relation's attach() method.
*
* Full credit goes to: https://github.com/Zizaco/entrust
*
* @param mixed $role
*/
public function attachRole($role)
{
if (is_object($role)) {
$role = $role->getKey();
}
if (is_array($role)) {
$role = $role['id'];
}
$this->roles()->attach($role);
}
/** /**
* @return HasMany * @return HasMany
*/ */
@ -109,6 +124,44 @@ class User extends Authenticatable
return $this->hasMany('FireflyIII\Models\ExportJob'); return $this->hasMany('FireflyIII\Models\ExportJob');
} }
/**
* Checks if the user has a role by its name.
*
* Full credit goes to: https://github.com/Zizaco/entrust
*
* @param string|array $name Role name or array of role names.
* @param bool $requireAll All roles in the array are required.
*
* @return bool
*/
public function hasRole($name, $requireAll = false)
{
if (is_array($name)) {
foreach ($name as $roleName) {
$hasRole = $this->hasRole($roleName);
if ($hasRole && !$requireAll) {
return true;
} elseif (!$hasRole && $requireAll) {
return false;
}
}
// If we've made it this far and $requireAll is FALSE, then NONE of the roles were found
// If we've made it this far and $requireAll is TRUE, then ALL of the roles were found.
// Return the value of $requireAll;
return $requireAll;
} else {
foreach ($this->roles as $role) {
if ($role->name == $name) {
return true;
}
}
}
return false;
}
/** /**
* @return HasManyThrough * @return HasManyThrough
*/ */
@ -125,6 +178,14 @@ class User extends Authenticatable
return $this->hasMany('FireflyIII\Models\Preference'); return $this->hasMany('FireflyIII\Models\Preference');
} }
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles(): BelongsToMany
{
return $this->belongsToMany('FireflyIII\Models\Role');
}
/** /**
* @return HasMany * @return HasMany
*/ */

View File

@ -20,7 +20,6 @@
"doctrine/dbal": "~2.5", "doctrine/dbal": "~2.5",
"league/commonmark": "~0.7", "league/commonmark": "~0.7",
"rcrowe/twigbridge": "~0.9", "rcrowe/twigbridge": "~0.9",
"zizaco/entrust": "dev-laravel-5",
"league/csv": "^7.1", "league/csv": "^7.1",
"laravelcollective/html": "^5.2" "laravelcollective/html": "^5.2"
}, },