[AC-173] Creating Custom Object for another user does not work
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Invalid |
Resolution Date | 2015-11-13T19:25:21.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | ArrowDB |
Labels | n/a |
Reporter | Alexander Rieger |
Assignee | Shak Hossain |
Created | 2015-06-22T14:07:31.000+0000 |
Updated | 2015-11-13T19:25:21.000+0000 |
Description
there seems to be a bug in Cloud.Objects.create when using arrowdb on appcelerator cluster. In the code below I login as an admin and create data for another user but the data is created for the admin which is wrong. Look at the log output and the resulting user id. Seems like the user_id field of Cloud.Objects.create is not read correctly.
With my old project where data is still hosted on titanium cluster this bug does not appear!
test code:
var Cloud = require('ti.cloud');
var userData = {
login: 'server',
password: 'password',
};
Cloud.Users.login(userData, function (e) {
if (e.success) {
console.log("login successful");
var adminUser = e.users[0];
console.log('admin: '+adminUser.admin + ' id:'+adminUser.id);
Cloud.Users.create({
username: 'test',
password: 'test',
password_confirmation: 'test'
}, function (e) {
if (e.success) {
var user = e.users[0];
console.log('Success:\n' +
'id of other user test: ' + user.id + '\n');
Cloud.Objects.create({classname: 'testData', user_id:user.id, fields:{data1:0,data2:1}},function (e) {
if (e.success) {
console.log('Create Success:\n' +e.testData.length);
console.log(JSON.stringify(e.testData));
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
} else {
console.log('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
} else {
console.log("login failed "+JSON.stringify(e));
}
});
Bug on appcelerator cluster: user id of cloud data is not equal to id of created user:
login successful
[INFO] : admin: true id:557212af730b8233ab009a7f
[INFO] : Success:
[INFO] : id of other user test: 55851f1e7ed7bb0b591490bd
[INFO] :
[INFO] : Create Success:
[INFO] : 1
[INFO] : [{"user_id":"557212af730b8233ab009a7f","created_at":"2015-06-20T08:06:55+0000","updated_at":"2015-06-20T08:06:55+0000","data1":0,"data2":1,"id":"55851f1f1b40070b91146ad7"}]
No bug on titanium cluster: user id of cloud data is equal to id of created user
[INFO] : admin: true id:543b75f3c7b8a7398c01abe3
[INFO] : Success:
[INFO] : id of other user test: 55851d58da3c52099007589a
[INFO] :
[INFO] : Create Success:
[INFO] : 1
[INFO] : [{"created_at":"2015-06-20T07:59:20+0000","updated_at":"2015-06-20T07:59:20+0000","data1":0,"data2":1,"id":"55851d58591153097528fd76","user":{"id":"55851d58da3c52099007589a","created_at":"2015-06-20T07:59:20+0000","updated_at":"2015-06-20T07:59:20+0000","external_accounts":[],"confirmed_at":"2015-06-20T07:59:20+0000","username":"test678","admin":"false","stats":{"photos":{"total_count":0},"storage":{"used":0}},"friend_counts":{"requests":0,"following":0,"friends":0,"followers":0}}}]
I saw now on docs that parameter name has changed: su_id : String ADMIN-ONLY User ID to create the object on behalf of. The current login user must be an application admin to create an object on behalf of another user. I tested this successfully. Therefore the issue can be marked as resolved.