Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Remove entrust package.
James Cole46856c939433
diff --git a/app/Models/Permission.php b/app/Models/Permission.phpdeleted file mode 100644index 7d0922d493..0000000000--- a/app/Models/Permission.php+++ /dev/null@@ -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-{-}diff --git a/app/Models/Role.php b/app/Models/Role.phpindex 406f3db3fc..9fb22152df 100644--- a/app/Models/Role.php+++ b/app/Models/Role.php@@ -3,21 +3,19 @@ declare(strict_types = 1);namespace FireflyIII\Models;-use Zizaco\Entrust\EntrustRole;+use Illuminate\Database\Eloquent\Model;+use Illuminate\Database\Eloquent\Relations\BelongsToMany;-/**- * FireflyIII\Models\Role- *- * @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++class Role extends Model{+ /**+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany+ */+ public function users(): BelongsToMany+ {+ return $this->belongsToMany('FireflyIII\User');+ }+}diff --git a/app/User.php b/app/User.phpindex 3f0b86d787..58746d5a6b 100644--- a/app/User.php+++ b/app/User.php@@ -3,10 +3,10 @@ declare(strict_types = 1);namespace FireflyIII;+use Illuminate\Database\Eloquent\Relations\BelongsToMany;use Illuminate\Database\Eloquent\Relations\HasMany;use Illuminate\Database\Eloquent\Relations\HasManyThrough;use Illuminate\Foundation\Auth\User as Authenticatable;-use Zizaco\Entrust\Traits\EntrustUserTrait;/*** 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\RuleGroup[] $ruleGroups* @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{- use EntrustUserTrait;/*** The attributes that are mass assignable.@@ -44,16 +43,12 @@ class User extends Authenticatable* @var array*/protected $fillable = ['email', 'password', 'blocked', 'blocked_code'];--/*** The attributes excluded from the model's JSON form.** @var array*/protected $hidden = ['password', 'remember_token'];--/*** The database table used by the model.*@@ -69,6 +64,26 @@ class User extends Authenticatablereturn $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*/@@ -109,6 +124,44 @@ class User extends Authenticatablereturn $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*/@@ -125,6 +178,14 @@ class User extends Authenticatablereturn $this->hasMany('FireflyIII\Models\Preference');}+ /**+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany+ */+ public function roles(): BelongsToMany+ {+ return $this->belongsToMany('FireflyIII\Models\Role');+ }+/*** @return HasMany*/diff --git a/composer.json b/composer.jsonindex 152fb7130e..45949b7898 100644--- a/composer.json+++ b/composer.json@@ -20,7 +20,6 @@"doctrine/dbal": "~2.5","league/commonmark": "~0.7","rcrowe/twigbridge": "~0.9",- "zizaco/entrust": "dev-laravel-5","league/csv": "^7.1","laravelcollective/html": "^5.2"},