Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Http/Controllers/Api/V1/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ public function update(UpdateUser $request, int $id): JsonResponse
$user->role = isset($input['role']) ? $input['role'] : $user->role;
$user->save();



return response()->json([
'message' => 'success',
'data' => $user,
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Kernel extends HttpKernel
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\Illuminate\Session\Middleware\StartSession::class,
\App\Http\Middleware\TerminateRequest::class,
\App\Http\Middleware\LogRequestResponse::class,
// \App\Http\Middleware\TerminateRequest::class,
// \App\Http\Middleware\LogRequestResponse::class,
];

/**
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Affiliation.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class Affiliation extends Model
],
State::STATE_AFFILIATION_LEFT => []
];

protected static array $transitionsAutomated = [];

public $table = 'affiliations';

Expand Down Expand Up @@ -216,6 +218,11 @@ public static function getTransitions(): array
return static::$transitions;
}

public function getTransitionsAutomated(): array
{
return static::$transitionsAutomated;
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
Expand Down
19 changes: 19 additions & 0 deletions app/Models/CustodianHasProjectOrganisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class CustodianHasProjectOrganisation extends Model
use FilterManager;

protected static array $transitions = [
State::STATE_ORG_INVITED => [
State::STATE_ORG_AWAITING_APPROVAL,
],
State::STATE_ORG_AWAITING_APPROVAL => [
State::STATE_PENDING, // I think we need something to move to declined too
],
State::STATE_PENDING => [
State::STATE_VALIDATION_IN_PROGRESS,
State::STATE_MORE_ORG_INFO_REQ_ESCALATION_MANAGER,
Expand All @@ -74,6 +80,7 @@ class CustodianHasProjectOrganisation extends Model
State::STATE_VALIDATION_COMPLETE => [
State::STATE_ORG_VALIDATION_DECLINED,
State::STATE_VALIDATION_COMPLETE,
State::STATE_ORG_REMOVED_FROM_PROJECT,
],
State::STATE_MORE_ORG_INFO_REQ_ESCALATION_MANAGER => [
State::STATE_MORE_ORG_INFO_REQ_ESCALATION_COMMITTEE,
Expand All @@ -89,13 +96,25 @@ class CustodianHasProjectOrganisation extends Model
State::STATE_VALIDATION_COMPLETE,
],
State::STATE_ORG_LEFT_PROJECT => [],
State::STATE_ORG_REMOVED_FROM_PROJECT => [],
];

protected static array $transitionsAutomated = [
State::STATE_ORG_INVITED,
State::STATE_ORG_AWAITING_APPROVAL,
State::STATE_PENDING,
];

public static function getTransitions(): array
{
return static::$transitions;
}

public function getTransitionsAutomated(): array
{
return static::$transitionsAutomated;
}

protected $table = 'custodian_has_project_has_organisation';

public $timestamps = true;
Expand Down
7 changes: 7 additions & 0 deletions app/Models/CustodianHasProjectUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,18 @@ class CustodianHasProjectUser extends Model
State::STATE_USER_LEFT_PROJECT => [],
];

protected static array $transitionsAutomated = [];

public static function getTransitions(): array
{
return static::$transitions;
}

public function getTransitionsAutomated(): array
{
return static::$transitionsAutomated;
}

protected static array $searchableColumns = ['projects.title'];
protected static array $sortableColumns = ['projects.title'];

Expand Down
7 changes: 7 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class Project extends Model
],
];

protected static array $transitionsAutomated = [];

protected $table = 'projects';

public $timestamps = true;
Expand Down Expand Up @@ -230,6 +232,11 @@ public static function getTransitions(): array
return static::$transitions;
}

public function getTransitionsAutomated(): array
{
return static::$transitionsAutomated;
}

public function projectHasOrganisations()
{
return $this->hasMany(
Expand Down
8 changes: 8 additions & 0 deletions app/Models/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class State extends Model
public const STATE_USER_LEFT_PROJECT = 'user_left_project'; // user left project
public const STATE_ORG_LEFT_PROJECT = 'org_left_project'; // org left project

public const STATE_ORG_INVITED = 'org_invited';
public const STATE_ORG_AWAITING_APPROVAL = 'org_awaiting_approval';
public const STATE_ORG_REMOVED_FROM_PROJECT = 'org_removed_from_project';


public const STATES = [
self::STATE_INVITED,
self::STATE_REGISTERED,
Expand Down Expand Up @@ -140,5 +145,8 @@ class State extends Model
self::STATE_ORG_VALIDATION_DECLINED,
self::STATE_USER_LEFT_PROJECT,
self::STATE_ORG_LEFT_PROJECT,
self::STATE_ORG_INVITED,
self::STATE_ORG_AWAITING_APPROVAL,
self::STATE_ORG_REMOVED_FROM_PROJECT,
];
}
7 changes: 7 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class User extends Authenticatable
State::STATE_VALIDATED => [],
];

protected static array $transitionsAutomated = [];

/**
* The attributes that are mass assignable.
*/
Expand Down Expand Up @@ -442,4 +444,9 @@ public static function getTransitions(): array
{
return static::$transitions;
}

public function getTransitionsAutomated(): array
{
return static::$transitionsAutomated;
}
}
25 changes: 23 additions & 2 deletions app/Observers/FileObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace App\Observers;

