couchdb, how to rename an attachment - content-management-system

I'm writing cms like application and I would like my images to be stored as attachments in couchdb.
The problem is in naming the attachments because I don't want my images to be named the same (e.g. /db/doc_id/thumb.jpg)
Ideally attachments names should depend on doc.name field. To make this work I would have to rename attachment each time user changed the name (description|alt) of current photo document.
So my question is: how to change attachment name? or maybe I should go other way in solving my problem?

Szymon,
I'd suggest considering using UUIDs for the document names, and storing the attachment as something "static" like "original", "thumb", "300wide", etc. The name given by the user when they upload the file can be stored as a key, and you can use a MapReduce index to retrieve the image/file using that name later.
If you go that route, though, you'll have to come at the "duplicates" problem a bit differently--as you could easily upload the same image multiple times with the same user-provided name and there would be no conflict.
Depending on what you're building, though, making the user provide a unique name is generally unwise--Flickr (among many others) doesn't, for instance.
If you really do need to make the doc_id == the name given by the user, then it would still be wise to store the attachments under static names, so you don't have to update the attachment name.
Lastly, if you feel you really must change the attachment name (and there are certainly cases where you need to), the simplest way is to GET the attachment from the old location (or with the document), PUT it as the new name, and DELETE the attachment with the old name.
Hope that helps!

Use this command >
curl -v http://localhost:5984/database/DocumentID/OldFileName?rev=RevisionID -X MOVE -H "Destination: NewFileName"

Related

OfficeJS - Retrieving document ID

We need to retrieve an ID that uniquely identifies a document, so that when a user opens the same document in different sessions (even a year apart) we can identify this in the logs.
In the API I found DocumentURL but this could change (if the document is moved?) and it might even be empty (if the document is never stored online?). We could hash a combination of properties like Author and Date Created but these too can change and thus can't be fully relied upon.
How do we access the ID of a document? Ideally we're looking for a solution that works for any type of document, but if currently there is only such a property for a Word document then that is sufficient as well.
EDIT: Adding scenarios that need to work because otherwise my request seems too simple (hence the down-votes?):
The user can open, edit, save, etc. other documents and the ID should ALWAYS be the same PER document. Similarly, if a user shares a document with someone else, the ID read by the other user (when running our add-in) should be the same as for the owner of that document.
The add-in needs to be portable and usable on multiple platforms. When a user opens the same document on Word Online and Win 32, on different computers, etc. the ID must always be the same for that document.
To create a unique ID, it takes only a little JavaScript to create a GUID. See this SO post for example: Create GUID/UUID in JavaScript
To store the ID, you could use a custom setting or custom property. See Persist State and Settings

Powermail - add submission ID to email

Is there a variable I can add that will output a unique ID to the generated email?
Something similar to a help desk ticket ID.
I found this, but it is not 100% reliable to get a unique ID:
http://lists.typo3.org/pipermail/typo3-dev/2009-December/038130.html
If not, can I generate a unique ID with typescript and feed it into the form?
(nearly) each record in TYPO3 gets an UId. I don't know whether the uid for save saved powermail data is already available in the finishers.
Otherwise timestamps normaly make good unique IDs so they are pretty large.
You might make it more unique if you append the IP, so this still will not guarrantee uniqueness.
You might create records when the empty form is called and so reserve an unique ID which gets used only if the user saves his data, but that is complicated too. (can not be done just with configuration of powermail)
Just do a <f:debug>{_all}</f:debug> into the HTML-Template. You will see every variable that you can use.

Master Data Services - Domain based attributes

We are using Master Data Services as an MDM solution for our SQL Server BI environment. I have an entity containing a first name and last name and then I have created a business rule that concatenates these two fields to form a full name which is then stored in the "name" system field of the entity.
I use this as a domain based entity in another entity. Then the user can then see the full name before linking it as a attribute in the second entity.
I want to be able to restrict the users from capturing data in the first entity against the name attribute because the business rule deals with the logic to populate this attribute. I have read that there are two ways to do this:
Set the display width to zero of the attribute. This does not seem to work, the explorer version still shows a narrow version of the field in the rows and the user can still edit the field in the detail pane.
Use the security to make the attribute read only. I have tried different combinations of this but it seems that you cannot use this functionality for a name field (system field).
This seems like pretty basic functionality that I require and it seems that there is no clear cut way to do this in MDS.
Any assistance will be appreciated.
Thanks
We do exactly the same thing.
I tested it, and whether you create a new member, or edit an existing member, the business rule just overwrites the manual input value in the name attribute.
Is there a specific 'business' reason why you need to restrict data input in the name field? If it is for Ux reasons, you can change the display name of the name attribute to something like 'Don't populate' or alternatively make it a '.', then the users won't know what to input.

Prettify MongoDb ObjectId

