Skip to content

Commit

Permalink
Merge pull request #572 from wri/feat/TM-1469-test-proj-org
Browse files Browse the repository at this point in the history
[TM-1469] Introduce an is_test flag to orgs and projects
  • Loading branch information
roguenet authored Nov 15, 2024
2 parents 29afd4d + f32a790 commit a44b75a
Show file tree
Hide file tree
Showing 22 changed files with 2,878 additions and 2 deletions.
56 changes: 56 additions & 0 deletions app/Console/Commands/OneOff/BackfillTestProjectsOrgs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Console\Commands\OneOff;

use App\Models\V2\Organisation;
use App\Models\V2\Projects\Project;
use Illuminate\Console\Command;

class BackfillTestProjectsOrgs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'one-off:backfill-test-projects-orgs';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Sets the is_test flag on test projects and organisations';

// In addition to these orgs, all projects within these orgs will get marked with is_test = true
private const TEST_ORGS = [
'7150d4ef-c785-49ed-9fb6-a28ef48ffb98', // 3SC PRODUCTION ORG (GT) - PLEASE IGNORE
'15c2a8dc-d395-11ed-8014-0682e69bfbec', // TM Org
'2470ced8-dc03-4d1e-9c64-b6445ac2c558', // test 0709
'f936d363-8409-401e-8711-708909cfa205', // Edward's Testing Playground
'15c07e71-d395-11ed-8014-0682e69bfbec', // Claire Trees Org
];

// These test projects are in an org that is not itself a test org
private const TEST_PROJECTS = [
'be1d70ad-9f0e-486f-a85a-86c075d6a4d1', // Conservation International test project
];

/**
* Execute the console command.
*/
public function handle()
{
foreach (Organisation::whereIn('uuid', self::TEST_ORGS)->get() as $organisation) {
$organisation->update(['is_test' => true]);

foreach ($organisation->projects as $project) {
$project->update(['is_test' => true]);
}
}

foreach (Project::whereIn('uuid', self::TEST_PROJECTS)->get() as $project) {
$project->update(['is_test' => true]);
}
}
}
20 changes: 20 additions & 0 deletions app/Http/Controllers/V2/Projects/AdminUpdateProjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers\V2\Projects;

use App\Http\Controllers\Controller;
use App\Http\Requests\V2\Projects\AdminUpdateProjectRequest;
use App\Http\Resources\V2\Projects\ProjectResource;
use App\Models\V2\Projects\Project;

