Not able to save permission - rally

I am attempting to create new project permissions for a user/project but the save is failing because "No valid Project provided". Looking at the network logs the RequestPayload in the server call is empty ({"ProjectPermission":{}}). Any ideas?
_addViewPermission: function() {
this.getModel().then({
success: this.createPP,
scope: this
}).then({
success: this.readPP,
scope: this
}).then({
success: function(result) {
console.log('success', result);
},
failure: function(error) {
console.log('oh noes!', error);
}
});
},
getModel: function() {
return Rally.data.ModelFactory.getModel({
type: 'ProjectPermission'
});
},
createPP: function(model) {
var permission = Ext.create(model, {
Project: "/project/51063976712",
Role: 'Viewer',
User: "/user/43049588391"
});
return permission.save();
},
readPP: function(permission){
console.log(permisson);
return permission.self.load(permission.getId(), {
fetch: ['Project', 'User', 'Role']
});
}

This is a longstanding strange defect in the AppSDK- sorry it tripped you up! I tried to find another stackoverflow post on it, but maybe it hasn't been asked here yet.
Anyway, the reason it is failing for you is that the Project field is marked as readonly even though it is required on create. So the proxy never sends along the project field even though you clearly specified it.
The workaround is to simply mark the project field as persistable before creating and saving a new record.
model.getField('Project').persist = true;

Related

Updating release field with Rally API fails, what's wrong and how to fix it?

I'm trying to update some release fields with the Rally API, but the requests fails when trying to save, I've tried with normal and custom fields. I can't figure out why this is happening.
Here's my portion of the code that attempts to do this:
launch: function() {
this._getReleaseModel().then({
success: function(model) {
console.log('release model: ', model)
return this._getReleaseRecord(model, 72984315568);
},
scope: this
}).then({
success: function(releaseRecord) {
console.log('release record:', releaseRecord);
this._updateReleaseRecord(releaseRecord, 'Name', 'Test Release Modified by API');
},
scope: this
});
}
_getReleaseModel: function() { // returns model promise
return Rally.data.ModelFactory.getModel({
type: 'Release'
});
},
_getReleaseRecord: function(model, objectID) { // returns record promise
return model.load(objectID);
},
_updateReleaseRecord: function(record, fieldToChange, newField) {
console.log('gonna update this record:', record);
record.set(fieldToChange, newField);
record.save({
callback: function(result, operation) {
if(operation.wasSuccessful()) {
console.log('record saved successfully');
}
else {
console.log('failed to save record');
}
}
})
}
Note I'm not pasting the whole app code for simplicity. Thank you.
So, the problem was that I was testing the rally code from a cloud9 server through app-debug.html. Apparently the save method can't access the Rally CA central from outside rally. I tested the code inside an actual rally custom html app and it worked fine. Thanks to Kyle for answering promptly either way.

Blueimp fileupload() callbacks not called

I am using Blueimp fileupload() to post image files to a django-tastypie API.
The code below works correctly as far as the file is being uploaded:
$("#image").fileupload({
dataType: 'json',
start: function() {
console.log("start fileupload");
},
progress: function(e, data) {
console.log(data.loaded + " " + data.total);
},
beforeSend: function(xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken'));
},
done: function(e, data) {
console.log("done uploading file.");
}
});
$("#image").bind('fileuploadfinished', function (e, data) {
console.log("fileuploadfinished");
});
However, the done callback is never called. I tried binding the fileuploadfinished and that is also never called.
start and progress are both called as expected.
beforeSend is undocumented, but is needed by django-tastypie for SessionAuthentication - removing it doesn't change that done and fileuploadfinished is never called.
As it turns out, django-tastypie correctly returns a 201 status code. However, this status code is not considered a success by fileupload.
This code handles the status code manually:
$("#image").fileupload({
dataType: 'json',
beforeSend: function(xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken'));
},
complete: function(xhr) {
if (xhr.readyState == 4) {
if (xhr.status == 201) {
console.log("Created");
}
} else {
console.log("NoGood");
}
},
});
That means, the complete callback is called whether success or failure, and checking the readyState and status together can tell whether it succeeded.
There are some other ways to get this to work, however I think this is the best. More details here:
Data inserted successful but jquery still returning error
I was having the same problem. it is because you set your datatype 'json'.
Just leave this out or put it to plain and it will work.
Your server , or uploadhandler isn't return a json answer.

Sencha Touch:How to capture Status code Returned by Server

