Skip to Content.
Sympa Menu

comanage-dev - [comanage-dev] r357 - in registry/trunk/app: Config/Schema Lib Model View/CoIdentifierAssignments

Subject: COmanage Developers List

List archive

[comanage-dev] r357 - in registry/trunk/app: Config/Schema Lib Model View/CoIdentifierAssignments


Chronological Thread 
  • From:
  • To:
  • Subject: [comanage-dev] r357 - in registry/trunk/app: Config/Schema Lib Model View/CoIdentifierAssignments
  • Date: Tue, 4 Sep 2012 04:08:28 -0400

Author: benno
Date: 2012-09-04 04:08:27 -0400 (Tue, 04 Sep 2012)
New Revision: 357

Modified:
registry/trunk/app/Config/Schema/schema.xml
registry/trunk/app/Lib/lang.php
registry/trunk/app/Model/CoIdentifierAssignment.php
registry/trunk/app/Model/EmailAddress.php
registry/trunk/app/View/CoIdentifierAssignments/fields.inc
Log:
Implement automatic identifier assignment for email addresses (CO-434)

Modified: registry/trunk/app/Config/Schema/schema.xml
===================================================================
--- registry/trunk/app/Config/Schema/schema.xml 2012-09-02 23:25:44 UTC (rev
356)
+++ registry/trunk/app/Config/Schema/schema.xml 2012-09-04 08:08:27 UTC (rev
357)
@@ -692,6 +692,7 @@
<field name="identifier_type" type="C" size="32">
<notnull />
</field>
+ <field name="email_type" type="C" size="32" />
<field name="description" type="C" size="256" />
<field name="login" type="L" />
<field name="algorithm" type="C" size="2" />

Modified: registry/trunk/app/Lib/lang.php
===================================================================
--- registry/trunk/app/Lib/lang.php 2012-09-02 23:25:44 UTC (rev 356)
+++ registry/trunk/app/Lib/lang.php 2012-09-04 08:08:27 UTC (rev 357)
@@ -398,6 +398,8 @@
'fd.ia.maximum.desc' => 'The maximum value for randomly generated
identifiers',
'fd.ia.minimum' => 'Minimum',
'fd.ia.minimum.desc' => 'The minimum value for randomly generated
identifiers, or the starting value for sequences',
+ 'fd.ia.type.email' => 'Email Type',
+ 'fd.ia.type.email.desc' => 'For Identifier Assignments applied to Type
<i>Mail</i>, an Email Address (instead of an Identifier) will be created with
this type (if not blank)',
// The next set must be named fd.model.validation-field
'fd.identifier.identifier' => 'Identifier',
'fd.identifier.login' => 'Login',

