-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from wri/release/nimble-neem
[RELEASE] Nimble Neem
- Loading branch information
Showing
43 changed files
with
739 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\OneOff; | ||
|
||
use App\Models\V2\Nurseries\NurseryReport; | ||
use App\Models\V2\Projects\ProjectReport; | ||
use App\Models\V2\Sites\SiteReport; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class BackfillHidden extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'one-off:backfill-hidden'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Fills the \'hidden\' field of report-associated models based on form responses'; | ||
|
||
private const REPORT_TYPES = [ | ||
ProjectReport::class, | ||
SiteReport::class, | ||
NurseryReport::class, | ||
]; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$count = 0; | ||
foreach (self::REPORT_TYPES as $reportType) { | ||
$count += $reportType::count(); | ||
} | ||
$bar = $this->output->createProgressBar($count); | ||
$bar->start(); | ||
|
||
foreach (self::REPORT_TYPES as $reportType) { | ||
$reportType::chunkById(100, function ($reports) use ($bar) { | ||
foreach ($reports as $report) { | ||
$this->findRelationsToHide($report); | ||
$bar->advance(); | ||
} | ||
}); | ||
} | ||
$bar->finish(); | ||
} | ||
|
||
protected function findRelationsToHide($entity) | ||
{ | ||
$questions = $entity->getForm()->sections->map(fn ($section) => $section->questions)->flatten(); | ||
$formConfig = $entity->getFormConfig(); | ||
$linkedFieldQuestions = $questions->filter(function ($question) use ($formConfig) { | ||
$property = data_get($formConfig, "relations.$question->linked_field_key.property"); | ||
|
||
return ! empty($property) && ! empty($question->parent_id); | ||
}); | ||
|
||
foreach ($linkedFieldQuestions as $question) { | ||
if (empty($entity->answers) || $entity->answers[$question->parent_id] !== false) { | ||
continue; | ||
} | ||
|
||
$relation = $entity->{$question->input_type}(); | ||
$collection = $question->collection; | ||
if (! empty($collection)) { | ||
$relation->where('collection', $collection); | ||
} | ||
|
||
$count = $relation->count(); | ||
if ($count > 0) { | ||
$relation->update(['hidden' => true, 'updated_at' => DB::raw('updated_at')]); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/Http/Controllers/V2/User/AdminUsersOrganizationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V2\User; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\V2\Organisation; | ||
use App\Models\V2\User; | ||
use Illuminate\Http\Request; | ||
|
||
class AdminUsersOrganizationController extends Controller | ||
{ | ||
public function __invoke(Organisation $organisation, Request $request) | ||
{ | ||
$this->authorize('readAll', User::class); | ||
$OwnersWithRequestStatus = $organisation->owners->map(function ($user) { | ||
$user['status'] = 'approved'; | ||
|
||
return $user; | ||
}); | ||
$partnersWithRequestStatus = $organisation->partners->map(function ($user) { | ||
$user['status'] = $user->pivot->status; | ||
|
||
return $user; | ||
}); | ||
|
||
$usersOrganisation = $OwnersWithRequestStatus->merge($partnersWithRequestStatus); | ||
|
||
return response()->json($usersOrganisation); | ||
} | ||
} |
Oops, something went wrong.