-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify 'upload_files' capability when displaying upload UI in media b…
…locks (#4155) * Use OPTIONS Rest API Media Request to get user `upload_file` capability Edit the preloaded path and adapt the way apiFetch is preloading the requests using the OPTIONS method. Add a hasUploadPermissions property to core/data * Introduce the MediaUploadCheck component Start using it into the MediaPlaceHolder to inform the contributor role he cannot upload media. If the block supports selecting an URL, the instruction will inform the contributor role he can only add a link to a media. * Display a message to the contributor about the featured image As it is not possible to fetch the Featured image for this role, no matter the context of the REST request, display a message to inform him managing the featured image needs the upload files cap. * Enforce strict format of the preloaded path when an array is used This is to bring into Gutenberg the improvement @danielbachhuber committed in WordPress 5.0 branch See https://core.trac.wordpress.org/changeset/43833 * Make sure the Inline Image is only available to users with the upload_files cap * Update generated data-core docs * Apply @gziolo recommandations and fix a failing unit test
- Loading branch information
Showing
12 changed files
with
262 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
export function MediaUploadCheck( { hasUploadPermissions, fallback = null, children } ) { | ||
return hasUploadPermissions ? children : fallback; | ||
} | ||
|
||
export default withSelect( ( select ) => { | ||
let hasUploadPermissions = false; | ||
if ( undefined !== select( 'core' ) ) { | ||
hasUploadPermissions = select( 'core' ).hasUploadPermissions(); | ||
} | ||
|
||
return { | ||
hasUploadPermissions: hasUploadPermissions, | ||
}; | ||
} )( MediaUploadCheck ); |
Oops, something went wrong.