applications management
parent
1c67a2fce3
commit
bb340b7a81
|
|
@ -24,6 +24,7 @@ class Application extends Model {
|
|||
protected $fillable = [
|
||||
'submitter_id',
|
||||
'product_id',
|
||||
'expert_id',
|
||||
'status',
|
||||
'number',
|
||||
'applicant',
|
||||
|
|
@ -45,6 +46,10 @@ class Application extends Model {
|
|||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function expert(): BelongsTo {
|
||||
return $this->belongsTo(CompanyMember::class);
|
||||
}
|
||||
|
||||
public function conclusions(): HasMany {
|
||||
return $this->hasMany(Conclusion::class);
|
||||
}
|
||||
|
|
@ -65,7 +70,7 @@ class Application extends Model {
|
|||
|
||||
public function getAddresseesAttribute() {
|
||||
return CompanyMember::query()->mainCompany()->whereHas('objects', function($query) {
|
||||
Field::applyFilters($query, collect(['types' => 'company-member-properties', 'moderate-permissions' => 'applications']));
|
||||
Field::applyFilters($query, collect(['types' => 'company-member-properties', 'moderate-permissions' => 'manage-applications']));
|
||||
})->get();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ class Asset extends Model {
|
|||
public function links()
|
||||
{
|
||||
$result = [
|
||||
'open' => url("/api/assets/{$this->uuid}"),
|
||||
'download' => url("/api/assets/{$this->uuid}/download")
|
||||
'open' => asset("/api/assets/{$this->uuid}"),
|
||||
'download' => asset("/api/assets/{$this->uuid}/download")
|
||||
];
|
||||
if ($this->type == 'image') {
|
||||
$result['full'] = url("/api/assets/{$this->uuid}/render");
|
||||
$result['thumb'] = url("/api/assets/{$this->uuid}/render?width=300");
|
||||
$result['full'] = asset("/api/assets/{$this->uuid}/render");
|
||||
$result['thumb'] = asset("/api/assets/{$this->uuid}/render?width=300");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ namespace App\Models;
|
|||
|
||||
use App\Events\UserRegistered;
|
||||
use App\Mail\PasswordResetRequested;
|
||||
use App\Models\Advisories\Advisory;
|
||||
use App\Models\Advisories\AdvisoryMember;
|
||||
use App\Models\Advisories\AdvisoryMemberRank;
|
||||
use App\Models\Applications\Conclusion;
|
||||
use App\Models\Companies\Company;
|
||||
use App\Models\Companies\CompanyMember;
|
||||
|
|
@ -112,6 +110,11 @@ class User extends Authenticatable {
|
|||
Field::applyFilters($query, collect(['types' => 'company-member-properties', 'moderate-permissions' => 'applications']));
|
||||
})->exists();
|
||||
}
|
||||
public function getIsApplicationsManagerAttribute(): bool {
|
||||
return $this->membership()->mainCompany()->whereHas('objects', function($query) {
|
||||
Field::applyFilters($query, collect(['types' => 'company-member-properties', 'moderate-permissions' => 'manage-applications']));
|
||||
})->exists();
|
||||
}
|
||||
|
||||
public function getPrivilegesAttribute(): array {
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class ApplicationForms extends FormsService {
|
|||
}
|
||||
|
||||
public function commonGroupFields(?Application $model): array {
|
||||
$user = Auth::user();
|
||||
$fields = [
|
||||
[
|
||||
'name' => 'applicant',
|
||||
|
|
@ -54,14 +55,14 @@ class ApplicationForms extends FormsService {
|
|||
'title' => 'Email',
|
||||
'type' => FieldType::STRING,
|
||||
'required' => true,
|
||||
'value' => $model->phone ?? null
|
||||
'value' => $model ? ($model->email ?? null) : ($user->email ?? null)
|
||||
],
|
||||
[
|
||||
'name' => 'phone',
|
||||
'title' => 'Телефон',
|
||||
'type' => FieldType::STRING,
|
||||
'required' => true,
|
||||
'value' => $model->phone ?? null
|
||||
'value' => $model ? ($model->phone ?? null) : ($user->phone ?? null)
|
||||
],
|
||||
[
|
||||
'name' => 'product_name',
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class PermissionsService {
|
|||
}
|
||||
|
||||
public function applicationPermissions(): array {
|
||||
return ['edit' => $this->model->submitter_id === $this->user->id, 'reply' => $this->user->isExpert];
|
||||
return ['edit' => $this->model->submitter_id === $this->user->id, 'reply' => $this->user->isExpert, 'manage' => $this->user->isApplicationsManager];
|
||||
}
|
||||
|
||||
public function pagePermissions(): array {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Transformers\Applications;
|
|||
|
||||
use App\Models\Applications\Application;
|
||||
use App\Services\PermissionsService;
|
||||
use App\Transformers\Companies\CompanyMemberTransformer;
|
||||
use App\Transformers\Objects\ObjectTransformer;
|
||||
use App\Transformers\Products\ProductTransformer;
|
||||
use App\Transformers\Users\UserTransformer;
|
||||
|
|
@ -16,7 +17,7 @@ class ApplicationTransformer extends TransformerAbstract {
|
|||
protected array $defaultIncludes = [];
|
||||
|
||||
protected array $availableIncludes = [
|
||||
'submitter', 'product', 'properties', 'conclusions', 'permissions'
|
||||
'submitter', 'expert', 'product', 'properties', 'conclusions', 'permissions'
|
||||
];
|
||||
|
||||
public function transform(Application $model): array {
|
||||
|
|
@ -37,6 +38,10 @@ class ApplicationTransformer extends TransformerAbstract {
|
|||
return $model->submitter ? $this->item($model->submitter, new UserTransformer()) : null;
|
||||
}
|
||||
|
||||
public function includeExpert(Application $model): ?Item {
|
||||
return $model->expert ? $this->item($model->expert, new CompanyMemberTransformer()) : null;
|
||||
}
|
||||
|
||||
public function includeProduct(Application $model): ?Item {
|
||||
return $model->product ? $this->item($model->product, new ProductTransformer()) : null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,12 @@ class CreateApplicationsTable extends Migration
|
|||
$table->char('uuid', 36)->index()->unique();
|
||||
$table->integer('submitter_id')->index()->nullable();
|
||||
$table->integer('product_id')->index()->nullable();
|
||||
$table->integer('expert_id')->index()->nullable();
|
||||
$table->string('status')->index()->nullable();
|
||||
$table->string('number')->index()->nullable();
|
||||
$table->string('applicant', 750)->index()->nullable();
|
||||
$table->string('email')->index()->nullable();
|
||||
$table->string('phone')->index()->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddInApplicationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('applications', function (Blueprint $table) {
|
||||
$table->string('email')->index()->nullable()->after('applicant');
|
||||
$table->string('phone')->index()->nullable()->after('email');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('applications', function (Blueprint $table) {
|
||||
$table->dropColumn(['email', 'phone']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ class DictionariesTableSeeder extends Seeder {
|
|||
],
|
||||
'moderate-permissions' => [
|
||||
'title' => 'Права',
|
||||
'items' => ['applications' => 'Рассмотрение предварительных заявок']
|
||||
'items' => ['applications' => 'Рассмотрение предварительных заявок', 'manage-applications' => 'Распределение предварительных заявок']
|
||||
]
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue