BP_REST_Document_Endpoint::get_document_current_user_permissions( BP_Document $document, array $request )
Get document permissions based on current user.
Description
Parameters
- $document
-
(Required) The Document object.
- $request
-
(Required) Request parameter as array.
Return
(array)
Source
File: bp-document/classes/class-bp-rest-document-endpoint.php
protected function get_document_current_user_permissions( $document, $request ) { $retval = array( 'download' => 0, 'copy_download_link' => 0, 'edit_privacy' => 0, 'edit_post_privacy' => 0, 'rename' => 0, 'move' => 0, 'delete' => 0, ); $document_privacy = array(); if ( ! empty( $document->attachment_id ) ) { $document_privacy = bp_document_user_can_manage_document( $document->id, bp_loggedin_user_id() ); } else { $document_privacy = bp_document_user_can_manage_folder( $document->id, bp_loggedin_user_id() ); } if ( ! empty( $document_privacy ) ) { if ( isset( $document_privacy['can_download'] ) && true === (bool) $document_privacy['can_download'] ) { $retval['download'] = 1; $retval['copy_download_link'] = 1; } if ( isset( $document_privacy['can_manage'] ) && true === (bool) $document_privacy['can_manage'] ) { $retval['rename'] = 1; $retval['delete'] = 1; if ( 0 === (int) $document->group_id && 0 === (int) $document->parent ) { if ( ! empty( $document->attachment_id ) ) { $child_activity = get_post_meta( $document->attachment_id, 'bp_document_activity_id', true ); if ( $child_activity ) { $parent_activity_id = get_post_meta( $document->attachment_id, 'bp_document_parent_activity_id', true ); if ( bp_is_active( 'activity' ) ) { $retval['edit_post_privacy'] = $parent_activity_id; } else { $retval['edit_post_privacy'] = $document->activity_id; } } } else { $retval['edit_privacy'] = 1; } } } if ( isset( $document_privacy['can_add'] ) && true === (bool) $document_privacy['can_add'] ) { $retval['move'] = 1; } } if ( isset( $request['support'] ) && ( 'activity' === $request['support'] || 'forums' === $request['support'] || 'message' === $request['support'] ) ) { unset( $retval['rename'] ); if ( 'activity' === $request['support'] || 'message' === $request['support'] || 'forums' === $request['support'] ) { unset( $retval['edit_privacy'] ); unset( $retval['edit_post_privacy'] ); } if ( 'message' === $request['support'] ) { unset( $retval['move'] ); unset( $retval['delete'] ); } if ( 'forums' === $request['support'] ) { unset( $retval['move'] ); } } return $retval; }
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.