akaunting 3.0 (the last dance)

This commit is contained in:
Burak Civan
2022-06-01 10:15:55 +03:00
parent cead09f6d4
commit d9c0764572
3812 changed files with 126831 additions and 102949 deletions

View File

@ -2,16 +2,15 @@
namespace App\Models\Auth;
use Akaunting\Sortable\Traits\Sortable;
use App\Traits\Tenants;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Laratrust\Models\LaratrustPermission;
use Laratrust\Traits\LaratrustPermissionTrait;
use Kyslik\ColumnSortable\Sortable;
use Lorisleiva\LaravelSearchString\Concerns\SearchString;
class Permission extends LaratrustPermission
{
use HasFactory, LaratrustPermissionTrait, SearchString, Sortable, Tenants;
use LaratrustPermissionTrait, SearchString, Sortable, Tenants;
protected $table = 'permissions';
@ -79,14 +78,4 @@ class Permission extends LaratrustPermission
return $title;
}
/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
protected static function newFactory()
{
return \Database\Factories\Permission::new();
}
}

View File

@ -2,16 +2,15 @@
namespace App\Models\Auth;
use Akaunting\Sortable\Traits\Sortable;
use App\Traits\Tenants;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Laratrust\Models\LaratrustRole;
use Laratrust\Traits\LaratrustRoleTrait;
use Kyslik\ColumnSortable\Sortable;
use Lorisleiva\LaravelSearchString\Concerns\SearchString;
class Role extends LaratrustRole
{
use HasFactory, LaratrustRoleTrait, SearchString, Sortable, Tenants;
use LaratrustRoleTrait, SearchString, Sortable, Tenants;
protected $table = 'roles';
@ -22,6 +21,40 @@ class Role extends LaratrustRole
*/
protected $fillable = ['name', 'display_name', 'description', 'created_from', 'created_by'];
/**
* Get the line actions.
*
* @return array
*/
public function getLineActionsAttribute()
{
$actions = [];
$actions[] = [
'title' => trans('general.edit'),
'icon' => 'edit',
'url' => route('roles.roles.edit', $this->id),
'permission' => 'update-roles-roles',
];
$actions[] = [
'title' => trans('general.duplicate'),
'icon' => 'file_copy',
'url' => route('roles.roles.duplicate', $this->id),
'permission' => 'create-roles-roles',
];
$actions[] = [
'type' => 'delete',
'icon' => 'delete',
'route' => 'roles.roles.destroy',
'permission' => 'delete-roles-roles',
'model' => $this,
];
return $actions;
}
/**
* Scope to get all rows filtered, sorted and paginated.
*
@ -39,14 +72,4 @@ class Role extends LaratrustRole
return $query->usingSearchString($search)->sortable($sort)->paginate($limit);
}
/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
protected static function newFactory()
{
return \Database\Factories\Role::new();
}
}

View File

@ -2,11 +2,12 @@
namespace App\Models\Auth;
use App\Traits\Tenants;
use Akaunting\Sortable\Traits\Sortable;
use App\Notifications\Auth\Reset;
use App\Traits\Media;
use App\Traits\Owners;
use App\Traits\Sources;
use App\Traits\Tenants;
use App\Traits\Users;
use App\Utilities\Date;
use Illuminate\Contracts\Translation\HasLocalePreference;
@ -14,7 +15,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Kyslik\ColumnSortable\Sortable;
use Laratrust\Traits\LaratrustUserTrait;
use Lorisleiva\LaravelSearchString\Concerns\SearchString;
@ -65,11 +65,11 @@ class User extends Authenticatable implements HasLocalePreference
{
parent::boot();
static::retrieved(function($model) {
static::retrieved(function ($model) {
$model->setCompanyIds();
});
static::saving(function($model) {
static::saving(function ($model) {
$model->unsetCompanyIds();
});
}
@ -94,6 +94,10 @@ class User extends Authenticatable implements HasLocalePreference
*/
public function getNameAttribute($value)
{
if (empty($value)) {
return trans('general.na');
}
return ucfirst($value);
}
@ -106,7 +110,7 @@ class User extends Authenticatable implements HasLocalePreference
if (setting('default.use_gravatar', '0') == '1') {
try {
// Check for gravatar
$url = 'https://www.gravatar.com/avatar/' . md5(strtolower($this->getAttribute('email'))).'?size=90&d=404';
$url = 'https://www.gravatar.com/avatar/' . md5(strtolower($this->getAttribute('email'))) . '?size=90&d=404';
$client = new \GuzzleHttp\Client(['verify' => false]);
@ -141,14 +145,6 @@ class User extends Authenticatable implements HasLocalePreference
}
}
/**
* Send reset link to user via email
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new Reset($token));
}
/**
* Always capitalize the name when we save it to the database
*/
@ -165,6 +161,14 @@ class User extends Authenticatable implements HasLocalePreference
$this->attributes['password'] = bcrypt($value);
}
/**
* Send reset link to user via email
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new Reset($token));
}
/**
* Scope to get all rows filtered, sorted and paginated.
*
@ -294,6 +298,48 @@ class User extends Authenticatable implements HasLocalePreference
return $this->locale;
}
/**
* Get the line actions.
*
* @return array
*/
public function getLineActionsAttribute()
{
$actions = [];
if (user()->id == $this->id) {
return $actions;
}
if (! $this->hasPendingInvitation()) {
$actions[] = [
'title' => trans('general.edit'),
'icon' => 'edit',
'url' => route('users.edit', $this->id),
'permission' => 'update-auth-users',
];
}
if ($this->hasPendingInvitation()) {
$actions[] = [
'title' => trans('general.resend') . ' ' . trans_choice('general.invitations', 1),
'icon' => 'replay',
'url' => route('users.invite', $this->id),
'permission' => 'update-auth-users',
];
}
$actions[] = [
'type' => 'delete',
'icon' => 'delete',
'route' => 'users.destroy',
'permission' => 'delete-auth-users',
'model' => $this,
];
return $actions;
}
/**
* Create a new factory instance for the model.
*

View File

@ -0,0 +1,40 @@
<?php
namespace App\Models\Auth;
use App\Abstracts\Model;
class UserInvitation extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user_invitations';
protected $tenantable = false;
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = ['user_id', 'company_id', 'token'];
public function user()
{
return $this->belongsTo('App\Models\Auth\User');
}
/**
* Scope a query to only include given token value.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return void
*/
public function scopeToken($query, $token)
{
$query->where('token', $token);
}
}