use App\Models\File;
use App\Models\User;
use App\Models\State;
use App\Jobs\SendEmailJob;
use App\Models\Organisation;
use Hdruk\LaravelMjml\Models\EmailTemplate;
use App\Jobs\ProcessCSVSubmission;
use App\Models\OrganisationHasFile;
use App\Models\User;
use App\Models\ProjectHasOrganisation;
use Hdruk\LaravelMjml\Models\EmailTemplate;
use App\Models\CustodianHasProjectOrganisation;

class FileObserver
{
Expand All @@ -30,9 +33,27 @@ public function updated(File $file): void
])->first()->organisation_id;

$this->sendEmail($file, $organisationId);

$this->statusCustodianHasProjectOrganisation($organisationId);
}
}

protected function statusCustodianHasProjectOrganisation(int $organisationId): void
{
$projectHasOrganisations = ProjectHasOrganisation::where([
'organisation_id' => $organisationId,
])->pluck('id')->toArray();

$custodianHasProjectOrganisationIds = CustodianHasProjectOrganisation::whereIn('project_has_organisation_id', $projectHasOrganisations)->pluck('id')->toArray();
foreach ($custodianHasProjectOrganisationIds as $custodianHasProjectOrganisationId) {
$custodianHasProjectOrganisation = CustodianHasProjectOrganisation::where('id', $custodianHasProjectOrganisationId)->first();
if ($custodianHasProjectOrganisation->getState() === State::STATE_ORG_INVITED) {
$custodianHasProjectOrganisation->setState(State::STATE_ORG_AWAITING_APPROVAL);
}
}

}

protected function sendEmail(File $file, int $organisationId): void
{
$organisation = Organisation::where('id', $organisationId)->first();
Expand Down
21 changes: 16 additions & 5 deletions app/Observers/ProjectHasOrganisationObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace App\Observers;

use App\Models\CustodianHasProjectOrganisation;
use App\Models\ProjectHasOrganisation;
use App\Models\ProjectHasCustodian;
use App\Models\State;
use App\Traits\ValidationManager;
use App\Models\ProjectHasCustodian;
use App\Models\ProjectHasOrganisation;
use App\Models\CustodianHasProjectOrganisation;

class ProjectHasOrganisationObserver
{
Expand All @@ -20,10 +21,20 @@ public function created(ProjectHasOrganisation $pho): void
$custodianIds = ProjectHasCustodian::where(['project_id' => $pho->project_id])->pluck("custodian_id")->toArray();

foreach ($custodianIds as $custodianId) {
CustodianHasProjectOrganisation::firstOrCreate([
$checking = CustodianHasProjectOrganisation::where([
'custodian_id' => $custodianId,
'project_has_organisation_id' => $projectHasOrganisationId
]);
])->first();

if (is_null($checking)) {
$create = CustodianHasProjectOrganisation::create([
'custodian_id' => $custodianId,
'project_has_organisation_id' => $projectHasOrganisationId
]);

$custodianHasProjectOrganisation = CustodianHasProjectOrganisation::where('id', $create->id)->first();
$custodianHasProjectOrganisation->setState(State::STATE_ORG_INVITED);
}
}
}
}
5 changes: 5 additions & 0 deletions app/Traits/StateWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ public static function getAllStates(): array
$allStates = array_unique(array_merge($keys, $values));
return array_values($allStates);
}

public static function getAutomatedTransitions(): array
{
return static::getAutomatedTransitions();
}
}