New resource for "owned" and review request independent file attachments

Review Request #6220 — Created Aug. 12, 2014 and discarded

rvaiya
Review Board
master
6217
reviewboard, students

New resource for user file attachments.

New file attachment resource was creating using the frontend backbone/RB.BaseResource model and post/put/get were tested manually.

  • Successfully created a file attachment user content is always empty upon creation as expected
  • Successfully posted caption and file data
  • Successfully modified and saved caption data
  • Tried to update file a second time and observed the expected behaviour (it failed)
  • Manually tested get_list by making a request to /api/file-attachments/, it returned a list of all file attachments owned by the user making the request as expected.
Description From Last Updated

'reviewboard' imported but unused

reviewbotreviewbot

Col: 13 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 22 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 22 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 17 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 26 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 28 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 22 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 22 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 17 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 26 E241 multiple spaces after ':'

reviewbotreviewbot

Col: 28 E241 multiple spaces after ':'

reviewbotreviewbot

local variable 'positions_key' is assigned to but never used

reviewbotreviewbot

redefinition of unused 'FileDiffMigrationTests' from line 726

reviewbotreviewbot

list comprehension redefines 'file_attachment' from line 583

reviewbotreviewbot

We generally avoid the ternary form because it's annoying. How about rewriting this as: if self.orig_filename: return self.orig_filename elif self.file: ...

daviddavid

Why did you make this change?

daviddavid

Trailing spaces in javascript can break IE.

daviddavid

Remove this line.

daviddavid

This should probably include everything if it's an admin making the request.

daviddavid

Docstrings should generally follow the same format that you might use for a commit message -- the first line should ...

daviddavid

Same comments as the above docstring.

daviddavid

What happens if you just let it assign None to the caption field?

daviddavid

PERMISSION_DENIED doesn't seem quite right. How about creating a new error, FILE_ALREADY_EXISTS?

daviddavid

'User' imported but unused

reviewbotreviewbot

'User' imported but unused

reviewbotreviewbot
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/attachments/forms.py
        reviewboard/webapi/resources/root.py
    
    
    
    Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/attachments/forms.py
        reviewboard/webapi/resources/root.py
    
    
  2. 
      
RV
RV
RV
RV
RV
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/attachments/forms.py
        reviewboard/webapi/resources/root.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/attachments/forms.py
        reviewboard/webapi/resources/root.py
    
    
  2. 
      
RV
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/attachments/forms.py
        reviewboard/webapi/resources/root.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/attachments/forms.py
        reviewboard/webapi/resources/root.py
    
    
  2. 
      
RV
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/attachments/forms.py
        reviewboard/webapi/resources/root.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/attachments/forms.py
        reviewboard/webapi/resources/root.py
    
    
  2. 
      
RV
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/diffviewer/management/commands/condensediffs.py
        reviewboard/attachments/models.py
        reviewboard/diffviewer/managers.py
        reviewboard/reviews/markdown_utils.py
        reviewboard/reviews/tests.py
        reviewboard/webapi/resources/review_request.py
        reviewboard/webapi/tests/test_review_request.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/staticbundles.py
        reviewboard/webapi/resources/review_request_draft.py
        reviewboard/webapi/tests/test_review_request_draft.py
        reviewboard/scmtools/svn/subvertpy.py
    
    Ignored Files:
        reviewboard/static/rb/js/configForms/models/tests/resourceListItemModelTests.js
        reviewboard/static/rb/css/ui/boxes.less
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
        reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/diffviewer/management/commands/condensediffs.py
        reviewboard/attachments/models.py
        reviewboard/diffviewer/managers.py
        reviewboard/reviews/markdown_utils.py
        reviewboard/reviews/tests.py
        reviewboard/webapi/resources/review_request.py
        reviewboard/webapi/tests/test_review_request.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/staticbundles.py
        reviewboard/webapi/resources/review_request_draft.py
        reviewboard/webapi/tests/test_review_request_draft.py
        reviewboard/scmtools/svn/subvertpy.py
    
    Ignored Files:
        reviewboard/static/rb/js/configForms/models/tests/resourceListItemModelTests.js
        reviewboard/static/rb/css/ui/boxes.less
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
        reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js
    
    
  2. 
      