Modified: registry/trunk/app/Model/CoIdentifierAssignment.php
===================================================================
--- registry/trunk/app/Model/CoIdentifierAssignment.php 2012-09-02 23:25:44
UTC (rev 356)
+++ registry/trunk/app/Model/CoIdentifierAssignment.php 2012-09-04 08:08:27
UTC (rev 357)
@@ -58,6 +58,17 @@
'required' => false,
'allowEmpty' => false
),
+ 'email_type' => array(
+ 'rule' => array(
+ 'inList',
+ array(
+ ContactEnum::Home,
+ ContactEnum::Office
+ )
+ ),
+ 'required' => false,
+ 'allowEmpty' => true
+ ),
'description' => array(
'rule' => '/.*/',
'required' => false
@@ -120,13 +131,23 @@
public function assign($coIdentifierAssignment, $coPersonID) {
$ret = null;

+ // Determine if we are actually assigning an email address instead of an
identifier.
+ $assignEmail = false;
+
+ if($coIdentifierAssignment['CoIdentifierAssignment']['identifier_type']
== 'mail'
+ &&
isset($coIdentifierAssignment['CoIdentifierAssignment']['email_type'])
+ && $coIdentifierAssignment['CoIdentifierAssignment']['email_type'] !=
'') {
+ $assignEmail = true;
+ }
+
// Begin a transaction. This is more because we need to ensure the
integrity of
// data between SELECT and INSERT/UPDATE than that we expect to rollback.

$dbc = $this->getDataSource();
$dbc->begin();

- // See if the CO Person already has an identifier of this type, throw an
error if so
+ // Find the CO Person.
+
$args = array();
$args['conditions']['CoPerson.id'] = $coPersonID;
$args['contain'][] = 'Name';
@@ -144,10 +165,18 @@
// Check for the Identifier. If the person already has one of this sort,
// don't generate a new one.

- if($this->Co->CoPerson->Identifier->assigned($coPersonID,
-
$coIdentifierAssignment['CoIdentifierAssignment']['identifier_type'])) {
- $dbc->commit();
- throw new OverflowException(_txt('er.ia.already'));
+ if($assignEmail) {
+ if($this->Co->CoPerson->EmailAddress->assigned($coPersonID,
+
$coIdentifierAssignment['CoIdentifierAssignment']['email_type'])) {
+ $dbc->commit();
+ throw new OverflowException(_txt('er.ia.already'));
+ }
+ } else {
+ if($this->Co->CoPerson->Identifier->assigned($coPersonID,
+
$coIdentifierAssignment['CoIdentifierAssignment']['identifier_type'])) {
+ $dbc->commit();
+ throw new OverflowException(_txt('er.ia.already'));
+ }
}

// Generate the new identifier. This requires several steps. First,
substitute
@@ -189,20 +218,37 @@

$coIdentifierAssignment['CoIdentifierAssignment']['co_id'])) {
// This one's good... insert it into the table and break the loop

- $identifierData = array();
- $identifierData['Identifier']['identifier'] = $candidate;
- $identifierData['Identifier']['type'] =
$coIdentifierAssignment['CoIdentifierAssignment']['identifier_type'];
- $identifierData['Identifier']['login'] =
$coIdentifierAssignment['CoIdentifierAssignment']['login'];
- $identifierData['Identifier']['co_person_id'] =
$coPerson['CoPerson']['id'];
- $identifierData['Identifier']['status'] = StatusEnum::Active;
+ if($assignEmail) {
+ $emailAddressData = array();
+ $emailAddressData['EmailAddress']['mail'] = $candidate;
+ $emailAddressData['EmailAddress']['type'] =
$coIdentifierAssignment['CoIdentifierAssignment']['email_type'];
+ $emailAddressData['EmailAddress']['co_person_id'] =
$coPerson['CoPerson']['id'];
+
+ // We need to call create to reset the model state since we're
(possibly) doing multiple distinct
+ // saves against the same model.
+ $this->Co->CoPerson->EmailAddress->create($emailAddressData);
+
+ if($this->Co->CoPerson->EmailAddress->save($emailAddressData)) {
+ $ret = $this->Co->CoPerson->EmailAddress->id;
+ }
+ } else {
+ $identifierData = array();
+ $identifierData['Identifier']['identifier'] = $candidate;
+ $identifierData['Identifier']['type'] =
$coIdentifierAssignment['CoIdentifierAssignment']['identifier_type'];
+ $identifierData['Identifier']['login'] =
$coIdentifierAssignment['CoIdentifierAssignment']['login'];
+ $identifierData['Identifier']['co_person_id'] =
$coPerson['CoPerson']['id'];
+ $identifierData['Identifier']['status'] = StatusEnum::Active;
+
+ // We need to call create to reset the model state since we're
(possibly) doing multiple distinct
+ // saves against the same model.
+ $this->Co->CoPerson->Identifier->create($identifierData);
+
+ if($this->Co->CoPerson->Identifier->save($identifierData)) {
+ $ret = $this->Co->CoPerson->Identifier->id;
+ }
+ }

- // We need to call create to reset the model state since we're
(possibly) doing multiple distinct
- // saves against the same model.
- $this->Co->CoPerson->Identifier->create($identifierData);
-
- if($this->Co->CoPerson->Identifier->save($identifierData)) {
- $ret = $this->Co->CoPerson->Identifier->id;
-
+ if($ret) {
// Create a history record
try {

$this->Co->CoPerson->HistoryRecord->record($coPerson['CoPerson']['id'],
@@ -211,7 +257,9 @@
null,

ActionEnum::IdentifierAutoAssigned,
_txt('en.action',
null, ActionEnum::IdentifierAutoAssigned) . ': '
- . $candidate . ' ('
. $identifierData['Identifier']['type'] . ')');
+ . $candidate . ' ('
. $coIdentifierAssignment['CoIdentifierAssignment']['identifier_type']
+ . ($assignEmail ?
':'.$coIdentifierAssignment['CoIdentifierAssignment']['email_type'] : '')
+ . ')');
}
catch(Exception $e) {
$dbc->rollback();

Modified: registry/trunk/app/Model/EmailAddress.php
===================================================================
--- registry/trunk/app/Model/EmailAddress.php 2012-09-02 23:25:44 UTC (rev
356)
+++ registry/trunk/app/Model/EmailAddress.php 2012-09-04 08:08:27 UTC (rev
357)
@@ -73,4 +73,26 @@
public $cm_enum_types = array(
'type' => 'contact_t'
);
+
+ /**
+ * Determine if an email address of a given type is already assigned to a
CO Person.
+ *
+ * IMPORTANT: This function should be called within a transaction to ensure
+ * actions taken based on availability are atomic.
+ *
+ * @since COmanage Registry v0.7
+ * @param Integer CO Person ID
+ * @param String Type of candidate email address
+ * @return Boolean True if an email address of the specified type is
already assigned, false otherwise
+ */
+
+ public function assigned($coPersonID, $emailType) {
+ $args = array();
+ $args['conditions']['EmailAddress.co_person_id'] = $coPersonID;
+ $args['conditions']['EmailAddress.type'] = $emailType;
+
+ $r = $this->findForUpdate($args['conditions'], array('mail'));
+
+ return !empty($r);
+ }
}

Modified: registry/trunk/app/View/CoIdentifierAssignments/fields.inc
===================================================================
--- registry/trunk/app/View/CoIdentifierAssignments/fields.inc 2012-09-02
23:25:44 UTC (rev 356)
+++ registry/trunk/app/View/CoIdentifierAssignments/fields.inc 2012-09-04
08:08:27 UTC (rev 357)
@@ -59,6 +59,13 @@

document.getElementById('CoIdentifierAssignmentMaximum').disabled =
(document.getElementById('CoIdentifierAssignmentAlgorithm').value !=
'R');
+
+ if(document.getElementById('CoIdentifierAssignmentIdentifierType').value
!= 'mail') {
+ document.getElementById('CoIdentifierAssignmentEmailType').value = "";
+ document.getElementById('CoIdentifierAssignmentEmailType').disabled =
true;
+ } else {
+ document.getElementById('CoIdentifierAssignmentEmailType').disabled =
false;
+ }
}

function js_local_onload() {
@@ -74,6 +81,7 @@

document.getElementById('CoIdentifierAssignmentMaximum').disabled =
false;
document.getElementById('CoIdentifierAssignmentMinimum').disabled =
false;
+ document.getElementById('CoIdentifierAssignmentEmailType').disabled =
false;
}
</script>
<table id="<?php print $this->action; ?>_co_identifier_assignment"
class="ui-widget">
@@ -97,6 +105,7 @@
$attrs = array();
$attrs['value'] = (isset($co_identifier_assignments) ?
$co_identifier_assignments[0]['CoIdentifierAssignment']['identifier_type'] :
"");
$attrs['empty'] = false;
+ $attrs['onChange'] = 'fields_update_gadgets()';

if($e) {
print $this->Form->select('identifier_type',
@@ -114,6 +123,35 @@
</tr>
<tr class="line1">
<td>
+ <b><?php print _txt('fd.ia.type.email'); ?></b><br />
+ <font class="desc"><?php print _txt('fd.ia.type.email.desc');
?></font>
+ </td>
+ <td>
+ <?php
+ global $cm_lang, $cm_texts;
+ $attrs['value'] = (isset($co_identifier_assignments)
+ ?
$co_identifier_assignments[0]['CoIdentifierAssignment']['email_type']
+ : "");
+ $attrs['empty'] = true;
+
+ if($e) {
+ // XXX There is some inconsistency here and in EmailAddress
model/view as to which email types are actually permitted.
+ // Probably the best solution is to just rewrite emailaddress to
support extended types. See also CO-106.
+ print $this->Form->select('email_type',
+ $cm_texts[ $cm_lang ]['en.contact'],
+ $attrs);
+
+ if($this->Form->isFieldError('email_type')) {
+ print $this->Form->error('email_type');
+ }
+ } else {
+ print _txt('en.cpntact', null,
$co_identifier_assignments[0]['CoIdentifierAssignment']['email_type']);
+ }
+ ?>
+ </td>
+ </tr>
+ <tr class="line2">
+ <td>
<b><?php print _txt('fd.identifier.login'); ?></b><br />
<font class="desc"><?php print _txt('fd.identifier.login.desc');
?></font>
</td>
@@ -121,7 +159,7 @@
<?php print ($e ? $this->Form->input('login') :
Sanitize::html($co_identifier_assignments[0]['CoIdentifierAssignment']['login']));
?>
</td>
</tr>
- <tr class="line2">
+ <tr class="line1">
<td>
<b><?php print _txt('fd.ia.algorithm'); ?></b><br />
<font class="desc"><?php print _txt('fd.ia.algorithm.desc');
?></font>
@@ -149,7 +187,7 @@
?>
</td>
</tr>
- <tr class="line1">
+ <tr class="line2">
<td>
<b><?php print _txt('fd.ia.format'); ?></b><br />
<font class="desc"><?php print _txt('fd.ia.format.desc'); ?></font>
@@ -169,7 +207,7 @@
<?php endif; ?>
</td>
</tr>
- <tr class="line2">
+ <tr class="line1">
<td>
<b><?php print _txt('fd.ia.minimum'); ?></b><br />
<font class="desc"><?php print _txt('fd.ia.minimum.desc'); ?></font>
@@ -178,7 +216,7 @@
<?php print ($e ? $this->Form->input('minimum') :
Sanitize::html($co_identifier_assignments[0]['CoIdentifierAssignment']['minimum']));
?>
</td>
</tr>
- <tr class="line1">
+ <tr class="line2">
<td>
<b><?php print _txt('fd.ia.maximum'); ?></b><br />
<font class="desc"><?php print _txt('fd.ia.maximum.desc'); ?></font>
@@ -187,7 +225,7 @@
<?php print ($e ? $this->Form->input('maximum') :
Sanitize::html($co_identifier_assignments[0]['CoIdentifierAssignment']['maximum']));
?>
</td>
</tr>
- <tr class="line2">
+ <tr class="line1">
<td>
<b><?php print _txt('fd.ia.exclusions'); ?></b><br />
<font class="desc"><?php print _txt('fd.ia.exclusions.desc');
?></font>



  • [comanage-dev] r357 - in registry/trunk/app: Config/Schema Lib Model View/CoIdentifierAssignments, svnlog, 09/04/2012

Archive powered by MHonArc 2.6.16.

Top of Page