Skip to Content.
Sympa Menu

comanage-dev - [comanage-dev] r316 - in registry/trunk/app: Config Controller Lib Model

Subject: COmanage Developers List

List archive

[comanage-dev] r316 - in registry/trunk/app: Config Controller Lib Model


Chronological Thread 
  • From:
  • To:
  • Subject: [comanage-dev] r316 - in registry/trunk/app: Config Controller Lib Model
  • Date: Thu, 19 Jul 2012 22:12:12 -0400

Author: benno
Date: 2012-07-19 22:12:12 -0400 (Thu, 19 Jul 2012)
New Revision: 316

Added:
registry/trunk/app/Controller/VootController.php
Modified:
registry/trunk/app/Config/routes.php
registry/trunk/app/Controller/CoGroupsController.php
registry/trunk/app/Lib/lang.php
registry/trunk/app/Model/CoGroup.php
registry/trunk/app/Model/CoGroupMember.php
registry/trunk/app/Model/CoPerson.php
registry/trunk/app/Model/Identifier.php
Log:
Experimental VOOT support (CO-376)

Modified: registry/trunk/app/Config/routes.php
===================================================================
--- registry/trunk/app/Config/routes.php 2012-07-16 01:54:07 UTC (rev
315)
+++ registry/trunk/app/Config/routes.php 2012-07-20 02:12:12 UTC (rev
316)
@@ -38,6 +38,25 @@
CakePlugin::routes();

/**
+ * Experimental VOOT routing
+ */
+
+Router::connect(
+ '/voot/groups/:memberid/:groupid',
+ array('controller' => 'voot', 'action' => 'groups')
+);
+
+Router::connect(
+ '/voot/groups/:memberid',
+ array('controller' => 'voot', 'action' => 'groups')
+);
+
+Router::connect(
+ '/voot/people/:memberid/:groupid',
+ array('controller' => 'voot', 'action' => 'people')
+);
+
+/**
* Enable REST. These *MUST* come before the default CakePHP routes.
*/

@@ -67,4 +86,3 @@
* the built-in default routes.
*/
require CAKE . 'Config' . DS . 'routes.php';
-

Modified: registry/trunk/app/Controller/CoGroupsController.php
===================================================================
--- registry/trunk/app/Controller/CoGroupsController.php 2012-07-16
01:54:07 UTC (rev 315)
+++ registry/trunk/app/Controller/CoGroupsController.php 2012-07-20
02:12:12 UTC (rev 316)
@@ -164,6 +164,44 @@
}