RV
RV
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/reviews/views.py
        reviewboard/admin/views.py
        reviewboard/diffviewer/renderers.py
        reviewboard/webapi/resources/root.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/evolutions/__init__.py
        reviewboard/webapi/resources/diff.py
        reviewboard/staticbundles.py
        reviewboard/diffviewer/evolutions/raw_diff_file_data.py
        reviewboard/admin/forms.py
        reviewboard/attachments/models.py
        reviewboard/webapi/resources/base_original_file.py
        setup.py
        reviewboard/diffviewer/managers.py
        reviewboard/admin/siteconfig.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/admin/checks.py
        reviewboard/diffviewer/management/commands/condensediffs.py
        reviewboard/webapi/resources/base_patched_file.py
        reviewboard/scmtools/hg.py
        reviewboard/__init__.py
        reviewboard/webapi/resources/filediff.py
        reviewboard/diffviewer/diffutils.py
        reviewboard/diffviewer/models.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
        reviewboard/static/rb/js/resources/models/baseResourceModel.js
        docs/releasenotes/index.rst
        docs/manual/admin/installation/linux.rst
        docs/manual/admin/configuration/file-storage-settings.rst
        docs/releasenotes/2.0.6.rst
        AUTHORS
        docs/releasenotes/1.7.28.rst
        reviewboard/static/rb/js/diffviewer/views/diffRevisionSelectorView.js
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/reviews/views.py
        reviewboard/admin/views.py
        reviewboard/diffviewer/renderers.py
        reviewboard/webapi/resources/root.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/evolutions/__init__.py
        reviewboard/webapi/resources/diff.py
        reviewboard/staticbundles.py
        reviewboard/diffviewer/evolutions/raw_diff_file_data.py
        reviewboard/admin/forms.py
        reviewboard/attachments/models.py
        reviewboard/webapi/resources/base_original_file.py
        setup.py
        reviewboard/diffviewer/managers.py
        reviewboard/admin/siteconfig.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/admin/checks.py
        reviewboard/diffviewer/management/commands/condensediffs.py
        reviewboard/webapi/resources/base_patched_file.py
        reviewboard/scmtools/hg.py
        reviewboard/__init__.py
        reviewboard/webapi/resources/filediff.py
        reviewboard/diffviewer/diffutils.py
        reviewboard/diffviewer/models.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
        reviewboard/static/rb/js/resources/models/baseResourceModel.js
        docs/releasenotes/index.rst
        docs/manual/admin/installation/linux.rst
        docs/manual/admin/configuration/file-storage-settings.rst
        docs/releasenotes/2.0.6.rst
        AUTHORS
        docs/releasenotes/1.7.28.rst
        reviewboard/static/rb/js/diffviewer/views/diffRevisionSelectorView.js
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
    
    
  2. reviewboard/__init__.py (Diff revision 7)
     
     
     'reviewboard' imported but unused
    
  3. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 13
     E241 multiple spaces after ':'
    
  4. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 22
     E241 multiple spaces after ':'
    
  5. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 22
     E241 multiple spaces after ':'
    
  6. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 17
     E241 multiple spaces after ':'
    
  7. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 26
     E241 multiple spaces after ':'
    
  8. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 28
     E241 multiple spaces after ':'
    
  9. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 22
     E241 multiple spaces after ':'
    
  10. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 22
     E241 multiple spaces after ':'
    
  11. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 17
     E241 multiple spaces after ':'
    
  12. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 26
     E241 multiple spaces after ':'
    
  13. reviewboard/admin/siteconfig.py (Diff revision 7)
     
     
    Col: 28
     E241 multiple spaces after ':'
    
  14. reviewboard/admin/views.py (Diff revision 7)
     
     
     local variable 'positions_key' is assigned to but never used
    
  15. reviewboard/diffviewer/tests.py (Diff revision 7)
     
     
     redefinition of unused 'FileDiffMigrationTests' from line 726
    
  16. reviewboard/reviews/views.py (Diff revision 7)
     
     
     list comprehension redefines 'file_attachment' from line 583
    
  17. 
      
