Symfony form get user id - forms

In order to filter the available options on one section of my web application, I would like to get the user object at the form object. I found some information about possible ways to do that (using sfContext, for instance) but some users discouraged this approach.
What is a possible manner to achieve my purpose?

The best way is to add some logic to BaseForm so you can use self::getValidUser(); without ever using sfContext, which is indeed generally not recommended.
Check this awesome blog post for more infos : http://prendreuncafe.com/blog/post/2010/02/17/User-Dependant-Forms-with-Symfony

Related

Adaptive User Interface based on user experience

I need to modify a web application's interface based on user behavior. For example, new users will see the interface in a simplified way and expert users will see all the features of the application. How can I distinguish between the two types of users? The web application is built on Flask. How should I approach and is there any constructive tutorial that I can follow?
You could use Cookies/Local Storage to count and save how many times they have visited, or if they have visited before. This can be done through Flask, see here for how it's done: link.
Alternatively, give the user the option to toggle between the views, and use a cookie to save their option.

How to limit results by user globally in Eloquent?

I am using eloquent as part of a slim 3 project with slim-jwt-auth (https://github.com/tuupola/slim-jwt-auth), outside of Laravel. There are many situations where I want to control the items returned based on the user who is making the request.
From what I understand though, there is no way to add extra parameters such as user_id for use in eloquent global scope.
I found one blog post that initially looked helpful,
as it does exactly what I am trying to achieve (http://www.sdavara.com/Eloquent-Global-Scopes-A-cool-and-easy-way-to-fetch-loggedin-user-data/), but it relies on Laravel Auth.
The fact that my solution needs to work globally is important, as I have many nested relationships that should also be filtered by user id when queried.
Could anyone suggest what might be the best approach for achieving this?

Method to allow email recipients to change their account information

I'm using SugarCRM Community Edition. I have a bunch of contact information. There are fields I have empty that would like filled. I want each user to be able to fill out a form and fill in those fields.
I'm not sure how to hook each contact into the database. I imagine creating a generic form that somehow hooks into the database using a key. The form/php is not the issue. What is the 'key' and where is the 'door'? I think the door is the SOAP API but I'm not sure. The key, maybe the tracker id?
The only thing I am familiar with as far as interaction between an email campaign and the contact is the campaign 'Tracker'. I know the tracker url with removeme is used for allowing the user to opt out of emails. Is there a way to use this tracker to allow the person to edit their information? I think the answer to this is easy but I need some guidance.
One way of doing this is using the built-in REST api. There are a couple of helpful tutorials out there, here is a link to the one I used for guidance in a similar situation.
You can have a form post the data to your sugar crm's REST gateway, accessible via the url http://localhost/sugar/v2/rest.php.
Although it is quite straightforward to implement, you may want to look at this wrapper class that can be used to maybe keep things cleaner than the hacked up script churned out on the spur of the moment I used in my project.
Last but not least, be sure to glance over the documentation, in the Web Services section you will find more information.
Good-luck

Symfony design question - how can I share forms between apps?

I'm developing a site in Symfony, and I'm not sure what the best way is to handle this scenario.
I'm creating a party bookings system. Anyone can go to my frontend app and submit a new booking. Once they're finished, they'll just get a confirmation screen, they can't edit it. Easy.
Only certain users will be able to get to the admin app (it might be secured simply by being on an intranet, but that's not important, just assume it will be only accessible by admin users). They'll be able to view the list of submitted bookings. Easy.
My problem is around code re-use when allowing admin users to edit existing bookings. When you do generate-module in Symfony, the generated module (which as a newbie I'm assuming is a good example of structuring things) creates the form as a partial. I've had to customize this form a lot for my usage (lots of Javascript, etc), so of course I want to re-use this code, to be able to load an existing booking into this form. But there doesn't seem to be a way to share this partial between the apps (I've seen people mention making a plugin...but this seems complicated for this use).
I considered using an IFrame to load the form from the frontend and just passing an "id" parameter to load it in edit mode, but this would mean that the edit mode is not secure - anyone could go to the form on the frontend and pass this parameter to edit a booking.
I also considered putting all of the form display code (HTML, Javascript, etc) in a method on the form object, but this doesn't seem very MVC - all of the display code is then in the form. But this is only because I'm thinking of the form in the same way as a model - is that right?
I feel like this should be a common situation. You can share models and forms between apps, why can't you share this common form display code too?
Thanks!
You should reconsider having 2 applications in the first place. Not only you run into the code reuse problem, but also i18n, testings and other issues. I find it much easier to have 1 application with different bunch of modules for frontend and backend users. You can configure security per module. You can have one sign in form for all users and redirect them to appropriate module based on their credentials.
You can reuse partials between modules inside the same application, but you seem to be talking about two different applications (frontend and backend) so as far as i know the only way is to copy & paste the partial from one application to the other...

Jira RPC/SOAP GetCustomFields() can only be used by an administrator?

I'm currently using the Jira SOAP interface within a C# (I suppose the language used here isn't terribly important).
Basically, I'm creating an API and a Winform that wraps some of the functionality of the soap service so that our Devs can programmaticly add bugs when something goes wrong in our application.
As part of this, I need to know the custom field IDs that are in use in Jira, rather than hardcoding them (as they are still prone to the occasional change) I used the GetCustomFields() method in the jira-rpc api then filtered it, so that all the developer needs to know is the name of the field, then the ID is filled in for them automagically.
This all works fine, but with one quite important proviso: that you login to the SOAP/RPC service as a user with administrative privaliges.
The Jira documentation indicates that the soap/rpc service follows the usual workflows and security schemes, however I can't find anything anywhere that would appear to remove this restriction on enumerating custom fields (and quite why in any instance you would want someone to HAVE to be an administrator to gain this access, especially as the custom field id's tend to be in Jira's HTML source is beyond me)
Does anyone know if I've missed a setting somewhere? Or if there is some sort of work-around for this, short of hardcoding the custom field id's?
Or is this a case of having to delve in to Jira's RPC plugin and modifying the source for it in order to give me the functionality I require?
Cheers
Edit for the sake of google/posterity
Wow, all this time on, and it looks like Atlassian still haven't changed this behavior.
Worked around this by creating a custom dictionary that logs in as an administrative user, grabs the custom fields and then logs out. Not ideal, but it should work 'til atlassian change things
You're not missing anything - there's no way to get custom fields via standard SOAP API.
In JIRA Client, we learn about custom fields in two ways:
We download issues via RSS view of the issue navigator, or via XML representation of a specific issue. If a custom field is set for an issue, the XML will have its id, class and value (values).
From time to time we inspect the content of IssueNavigator search page - looking for searchers for the custom fields. Screen-scraping the HTML gives us not only ids of the custom fields but also possible values for enum fields.
This is hackery, of course, and it may go wrong, so a good API would have been a lot better.
In your case, I can suggest two solutions:
Create your own SOAP (or REST) remote API plugin that will give you just that info that you miss from the standard API. Since you're seemingly in control of your JIRA, you can install anything there.
Screen-scrape the "New Bug" page for the project and type of issue you need to submit. You'll get all the info - fields, options, default values, which field is required.