Merge pull request #813 from tainacan/feature/803
Relationship metadata option to only list items authored by current user. #803
This commit is contained in:
commit
d25cea3479
|
@ -119,6 +119,21 @@
|
|||
:message="$i18n.getHelperMessage('tainacan-relationship', 'accept_draft_items')"/>
|
||||
</b-field>
|
||||
|
||||
<b-field
|
||||
:addons="false"
|
||||
:label="$i18n.getHelperTitle('tainacan-relationship', 'accept_only_items_authored_by_current_user')">
|
||||
|
||||
<b-switch
|
||||
size="is-small"
|
||||
v-model="modelAcceptOnlyItemsAuthoredByCurrentUser"
|
||||
@input="emitValues()"
|
||||
true-value="yes"
|
||||
false-value="no" />
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('tainacan-relationship', 'accept_only_items_authored_by_current_user')"
|
||||
:message="$i18n.getHelperMessage('tainacan-relationship', 'accept_only_items_authored_by_current_user')"/>
|
||||
</b-field>
|
||||
|
||||
</section>
|
||||
</template>
|
||||
|
||||
|
@ -148,6 +163,7 @@
|
|||
collectionMessage: '',
|
||||
displayRelatedItemMetadata: [],
|
||||
modelAcceptDraftItems: 'no',
|
||||
modelAcceptOnlyItemsAuthoredByCurrentUser: 'no',
|
||||
isMetaqueryRelationshipEnabled: tainacan_plugin && tainacan_plugin.tainacan_enable_relationship_metaquery == true ? tainacan_plugin.tainacan_enable_relationship_metaquery : false
|
||||
}
|
||||
},
|
||||
|
@ -172,6 +188,7 @@
|
|||
this.modelSearch = '';
|
||||
this.modelDisplayInRelatedItems = 'no';
|
||||
this.modelAcceptDraftItems = 'no';
|
||||
this.modelAcceptOnlyItemsAuthoredByCurrentUser = 'no';
|
||||
this.emitValues();
|
||||
}
|
||||
},
|
||||
|
@ -193,6 +210,7 @@
|
|||
this.displayRelatedItemMetadata = this.value && this.value.display_related_item_metadata && Array.isArray(this.value.display_related_item_metadata) ? this.value.display_related_item_metadata : [];
|
||||
this.modelDisplayInRelatedItems = this.value && this.value.display_in_related_items ? this.value.display_in_related_items : 'no';
|
||||
this.modelAcceptDraftItems = this.value && this.value.accept_draft_items ? this.value.accept_draft_items : 'no';
|
||||
this.modelAcceptOnlyItemsAuthoredByCurrentUser = this.value && this.value.accept_only_items_authored_by_current_user ? this.value.accept_only_items_authored_by_current_user : 'no';
|
||||
},
|
||||
methods: {
|
||||
setErrorsAttributes( type, message ){
|
||||
|
@ -283,7 +301,8 @@
|
|||
search: this.modelSearch,
|
||||
display_in_related_items: this.modelDisplayInRelatedItems,
|
||||
display_related_item_metadata: this.displayRelatedItemMetadata,
|
||||
accept_draft_items: this.modelAcceptDraftItems
|
||||
accept_draft_items: this.modelAcceptDraftItems,
|
||||
accept_only_items_authored_by_current_user: this.modelAcceptOnlyItemsAuthoredByCurrentUser
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
<template
|
||||
v-if="!isLoading"
|
||||
slot="empty">
|
||||
{{ $i18n.get('info_no_item_found') }}
|
||||
{{ isAcceptingOnlyItemsAuthoredByCurrentUser ? $i18n.get('info_no_item_authored_by_you_found') : $i18n.get('info_no_item_found') }}
|
||||
</template>
|
||||
<template
|
||||
v-if="currentUserCanEditItems && (!$adminOptions.itemEditionMode || $adminOptions.allowItemEditionModalInsideModal)"
|
||||
|
@ -209,6 +209,12 @@
|
|||
this.itemMetadatum.metadatum &&
|
||||
this.itemMetadatum.metadatum.metadata_type_options &&
|
||||
this.itemMetadatum.metadatum.metadata_type_options.accept_draft_items === 'yes';
|
||||
},
|
||||
isAcceptingOnlyItemsAuthoredByCurrentUser() {
|
||||
return this.itemMetadatum &&
|
||||
this.itemMetadatum.metadatum &&
|
||||
this.itemMetadatum.metadatum.metadata_type_options &&
|
||||
this.itemMetadatum.metadatum.metadata_type_options.accept_only_items_authored_by_current_user === 'yes';
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
@ -230,7 +236,8 @@
|
|||
query['order'] = 'asc';
|
||||
query['fetch_only'] = 'title,document_mimetype,thumbnail';
|
||||
query['fetch_only_meta'] = this.isDisplayingRelatedItemMetadata ? (this.itemMetadatum.metadatum.metadata_type_options.display_related_item_metadata.filter(metadatumId => metadatumId !== 'thumbnail') + '') : (this.itemMetadatum.metadatum.metadata_type_options.search ? this.itemMetadatum.metadatum.metadata_type_options.search : '');
|
||||
if (this.isAcceptingDraftItems)
|
||||
|
||||
if ( this.isAcceptingDraftItems )
|
||||
query['status'] = ['publish','private','draft'];
|
||||
|
||||
axios.get('/collection/' + this.collectionId + '/items?' + qs.stringify(query) )
|
||||
|
@ -397,6 +404,9 @@
|
|||
if (this.isAcceptingDraftItems)
|
||||
query['status'] = ['publish','private','draft'];
|
||||
|
||||
if ( this.isAcceptingOnlyItemsAuthoredByCurrentUser )
|
||||
query['authorid'] = tainacan_plugin.user_data.ID;
|
||||
|
||||
if (this.selected.length > 0)
|
||||
query['exclude'] = this.selected.map((item) => item.value);
|
||||
|
||||
|
|
|
@ -71,6 +71,10 @@ class Relationship extends Metadata_Type {
|
|||
'accept_draft_items' => [
|
||||
'title' => __( 'List and accept draft items on the relation', 'tainacan' ),
|
||||
'description' => __( 'Include draft items as possible options to the relationship metadata.', 'tainacan' ),
|
||||
],
|
||||
'accept_only_items_authored_by_current_user' => [
|
||||
'title' => __( 'Bind items only by current author', 'tainacan' ),
|
||||
'description' => __( 'Accept stabelishing the replationship only with items authored by the current user editing the item.', 'tainacan' ),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
@ -121,6 +125,7 @@ class Relationship extends Metadata_Type {
|
|||
|
||||
case 'display_in_related_items':
|
||||
case 'accept_draft_items':
|
||||
case 'accept_only_items_authored_by_current_user':
|
||||
if ($option_value == 'yes')
|
||||
$readable_option_value = __('Yes', 'tainacan');
|
||||
else if ($option_value == 'no')
|
||||
|
@ -177,13 +182,19 @@ class Relationship extends Metadata_Type {
|
|||
// empty is ok
|
||||
if ( !empty($this->get_option('display_in_related_items')) && !in_array($this->get_option('display_in_related_items'), ['yes', 'no']) ) {
|
||||
return [
|
||||
'display_in_related_items' => __('Display in related items must be a option yes or no','tainacan')
|
||||
'display_in_related_items' => __('Display in related items must be an option yes or no','tainacan')
|
||||
];
|
||||
}
|
||||
// empty is ok
|
||||
if ( !empty($this->get_option('accept_draft_items')) && !in_array($this->get_option('accept_draft_items'), ['yes', 'no']) ) {
|
||||
return [
|
||||
'accept_draft_items' => __('Accept draft items must be a option yes or no','tainacan')
|
||||
'accept_draft_items' => __('Accept draft items must be an option yes or no','tainacan')
|
||||
];
|
||||
}
|
||||
// empty is ok
|
||||
if ( !empty($this->get_option('accept_only_items_authored_by_current_user')) && !in_array($this->get_option('accept_only_items_authored_by_current_user'), ['yes', 'no']) ) {
|
||||
return [
|
||||
'accept_only_items_authored_by_current_user' => __('Bind items only by current author must be an option yes or no','tainacan')
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -297,12 +297,21 @@ class Admin {
|
|||
$cur_user = wp_get_current_user();
|
||||
$user_caps = array();
|
||||
$prefs = array();
|
||||
$user_data = array();
|
||||
if ( $cur_user instanceof \WP_User ) {
|
||||
$tainacan_caps = \tainacan_roles()->get_repository_caps_slugs();
|
||||
foreach ($tainacan_caps as $tcap) {
|
||||
$user_caps[$tcap] = current_user_can( $tcap );
|
||||
}
|
||||
$prefs = get_user_meta( $cur_user->ID, 'tainacan_prefs', true );
|
||||
|
||||
if ( $cur_user->data && isset($cur_user->data->user_email) && isset($cur_user->data->display_name) ) {
|
||||
$user_data = array(
|
||||
'ID' => $cur_user->ID,
|
||||
'email' => $cur_user->data->user_email,
|
||||
'display_name' => $cur_user->data->display_name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$settings = [
|
||||
|
@ -314,6 +323,7 @@ class Admin {
|
|||
'i18n' => $tainacan_admin_i18n,
|
||||
'user_caps' => $user_caps,
|
||||
'user_prefs' => $prefs,
|
||||
'user_data' => $user_data,
|
||||
'base_url' => $TAINACAN_BASE_URL,
|
||||
'plugin_dir_url' => plugin_dir_url( __DIR__ ),
|
||||
'admin_url' => admin_url(),
|
||||
|
|
|
@ -839,6 +839,7 @@ return apply_filters( 'tainacan-i18n', [
|
|||
'info_no_user_found' => __( 'No user was found with this name.', 'tainacan' ),
|
||||
'info_no_item_found_filter' => __( 'No item was found here with these filters.', 'tainacan' ),
|
||||
'info_no_item_found' => __( 'No item was found.', 'tainacan' ),
|
||||
'info_no_item_authored_by_you_found' => __( 'No item authored by you was found.', 'tainacan' ),
|
||||
'info_item_not_saved' => __( 'Warning: Item not saved.', 'tainacan' ),
|
||||
'info_no_associated_role' => __( 'No associated role.', 'tainacan' ),
|
||||
'info_error_deleting_collection' => __( 'Error on deleting collection.', 'tainacan' ),
|
||||
|
|
Loading…
Reference in New Issue