1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Fixes for Templates - Add Assigned User functionality (#3044)

* Request Cancellation

* Add fields to settings

* Recurring invoice cancellation request

* change REST endpoint for entity_id templates
This commit is contained in:
David Bomba 2019-11-05 21:16:38 +11:00 committed by GitHub
parent 06a120e128
commit 97a4fb3696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 81 additions and 6 deletions

View File

@ -147,6 +147,11 @@ class Client extends BaseModel
return $this->belongsTo(User::class);
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
public function country()
{
return $this->belongsTo(Country::class);

View File

@ -15,5 +15,8 @@ use Illuminate\Database\Eloquent\Model;
class Credit extends BaseModel
{
//
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
}

View File

@ -38,4 +38,9 @@ class Expense extends BaseModel
{
return $this->morphMany(Document::class, 'documentable');
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
}

View File

@ -135,6 +135,11 @@ class Invoice extends BaseModel
return $this->belongsTo(User::class);
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
public function invitations()
{
return $this->hasMany(InvoiceInvitation::class);

View File

@ -77,6 +77,11 @@ class Payment extends BaseModel
return $this->belongsTo(User::class);
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
public function documents()
{
return $this->morphMany(Document::class, 'documentable');

View File

@ -50,6 +50,11 @@ class Product extends BaseModel
return $this->belongsTo(User::class);
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
public function documents()
{
return $this->morphMany(Document::class, 'documentable');

View File

@ -39,4 +39,9 @@ class Proposal extends BaseModel
return $this->morphMany(Document::class, 'documentable');
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
}

View File

@ -71,6 +71,11 @@ class Quote extends BaseModel
return $this->belongsTo(User::class);
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
public function invitations()
{
return $this->hasMany(QuoteInvitation::class);

View File

@ -110,6 +110,11 @@ class RecurringInvoice extends BaseModel
return $this->belongsTo(User::class);
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
public function invoices()
{
return $this->hasMany(Invoice::class, "id", "recurring_invoice_id");

View File

@ -107,6 +107,11 @@ class RecurringQuote extends BaseModel
return $this->belongsTo(User::class);
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
public function invitations()
{
$this->morphMany(RecurringQuoteInvitation::class);

View File

@ -45,4 +45,9 @@ class Task extends BaseModel
return $this->morphMany(Document::class, 'documentable');
}
public function assigned_user()
{
return $this->belongsTo(User::class ,'assigned_user_id', 'id');
}
}

View File

@ -28,7 +28,6 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Laracasts\Presenter\PresentableTrait;
class User extends Authenticatable implements MustVerifyEmail
@ -141,7 +140,6 @@ class User extends Authenticatable implements MustVerifyEmail
*/
public function setCompany($company)
{
\Log::error('setting company');
$this->company = $company;
}
@ -281,6 +279,19 @@ class User extends Authenticatable implements MustVerifyEmail
}
/**
* Returns a boolean value if the user is assigned to the current Entity
*
* @param string Entity
* @return bool
*/
public function assigned($entity) : bool
{
return ! empty($entity->assigned_user_id) && $entity->assigned_user_id == $this->id;
}
/**
* Flattens a stdClass representation of the User Permissions
* into a Collection
@ -350,5 +361,6 @@ class User extends Authenticatable implements MustVerifyEmail
return $this->email;
}
}

View File

@ -50,7 +50,8 @@ class EntityPolicy
return ($user->isAdmin() && $entity->company_id == $user->companyId())
|| ($user->hasPermission('edit_' . strtolower(class_basename($entity))) && $entity->company_id == $user->companyId())
|| $user->owns($entity);
|| $user->owns($entity)
|| $user->assigned($entity);
}
@ -68,7 +69,8 @@ class EntityPolicy
return ($user->isAdmin() && $entity->company_id == $user->companyId())
|| ($user->hasPermission('view_' . strtolower(class_basename($entity))) && $entity->company_id == $user->companyId())
|| $user->owns($entity);
|| $user->owns($entity)
|| $user->assigned($entity);
}

View File

@ -280,6 +280,7 @@ class CreateUsersTable extends Migration
$table->increments('id');
$table->unsignedInteger('company_id')->index();
$table->unsignedInteger('user_id')->index();
$table->unsignedInteger('assigned_user_id')->nullable();
$table->string('name')->nullable();
$table->string('website')->nullable();
@ -412,6 +413,7 @@ class CreateUsersTable extends Migration
$t->increments('id');
$t->unsignedInteger('client_id')->index();
$t->unsignedInteger('user_id');
$t->unsignedInteger('assigned_user_id')->nullable();
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('status_id');
@ -478,6 +480,7 @@ class CreateUsersTable extends Migration
$t->increments('id');
$t->unsignedInteger('client_id')->index();
$t->unsignedInteger('user_id');
$t->unsignedInteger('assigned_user_id')->nullable();
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('status_id')->index();
@ -541,6 +544,7 @@ class CreateUsersTable extends Migration
$t->increments('id');
$t->unsignedInteger('client_id')->index();
$t->unsignedInteger('user_id');
$t->unsignedInteger('assigned_user_id')->nullable();
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('status_id')->index();
@ -602,6 +606,7 @@ class CreateUsersTable extends Migration
$t->increments('id');
$t->unsignedInteger('client_id')->index();
$t->unsignedInteger('user_id');
$t->unsignedInteger('assigned_user_id')->nullable();
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('status_id');
$t->unsignedInteger('design_id');
@ -708,6 +713,7 @@ class CreateUsersTable extends Migration
$t->increments('id');
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('user_id');
$t->unsignedInteger('assigned_user_id')->nullable();
$t->string('custom_value1')->nullable();
$t->string('custom_value2')->nullable();
@ -743,6 +749,7 @@ class CreateUsersTable extends Migration
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('client_id')->index();
$t->unsignedInteger('user_id')->nullable();
$t->unsignedInteger('assigned_user_id')->nullable();
$t->unsignedInteger('client_contact_id')->nullable();
$t->unsignedInteger('invitation_id')->nullable();
$t->unsignedInteger('company_gateway_id')->nullable();
@ -784,6 +791,7 @@ class CreateUsersTable extends Migration
Schema::create('tasks', function ($table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('assigned_user_id')->nullable();
$table->unsignedInteger('company_id')->index();
$table->unsignedInteger('client_id')->nullable();
$table->unsignedInteger('invoice_id')->nullable();

View File

@ -84,7 +84,7 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
Route::post('refresh', 'Auth\LoginController@refresh');
Route::get('templates/{entity}/create', 'TemplateController@create')->name('templates.create');
Route::get('templates/{entity}/{entity_id}', 'TemplateController@show')->name('templates.show');
Route::post('templates/{entity}/{entity_id}', 'TemplateController@show')->name('templates.show');
/*
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit