Skip to content

Commit

Permalink
Initial commit of Mostly Static Pages (CFM-62), InvitationAccepter (C…
Browse files Browse the repository at this point in the history
…FM-334) and UpsertTrait (CFM-423)
  • Loading branch information
Benn Oshrin authored and Ioannis committed Dec 15, 2024
1 parent 60bdb3c commit 21c4ecc
Show file tree
Hide file tree
Showing 46 changed files with 2,024 additions and 94 deletions.
14 changes: 14 additions & 0 deletions app/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ function (RouteBuilder $builder) {
* ...and connect the rest of 'Pages' controller's URLs.
*/
$builder->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);

/**
* Registry allows URLs of the form /coid/name to render as a Mostly Static Page.
*
* Note this will effectively route any URL of the form /registry/x, where x consists of
* digits, to the Pages controller. We need to filter on digits, or we'll end up taking
* over all controllers as well. (The implication is we can't have a controller whose
* name consists entirely of digits, but we probably shouldn't...)
*/
$builder->connect(
'/{coid}/{name}',
['controller' => 'Pages', 'action' => 'show' ],
['coid' => '\d+', 'pass' => ['coid', 'name']]
);

/*
* Connect catchall routes for all controllers.
Expand Down
24 changes: 22 additions & 2 deletions app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"id": { "type": "integer", "autoincrement": true, "primarykey": true },
"identifier_assignment_id": { "type": "integer", "foreignkey": { "table": "identifier_assignments", "column": "id" }, "notnull": true },
"language": { "type": "string", "size": 16 },
"message_template_id": { "type": "integer", "foreignkey": { "table": "message_templates", "column": "id" } },
"name": { "type": "string", "size": 128, "notnull": true },
"ordr": { "type": "integer" },
"person_id": { "type": "integer", "foreignkey": { "table": "people", "column": "id" } },
Expand Down Expand Up @@ -598,6 +599,22 @@
}
},

"mostly_static_pages": {
"columns": {
"id": {},
"co_id": {},
"name": {},
"title": { "type": "string", "size": 256 },
"description": {},
"status": {},
"context": {},
"body": { "type": "text" }
},
"indexes": {
"mostly_static_pages_i1": { "columns": [ "co_id" ] }
}
},

"enrollment_flows": {
"columns": {
"id": {},
Expand Down Expand Up @@ -626,10 +643,13 @@
"status": {},
"plugin": {},
"ordr": {},
"actor_type": { "type": "string", "size": 2 }
"actor_type": { "type": "string", "size": 2 },
"message_template_id": {},
"redirect_on_handoff": { "type": "string", "size": 256 }
},
"indexes": {
"enrollment_flow_steps_i1": { "columns": [ "enrollment_flow_id" ]}
"enrollment_flow_steps_i1": { "columns": [ "enrollment_flow_id" ]},
"enrollment_flow_steps_i2": { "needed": false, "columns": [ "message_template_id" ]}
}
},

Expand Down
33 changes: 33 additions & 0 deletions app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ msgstr "{0,plural,=1{Enrollment Attribute} other{Enrollment Attributes}}"
msgid "enumeration.DefaultValueValidityType.after"
msgstr "Days After Finalization"

msgid "error.PetitionAcceptances.exists"
msgstr "An Invitation for this Petition already exists"

msgid "error.PetitionAcceptances.expired"
msgstr "This Invitation has expired"

msgid "error.PetitionAcceptances.processed"
msgstr "This Invitation has already been processed"

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

Expand Down Expand Up @@ -131,8 +140,32 @@ msgstr "Telephone Number Type"
msgid "field.EnrollmentAttributes.url_type_id"
msgstr "URL Type"

msgid "field.InvitationAccepters.invitation_validity"
msgstr "Invitation Validity"

msgid "field.InvitationAccepters.invitation_validity.desc"
msgstr "Time in minutes before the invitation expires, default is 1440 (1 day)"

msgid "field.InvitationAccepters.welcome_message"
msgstr "Welcome Message"

msgid "result.accept.accepted"
msgstr "Invitation Accepted"

msgid "result.accept.declined"
msgstr "Invitation Declined"

msgid "result.attr.saved"
msgstr "Petition Attributes recorded"

msgid "result.basicattr.finalized"
msgstr "Name, Email Address, and Person Role created during finalization"

msgid "result.InvitationAccepters.accepted"
msgstr "Invitation Accepted at {0}"

msgid "result.InvitationAccepters.declined"
msgstr "Invitation Declined at {0}"

msgid "result.InvitationAccepters.none"
msgstr "No response to invitation yet"
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public function dispatch(string $id) {
public function display(string $id) {
$petition = $this->getPetition();

$this->set('vv_basic_petition_attribute_set', $this->BasicAttributeCollectors
->BasicPetitionAttributeSets
$this->set('vv_petition_basic_attribute_set', $this->BasicAttributeCollectors
->PetitionBasicAttributeSets
->find()
->where(['BasicPetitionAttributeSets.petition_id' => $petition->id])
->where(['PetitionBasicAttributeSets.petition_id' => $petition->id])
->firstOrFail());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
/**
* COmanage Registry Basic Invitation Accepters Controller
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry-plugins
* @since COmanage Registry v5.1.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types=1);

namespace CoreEnroller\Controller;

use Cake\ORM\TableRegistry;
use App\Controller\StandardEnrollerController;
use App\Lib\Enum\PetitionActionEnum;

class InvitationAcceptersController extends StandardEnrollerController {
public $paginate = [
'order' => [
'InvitationAccepters.id' => 'asc'
]
];

/**
* Dispatch an Enrollment Flow Step.
*
* @since COmanage Registry v5.1.0
* @param string $id Invitation Accepter ID
*/