/**
+ * Obtain all CO Groups.
+ * - postcondition: $<object>s set on success (REST or HTML), using
pagination (HTML only)
+ * - postcondition: HTTP status returned (REST)
+ * - postcondition: Session flash message updated (HTML) on suitable error
+ *
+ * @since COmanage Registry v0.6
+ */
+
+ function index() {
+ if($this->restful && !empty($this->params['url']['copersonid'])) {
+ // We need to retrieve via a join, which StandardController::index()
doesn't
+ // currently support.
+
+ try {
+ $groups =
$this->CoGroup->findForCoPerson($this->params['url']['copersonid']);
+
+ if(!empty($groups)) {
+ $this->set('co_groups', $groups);
+
+ // We also need to pass member/ownership in these groups.
+
+ $this->set('co_group_members',
+
$this->CoGroup->CoGroupMember->findCoPersonGroupRoles($this->params['url']['copersonid']));
+ } else {
+ $this->restResultHeader(204, "CO Person Has No Groups");
+ return;
+ }
+ }
+ catch(InvalidArgumentException $e) {
+ $this->restResultHeader(404, "CO Person Unknown");
+ return;
+ }
+ } else {
+ parent::index();
+ }
+ }
+
+ /**
* Authorization for this Controller, called by Auth component
* - precondition: Session.Auth holds data used for authz decisions
* - postcondition: $permissions set with calculated permissions

Modified: registry/trunk/app/Lib/lang.php
===================================================================
--- registry/trunk/app/Lib/lang.php 2012-07-16 01:54:07 UTC (rev 315)
+++ registry/trunk/app/Lib/lang.php 2012-07-20 02:12:12 UTC (rev 316)
@@ -251,6 +251,7 @@
'er.ia.exists' => 'The identifier "%1$s" is already in use',
'er.ia.failed' => 'Failed to find a unique identifier to assign',
'er.ia.none' => 'No identifier assignments configured',
+ 'er.id.unk' => 'Unknown Identifier',
'er.inv.exp' => 'Invitation Expired',
'er.inv.nf' => 'Invitation Not Found',
'er.nd.already' => 'NSF Demographic data already exists for this person',

Modified: registry/trunk/app/Model/CoGroup.php
===================================================================
--- registry/trunk/app/Model/CoGroup.php 2012-07-16 01:54:07 UTC (rev
315)
+++ registry/trunk/app/Model/CoGroup.php 2012-07-20 02:12:12 UTC (rev
316)
@@ -43,6 +43,8 @@
// Default ordering for find operations
public $order = array("CoGroup.name");

+ public $actsAs = array('Containable');
+
// Validation rules for table elements
public $validate = array(
'co_id' => array(
@@ -75,4 +77,42 @@
public $cm_enum_types = array(
'status' => 'status_t'
);
+
+ /**
+ * Obtain all groups for a CO person.
+ *
+ * @since COmanage Registry v0.6
+ * @param Integer CO Person ID
+ * @param Integer Maximium number of results to retrieve (or null)
+ * @param Integer Offset to start retrieving results from (or null)
+ * @param String Field to sort by (or null)
+ * @return Array Group information, as returned by find
+ */
+
+ function findForCoPerson($coPersonId, $limit=null, $offset=null,
$order=null) {
+ $args = array();
+ $args['joins'][0]['table'] = 'co_group_members';
+ $args['joins'][0]['alias'] = 'CoGroupMember';
+ $args['joins'][0]['type'] = 'INNER';
+ $args['joins'][0]['conditions'][0] =
'CoGroup.id=CoGroupMember.co_group_id';
+ $args['conditions']['CoGroup.status'] = StatusEnum::Active;
+ $args['conditions']['CoGroupMember.co_person_id'] = $coPersonId;
+ $args['conditions']['OR']['CoGroupMember.member'] = 1;
+ $args['conditions']['OR']['CoGroupMember.owner'] = 1;
+ $args['contain'] = false;
+
+ if($limit) {
+ $args['limit'] = $limit;
+ }
+
+ if($offset) {
+ $args['offset'] = $offset;
+ }
+
+ if($order) {
+ $args['order'] = $order;
+ }
+
+ return $this->find('all', $args);
+ }
}

Modified: registry/trunk/app/Model/CoGroupMember.php
===================================================================
--- registry/trunk/app/Model/CoGroupMember.php 2012-07-16 01:54:07 UTC (rev
315)
+++ registry/trunk/app/Model/CoGroupMember.php 2012-07-20 02:12:12 UTC (rev
316)
@@ -42,6 +42,8 @@
// Default ordering for find operations
public $order = array("co_person_id");

+ public $actsAs = array('Containable');
+
// Validation rules for table elements
public $validate = array(
'co_group_id' => array(
@@ -59,4 +61,37 @@
'rule' => array('boolean')
)
);
+
+ /**
+ * Obtain the group roles for a CO person.
+ *
+ * @since COmanage Registry v0.6
+ * @param Integer CO Person ID
+ * @return Array An array of two array: group IDs for which the person is
a member, and group IDs for which the person is an owner
+ */
+
+ function findCoPersonGroupRoles($coPersonId) {
+ $ret = array(
+ 'member' => array(),
+ 'owner' => array()
+ );
+
+ $args = array();
+ $args['conditions']['CoGroupMember.co_person_id'] = $coPersonId;
+ $args['contain'] = false;
+
+ $memberships = $this->find('all', $args);
+
+ foreach($memberships as $m) {
+ if(isset($m['CoGroupMember']['member']) &&
$m['CoGroupMember']['member']) {
+ $ret['member'][] = $m['CoGroupMember']['co_group_id'];
+ }
+
+ if(isset($m['CoGroupMember']['owner']) &&
$m['CoGroupMember']['owner']) {
+ $ret['owner'][] = $m['CoGroupMember']['co_group_id'];
+ }
+ }
+
+ return $ret;
+ }
}

