Re: [rt-users] Using Ajax with Mason in RT
On 16.8.2012 18:48, Thomas Sibley wrote: 403 is Forbidden. RT denies direct requests to /Elements/ directories (among other internal components). This denial happens in RT's normal request handling phase, which doesn't get called when you set inherit = undef. Hi Thomas, thank you, moving it outside of elements to custom directory did the trick. It finally works! Please just remove the %flags section all together. You also lose things like encoding handling, not to mention authentication, when you disable RT's request handling. I have gladly thrown it away... If I keep it, I get back following error: syntax error at /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent line 15, at EOF I'm betting it's the semicolon in the %flags section. Remove it. The line number being off is Mason getting it wrong (I'll bet it's the line # of the Mason object file). Heh, I am used to missing semicolon, not the other way round. Anyway this was really the cause. Removing it made it worked, although it is no longer necessary because of what was written before. Still, I wonder how come that Paul could successfully run my scripts... Anyway, big thanks to you. Martin
Re: [rt-users] Using Ajax with Mason in RT
On Fri, Aug 17, 2012 at 3:26 AM, Martin Drasar dra...@ics.muni.cz wrote: Still, I wonder how come that Paul could successfully run my scripts... Because I didn't put it in Elements, I put it in the directory with the code I was working on, and because I didn't try it with %flags. If there is one thing that's annoyed me about my whole experience with RT it's the way errors either get eaten up or mis-reported. I don't know if that's the fault of Perl, Mason or RT, but I frequently find myself having to put RT::Logger-debug statements every other line just so I can figure out where it's silently failing, and then minutely examining the line to discover that (as happened yesterday) I had an extra $ in front of a variable name. -- http://www.linkedin.com/in/paultomblin http://careers.stackoverflow.com/ptomblin
Re: [rt-users] Using Ajax with Mason in RT
On 08/17/2012 04:30 AM, Paul Tomblin wrote: If there is one thing that's annoyed me about my whole experience with RT it's the way errors either get eaten up or mis-reported. I don't know if that's the fault of Perl, Mason or RT, but I frequently find myself having to put RT::Logger-debug statements every other line just so I can figure out where it's silently failing, and then minutely examining the line to discover that (as happened yesterday) I had an extra $ in front of a variable name. Rarely in my experience do things completely silently fail. If you run across such reproducible cases where an error completely disappears, file a bug report. Mason often gets line numbers right, but sometimes doesn't because of the way it's implemented. If you're not in a Mason special block (%args, %flags), most pure Perl errors (from % lines or %perl or %init) are fairly explanatory. The special blocks are, well, special and Not Quite Perl.
Re: [rt-users] Using Ajax with Mason in RT
Hi, it appears I've reached a dead end... This is my javascript ajax call (practically identical to the one Paul posted): jQuery.ajax ( { type: 'POST', url: 'Elements/TestComponent', data: { 'ip': ip }, dataType: 'json', traditional: true, success: successCallback, error: errorCallback } ); According to Tamper Data, it gets sent and it looks like it contains the right data. This is my component: % $r-content_type('application/json'); % JSON( \@something ) |n % % $m-abort(); %init my @something; push (@something, 'something'); /%init %flags inherit = undef; /%flags The problem is, when I remove the flags section, the ajax call fails with 403. If I keep it, I get back following error: syntax error at /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent line 15, at EOF Anyone got any idea? Thanks, Martin
Re: [rt-users] Using Ajax with Mason in RT
On Thu, Aug 16, 2012 at 5:22 AM, Martin Drasar dra...@ics.muni.cz wrote: The problem is, when I remove the flags section, the ajax call fails with 403. If I keep it, I get back following error: syntax error at /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent line 15, at EOF Do you see anything in the logs? -- http://www.linkedin.com/in/paultomblin http://careers.stackoverflow.com/ptomblin
Re: [rt-users] Using Ajax with Mason in RT
On 16.8.2012 13:15, Paul Tomblin wrote: On Thu, Aug 16, 2012 at 5:22 AM, Martin Drasar dra...@ics.muni.cz mailto:dra...@ics.muni.cz wrote: The problem is, when I remove the flags section, the ajax call fails with 403. If I keep it, I get back following error: syntax error at /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent line 15, at EOF Do you see anything in the logs? Nope... rt.log is empty, apache error log as well and the only thing I see in access log is 'POST /Ticket/Elements/TestComponent HTTP/1.1 200 1322' I can post the code stack, but I am afraid that there is not much that can help... Martin
Re: [rt-users] Using Ajax with Mason in RT
On Thu, Aug 16, 2012 at 7:24 AM, Martin Drasar dra...@ics.muni.cz wrote: On 16.8.2012 13:15, Paul Tomblin wrote: On Thu, Aug 16, 2012 at 5:22 AM, Martin Drasar dra...@ics.muni.cz mailto:dra...@ics.muni.cz wrote: The problem is, when I remove the flags section, the ajax call fails with 403. If I keep it, I get back following error: syntax error at /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent line 15, at EOF Do you see anything in the logs? Nope... rt.log is empty, apache error log as well and the only thing I see in access log is 'POST /Ticket/Elements/TestComponent HTTP/1.1 200 1322' I can post the code stack, but I am afraid that there is not much that can help... Martin Unfortunately somewhere between RT and Mason and perl a lot of the errors go unreported - you just have to narrow down where the problem is with a lot of calls to $RT::Logger-debug. But first things first, you need to turn up the logging in /opt/rt4/etc/RT_SiteConfig.pm Set( $LogToScreen, debug); Set( $LogToSyslog, debug); You also need to have a look at line 15 and before in your component. -- http://www.linkedin.com/in/paultomblin http://careers.stackoverflow.com/ptomblin
Re: [rt-users] Using Ajax with Mason in RT
On 16.8.2012 13:37, Paul Tomblin wrote: Unfortunately somewhere between RT and Mason and perl a lot of the errors go unreported - you just have to narrow down where the problem is with a lot of calls to $RT::Logger-debug. But first things first, you need to turn up the logging in /opt/rt4/etc/RT_SiteConfig.pm Set( $LogToScreen, debug); Set( $LogToSyslog, debug); You also need to have a look at line 15 and before in your component. When I said that I saw nothing in rt.log I meant nothing of importance. I have the debug logging turned on. As for the line 15 - I have posted the entire component two mails before. It only has 12! lines and the reported error is at EOF. That would indicate that there might be something unfinished like missing bracket or such. However, by looking at the code, I can't see anything wrong. First it was almost direct copy of the code you sent at first and then when it did not work I used component from share/html/Helpers/Autocomplete/ by Thomas advice as a template. But nothing seems to work. I have made even smaller component, in fact smallest that does not 403 on me: %flags inherit = undef; /%flags Ajax request on this component fails with this error: Error during compilation of /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent:brsyntax error at (eval 1164) line 12, at EOF It is as before, the error should be at line 12, but the component itself has only 3 lines. There is something fishy going on... Martin
Re: [rt-users] Using Ajax with Mason in RT
It may be a shot in the dark. But are you by chance editing the files in a windows text editor and copying them over? Or more specifically was it originally created on a windows box? There may be carriage returns in the file that are causing issues. If that is the case you can dos2unix the file and clean it up. I may be way off, but I have run into that in the past quite a bit with other *nix apps when users edit files in winworld. Sent from my mobile device. On Aug 16, 2012, at 8:00 AM, Martin Drasar dra...@ics.muni.cz wrote: On 16.8.2012 13:37, Paul Tomblin wrote: Unfortunately somewhere between RT and Mason and perl a lot of the errors go unreported - you just have to narrow down where the problem is with a lot of calls to $RT::Logger-debug. But first things first, you need to turn up the logging in /opt/rt4/etc/RT_SiteConfig.pm Set( $LogToScreen, debug); Set( $LogToSyslog, debug); You also need to have a look at line 15 and before in your component. When I said that I saw nothing in rt.log I meant nothing of importance. I have the debug logging turned on. As for the line 15 - I have posted the entire component two mails before. It only has 12! lines and the reported error is at EOF. That would indicate that there might be something unfinished like missing bracket or such. However, by looking at the code, I can't see anything wrong. First it was almost direct copy of the code you sent at first and then when it did not work I used component from share/html/Helpers/Autocomplete/ by Thomas advice as a template. But nothing seems to work. I have made even smaller component, in fact smallest that does not 403 on me: %flags inherit = undef; /%flags Ajax request on this component fails with this error: Error during compilation of /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent:brsyntax error at (eval 1164) line 12, at EOF It is as before, the error should be at line 12, but the component itself has only 3 lines. There is something fishy going on... Martin
Re: [rt-users] Using Ajax with Mason in RT
On Thu, Aug 16, 2012 at 8:00 AM, Martin Drasar dra...@ics.muni.cz wrote: Ajax request on this component fails with this error: Error during compilation of /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent:brsyntax error at (eval 1164) line 12, at EOF I copied your code into my web app, and it worked fine. Firebug shows me that the ajax call returned [something] I'd go with Joe's suggestion, or maybe something in an autohandler or dhandler that is screwing things up. -- http://www.linkedin.com/in/paultomblin http://careers.stackoverflow.com/ptomblin
Re: [rt-users] Using Ajax with Mason in RT
On 16.8.2012 14:27, Paul Tomblin wrote: I copied your code into my web app, and it worked fine. Firebug shows me that the ajax call returned [something] I'd go with Joe's suggestion, or maybe something in an autohandler or dhandler that is screwing things up. Thank you both for suggestions... I am editting the file via putty through ssh. As I don't use any special characters, I don't think this could be the reason. I have tried to move working script ./share/html/Helpers/Autocomplete/Groups to my local directory local/html/Ticket/Elements/ and the symptoms are the same. Not having inherit set to undef cause it to 403. Having it set results in the typical compilation error. I have also tried to move my component from local directory to share/html/Ticket/Elements, but that did not change anything. My question is - how can I diagnose, whether there is a problem with (auto|d)handlers? I haven't touched any of them since the installation. Martin
Re: [rt-users] Using Ajax with Mason in RT
On Thu, Aug 16, 2012 at 9:21 AM, Martin Drasar dra...@ics.muni.cz wrote: My question is - how can I diagnose, whether there is a problem with (auto|d)handlers? I haven't touched any of them since the installation. Ok, this is a real desperation measure, but I modified /opt/rt4/lib/RT.pm and added a call to Carp::cluck in both the $SIG{__WARN__} and $SIG{__DIE__} handlers. It adds a tiny bit more information in a few cases that normally go unremarked by RT. Also, make sure and restart your server after making changes, because the code that is supposed to pick up changes doesn't always do so. -- http://www.linkedin.com/in/paultomblin http://careers.stackoverflow.com/ptomblin
Re: [rt-users] Using Ajax with Mason in RT
On 16.8.2012 16:04, Paul Tomblin wrote: On Thu, Aug 16, 2012 at 9:21 AM, Martin Drasar dra...@ics.muni.cz mailto:dra...@ics.muni.cz wrote: My question is - how can I diagnose, whether there is a problem with (auto|d)handlers? I haven't touched any of them since the installation. Ok, this is a real desperation measure, but I modified /opt/rt4/lib/RT.pm and added a call to Carp::cluck in both the $SIG{__WARN__} and $SIG{__DIE__} handlers. It adds a tiny bit more information in a few cases that normally go unremarked by RT. Also, make sure and restart your server after making changes, because the code that is supposed to pick up changes doesn't always do so. Thank you for not giving up... My first attempt - putting cluck outside the block in handler that checks for being inside eval. Looking inside the log and finding bazillion of stack traces. Thinking about switching careers... My second attempt - putting it in correct place. Looking inside the log and finding nothing. Thinking about switching careers... I always restart the apache server and reload the page before trying something new. Working in debug mode, mason cache is empty. Martin
Re: [rt-users] Using Ajax with Mason in RT
Just a quick update - Paul tried to run files from my machine on his and the result was that everything was working ok. So the situation is as follows: - brand new installation of RT-4.0.6 - database moved from RT-3.8.7, upgrade went well - only local changes are those mentioned in this thread, plus the RT_SiteConfig.pm and an import of one css file via css/base/main.css/End callback - $ uname -a Linux rt-mirror 2.6.32-5-686 #1 SMP Sun May 6 04:01:19 UTC 2012 i686 GNU/Linux Any ideas are welcome Thanks, Martin
Re: [rt-users] Using Ajax with Mason in RT
On 08/16/2012 02:22 AM, Martin Drasar wrote: This is my component: % $r-content_type('application/json'); % JSON( \@something ) |n % % $m-abort(); %init my @something; push (@something, 'something'); /%init %flags inherit = undef; /%flags The problem is, when I remove the flags section, the ajax call fails with 403. 403 is Forbidden. RT denies direct requests to /Elements/ directories (among other internal components). This denial happens in RT's normal request handling phase, which doesn't get called when you set inherit = undef. Please just remove the %flags section all together. You also lose things like encoding handling, not to mention authentication, when you disable RT's request handling. If I keep it, I get back following error: syntax error at /home/RT/RT-4.0.6/local/html/Ticket/Elements/TestComponent line 15, at EOF I'm betting it's the semicolon in the %flags section. Remove it. The line number being off is Mason getting it wrong (I'll bet it's the line # of the Mason object file).
[rt-users] Using Ajax with Mason in RT
Hi, I have used MakeClicky actions to extend the RT UI and now I would like my extensions to do some ajax stuff on click. I would like to know, how I can create new Mason component and set it as a valid target for the ajax request. Any help is really appreciated. Thanks, Martin
Re: [rt-users] Using Ajax with Mason in RT
On Wed, Aug 15, 2012 at 11:37 AM, Martin Drasar dra...@ics.muni.cz wrote: I have used MakeClicky actions to extend the RT UI and now I would like my extensions to do some ajax stuff on click. I would like to know, how I can create new Mason component and set it as a valid target for the ajax request. Any help is really appreciated. If you want your AJAX to return JSON, you need to do the following: 1. Do all the work of building the return component in the %init. I make it a hashref called $ret. 2. In the web section of the file (the part that isn't enclosed in %init or other Mason tags: % $r-content_type('application/json'); % $m-clear_buffer; % JSON::to_json( $ret, { utf8 = 1, allow_blessed = 1, convert_blessed = 1, } ) |n % % $m-abort; 3. Declare as %args all the parameters you pass it 4. Turn off any inheritance with %flags inherit = undef /%flags 5. Call it in your Javascript like so: jQuery.ajax({ type: 'POST', url:'assign_ticket.mas', data: { 'ticketid': ticketId, 'assignTo': rt_user_id, 'reason': reason, 'currentUserId':% $session{'CurrentUser'}-id % }, dataType: 'json', traditional:true, success:changeStatusSuccessCallback, error: changeStatusErrorCallback }); function changeStatusSuccessCallback(json) { if (json.status == 'error') { alert('Error: ' + json.error_msg); } else { document.location.reload(true); } } function changeStatusErrorCallback(jqXHR, textStatus, errorThrown) { alert(textStatus + : + errorThrown); } I'll leave it to you to figure out something better to do with the return callbacks. -- http://www.linkedin.com/in/paultomblin http://careers.stackoverflow.com/ptomblin
Re: [rt-users] Using Ajax with Mason in RT
On 15.8.2012 17:44, Paul Tomblin wrote: If you want your AJAX to return JSON, you need to do the following: ... Wow, thanks a lot for your superquick reply! Martin
Re: [rt-users] Using Ajax with Mason in RT
On 08/15/2012 08:44 AM, Paul Tomblin wrote: 4. Turn off any inheritance with %flags inherit = undef /%flags Please note that this step completely bypasses any authentication and request setup that RT normally does. Users who are *not logged in* will be able to request your ajax endpoint, regardless of where it is in the directory tree (i.e. it doesn't have to be under /NoAuth/). It it not necessary to simply return JSON (see the autocomplete endpoints under share/html/Helpers/Autocomplete/).
Re: [rt-users] Using Ajax with Mason in RT
I don't know why I had the problem before with my ajax files when I didn't have the inherit = undef before, but I took them all out and all my ajax calls appear to still be working. So I guess you don't need that %flags section. -- http://www.linkedin.com/in/paultomblin http://careers.stackoverflow.com/ptomblin
Re: [rt-users] Using Ajax with Mason in RT
On Wed, Aug 15, 2012 at 9:59 PM, Paul Tomblin ptomb...@xcski.com wrote: I don't know why I had the problem before with my ajax files when I didn't have the inherit = undef before, but I took them all out and all my ajax calls appear to still be working. So I guess you don't need that %flags section. May be you didn't have -abort calls and RT was adding footer. -- Best regards, Ruslan.