class AdminUpdateProjectController extends Controller
{
public function __invoke(Project $project, AdminUpdateProjectRequest $request): ProjectResource
{
$this->authorize('update', $project);

$project->update($request->validated());

return new ProjectResource($project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function __invoke(Request $request): EntityWithSchemaResource
'organisation_id' => $application->organisation->id,
'application_id' => $application->id,
'status' => EntityStatusStateMachine::STARTED,
'is_test' => $application->organisation->is_test,
'project_status' => null,
'name' => $projectPitch->project_name,
'boundary_geojson' => $projectPitch->proj_boundary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function rules()
'type' => 'sometimes|nullable|string',
'subtype' => 'sometimes|nullable|string',
'private' => 'sometimes|boolean',
'is_test' => 'sometimes|boolean',
'name' => 'sometimes|nullable|string',
'phone' => 'sometimes|nullable|string',
'hq_address' => 'sometimes|nullable|string',
Expand Down
15 changes: 15 additions & 0 deletions app/Http/Requests/V2/Projects/AdminUpdateProjectRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Requests\V2\Projects;

use Illuminate\Foundation\Http\FormRequest;

class AdminUpdateProjectRequest extends FormRequest
{
public function rules()
{
return [
'is_test' => 'sometimes|boolean',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function toArray($request)
'uuid' => $this->uuid,
'name' => $this->name,
'status' => $this->status,
'is_test' => $this->is_test,
'readable_status' => $this->readable_status,
'type' => $this->type,
'updated_at' => $this->updated_at,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function toArray($request)
{
$data = [
'uuid' => $this->uuid,
'is_test' => $this->is_test,
'status' => $this->status,
'readable_status' => $this->readable_status,
'type' => $this->type,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/V2/Projects/ProjectLiteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function toArray($request)
{
$data = [
'uuid' => $this->uuid,
'is_test' => $this->is_test,
'ppc_external_id' => $this->ppc_external_id ?? $this->id,
'framework_key' => $this->framework_key,
'framework_uuid' => $this->framework_uuid,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/V2/Projects/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function toArray($request)
'ppc_external_id' => $this->ppc_external_id ?? $this->id,
'name' => $this->name,
'status' => $this->status,
'is_test' => $this->is_test,
'readable_status' => $this->readable_status,
'project_status' => $this->project_status,
'update_request_status' => $this->update_request_status,
Expand Down
1 change: 1 addition & 0 deletions app/Models/V2/Organisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class Organisation extends Model implements MediaModel
];

public $casts = [
'is_test' => 'boolean',
'private' => 'boolean',
'founding_date' => 'date',
'fin_start_month' => 'integer',
Expand Down
2 changes: 2 additions & 0 deletions app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Project extends Model implements MediaModel, AuditableContract, EntityMode
protected $fillable = [
'name',
'status',
'is_test',
'update_request_status',
'project_status',
'framework_key',
Expand Down Expand Up @@ -185,6 +186,7 @@ class Project extends Model implements MediaModel, AuditableContract, EntityMode
];

public $casts = [
'is_test' => 'boolean',
'land_tenures' => 'array',
'land_tenure_project_area' => 'array',
'land_use_types' => 'array',
Expand Down
33 changes: 33 additions & 0 deletions database/migrations/2024_11_14_173836_add_is_test_proj_org.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('organisations', function (Blueprint $table) {
$table->boolean('is_test')->default(false);
});
Schema::table('v2_projects', function (Blueprint $table) {
$table->boolean('is_test')->default(false);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('organisations', function (Blueprint $table) {
$table->dropColumn('is_test');
});
Schema::table('v2_projects', function (Blueprint $table) {
$table->dropColumn('is_test');
});
}
};
2 changes: 2 additions & 0 deletions openapi-src/V2/definitions/ProjectFullRead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ properties:
type: string
uuid:
type: string
is_test:
type: boolean
status:
type: string
organisation:
Expand Down
2 changes: 2 additions & 0 deletions openapi-src/V2/definitions/ProjectLiteRead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ properties:
type: string
uuid:
type: string
is_test:
type: boolean
status:
type: string
name:
Expand Down
2 changes: 2 additions & 0 deletions openapi-src/V2/definitions/V2AdminOrganisationRead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ properties:
type: string
type:
type: string
is_test:
type: boolean
private:
type: boolean
name:
Expand Down
4 changes: 3 additions & 1 deletion openapi-src/V2/definitions/V2AdminOrganisationUpdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ properties:
type: string
private:
type: boolean
is_test:
type: boolean
name:
type: string
phone:
Expand Down Expand Up @@ -148,4 +150,4 @@ properties:
tags:
type: array
items:
type: string
type: string
5 changes: 5 additions & 0 deletions openapi-src/V2/definitions/V2AdminProjectUpdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
title: V2AdminProjectUpdate
type: object
properties:
is_test:
type: boolean
2 changes: 2 additions & 0 deletions openapi-src/V2/definitions/_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,5 @@ DashboardIndicatorHectaresRestorationData:
$ref: './DashboardIndicatorHectaresRestorationData.yml'
UserCreateComplete:
$ref: './UserCreateComplete.yml'
V2AdminProjectUpdate:
$ref: './V2AdminProjectUpdate.yml'
20 changes: 20 additions & 0 deletions openapi-src/V2/paths/Projects/put-v2-admin-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
summary: Updates a specific project
operationId: put-v2-admin-project
tags:
- V2 Projects
parameters:
- in: body
name: body
schema:
$ref: '../../definitions/_index.yml#/V2AdminProjectUpdate'
- type: string
in: path
name: UUID
required: true
responses:
'200':
description: OK
schema:
type: array
items:
$ref: '../../definitions/_index.yml#/ProjectFullRead'
2 changes: 2 additions & 0 deletions openapi-src/V2/paths/_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,8 @@
delete:
$ref: './Sites/Monitoring/delete-v2-admin-site-monitorings-uuid.yml'
'/v2/admin/projects/{UUID}':
put:
$ref: './Projects/put-v2-admin-project.yml'
delete:
summary: Delete a project
operationId: delete-v2-admin-projects-UUID
Expand Down
Loading

0 comments on commit a44b75a

Please sign in to comment.