Kademi - allow front end user to delete a file they have uploaded - kademi

I am trying to allow front end user to delete a file they have uploaded.
#docs() tells me that $page.lead.files has a method called .remove() that accepts either an Int or an Object.
I keep getting a response of "false" when using this method. I am trying to pass and ID or Object of a file within $page.lead.files object.
Debugging...
User: https://spinsurance.admin.kademi.com.au/manageUsers/116783806/#summary-tab
Page: https://crm.spinsurance.co.nz/leads/148615383/
Source: https://spinsurance.admin.kademi.com.au/repositories/spcrm/version1/theme/apps/leadman/components/texteditor?fileName=leadDetailTabContentComponent.html
Under section on page called: Uploaded Files.
Click big red Delete button. (I don't mind if this file gets deleted)
Thanks for your help in advance.

The Lead.files property is a persisted list. Its not a good idea to try to modify the database using that approach.
Note that lead files are exposed as http addressable resources, which support the http DELETE method
So the simplest approach is to delete from the browser using ajax
Eg
DELETE /leads/123/myfile.pdf

Related

How to use user data in typo3 flux template without caching it

I try to get user session data in a typo3 flux content element. with {user.first_name} I can access the first name of the user, but this will get cached, meaning alls users will see the name of the first one accessing the page. How can I uncache that or load user session data in this template.
What I already tried:
<f:cache.disable> </f:cache.disable> unfortunately the user variable
are still cached...
<v:render.uncache> To make the user session data
accessible in the partial I need to pass it as a parameter, but the
parameters do get cached :(
<f:security.ifAuthenticated> does only
check for permission, but caches aswell.
Working methods:
adding config.no_cache = 1 or page.config.no_cache = 1 in the typoscript setup works, but I would like to use a solution in flux without typoscript, the USER_INT equival solution should be v:render.uncache, but the argument to be passed is cached as explained above
Thanks for any help
You have to use <v:render.uncache> and fetch the user session data inside the partial.
See https://github.com/FluidTYPO3/vhs/issues/1705

Adding custom data based attributes based on Response object

Halo ! I'm trying to implement dropzonejs in a very specific way. Actually I follow the standard implementation described on the official page. Everything works perfectly.
But I'm willing to attach the server's generated URI for each uploaded file directly when uploaded : when uploading it's creating a database entry with some stuff like a page uri with title etc. This mean that the server would return as a response the id of the database saved file in order to attach the href attribute with its value to the the element in front.
This is quite ok to do this when only one file is uploaded, but it becomes trickier when bulk uploading.
So maybe I didn't understand the documentation well (and I'm quite sure I didn't), but is there any way to add custom data-dz-like attributes based on my server's response ? I'd like something like data-dz-url where the url points to a database entity (not the file itself).
Or if not if there is an "easy way" to handle this.
Thanks a lot
Here is the answer :
myDropzone.on('success', (file, response) => {
file.previewElement.href = "/admin/media/"+response.id+"/show/"
})
file is reference to the current uploaded element. It's possible to extend it's html attributes through previewElement. Setting the data-type attribute in the template before, then assigning it the right value works aswell.
Hope this will help some.

Setting Absolute Uri in MVC 3

Is it possible to set the absoluteURI in the controller after clicking on an action link? So for example:
User clicks on a link called "GoHere". The current URL is domain.com/section/place. When the link hits the method in the controller, it recognizes that the user is currently in a section called "section", even though in the file structure section doesn't exist. The link itself actually points to domain.com/place2. Instead of returning a URL of domain.com/place2, it returns domain.com/section/place2.
The reason I ask is because for what I'm doing, the section is completely arbitrary and doesn't exist. It's just there to give the impression that the user is in another section. I know I could create extra sets of controllers, but I'm trying to get around this since for management purposes it's better if I just have one set of controllers. Is this possible? Thanks.
In your gobal.asax, try setting your route to require section for the control. Maybe "{control}/section/{action}/" and whatever else you need.

Posting a collection to MVC3 from Plupload

I've got a documents upload page in an MVC3 application that lets the user upload documents to be stored in a database and associated with a parent entity in the database. There are also some permissions that the user can customize to stipulate who can access the document.
I've implemented my document upload functionality with Plupload, The behavior that it's working with is that essentially it will take a queue of files, and upload them for me to a specific action dedicated to recieving this information, and when they are posted each file is given a unique name (something like p16kearti61rf31qb61fogjm2127i3.jpg for example.)
Once all of the files have been uploaded in plupload, the parent form is submitted with the information about the files plupload just uploaded as well as some other data for the documents like the Primary Key of the object they are to be associated with, and the groups that have been checked off for it's permissions aspect. Now this works fine except that I can't find a strongly typed object structure that MVC will bind my data to so that I can work with the posted back data. Here's an idea of what is in my Request.Form collection, what I'm looking for is some insight on how to best capture this information in my action. I have complete control over the naming of the controls for the document permissions, but the plupload controls are built in and I'd don't know if I can change them.
__RequestVerificationToken: "...XDsBA5oZA9Ku2oPPdyyi2J+DbvoKRY9HJ2...etc"
ownerId: "CCEE2ADF-633D-4D55-90EE-2829D352BEEB"
uploader_0_tmpname: "p16kearti61rf31qb61fogjm2127i3.jpg"
uploader_0_name: "picture1.jpg"
uploader_0_status: "done"
uploader_1_tmpname: "p16kearti61kqu8tsmja67911v44.jpg"
uploader_1_name: "picture2.jpg"
uploader_1_status: "done"
uploader_2_tmpname: "p16kebp785gci1e291i543cc1c8k4.jpg"
uploader_2_name: "picture3.jpg"
uploader_2_status: "done"
uploader_count: "3"
documentGroups[B8C97C5C-B1B8-43C2-89F1-B1DF353AF677]: "false"
documentGroups[A2C8331C-7068-4611-82BF-6F0C61C8BA7D]: "false"
documentGroups[6DCBF4A8-B863-49E6-AAE9-2A0E372FF622]: "true"
documentGroups[05C04E05-D7A8-45D6-8138-2FA36F0A5922]: "false"
documentGroups[3E2F2B1B-FAAA-420A-B9A1-F223ADF66AF0]: "true"
Any suggestions on how to write my action method? I was hoping for something like this but I can't get it to work.
public ActionResult Upload(Guid ownerId, IList<PluploadFile> uploader, IList<bool> documentGroups)
Just in case someone else was looking for an update on this (and since I got no response to my question what-so-ever), I ended up splitting my post into two; one handled by plUpload which I use to save the file(s) to a temp folder using the unique names pased in to the Action from plUpload (such as p16kearti61rf31qb61fogjm2127i3.jpg), and the other when I post the wrapping form which holds the information I need and the unique names plupload has as well as some fields indicating the status result of the original upload. The problem is that because it's two posts I now have to look at maintaining the contents of my temp folder in case the user uploads documents but doesn't submit the wrapping form. Not the solution I wanted but I can't an alternative working as expected.

GET vs POST in AJAX?

Why are there GET and POST requests in AJAX as it does not affect page URL anyway? What difference does it make by passing sensitive data over GET in AJAX as the data is not getting reflected to page URL?
You should use the proper HTTP verb according to what you require from your web service.
When dealing with a Collection URI like: http://example.com/resources/
GET: List the members of the collection, complete with their member URIs for further navigation. For example, list all the cars for sale.
PUT: Meaning defined as "replace the entire collection with another collection".
POST: Create a new entry in the collection where the ID is assigned automatically by the collection. The ID created is usually included as part of the data returned by this operation.
DELETE: Meaning defined as "delete the entire collection".
When dealing with a Member URI like: http://example.com/resources/7HOU57Y
GET: Retrieve a representation of the addressed member of the collection expressed in an appropriate MIME type.
PUT: Update the addressed member of the collection or create it with the specified ID.
POST: Treats the addressed member as a collection in its own right and creates a new subordinate of it.
DELETE: Delete the addressed member of the collection.
Source: Wikipedia
Well, as for GET, you still have the url length limitation. Other than that, it is quite conceivable that the server treats POST and GET requests differently; thus the need to be able to specify what request you're doing.
Another difference between GET and POST is the way caching is handled in browsers. POST response is never cached. GET may or may not be cached based on the caching rules specified in your response headers.
Two primary reasons for having them:
GET requests have some pretty restrictive limitations on size; POST are typically capable of containing much more information.
The backend may be expecting GET or POST, depending on how it's designed. We need the flexibility of doing a GET if the backend expects one, or a POST if that's what it's expecting.
It's simply down to respecting the rules of the http protocol.
Get - calls must be idempotent. This means that if you call it multiple times you will get the same result. It is not intended to change the underlying data. You might use this for a search box etc.
Post - calls are NOT idempotent. It is allowed to make a change to the underlying data, so might be used in a create method. If you call it multiple times you will create multiple entries.
You normally send parameters to the AJAX script, it returns data based on these parameters. It works just like a form that has method="get" or method="post". When using the GET method, the parameters are passed in the query string. When using POST method, the parameters are sent in the post body.
Generally, if your parameters have very few characters and do not contain sensitive information then you send them via GET method. Sensitive data (e.g. password) or long text (e.g. an 8000 character long bio of a person) are better sent via POST method.
Thanks..
I mainly use the GET method with Ajax and I haven't got any problems until now except the following:
Internet Explorer (unlike Firefox and Google Chrome) cache GET calling if using the same GET values.
So, using some interval with Ajax GET can show the same results unless you change URL with irrelevant random number usage for each Ajax GET.
Others have covered the main points (context/idempotency, and size), but i'll add another: encryption. If you are using SSL and want to encrypt your input args, you need to use POST.
When we use the GET method in Ajax, only the content of the value of the field is sent, not the format in which the content is. For example, content in the text area is just added in the URL in case of the GET method (without a new line character). That is not the case in the POST method.

Resources