How can I post the custom field to Workfront through workfront REST API - rest

In workfront, we want to create a custom form(custom fields) for an Issue. How can I use Workfront REST API to do a POST request and create the custom fields in a custom form for that issue in workfront?
https://developers.workfront.com/api-docs/api-explorer/

You POST the same as you would to a system field. Simply prefix the field name with DE:.
attask/api-internal//user/xxxxxxxxx?DE:foo=bar
The above sets the field 'foo' to the string 'bar'.
If the custom field is not present on the object (not on a custom form already attached) then you will first need to attach one.
attask/api-internal/user/xxxxxxxxxx?updates={objectCategories:[{categoryID:`"customformUUID`",categoryOrder:0,objCode:`"CTGY`"}]}

Related

Custom Model Binding - Changing Property type in Post

I am working on a project where i receive objects from a client in a Post body and i map them to a model i created so i can store them in a db. One of the child classes in the body is an attributes class shown below attributes
When i use it in a Post, we have been getting the following data and the value field can be any type. In the end i want them all to be converted to strings Post Body
In my HttpPost in the controller, it fails to convert the json to this type because the one record is a bool. How do i allow multiple types?

Generate custom Azure web form

I am working on Azure C# project. There is webrole with web form collecting customer’s information.
Depending on the information, they submit I need to create new custom web form for each one of them.
How can I generate new web form with custom web controls inside same site with code? I would prefer not create different site for each customer.
Any ideas appreciated!
You don't have to create a custom web form for each customer, you can have it all in on dynamic form and draw the input controls according to the customer.
You will have to have a form a form or a database table to configure the input needed for each customer which will be used in drawing the form.
ex:
You can have a table named: CustomerAttibute with the following columns
Customer ID
Attribute Name
Attribute Type (Number, text, boolean, ...)
Is Required
Validation Reg Expression
In the web form, you will read the customer ID and retrieve the attributes related to that customer, and use these attributes to draw the form, ex: an attribute of type text will be rendered as a textbox but an attribute of type boolean will be rendered as a checkbox
Capture the values from the user and insert it into another table, ex: CustomerAttributeValue which will have the attribute ID and attribute value, the value will be string to accommodate for any type

Foreign entity in form into different kind of input

I have two entities: product and category (Symfony 2.3).
I want to create a form in which an user can choose a product by first selecting the category. A user selects the category by clicking on image, then I want to set the image's value into a hidden input, but I don't see how can I change a foreign entity choice list to a hidden input (http://symfony.com/doc/current/reference/forms/types/entity.html).
How can I accomplish this? (how to change form input to hidden)
If I set cascade validation to true, will it for example check if a category really exist. (To prevent putting products with non-existing category from malicious users) ?
Part 1
To do this you need to use a data transformer to do two things:
transform an entity into an identifier that is either a string or integer so a form can render it as a hidden field.
transform the string or integer identifier into the entity when the form is submitted so that the parent entity can be saved with the correct relationship
The symfony docs I linked to above (here too) actually walk though an entire example of using a data transformer with a form.
As a shameless plug (because I believe it is helpful) I have written a little tutorial on using a data transformer for a hidden field with an entity id: http://lrotherfield.com/blog/symfony2-forms-entity-as-hidden-field/
Part 2
If you are using the data transformer then you don't need to worry about malicious users. The data transformer will fail because it will not be able to reverse transform the category from the fake id. In my tutorial the transformer will throw a Symfony\Component\Form\Exception\TransformationFailedException exception.
You can also write a validator (potentially using a call back) if you wanted that checks that the submitted category is real if you want an error to show in the form. Doctrine wont allow you to persist a fake category relationship as the foreign key constraint will fail.

In Tastypie is there a way to change a resources excludes based on the authentication?

Consider the example of a user resource that has profile pic and email fields. Where any user may see any other users profile pic but a user may only see their own email address.
Is it possible to setup tastypie so that the set of excluded fields can be varied based on the authenticated user?
I realize that an alternative approach is to create separate full and restricted user resources. But for the moment I just want to know whether the approach of limiting the fields based on user authentication is even doable in tastypie.
Also it doesn't have to be the excludes, in the same vein is there a way instead to change the fields property based on the requesting user?
I dont think excluded fields can be brought back into the picture in an elegant fashion. You could probably manipulate the object list based on the request using some object manipulation by including the get_object_list in your resource
But it would be much better and more logical for you to use the apply_limits method in your custom authorization class.
Yes there is a way to do it.
If you define email to be a separate field, not the one of the User(might work and with that but never did it).
You can define dehydrate_email where the bundle.request contains the current request and you could get it. It won't be exactly excluded as a field but it will be None for others.
I created a ModelResource subclass that can be multiple inherited into the required ModelResource instances. Like:
class ResourceThatNeedsToExcludeSomeFields(ExcludeResource, ModelResource):
pass
It takes in the fields to be excluded via GET parameters (like "&exclude=username")
class ExcludeResource(ModelResource):
"""
Generic class to implement exclusion of fields in all the ModelResource classes
All ModelResource classes will be muliple inherited by this class, whose dehydrate method has been overriden
"""
# STACK: How to exclude some fields from a resource list created by tastypie?
def dehydrate(self, bundle):
# I was taking the exclude fields from get paramaters as a comma separated value
if bundle.request.GET.get('exclude'):
exclude_fields = bundle.request.GET.get('exclude').split(',')
for field in exclude_fields:
if str(field) in bundle.data.keys():
del bundle.data[str(field)]
return bundle
You can modify this to get the exclude fields based on user group (or whatever criteria you base the fields on) like this:
class ExcludeResource(ModelResource):
"""
Generic class to implement exclusion of fields in all the ModelResource classes
All ModelResource classes will be muliple inherited by this class, whose dehydrate method has been overriden
"""
# STACK: How to exclude some fields from a resource list created by tastypie?
def dehydrate(self, bundle):
exclude_fields = <get a comma separated list of fields to be excluded based in bundle.request.user>
for field in exclude_fields:
if str(field) in bundle.data.keys():
del bundle.data[str(field)]
return bundle
However, this snippet will not work for related resources specified with "full=True"

CakePHP - Automatically populate form fields from model

I thought the form helper did this already, but can the fields in my form automatically be populated with values from the model or do I have to set them all as template variables and set them all as the value of each field manually?
The form is for a user profile, so I just want it to put the user's names, email, etc in the correct form fields automatically.
for example: in controller $this->data = $this->Model->find('first',array(...));
in view:
$this->Form->create('Model');
$this->Form->input('field1');
...
$this->Form->end('Save');