comanage-dev - [comanage-dev] r120 - in trunk/app: controllers libs models
Subject: COmanage Developers List
List archive
- From:
- To:
- Subject: [comanage-dev] r120 - in trunk/app: controllers libs models
- Date: Mon, 28 Nov 2011 20:17:43 -0500
Author: benno
Date: 2011-11-28 20:17:43 -0500 (Mon, 28 Nov 2011)
New Revision: 120
Modified:
trunk/app/controllers/co_org_identity_links_controller.php
trunk/app/controllers/co_people_controller.php
trunk/app/libs/lang.php
trunk/app/models/co_org_identity_link.php
trunk/app/models/co_person.php
Log:
Prohibit an org identity from being added more than once to the same CO
[CO-200]
Modified: trunk/app/controllers/co_org_identity_links_controller.php
===================================================================
--- trunk/app/controllers/co_org_identity_links_controller.php 2011-11-28
04:12:55 UTC (rev 119)
+++ trunk/app/controllers/co_org_identity_links_controller.php 2011-11-29
01:17:43 UTC (rev 120)
@@ -54,18 +54,19 @@
//
// Returns:
// - true if dependency checks succeed, false otherwise.
-
+
// Check that the IDs (CO Person, Org Person) provided point to
existing entities.
-
+
if(empty($this->data['CoOrgIdentityLink']['co_person_id']))
{
$this->restResultHeader(403, "CoPerson Does Not Exist");
return(false);
- }
+ }
- $a =
$this->CoOrgIdentityLink->CoPerson->findById($this->data['CoOrgIdentityLink']['co_person_id']);
+ $this->CoOrgIdentityLink->CoPerson->contain();
+ $coPerson =
$this->CoOrgIdentityLink->CoPerson->findById($this->data['CoOrgIdentityLink']['co_person_id']);
- if(empty($a))
+ if(empty($coPerson))
{
$this->restResultHeader(403, "CoPerson Does Not Exist");
return(false);
@@ -77,14 +78,27 @@
return(false);
}
- $a =
$this->CoOrgIdentityLink->OrgIdentity->findById($this->data['CoOrgIdentityLink']['org_identity_id']);
+ // Can't contain OrgIdentity completely since Name is used for display
+ $this->CoOrgIdentityLink->OrgIdentity->contain('Name');
+ $orgIdentity =
$this->CoOrgIdentityLink->OrgIdentity->findById($this->data['CoOrgIdentityLink']['org_identity_id']);
- if(empty($a))
+ if(empty($orgIdentity))
{
$this->restResultHeader(403, "OrgIdentity Does Not Exist");
return(false);
}
+ // Check that an org identity being added is not already a member of
the CO.
+ // (A person can't be added to the same CO twice... that's what Person
Roles
+ // are for.) Note the UI check is in co_people_controller.
+
+
if($this->CoOrgIdentityLink->CoPerson->orgIdIsCoPerson($coPerson['CoPerson']['co_id'],
+
$orgIdentity['OrgIdentity']['id']))
+ {
+ $this->restResultHeader(403, "OrgIdentity Already Linked");
+ return(false);
+ }
+
return(true);
}
Modified: trunk/app/controllers/co_people_controller.php
===================================================================
--- trunk/app/controllers/co_people_controller.php 2011-11-28 04:12:55
UTC (rev 119)
+++ trunk/app/controllers/co_people_controller.php 2011-11-29 01:17:43
UTC (rev 120)
@@ -98,7 +98,8 @@
// Check if the target person is a member of any COU that the current
user
// does not have permissions over. If so, fail.
- foreach($curdata['CoPersonRole'] as $pr) {
+ foreach($curdata['CoPersonRole'] as $pr)
+ {
if(isset($pr['cou_id']) && $pr['cou_id'] != "")
{
if(!isset($this->viewVars['permissions']['cous'][ $pr['cou_id'] ]))
@@ -152,7 +153,33 @@
$this->data['Name']['id'] = $curdata['Name']['id'];
}
-
+
+ // Check that an org identity being added is not already a member of
the CO.
+ // (A person can't be added to the same CO twice... that's what Person
Roles
+ // are for.) Note the REST check is in
co_org_identity_links_controller.
+
+ if(!$curdata ||
+ ($this->data['CoOrgIdentityLink'][0]['org_identity_id']
+ != $curdata['CoOrgIdentityLink'][0]['org_identity_id']))
+ {
+ if($this->CoPerson->orgIdIsCoPerson($this->cur_co['Co']['id'],
+
$this->data['CoOrgIdentityLink'][0]['org_identity_id']))
+ {
+ $this->Session->setFlash(_txt('er.cop.member',
+ array(generateCn($this->data['Name']),
+ $this->cur_co['Co']['name'])),
+ '', array(), 'error');
+
+ $redirect['controller'] = 'co_people';
+ $redirect['action'] = 'index';
+ $redirect['co'] = $this->cur_co['Co']['id'];
+ $this->redirect($redirect);
+
+ // We won't actually accomplish anything with this return
+ return(false);
+ }
+ }
+
return(true);
}
@@ -261,7 +288,6 @@
// Construct a CoPerson from the OrgIdentity. We only populate
defaulted values.
$cop['Name'] = $orgp['Name'];
- $cop['CoPerson']['title'] = $orgp['OrgIdentity']['title']; // XXX
unclear that title should autopopulate
$cop['CoOrgIdentityLink'][0]['org_identity_id'] =
$orgp['OrgIdentity']['id'];
$this->set('co_people', array(0 => $cop));
Modified: trunk/app/libs/lang.php
===================================================================
--- trunk/app/libs/lang.php 2011-11-28 04:12:55 UTC (rev 119)
+++ trunk/app/libs/lang.php 2011-11-29 01:17:43 UTC (rev 120)
@@ -155,6 +155,7 @@
'er.co.unk' => 'Unknown CO',
'er.comember' => '%1$s is a member of one or more COs (%2$s) and
cannot be removed.',
'er.coumember' => '%1$s is a member of one or more COUs that you do
not manage (%2$s) and cannot be removed.',
+ 'er.cop.member' => '%1$s is already a member of %2$s and cannot be
added again. However, an additional role may be added.',
'er.cop.unk' => 'Unknown CO Person',
'er.cop.unk-a' => 'Unknown CO Person "%1$s"',
// XXX These should become er.copr (or tossed if not needed)
Modified: trunk/app/models/co_org_identity_link.php
===================================================================
--- trunk/app/models/co_org_identity_link.php 2011-11-28 04:12:55 UTC (rev
119)
+++ trunk/app/models/co_org_identity_link.php 2011-11-29 01:17:43 UTC (rev
120)
@@ -23,6 +23,9 @@
// Define class name for cake
var $name = "CoOrgIdentityLink";
+ // Add behaviors
+ var $actsAs = array('Containable');
+
// Association rules from this model to other models
var $belongsTo = array("CoPerson", // A CO Org Identity Link
is attached to one CO Person
"OrgIdentity"); // A CO Org Identity Link
is attached to one Org Identity
Modified: trunk/app/models/co_person.php
===================================================================
--- trunk/app/models/co_person.php 2011-11-28 04:12:55 UTC (rev 119)
+++ trunk/app/models/co_person.php 2011-11-29 01:17:43 UTC (rev 120)
@@ -23,6 +23,9 @@
// Define class name for cake
var $name = "CoPerson";
+ // Add behaviors
+ var $actsAs = array('Containable');
+
// Association rules from this model to other models
var $belongsTo = array("Co"); // A CO Person Source
is attached to one CO
@@ -76,5 +79,43 @@
var $cm_enum_types = array(
'status' => 'status_t'
);
+
+ function orgIdIsCoPerson($coId, $orgIdentityId)
+ {
+ // Determine if an org identity is already associated with a CO.
+ //
+ // Parameters:
+ // - coId: CO to check
+ // - orgIdentityId: Org Identity to check
+ //
+ // Preconditions:
+ // None
+ //
+ // Postconditions:
+ // None
+ //
+ // Returns:
+ // - true if $orgIdentityId is linked to $coId, false otherwise
+
+ // Try to retrieve a link for this org identity id where the co person
id
+ // is a member of this CO
+
+ $dbo = $this->getDataSource();
+
+ $args['joins'][0]['table'] =
$dbo->fullTableName($this->CoOrgIdentityLink);
+ $args['joins'][0]['alias'] = 'CoOrgIdentityLink';
+ $args['joins'][0]['type'] = 'INNER';
+ $args['joins'][0]['conditions'][0] =
'CoPerson.id=CoOrgIdentityLink.co_person_id';
+ $args['conditions']['CoOrgIdentityLink.org_identity_id'] =
$orgIdentityId;
+ $args['conditions']['CoPerson.co_id'] = $coId;
+ $args['contain'] = false;
+
+ $link = $this->find('first', $args);
+
+ if($link)
+ return(true);
+
+ return(false);
+ }
}
?>
\ No newline at end of file
- [comanage-dev] r120 - in trunk/app: controllers libs models, benno, 11/28/2011
Archive powered by MHonArc 2.6.16.