/**
 * A new or existing user file attachment.
 *
 * Model Attributes:
 *     caption (string):
 *         The file attachment's caption.
 *
 *     userName (string):
 *         The username of the owner of the file attachment.
 *
 *     downloadURL (string):
 *         The URL to download the file, for existing file attachments.
 *
 *     file (file):
 *         The file to upload. Only works for newly created
 *         UserFileAttachments.
 *
 *     filename (string):
 *         The name of the file, for existing file attachments.
 */
RB.UserFileAttachment = RB.BaseResource.extend({
    defaults() {
        return _.defaults({
            caption: null,
            userName: '',
            downloadURL: null,
            file: null,
            filename: null
        }, RB.BaseResource.prototype.defaults());
    },

    rspNamespace: 'file_attachment',
    payloadFileKeys: ['path'],

    attrToJsonMap: {
        downloadURL: 'absolute_url',
        file: 'path'
    },

    serializedAttrs: [
        'caption',
        'file'
    ],

    deserializedAttrs: [
        'caption',
        'downloadURL',
        'filename'
    ],

    serializers: {
        file: RB.JSONSerializers.onlyIfValue
    },

    /**
     * Return the URL to use for syncing the model.
     *
     * Returns:
     *     string:
     *     The URL for the resource.
     */
    url() {
        const username = this.get('userName');
        const url = `${SITE_ROOT}api/users/${username}/file-attachments/`;

        return this.isNew() ? url : `${url}${this.id}/`;
    }
});

/**
 * A new or existing user file attachment.
 *
 * Model Attributes:
 *     caption (string):
 *         The file attachment's caption.
 *
 *     userName (string):
 *         The username of the owner of the file attachment.
 *
 *     downloadURL (string):
 *         The URL to download the file, for existing file attachments.
 *
 *     file (file):
 *         The file to upload. Only works for newly created
 *         UserFileAttachments.
 *
 *     filename (string):
 *         The name of the file, for existing file attachments.
 */
RB.UserFileAttachment = RB.BaseResource.extend({
    defaults() {
        return _.defaults({
            caption: null,
            userName: '',
            downloadURL: null,
            file: null,
            filename: null
        }, RB.BaseResource.prototype.defaults());
    },

    rspNamespace: 'user_file_attachment',
    payloadFileKeys: ['path'],

    attrToJsonMap: {
        downloadURL: 'absolute_url',
        file: 'path'
    },

    serializedAttrs: [
        'caption',
        'file'
    ],

    deserializedAttrs: [
        'caption',
        'downloadURL',
        'filename'
    ],

    serializers: {
        file: RB.JSONSerializers.onlyIfValue
    },

    /**
     * Return the URL to use for syncing the model.
     *
     * Returns:
     *     string:
     *     The URL for the resource.
     */
    url() {
        const username = this.get('userName');
        const url = `${SITE_ROOT}api/users/${username}/user-file-attachments/`;

        return this.isNew() ? url : `${url}${this.id}/`;
    }
});

Fix resource paths for user file attachments.
Fix resource paths for user file attachments.

When I fixed the names in the user file attachments resource to make it
available within the API templates, I neglected to actually test the javascript
in the Review Board UI, which was still using the old paths and names. This
change fixes it.

Testing done:
Drag-and-dropped an image into a review header.

Reviewed at https://reviews.reviewboard.org/r/8860/
