Skip to content

CFM-31_Enrollment_Flows_enable_people_picker_for_self_service #337

Merged
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
3 changes: 2 additions & 1 deletion app/plugins/CoreEnroller/config/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"columns": {
"id": {},
"enrollment_flow_step_id": {},
"description": { "temporary": true, "type": "string", "size": 80 }
"description": { "temporary": true, "type": "string", "size": 80 },
"enable_person_find": { "type": "boolean" }
},
"indexes": {
"attribute_collectors_i1": { "columns": [ "enrollment_flow_step_id" ] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ msgstr "If set, the Approver must add a comment when approving or denying Petiti
msgid "field.AttributeCollectors.valid_through.default.after.desc"
msgstr "Days After Finalization"

msgid "field.AttributeCollectors.enable_person_find"
msgstr "Enable People Picker for Self Service"

msgid "field.AttributeCollectors.enable_person_find.desc"
msgstr "Enable people picker for self-service enrollments, see <a target=\"_top\" href=\"https://spaces.at.internet2.edu/display/COmanage/Attribute+Collector+Enroller+Plugin\">Attribute Collector documentation</a> for privacy considerations"

msgid "field.BasicAttributeCollectors.affiliation_type_id"
msgstr "Affiliation Type"

Expand Down
18 changes: 8 additions & 10 deletions app/plugins/CoreEnroller/templates/AttributeCollectors/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@

declare(strict_types = 1);

// Currently this Configuration View has no fields
// This view only supports edit
if($vv_action !== 'edit') {
return;
}

$this->Field->disableFormEditMode();

?>

<li>
<div class="field">
<?= __d('information', 'plugin.config.none'); ?>
</div>
</li>

print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'enable_person_find',
]]);
59 changes: 56 additions & 3 deletions app/src/Controller/ApiV2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@

namespace App\Controller;

use Cake\Controller\Controller;
use InvalidArgumentException;
use Cake\Chronos\Chronos;
use Cake\Controller\Controller;
use Cake\Http\Exception\BadRequestException;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;

use InvalidArgumentException;
use \App\Lib\Enum\EnrollmentAuthzEnum;
use \App\Lib\Enum\ProvisioningContextEnum;
use \App\Lib\Enum\SuspendableStatusEnum;

Expand Down Expand Up @@ -413,4 +413,57 @@ public function view($id = null) {
public function pick() {
$this->dispatchIndex(mode: 'picker');
}

/**
* Indicate whether this Controller will handle some or all authnz.
*
* @param EventInterface $event Cake event, ie: from beforeFilter
* @return string "no", "open", "authz", "yes", or "notauth"
* @since COmanage Registry v5.2.0
*/
public function willHandleAuth(\Cake\Event\EventInterface $event): string
{
$request = $this->getRequest();
$reqAction = $request->getParam('action');
$session = $request->getSession();
$mode = 'no';

$auth = $session->read('Auth');

// Calculate people picker permissions on the fly for an enrollment flow/petition
if(
$this->name == 'People'
&& $reqAction == 'pick'
&& !empty($request->getQuery('petition_id'))
) {
$petitionId = (int)$request->getQuery('petition_id');
// We need to check if this is part of an Enrollment Flow
$Petitions = $this->fetchTable('Petitions');

// Pull the Petition to find its CO
$petition = $Petitions->get(
$petitionId,
contain: ['EnrollmentFlows' => ['EnrollmentFlowSteps']]
);

// We need to check the Petitioner Authorization.
$hasAuthorizedUser = $petition->enrollment_flow->authz_type == EnrollmentAuthzEnum::AuthUser
? !empty($auth['external']['user']) : true;

foreach ($petition->enrollment_flow->enrollment_flow_steps as $step) {
if ($step->plugin == 'CoreEnroller.AttributeCollectors') {
$AttributeCollectors = $this->fetchTable('CoreEnroller.AttributeCollectors');
$attributeCollectorsRecord = $AttributeCollectors->find()
->where(['enrollment_flow_step_id' => $step->id])
->contain(['EnrollmentAttributes'])
->first();

$mode = $hasAuthorizedUser && $attributeCollectorsRecord->enable_person_find ? 'yes' : 'no';
}
}
Comment on lines +439 to +463
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of special logic for an API controller. While we can probably leave the outermost test (if(People && pick && petition_id)) in place until we have more use cases to refactor, the actual logic of whether or not the PeoplePicker is enabled should go in PetitionsTable. Or really in EnrollmentFlowsTable, but since we have a Petition ID as context here, and there is a similar function PetitionsTable::isApproverForFlow() already, PetitionsTable::isPersonFindEnabled() probably makes more sense.

}

// Apply standard behavior
return $mode;
}
}
2 changes: 1 addition & 1 deletion app/src/View/Helper/PetitionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function populateAutoViewVars(): void
{
// XXX Find the co id
foreach (
$this->enrollmentAttributesTable->calculateAutoViewVars($this->petition?->enrollment_flow?->co_id,$this->entity) as $vvar => $value
$this->enrollmentAttributesTable->calculateAutoViewVars($this->petition?->enrollment_flow?->co_id, $this->entity) as $vvar => $value
) {
$this->getView()->set($vvar, $value);
}
Expand Down