Skip to content

Commit

Permalink
Merge remote-tracking branch 'dgt/4.1-dev-mm-cando' into j4/media/ico…
Browse files Browse the repository at this point in the history
…ns-permissions
  • Loading branch information
laoneo committed Feb 3, 2022
2 parents d0d4ed7 + b6f5afd commit b4fe213
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Api {
this.videoExtensions = options.videoExtensions;
this.documentExtensions = options.documentExtensions;
this.mediaVersion = (new Date().getTime()).toString();
this.canEdit = options.canEdit || false;
this.canDelete = options.canDelete || false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:main-action="openPreview"
:closing-action="hideActions"
@keyup.up="$refs.actionDelete.$el.focus()"
@keyup.down="$refs.actionDownload.$el.focus()"
@keyup.down="$refs.actionDelete.$el.previousElementSibling.focus()"
/>
</li>
<li>
Expand All @@ -39,26 +39,27 @@
:main-action="download"
:closing-action="hideActions"
@keyup.up="$refs.actionPreview.$el.focus()"
@keyup.down="$refs.actionRename.$el.focus()"
@keyup.down="$refs.actionPreview.$el.previousElementSibling.focus()"
/>
</li>
<li>
<media-browser-action-item-rename
v-if="canEdit"
ref="actionRename"
:on-focused="focused"
:main-action="openRenameModal"
:closing-action="hideActions"
@keyup.up="
downloadable
? $refs.actionDownload.$el.focus()
: $refs.actionDelete.$el.focus()
: $refs.actionDownload.$el.previousElementSibling.focus()
"
@keyup.down="
canEdit
? $refs.actionEdit.$el.focus()
: shareable
? $refs.actionShare.$el.focus()
: $refs.actionDelete.$el.focus()
: $refs.actionShare.$el.previousElementSibling.focus()
"
/>
</li>
Expand All @@ -70,7 +71,7 @@
:main-action="editItem"
:closing-action="hideActions"
@keyup.up="$refs.actionRename.$el.focus()"
@keyup.down="$refs.actionShare.$el.focus()"
@keyup.down="$refs.actionRename.$el.previousElementSibling.focus()"
/>
</li>
<li>
Expand All @@ -83,26 +84,27 @@
@keyup.up="
canEdit
? $refs.actionEdit.$el.focus()
: $refs.actionRename.$el.focus()
: $refs.actionEdit.$el.previousElementSibling.focus()
"
@keyup.down="$refs.actionDelete.$el.focus()"
/>
</li>
<li>
<media-browser-action-item-delete
v-if="canDelete"
ref="actionDelete"
:on-focused="focused"
:main-action="openConfirmDeleteModal"
:hide-actions="hideActions"
@keyup.up="
shareable
? $refs.actionShare.$el.focus()
: $refs.actionRename.$el.focus()
: $refs.actionShare.$el.previousElementSibling.focus()
"
@keyup.down="
previewable
? $refs.actionPreview.$el.focus()
: $refs.actionRename.$el.focus()
: $refs.actionPreview.$el.previousElementSibling.focus()
"
/>
</li>
Expand All @@ -120,7 +122,8 @@ export default {
item: { type: Object, default: () => {} },
onFocused: { type: Function, default: () => {} },
edit: { type: Function, default: () => {} },
editable: { type: Function, default: () => false },
editable: { type: Boolean, default: false },
deletable: { type: Boolean, default: false },
previewable: { type: Boolean, default: false },
downloadable: { type: Boolean, default: false },
shareable: { type: Boolean, default: false },
Expand All @@ -135,6 +138,9 @@ export default {
canEdit() {
return this.editable();
},
canDelete() {
return this.deletable();
},
},
watch: {
// eslint-disable-next-line
Expand Down Expand Up @@ -184,16 +190,18 @@ export default {
/* Open actions dropdown */
openActions() {
this.showActions = true;
if (this.previewable) {
this.$nextTick(() => this.$refs.actionPreview.$el.focus());
} else {
this.$nextTick(() => this.$refs.actionRename.$el.focus());
const buttons = [...this.$el.parentElement.querySelectorAll('.media-browser-actions-list button')];
if (buttons.length) {
buttons[0].focus();
}
},
/* Open actions dropdown and focus on last element */
openLastActions() {
this.showActions = true;
this.$nextTick(() => this.$refs.actionDelete.$el.focus());
const buttons = [...this.$el.parentElement.querySelectorAll('.media-browser-actions-list button')];
if (buttons.length) {
this.$nextTick(() => buttons[buttons.length - 1].focus());
}
},
editItem() {
this.edit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<media-browser-action-items-container
ref="container"
:focused="focused"
:deleteable="canDelete"
:item="item"
:previewable="true"
:downloadable="true"
Expand All @@ -26,6 +27,8 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemAudio',
// eslint-disable-next-line vue/require-prop-types
Expand All @@ -36,6 +39,12 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
</div>
<media-browser-action-items-container
ref="container"
:editable="canEdit"
:deletable="canDelete"
:focused="focused"
:item="item"
/>
</div>
</template>
<script>
import navigable from '../../../mixins/navigable.es6';
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemDirectory',
Expand All @@ -37,6 +40,12 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Handle the on preview double click event */
onPreviewDblClick() {
this.navigateTo(this.item.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
ref="container"
:focused="focused"
:item="item"
:edit="editItem"
:can-edit="canEdit"
:editable="canEdit"
:deletable="canDelete"
:previewable="true"
:downloadable="true"
:shareable="true"
Expand All @@ -33,6 +33,8 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemDocument',
// eslint-disable-next-line vue/require-prop-types
Expand All @@ -43,6 +45,12 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
ref="container"
:focused="focused"
:item="item"
:editable="canEdit"
:deletable="canDelete"
:previewable="true"
:downloadable="true"
:shareable="true"
Expand All @@ -30,6 +32,8 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemFile',
// eslint-disable-next-line vue/require-prop-types
Expand All @@ -40,6 +44,12 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
:item="item"
:edit="editItem"
:editable="canEdit"
:deletable="canDelete"
:previewable="true"
:downloadable="true"
:shareable="true"
Expand Down Expand Up @@ -59,7 +60,10 @@ export default {
methods: {
/* Check if the item is a document to edit */
canEdit() {
return ['jpg', 'jpeg', 'png'].includes(this.item.extension.toLowerCase());
return api.canEdit && ['jpg', 'jpeg', 'png'].includes(this.item.extension.toLowerCase());
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
ref="container"
:focused="focused"
:item="item"
:editable="canEdit"
:deletable="canDelete"
:previewable="true"
:downloadable="true"
:shareable="true"
Expand All @@ -26,6 +28,8 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemVideo',
// eslint-disable-next-line vue/require-prop-types
Expand All @@ -36,6 +40,12 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down
10 changes: 7 additions & 3 deletions administrator/components/com_media/tmpl/media/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Uri\Uri;

$app = Factory::getApplication();
$params = ComponentHelper::getParams('com_media');
$input = Factory::getApplication()->input;
$input = $app->input;

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
Expand All @@ -39,7 +40,7 @@
$mediaTypes = '&mediatypes=' . $input->getString('mediatypes', '0,1,2,3');

// Populate the media config
$config = array(
$config = [
'apiBaseUrl' => Uri::base() . 'index.php?option=com_media&format=json' . $mediaTypes,
'csrfToken' => Session::getFormToken(),
'filePath' => $params->get('file_path', 'images'),
Expand All @@ -54,7 +55,10 @@
'providers' => (array) $this->providers,
'currentPath' => $this->currentPath,
'isModal' => $tmpl === 'component',
);
'canCreate' => $app->getIdentity()->authorise('core.create', 'com_media'),
'canEdit' => $app->getIdentity()->authorise('core.edit', 'com_media'),
'canDelete' => $app->getIdentity()->authorise('core.delete', 'com_media'),
];
$this->document->addScriptOptions('com_media', $config);
?>
<div id="com-media"></div>

0 comments on commit b4fe213

Please sign in to comment.