I am developing a Sencha touch application using SAP 'Odata' proxy.
In my store I am calling the URL for READ operation
http:///sap/opu/odata/sap/TECHHELP/Tickets
I am loading the store manually in the controller using the following code
var ticketStore = Ext.getStore("Tickets");
var proxy=ticketStore.getProxy();
ticketStore.load(function(records, operation, success) {
if(success){
console.log('loaded records');
}
else{
console.log('loading failed');
}
}, this);
When the application is executed in browser, in network tab I can see the format
Status Code:401 Unauthorized
Now when the URL is executed, I want to capture the exact status Code and the Message in the application.
I want to capture the possible error conditions by checking the status codes returned from server for Eg: 500,401,200,204
How Can I do this?
Regards,
P
this was helpful for me.
new Ext.data.Store({
model: "Your Model",
proxy:{
type: 'ajax',
url: "SomeURL",
reader: new Ext.data.JsonReader({
type: 'json',
root: 'SOME ROOT'
}),
listeners: {
exception:function (proxy, response,operation) {
console.log(response.status);
console.log(response.responseText);
}
}
}
})
May be this will helpful for you.

Worklight 5.0.6 JSONStore with Sync error

I try to init JSONStore Sync with Adapter in Worklight 5.0.6 like below:
var usersSearchFields = {"age":"integer","name.demo":"string"},
usersAdapterOptions = {
name: 'user',
replace: 'updateUser',
remove: 'deleteUser',
add: 'addUser',
load: {
procedure: 'getUsers',
params: [],
key: 'users'
},
accept: function (data) {
return (data.status === 200);
}
};
var collections = {
users : {
searchFields : usersSearchFields,
adapter : usersAdapterOptions
}
};
var options = {
username: 'carlos',
password: '123'
};
var usersCollection=WL.JSONStore.init(collections, options)
.then(function (res) {
logMessage('Collection has been initialized');
})
.fail(function (errobject) {
WL.Logger.debug(errobject.toString());
});
It runs successfully in the first time but after i exit app then return, it gets error:
*"PROVISION_TABLE_SEARCH_FIELDS_MISMATCH"*
Anyone can help me please? Thank you very much.
It looks like the following known issue:
PM85364: JSONSTORE ERROR AFTER FIRST LAUNCH ON ANDROID WITH '.' IN SEARCH FIELDS.. To fix it upgrade to the 5.0.6.1 Fix Pack (Source).
Typically:
-2 PROVISION_TABLE_SEARCH_FIELDS_MISMATCH
You cannot change search fields without calling destroy or removeCollection and init or initCollection with the new search fields. This error can happen if you change the name or type of the search field. For example: {key: 'string'} to {key: 'number'} or {myKey: 'string'} to {theKey: 'string'}.
The documentation is here. I also recommend this StackOverflow answer on JSONStore debugging.
This fixes issues like the one you're facing:
Reset the Simulator or Emulator and/or call WL.JSONStore.destroy().

Read ExtJS message from ajax store

I have an ExtJS store with an ajax proxy and json reader:
Ext.create('Ext.data.Store', {
proxy: {
type: 'ajax',
url: '...',
reader: {
type: 'json',
root: 'data',
totalProperty: 'totalCount',
messageProperty: 'message',
successProperty: 'success'
},
...
This is what I get from the server:
data: [...]
message: "I want to read this string after the store is loaded"
success: true
totalCount: x
Now I want to access the 'message' when the store is loaded - where do I get it? I looked a lot but I can't find a place to hook in? The only listener in the proxy is exception, that doesn't really help me.
use store load event:
Ext.create('Ext.data.Store', {
listeners: {
'load': function(store, records, successful, operation) {
alert(operation.resultSet.message);
}
},
proxy: {
// ...
UPDATE
It appears that documentation for load event is wrong. The correct list of arguments is (store, records, successful) (no operation argument). Therefore the solution above wouldn't work.
However there is reader's rawData property which can help:
Ext.create('Ext.data.Store', {
listeners: {
'load': function(store, records, successful) {
alert(store.getProxy().getReader().rawData.message);
}
},
proxy: {
// ...
My answer applies to ExtJs 4.1.x. I spent some time reading the code and it seems that one way to do this is to provide a callback in the store beforeload event instead of handling the load event. The callback is passed the operation object which will contain the original request parameters and in case of success it will contain the response object and the data (parsed) under the resultSet property.
In other case:
myStore.load({
callback : function(object, response, success) {
// on error response: success = false
if(!success) {
// i don't remember de correct path to get "message" or "responseText"
console.log(response.response.responseText);
} else {
...
}
});
Cya!
I get the message in the following way although I load manually and do not use events here:
var initData = Ext.create('My.data.SomeAjaxStore');
initData.load(function(records, operation, success) {
if (!success || operation.hasException()) {
// Here is your message from server
// In case of HTTP error you get:
// {
// status: 404,
// statusText: "Not Found"
// }
var error = operation.getError();
Ext.log({msg:[Ext.getClassName(me), ": Command failure: ", error].join(""), level:"error"});
}