We are developing photo gallery which is storing huge amount of photos. We have choosed MongoDB's GridFS for image storage. Every thing looks fine.
But every time when user has to delete the photo we thought of deleting particular photo based on its "ObjectId", but Sending ObjectId to client side looks ugly because of its length. Deleting based on photo name is not possible because its not unique.
So how do we prettify the ObjectId to send it to client side?
Not sure if this belongs as an answer since it's subjective, but then again, so is the question:
If you want to not involve another field, you can change the encoding of the id. I think base64 looks just fine:
55036ee50202b73c1a021897 -> NTUwMzZlZTUwMjAyYjczYzFhMDIxODk3
Another option is to generate a random string and store it on the document, which gives you a lot of customizability in the appearance. For example, you could do 4 digit codes with only upper-case characters like BUZQ. However, be sure to create a unique index so you don't accidentally create duplicate identifiers.

How to generate one-time-use links? Any CMS or framework solutions?

I'm making a site for a writers management company. They get tons of script submissions every day from prospective and often unsolicited writers. The new site will allow a prospective writer to submit a short logline / sample of his or her idea. This idea gets sent to an email account at the management group. If the management group likes what they see, they want to be able to approve that submission from within the email and have a unique link dispatched to the submitter to upload their full script. This link would either only work once, or only for a certain amount of time so that only the intended recipient could use it.
So, can anyone point me in the direction of some sort of (I'm assumine PHP + mySQL) CMS or framework that could accomplish this? I've searched a lot, but I can't seem to figure out the right way to phrase this query to a search engine.
I have moderate programming experience, but not much with PHP outside of some simple Wordpress hacks.
Thanks!
I will just give you general guidelines on a simple way to construct such a system.
I assume that the Writer is somehow Registered into the system, and his/her profile contains a valid mail address.
So, when he submits the sample, you would create an entry on the "Sample" table. Then you would mail a Manager with the sample and a link. This link would point to a script giving the database "id" of the sample as a parameter (this script should verify that the manager is logged on -- if not, show the login screen and after successful login redirect him back).
This script would then be aware of the Manager's intention to allow the Writer to submit his work. Now the fun begins.
There are many possibilities:
You can create an entry in an appropriate "SubmitAuthorizations" DB table containing the id of the Writer and the date this authorization was given (ie, the date when the row was added to your DB). Then you simply send a mail to the Writer with a link like "upload.php?id=42", where the id is the authorization id. This script would check if the logged user is the correct Writer, and if he is within the allowed timeframe (by comparing the stored "authorization date" and the current date).
The next is the one I prefer: without a special table just for handling something trivial (let's say you will never want to "edit" an authorization, nor "cancel" it, but it may still "expire"). You simply simply give the Writer a link with 2 parameters: the date the authorization was given and an authorization key, like: "upload.php?authDate=20091030&key=87a62d726ef7..."
Let me explain how it works.
The script would first verify if the Writer is logged on (if not, show the login page with a redirection after successful login).
So, now it's time to validate the request: that is, check if this is not a "forged" link. How to do this? It's just a "smart" way of construction this authorization key.
You can do something like:
key = hash(concat(userId, ";", authDate, ";", seed));
Well, here hash() is what we call a "one-way function", like MD5, SHA1, etc. Then concat() is simply a string concatenation function. Finally seed is something like a "master password", completely random and that will not change (for if you change it all the issued links would stop working) just to increase security -- let's say a hacker correctly guesses you are using MD5 (which is easy) and the he tries to hack your system by hashing some combinations of the username and the date.
Also, for a request to be valid, it must be in the correct time frame.
So, if both the key is valid, and the date is within the time frame, you are able to accept an upload.
Some points to note:
This is a very simple system, but might be exactly what you need.
You should avoid MD5 for the hashing function, take something like SHA1 instead.
For the link sent to the Writer, you could "obfuscate" the parameter names, ie, call them "k" for the "key" and "d" for the "authDate".
For the date, you could chose another format, more "cryptic", like the unix epoch.
Finally, you can encode the parameters with something like "base64" (or simply apply some character replacing function like rot13 for instance, but that take digits into account aswell) just in order to make them more difficult to guessing
Just for completeness, in the validation script you can also check if the Writer has already sent a file on the time frame, thus making it impossible to him to send many files within the time frame.
I have recently implemented something like this twice on the company I work for, for two completely different uses. Once you get the idea, it is extremelly simple to implement it -- maybe less than 10 lines of code for the whole key-generation and validation process.
On one of them, the agent equivalent to your Writer had no account into the system (actually it would be his first contact with the system) -- there was only his "profile" on the system, managed by someone else. In this case, you would have to include the "Writer"'s id on the parameters to the "Upload" script aswell.
I hope this helps, and that it was clear enough. If I find the time, I will blog about it with an working example on some language.