1

Re: User access via webservice

Hello,

we are having the following problem: our userdatabase is in an ldap directory and we want to use the information there in the created_by and changed_by fields. We want to perform these steps:
* our website is autheniticating the user agains ldap - works
* our website checks if there is an associated person entry in indicia, if not it creates one via the data service - works
* our website checks if there is an user associated to the person, and if not it creates one - does not work
* our website uses the user_id when submitting data - works partially

check and create user entry

The users webservice does not filter on person_id. As a workaround I've added person_id to the view list_users.
Saving users using the submission service seems not possible. If I want to create a user for an exsinsting person I get the following answer:

{"error":"Unknown Exception: Validation error","errors":{"user:general":"Undefined index:  id"}}

And the log says:

2011-10-17 13:27:45 +02:00 --- error: #8: Exception during validation. Undefined index:  id at line 52 in file /var/www-test/htdocs/indicia/application/models/user.php
2011-10-17 13:27:45 +02:00 --- debug: Stack trace:
        /var/www-test/htdocs/indicia/application/models/user.php - line 52 - indicia_error_handler
        /var/www-test/htdocs/indicia/application/libraries/MY_ORM.php - line 493 - validate
        /var/www-test/htdocs/indicia/application/libraries/MY_ORM.php - line 431 - validateAndSubmit
        /var/www-test/htdocs/indicia/application/libraries/MY_ORM.php - line 395 - inner_submit
        /var/www-test/htdocs/indicia/modules/indicia_svc_data/controllers/services/data.php - line 881 - submit
        /var/www-test/htdocs/indicia/modules/indicia_svc_data/controllers/services/data.php - line 869 - submit_single
        /var/www-test/htdocs/indicia/modules/indicia_svc_data/controllers/services/data.php - line 840 - submit
        Unknown file - line Unknown - save
        /var/www-test/htdocs/indicia/system/core/Kohana.php - line 291 - invokeArgs
        Unknown file - line Unknown - instance
        /var/www-test/htdocs/indicia/system/core/Event.php - line 209 - call_user_func
        /var/www-test/htdocs/indicia/system/core/Bootstrap.php - line 55 - run
        /var/www-test/htdocs/indicia/index.php - line 112 - require

2011-10-17 13:27:45 +02:00 --- debug: Record did not validate
2011-10-17 13:27:45 +02:00 --- debug: Field general: Undefined index:  id
2011-10-17 13:27:45 +02:00 --- debug: Done inner submit of model user with result 
2011-10-17 13:27:45 +02:00 --- debug: <pre>(array) Array
(
    [user:general] =&gt; Undefined index:  id
)
</pre>
2011-10-17 13:27:45 +02:00 --- debug: Rolling back transaction.

Submitted data is:

[submission] => {"id":"user","fields":{"core_role_id":{"value":"1"},"username":{"value":"user.name"},"person_id":{"value":"323"}}}

Setting created_by_id on submitting data
If I set breated_by_id on a submission and read the entety from the warehouse, it says correctly created_by_id=xxx but updated_by_id=1


Regards

Daniel

2

Re: User access via webservice

Hi Daniel
The code which creates users passes id='' in the form array (and submission) which is why our code works but not yours. If you replace line 52 in application/models/user.php with the following does it fix it?

$id = isset($array->id) ? ','.$array->id : '';
$array->add_rules('username', 'required', 'length[5,30]', "unique[users,username$id]");

Also there is a fix for the handling of the updated_by_id in application/libraries/MY_Orm.php (revision 3219).

Cheers

John van Breda
Biodiverse IT

3

Re: User access via webservice

Hi John,

the fix seems to not fix it all ;-) The result for the above request is now:

{"error":"Unknown Exception: Validation error","errors":{"user:general":"Undefined offset: 2"}}

Regards

Daniel

4

Re: User access via webservice

The fix for the updated_by / created_by works

5

Re: User access via webservice

I've added a "," between "username" and "$id". No I get:

{"error":"Unknown Exception: Validation error","errors":{"user:general":"<strong>An error occurred<\/strong><br\/>Undefined index: auth_user"}}

The log says:

011-10-21 13:02:37 +02:00 --- error: #8: Exception during postSubmit in user model.. Undefined index: auth_user at line 88 in file /var/www-test/htdocs/indicia/application/models/website.php
2011-10-21 13:02:37 +02:00 --- debug: Stack trace:
        /var/www-test/htdocs/indicia/application/models/website.php - line 88 - indicia_error_handler
        /var/www-test/htdocs/indicia/application/models/user.php - line 109 - in_allowed_websites
        /var/www-test/htdocs/indicia/application/libraries/MY_ORM.php - line 447 - postSubmit
        /var/www-test/htdocs/indicia/application/libraries/MY_ORM.php - line 401 - inner_submit
        /var/www-test/htdocs/indicia/modules/indicia_svc_data/controllers/services/data.php - line 881 - submit
        /var/www-test/htdocs/indicia/modules/indicia_svc_data/controllers/services/data.php - line 869 - submit_single
        /var/www-test/htdocs/indicia/modules/indicia_svc_data/controllers/services/data.php - line 840 - submit
        Unknown file - line Unknown - save
        /var/www-test/htdocs/indicia/system/core/Kohana.php - line 291 - invokeArgs
        Unknown file - line Unknown - instance
        /var/www-test/htdocs/indicia/system/core/Event.php - line 209 - call_user_func
        /var/www-test/htdocs/indicia/system/core/Bootstrap.php - line 55 - run
        /var/www-test/htdocs/indicia/index.php - line 112 - require

2011-10-21 13:02:37 +02:00 --- debug: Done inner submit of model user with result 
2011-10-21 13:02:37 +02:00 --- debug: <pre>(array) Array
(
    [user:general] =&gt; &lt;strong&gt;An error occurred&lt;/strong&gt;&lt;br/&gt;Undefined index: auth_user
)
</pre>
2011-10-21 13:02:37 +02:00 --- debug: Rolling back transaction.

6

Re: User access via webservice

Hi Daniel
There were some assumptions in the code that user submissions came from the warehouse user edit form. I've fixed these problems in revision 3256 in SVN.
Best wishes

John van Breda
Biodiverse IT

7

Re: User access via webservice

Hi John,

it works. But I have a little thing: I must explecit say "core_role_id=null" should it not be allowed to just not set the "core_role_id" parameter a all?

Best wishes

Daniel