Skip to Content.
Sympa Menu

comanage-dev - Re: [comanage-dev] Fwd: [JIRA] (CO-242) Error in inviting a person to a co

Subject: COmanage Developers List

List archive

Re: [comanage-dev] Fwd: [JIRA] (CO-242) Error in inviting a person to a co


Chronological Thread 
  • From: Scott Koranda <>
  • To: Benn Oshrin <>
  • Cc: comanage-dev <>
  • Subject: Re: [comanage-dev] Fwd: [JIRA] (CO-242) Error in inviting a person to a co
  • Date: Fri, 17 Feb 2012 16:30:03 -0600

> On 2/16/12 4:23 PM, Scott Koranda wrote:
>
> >So it is co_person_id in cm_co_org_identity_links that is not
> >being set and I believe the error is accurate--you do want
> >that to be set.
>
> Cake should automagically populate the cross reference by populating
> co_person_id after co_person is saved.
>
> >I think the problem is that the line
> >
> >$model->saveAll($data)
> >
> >in the add() method of the StandardController is really a
> >saveAssociate() call and for that call the default is to
> >validate *all* records before any are saved. See
> >
> >http://book.cakephp.org/2.0/en/models/saving-your-data.html
> >
> >But since the CoPerson object has not been saved there is no
> >co_person_id that can go into cm_co_org_identity_links.
> >
> >If you agree that my analysis is correct, then how do you want
> >to unwind this?
>
> We're sort of coming at this from two sides of the same coin.
> Arguably, CoOrgIdentityLink::model shouldn't require co_person_id to
> be set because at the time the pages are submitted (for HTML pages)
> there is no value to submit. We could update the controller to
> modify or drop the validation requirements when not !this->restful.
>
> >There is an option to saveAssociated() so that validation
> >happens table by table (validate = 'true' instead of the
> >default validate = 'false'), but do we want that to be applied
> >for every call to add() of the StandardController?
>
> This would be the other way to handle it. It's plausible this is a
> general solution to this class of problem... always validate per
> model save rather than all at once up front. That avoids having to
> effectively have two validate approaches (one for HTML, one for
> REST).
>
> Previously, this worked because the validation requirements weren't
> there. (I added them because of changes to the REST validations as
> part of CO-112.) As such, I'm still inclined to favor the approach
> where $validate correctly reflects what validations are actually
> needed.
>

As discussed on the call today I have added an add() method to
the CoPeopleController class that overrides the add() method
in the parent StandardController class.

A diff is attached.

I have tested this patch and it correctly updates the
CoPeople and CoOrgIdentityLink tables.

Benn can you please look at the diff and let me know what if
anything you want changed or if I have overlooked some side
effect?

Thanks,

Scott


Index: Controller/CoPeopleController.php
===================================================================
--- Controller/CoPeopleController.php (revision 229)
+++ Controller/CoPeopleController.php (working copy)
@@ -249,6 +249,43 @@
}

/**
+ * Add the person identified by the Org Identity to the identified CO.
+ * - precondition: org_identity_id and co_id set in $this->request->params
+ *
+ * @since COmanage Registry v0.4
+ * @return void
+ */
+
+ function add() {
+ // The parent add() method is overridden here so that for non REST calls
+ // the validation can be relaxed to allow the normal saveAll() call
+ // in the parent add() method to complete without a validation error.
+ // If the validation is not relaxed so that co_person_id and
org_identity_id
+ // are not required then the validation of all the tables before any
updates
+ // will cause a validation error for the model CoOrgIdentityLink.
+
+ if(!$this->restful) {
+ $this->loadModel('CoOrgIdentityLink');
+
+ // dynamically relax the validation for the CoOrgIdentityLink model
+ $this->CoOrgIdentityLink->validate = array(
+ 'co_person_id' => array(
+ 'rule' => 'numeric',
+ 'required' => false // default for model is true
+ ),
+ 'org_identity_id' => array(
+ 'rule' => 'numeric',
+ 'required' => false // default for model is true
+ )
+ );
+ }
+
+ // call the add() method for the parent StandardController class
+ parent::add();
+
+ }
+
+ /**
* Authorization for this Controller, called by Auth component
* - precondition: Session.Auth holds data used for authz decisions
* - postcondition: $permissions set with calculated permissions



Archive powered by MHonArc 2.6.16.

Top of Page