Modified: registry/trunk/app/Model/CoPerson.php
===================================================================
--- registry/trunk/app/Model/CoPerson.php 2012-07-16 01:54:07 UTC (rev
315)
+++ registry/trunk/app/Model/CoPerson.php 2012-07-20 02:12:12 UTC (rev
316)
@@ -117,6 +117,93 @@
);

/**
+ * Obtain all people associated with a Group
+ *
+ * @since COmanage Registry v0.6
+ * @param Integer CO Group ID
+ * @param Integer Maximium number of results to retrieve (or null)
+ * @param Integer Offset to start retrieving results from (or null)
+ * @return Array CoPerson information, as returned by find (with some
associated data)
+ */
+
+ function findForCoGroup($coGroupId, $limit=null, $offset=null) {
+ $args = array();
+ $args['joins'][0]['table'] = 'co_group_members';
+ $args['joins'][0]['alias'] = 'CoGroupMember';
+ $args['joins'][0]['type'] = 'INNER';
+ $args['joins'][0]['conditions'][0] =
'CoPerson.id=CoGroupMember.co_person_id';
+ $args['conditions']['CoGroupMember.co_group_id'] = $coGroupId;
+ $args['conditions']['OR']['CoGroupMember.member'] = 1;
+ $args['conditions']['OR']['CoGroupMember.owner'] = 1;
+ // We use contain here to pull data for VootController
+ $args['contain'][] = 'Name';
+ $args['contain'][] = 'EmailAddress';
+
+ if($limit) {
+ $args['limit'] = $limit;
+ }
+
+ if($offset) {
+ $args['offset'] = $offset;
+ }
+
+ return $this->find('all', $args);
+ }
+
+ /**
+ * Obtain all CO Person IDs for an identifier.
+ *
+ * @since COmanage Registry v0.6
+ * @param String Identifier
+ * @param String Identifier type (null for any type; not recommended)
+ * @return Array CO Person IDs
+ * @throws InvalidArgumentException
+ */
+
+ function idsForIdentifier($identifier, $identifierType=null) {
+ // First pull the identifier record
+
+ $args = array();
+ $args['conditions']['Identifier.identifier'] = $identifier;
+ $args['contain'] = false;
+
+ if($identifierType) {
+ $args['conditions']['Identifier.type'] = $identifierType;
+ }
+
+ // If identifierType is null, we might get more than one record, in which
+ // case we behave nondeterministically. We can't pull all records, since
we
+ // might get multiple people. Better to supply a type.
+ $id = $this->Identifier->find('first', $args);
+
+ if(!empty($id)) {
+ if(isset($id['Identifier']['co_person_id'])) {
+ // The identifier is attached to a CO Person, return that ID.
+
+ return array($id['Identifier']['co_person_id']);
+ } else {
+ // Map the org identity to a CO person. We might pull more than one.
+ // In this case, it's OK since they come back to the same org person.
+
+ $args = array();
+ $args['conditions']['CoOrgIdentityLink.org_identity_id'] =
$id['Identifier']['org_identity_id'];
+ $args['fields'][] = 'CoOrgIdentityLink.co_person_id';
+ $args['contain'] = false;
+
+ $links = $this->CoOrgIdentityLink->find('list', $args);
+
+ if(!empty($links)) {
+ return array_values($links);
+ }
+ }
+
+ throw new InvalidArgumentException(_txt('er.cop.unk'));
+ } else {
+ throw new InvalidArgumentException(_txt('er.id.unk'));
+ }
+ }
+
+ /**
* Attempt to match existing records based on the provided criteria.
*
* @since COmanage Registry v0.5

Modified: registry/trunk/app/Model/Identifier.php
===================================================================
--- registry/trunk/app/Model/Identifier.php 2012-07-16 01:54:07 UTC (rev
315)
+++ registry/trunk/app/Model/Identifier.php 2012-07-20 02:12:12 UTC (rev
316)
@@ -43,6 +43,8 @@
// Default ordering for find operations
public $order = array("identifier");

+ public $actsAs = array('Containable');
+
// Validation rules for table elements
public $validate = array(
// Don't require any element since $belongsTo saves won't validate if
they're empty



  • [comanage-dev] r316 - in registry/trunk/app: Config Controller Lib Model, svnlog, 07/19/2012

Archive powered by MHonArc 2.6.16.

Top of Page