Search code examples
appceleratorappcelerator-mobileappcelerator-titanium

Updating a User (not the logged in User) in Appcelerator


I want to enable an admin. user to update User info (e.g. First Name, Last Name, etc.) I have a List View of Users...when admin User selects one of the Users to update, details are shown, but actual update is applied to Admin User. Not the User I'm trying to Update.

function updateUser() {
   Cloud.Users.update({
       // Id of User to Update
       id : userId,
       first_name : firstNameValue.value,
       last_name : lastNameValue.value,
   }, function(e) {
       if (e.success) {
           var user = e.users[0];
           //alert('Success:\n' + 'id: ' + user.id + '\n' + 'first name: ' + user.first_name + '\n' + 'last name: ' + user.last_name);
       } else {
           alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
       }
   });
};

Solution

  • As stated in the docs, Cloud.User.update

    Update the current user.

    This should explain why your code is updating the admin user.

    But I also found in the documentation for Users: Update Current User the following parameter

    su_id : String [ADMIN-ONLY]

    User ID to update this user on behalf of. The current login user must be an application admin to update a user on behalf of another user.

    I would try with it. (BTW I never used it, but still I hope it could help you)