chipx86
  1. Something went terribly wrong with this commit. Make sure you have master merged into your branch.

    1. Sorry about that, I have my own repository where I store some of my branches and rbt post was using the master branch upstream of the branch I was working on (which was out of date). I have resolved the issue and updated the review request.

  2. 
      
RV
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/staticbundles.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/models.py
        reviewboard/staticbundles.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
    
    
  2. 
      
david
  1. This also needs unit tests for the new API.

  2. reviewboard/attachments/models.py (Diff revision 8)
     
     

    We generally avoid the ternary form because it's annoying. How about rewriting this as:

    if self.orig_filename:
        return self.orig_filename
    elif self.file:
        return os.path.basename(self.file.name)
    else:
        return None
    
  3. Why did you make this change?

  4. Trailing spaces in javascript can break IE.

    1. I don't see any trailing spaces.

  5. Remove this line.

  6. This should probably include everything if it's an admin making the request.

  7. Docstrings should generally follow the same format that you might use for a commit message -- the first line should be a summary, and then additional paragraphs can go into more explanation.

    Indentation should also be:

    def create(self, request, *args, **kwargs):
        """Create a FileAttachment
    
        Here's some more explanation.
        """
    

    I'm also not 100% sure we should completely ignore the POST parameters. If a file or caption is present, we should use it (the web UI isn't the only consumer of the API).

  8. Same comments as the above docstring.

  9. What happens if you just let it assign None to the caption field?

  10. PERMISSION_DENIED doesn't seem quite right. How about creating a new error, FILE_ALREADY_EXISTS?

  11. 
      
RV
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/attachments/models.py
        reviewboard/webapi/errors.py
        reviewboard/attachments/evolutions/__init__.py
        reviewboard/attachments/mimetypes.py
        reviewboard/attachments/evolutions/file_attachment_ownership.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/forms.py
        reviewboard/staticbundles.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
    
    
    
    Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/attachments/models.py
        reviewboard/webapi/errors.py
        reviewboard/attachments/evolutions/__init__.py
        reviewboard/attachments/mimetypes.py
        reviewboard/attachments/evolutions/file_attachment_ownership.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/forms.py
        reviewboard/staticbundles.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
    
    
  2.  'User' imported but unused
    
  3. 
      
RV
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/attachments/models.py
        reviewboard/webapi/errors.py
        reviewboard/attachments/evolutions/__init__.py
        reviewboard/attachments/mimetypes.py
        reviewboard/attachments/evolutions/file_attachment_ownership.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/forms.py
        reviewboard/staticbundles.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/attachments/models.py
        reviewboard/webapi/errors.py
        reviewboard/attachments/evolutions/__init__.py
        reviewboard/attachments/mimetypes.py
        reviewboard/attachments/evolutions/file_attachment_ownership.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/forms.py
        reviewboard/staticbundles.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
    
    
  2.  'User' imported but unused
    
  3. 
      
RV
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/attachments/models.py
        reviewboard/webapi/errors.py
        reviewboard/attachments/evolutions/__init__.py
        reviewboard/attachments/mimetypes.py
        reviewboard/attachments/evolutions/file_attachment_ownership.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/forms.py
        reviewboard/staticbundles.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/root.py
        reviewboard/attachments/models.py
        reviewboard/webapi/errors.py
        reviewboard/attachments/evolutions/__init__.py
        reviewboard/attachments/mimetypes.py
        reviewboard/attachments/evolutions/file_attachment_ownership.py
        reviewboard/webapi/resources/file_attachment_user.py
        reviewboard/attachments/forms.py
        reviewboard/staticbundles.py
    
    Ignored Files:
        reviewboard/static/rb/js/resources/models/apiTokenModel.js
        reviewboard/static/rb/js/resources/models/fileAttachmentUserModel.js
    
    
  2. 
      
RV
Review request changed

Status: Discarded

Loading...