public function dispatch(string $id) {
$petition = $this->getPetition();

$cfg = $this->InvitationAccepters->get($id);

$this->set('vv_config', $cfg);

$PetitionAcceptances = TableRegistry::getTableLocator()->get('CoreEnroller.PetitionAcceptances');

$pa = $PetitionAcceptances->find()->where(['petition_id' => $petition->id])->first();

$this->set('vv_pa', $pa);

if($this->request->is(['post', 'put'])) {
$data = $this->request->getData();

$accepted = (bool)$data['accepted'];

try {
$PetitionAcceptances->processReply(
$petition->id,
$cfg->enrollment_flow_step_id,
$accepted
);

if($accepted) {
// On acceptance, indicate the step is completed and generate a redirect
// to the next step

$link = $this->getPrimaryLink(true);

return $this->finishStep(
enrollmentFlowStepId: $link->value,
petitionId: $petition->id,
comment: __d('core_enroller', ($accepted ? 'result.accept.accepted' : 'result.accept.declined'))
);
} else {
// On decline, set a flash message and redirect to the petition complete landing
$this->Flash->success(__d('core_enroller', 'result.accept.declined'));

$coId = $this->getCOID();

return $this->redirect("/$coId/petition-complete");
}
}
catch(\Exception $e) {
$this->Flash->error($e->getMessage());
}
} else {
// Record that the invitation was viewed
$PetitionHistoryRecords = TableRegistry::getTableLocator()->get('PetitionHistoryRecords');

$PetitionHistoryRecords->record(
petitionId: $petition->id,
enrollmentFlowStepId: $cfg->enrollment_flow_step_id,
action: PetitionActionEnum::InvitationViewed,
comment: __d('result', 'Petitions.viewed.inv')
// actorPersonId
);
}

// Fall through and let the form render*/

$this->render('/Standard/dispatch');
}

/**
* Display information about this Step.
*
* @since COmanage Registry v5.1.0
* @param string $id Invitation Accepters ID
*/

public function display(string $id) {
$petition = $this->getPetition();

$PetitionAcceptances = TableRegistry::getTableLocator()->get('CoreEnroller.PetitionAcceptances');

$this->set('vv_pa', $PetitionAcceptances->find()->where(['petition_id' => $petition->id])->first());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* COmanage Registry Basic Petition Attribute Set Entity
* COmanage Registry Invitation Accepter Entity
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
Expand Down Expand Up @@ -31,7 +31,7 @@

use Cake\ORM\Entity;

class BasicPetitionAttributeSet extends Entity {
class InvitationAccepter extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
Expand Down
49 changes: 49 additions & 0 deletions app/plugins/CoreEnroller/src/Model/Entity/PetitionAcceptance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* COmanage Registry Petition Acceptance Entity
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry-plugins
* @since COmanage Registry v5.1.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types=1);

namespace CoreEnroller\Model\Entity;

use Cake\ORM\Entity;

class PetitionAcceptance extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected $_accessible = [
'*' => true,
'id' => false,
'slug' => false,
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* COmanage Registry Petition Basic Attribute Set Entity
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry-plugins
* @since COmanage Registry v5.1.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types=1);

namespace CoreEnroller\Model\Entity;

use Cake\ORM\Entity;

class PetitionBasicAttributeSet extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected $_accessible = [
'*' => true,
'id' => false,
'slug' => false,
];
}
Loading

0 comments on commit 21c4ecc

Please sign in to comment.