Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Conversation

@nullvariable
Copy link
Contributor

update permissions check to match core. Removes checks for create/edit_post permissions in favor of upload_files. Should resolve #2516

@codecov-io
Copy link

codecov-io commented Jun 30, 2016

Current coverage is 94.62%

Merging #2571 into develop will increase coverage by 0.02%

@@            develop      #2571   diff @@
==========================================
  Files            11         11          
  Lines          3644       3644          
  Methods         172        172          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           3447       3448     +1   
+ Misses          197        196     -1   
  Partials          0          0          

Powered by Codecov. Last updated by 39100ee...c5ec6da

@danielbachhuber
Copy link
Member

Removes checks for create/edit_post permissions in favor of upload_files.

Can you make sure there's a test case included for the scenario outlined on the original issue?

@nullvariable
Copy link
Contributor Author

@danielbachhuber sure, the existing test case seemed to work well, it tests if a subscriber can upload (a role which does not have upload_files), there is also a test case for uploads working for a user with edit_posts, which in a default role setup overlaps with admin/editor/author being the only roles with upload_files.

So the test I would write would add a new role with only the upload files capability and then test if that role can upload a file, does that sound like what you're looking for?

@danielbachhuber
Copy link
Member

So the test I would write would add a new role with only the upload files capability and then test if that role can upload a file, does that sound like what you're looking for?

Yep

extended the setup function to create a custom role with 'upload_files' permission and created two tests which check if a user with upload_files can create attachments, and also if a user with upload attachments but no edit permissions is rejected when attempting to add an attachment to a post they do not have permissions on.
@nullvariable
Copy link
Contributor Author

@danielbachhuber that should do the trick

@joehoyle
Copy link
Member

This looks good to me, presuming this is core's behaviour which I haven't actually verified. Given updating the attachment probably does require edit_posts. I'd be interested in how cores handles this if the user only has upload_file. In the case of uploading with the REST API, you don't get to send any attachment data (such as title, description etc) in the initial create request as the body is used for the raw image data, thus edit_post is virtually always required to create an attachment.

@nullvariable
Copy link
Contributor Author

@joehoyle I reviewed all the places that I could find in core here: #2516 (comment)

as best I could tell with core you can create an attachment without edit_posts

'role' => 'contributor',
) );
//matches core capabilities for subscriber role and adds upload_files
_x( 'File upload role', 'User role' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this thing doing here? :) Don't think it's needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well 'File upload role' in line 25 should be translated but doesn't need to be for tests I guess

Copy link
Member

@joehoyle joehoyle Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but you are not assigning it to anything, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. We'd either need to add a variable and pass it to the add_role function or just remove it since our goal here isn't really to test translations. I can modify it either way, but I'd lean towards removing it since it's not the goal of the test and won't really have an impact either way.

@joehoyle joehoyle modified the milestones: 2.0, 2.0 Beta 14 Aug 17, 2016
@kadamwhite
Copy link
Contributor

kadamwhite commented Sep 13, 2016

From PR review today, these are the outstanding TODOs here:

  • Verify this is how Core actually works
  • Clean up the test cases

@nullvariable we're moving this to needs-refresh (discussion)

@adamsilverstein
Copy link

@nullvariable Thanks for your contribution here. I verified this is actually how core works (as well as that is possible given the variance) and created a refreshed patch (cleaning up the unit test a bit) in #2743.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uploading an attachment should not require the edit_posts capability

6 participants