mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-67795 contentbank: delete content UI
- Loading branch information
Showing
6 changed files
with
283 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,162 @@ | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Module to manage content bank actions, such as delete or rename. | ||
* | ||
* @module core_contentbank/actions | ||
* @package core_contentbank | ||
* @copyright 2020 Sara Arjona <sara@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
define([ | ||
'jquery', | ||
'core/ajax', | ||
'core/notification', | ||
'core/str', | ||
'core/templates', | ||
'core/url', | ||
'core/modal_factory', | ||
'core/modal_events'], | ||
function($, Ajax, Notification, Str, Templates, Url, ModalFactory, ModalEvents) { | ||
|
||
/** | ||
* List of action selectors. | ||
* | ||
* @type {{DELETE_CONTENT: string}} | ||
*/ | ||
var ACTIONS = { | ||
DELETE_CONTENT: '[data-action="deletecontent"]', | ||
}; | ||
|
||
/** | ||
* Actions class. | ||
*/ | ||
var Actions = function() { | ||
this.registerEvents(); | ||
}; | ||
|
||
/** | ||
* Register event listeners. | ||
*/ | ||
Actions.prototype.registerEvents = function() { | ||
$(ACTIONS.DELETE_CONTENT).click(function(e) { | ||
e.preventDefault(); | ||
|
||
var contentname = $(this).data('contentname'); | ||
var contentid = $(this).data('contentid'); | ||
var contextid = $(this).data('contextid'); | ||
|
||
var strings = [ | ||
{ | ||
key: 'deletecontent', | ||
component: 'core_contentbank' | ||
}, | ||
{ | ||
key: 'deletecontentconfirm', | ||
component: 'core_contentbank', | ||
param: { | ||
name: contentname, | ||
} | ||
}, | ||
{ | ||
key: 'delete', | ||
component: 'core' | ||
}, | ||
]; | ||
|
||
var deleteButtonText = ''; | ||
Str.get_strings(strings).then(function(langStrings) { | ||
var modalTitle = langStrings[0]; | ||
var modalContent = langStrings[1]; | ||
deleteButtonText = langStrings[2]; | ||
|
||
return ModalFactory.create({ | ||
title: modalTitle, | ||
body: modalContent, | ||
type: ModalFactory.types.SAVE_CANCEL, | ||
large: true | ||
}); | ||
}).done(function(modal) { | ||
modal.setSaveButtonText(deleteButtonText); | ||
modal.getRoot().on(ModalEvents.save, function() { | ||
// The action is now confirmed, sending an action for it. | ||
return deleteContent(contentid, contextid); | ||
}); | ||
|
||
// Handle hidden event. | ||
modal.getRoot().on(ModalEvents.hidden, function() { | ||
// Destroy when hidden. | ||
modal.destroy(); | ||
}); | ||
|
||
// Show the modal. | ||
modal.show(); | ||
|
||
return; | ||
}).catch(Notification.exception); | ||
}); | ||
}; | ||
|
||
/** | ||
* Delete content from the content bank. | ||
* | ||
* @param {int} contentid The content to delete. | ||
* @param {int} contextid The contextid where the content belongs. | ||
*/ | ||
function deleteContent(contentid, contextid) { | ||
var request = { | ||
methodname: 'core_contentbank_delete_content', | ||
args: { | ||
contentids: {contentid} | ||
} | ||
}; | ||
|
||
var requestType = 'success'; | ||
Ajax.call([request])[0].then(function(data) { | ||
if (data.result) { | ||
return Str.get_string('contentdeleted', 'core_contentbank'); | ||
} | ||
requestType = 'error'; | ||
return Str.get_string('contentnotdeleted', 'core_contentbank'); | ||
|
||
}).done(function(message) { | ||
var params = { | ||
contextid: contextid | ||
}; | ||
if (requestType == 'success') { | ||
params.statusmsg = message; | ||
} else { | ||
params.errormsg = message; | ||
} | ||
// Redirect to the main content bank page and display the message as a notification. | ||
window.location.href = Url.relativeUrl('contentbank/index.php', params, false); | ||
}).fail(Notification.exception); | ||
} | ||
|
||
return /** @alias module:core_contentbank/actions */ { | ||
// Public variables and functions. | ||
|
||
/** | ||
* Initialise the contentbank actions. | ||
* | ||
* @method init | ||
* @return {Actions} | ||
*/ | ||
'init': function() { | ||
return new Actions(); | ||
} | ||
}; | ||
}); |
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,70 @@ | ||
@core @core_contentbank @contentbank_h5p @_file_upload @javascript | ||
Feature: Delete H5P file from the content bank | ||
In order remove H5P content from the content bank | ||
As an admin | ||
I need to be able to delete any H5P content from the content bank | ||
|
||
Background: | ||
Given I log in as "admin" | ||
And I follow "Manage private files..." | ||
And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager | ||
And I click on "Save changes" "button" | ||
And I click on "Content bank" "link" | ||
And I click on "Upload" "link" | ||
And I click on "Choose a file..." "button" | ||
And I click on "Private files" "link" in the ".fp-repo-area" "css_element" | ||
And I click on "filltheblanks.h5p" "link" | ||
And I click on "Select this file" "button" | ||
And I click on "Save changes" "button" | ||
|
||
Scenario: Admins can delete content from the content bank | ||
Given I click on "Content bank" "link" | ||
And I wait until the page is ready | ||
And I should see "filltheblanks.h5p" | ||
When I follow "filltheblanks.h5p" | ||
And I open the action menu in "region-main-settings-menu" "region" | ||
Then I should see "Delete" | ||
And I choose "Delete" in the open action menu | ||
And I should see "Are you sure you want to delete content 'filltheblanks.h5p'?" | ||
And I click on "Cancel" "button" in the "Delete content" "dialogue" | ||
And I should see "filltheblanks.h5p" | ||
And I open the action menu in "region-main-settings-menu" "region" | ||
And I choose "Delete" in the open action menu | ||
And I click on "Delete" "button" in the "Delete content" "dialogue" | ||
And I wait until the page is ready | ||
And I should see "The content has been deleted." | ||
And I should not see "filltheblanks.h5p" | ||
|
||
Scenario: Users without the required capability can only delete their own content | ||
Given the following "permission overrides" exist: | ||
| capability | permission | role | contextlevel | reference | | ||
| moodle/contentbank:deleteanycontent | Prohibit | manager | System | | | ||
And the following "users" exist: | ||
| username | firstname | lastname | email | | ||
| manager | Max | Manager | man@example.com | | ||
And the following "role assigns" exist: | ||
| user | role | contextlevel | reference | | ||
| manager | manager | System | | | ||
And I log out | ||
When I log in as "manager" | ||
And I click on "Content bank" "link" | ||
And I wait until the page is ready | ||
And I should see "filltheblanks.h5p" | ||
And I follow "filltheblanks.h5p" | ||
Then ".header-actions-container" "css_element" should not exist | ||
And I click on "Private files" "link" | ||
And I upload "h5p/tests/fixtures/find-the-words.h5p" file to "Files" filemanager | ||
And I click on "Save changes" "button" | ||
And I click on "Content bank" "link" | ||
And I click on "Upload" "link" | ||
And I click on "Choose a file..." "button" | ||
And I click on "Private files" "link" in the ".fp-repo-area" "css_element" | ||
And I click on "find-the-words.h5p" "link" | ||
And I click on "Select this file" "button" | ||
And I click on "Save changes" "button" | ||
And I wait until the page is ready | ||
And I should see "filltheblanks.h5p" | ||
And I should see "find-the-words.h5p" | ||
When I follow "find-the-words.h5p" | ||
And I open the action menu in "region-main-settings-menu" "region" | ||
Then I should see "Delete" |
Oops, something went wrong.