Skip to content

Commit

Permalink
Merge pull request #48880 from nextcloud/backport/48749/stable27
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Oct 31, 2024
2 parents fa6001d + 31be95e commit e7fa59a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
22 changes: 21 additions & 1 deletion apps/files_external/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,25 @@ StorageConfig.prototype = {
* @param {Function} [options.error] error callback
*/
save: function(options) {
var self = this;
var url = OC.generateUrl(this._url);
var method = 'POST';
if (_.isNumber(this.id)) {
method = 'PUT';
url = OC.generateUrl(this._url + '/{id}', {id: this.id});
}

window.OC.PasswordConfirmation.requirePasswordConfirmation(() => this._save(method, url, options), options.error);
},

/**
* Private implementation of the save function (called after potential password confirmation)
* @param {string} method
* @param {string} url
* @param {{success: Function, error: Function}} options
*/
_save: function(method, url, options) {
self = this;

$.ajax({
type: method,
url: url,
Expand Down Expand Up @@ -352,6 +363,15 @@ StorageConfig.prototype = {
}
return;
}

window.OC.PasswordConfirmation.requirePasswordConfirmation(() => this._destroy(options), options.error)
},

/**
* Private implementation of the DELETE method called after password confirmation
* @param {{ success: Function, error: Function }} options
*/
_destroy: function(options) {
$.ajax({
type: 'DELETE',
url: OC.generateUrl(this._url + '/{id}', {id: this.id}),
Expand Down
15 changes: 8 additions & 7 deletions apps/files_external/lib/Controller/UserStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IGroupManager;
Expand Down Expand Up @@ -120,9 +122,9 @@ public function show($id, $testOnly = true) {
* @param array $mountOptions backend-specific mount options
*
* @return DataResponse
*
* @NoAdminRequired
*/
#[NoAdminRequired]
#[PasswordConfirmationRequired]
public function create(
$mountPoint,
$backend,
Expand Down Expand Up @@ -176,9 +178,9 @@ public function create(
* @param bool $testOnly whether to storage should only test the connection or do more things
*
* @return DataResponse
*
* @NoAdminRequired
*/
#[NoAdminRequired]
#[PasswordConfirmationRequired]
public function update(
$id,
$mountPoint,
Expand Down Expand Up @@ -226,11 +228,10 @@ public function update(

/**
* Delete storage
*
* @NoAdminRequired
*
* {@inheritdoc}
*/
#[NoAdminRequired]
#[PasswordConfirmationRequired]
public function destroy($id) {
return parent::destroy($id);
}
Expand Down
13 changes: 12 additions & 1 deletion apps/files_external/tests/js/settingsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ describe('OCA.Files_External.Settings tests', function() {
var clock;
var select2Stub;
var select2ApplicableUsers;
var passwordConfirmationStub;

beforeEach(function() {
beforeAll(() => {
clock = sinon.useFakeTimers();
passwordConfirmationStub = sinon.stub(window.OC.PasswordConfirmation, 'requirePasswordConfirmation');
passwordConfirmationStub.callsArg(0);
})

beforeEach(function() {
passwordConfirmationStub.resetHistory()
select2ApplicableUsers = [];
select2Stub = sinon.stub($.fn, 'select2').callsFake(function(args) {
if (args === 'val') {
Expand Down Expand Up @@ -236,6 +243,8 @@ describe('OCA.Files_External.Settings tests', function() {
var $saveButton = $tr.find('td.save .icon-checkmark');
$saveButton.click();

sinon.assert.calledOnce(passwordConfirmationStub);

expect(fakeServer.requests.length).toEqual(1);
var request = fakeServer.requests[0];
expect(request.url).toEqual(OC.getRootPath() + '/index.php/apps/files_external/globalstorages');
Expand Down Expand Up @@ -270,6 +279,8 @@ describe('OCA.Files_External.Settings tests', function() {
var $saveButton = $tr.find('td.save .icon-checkmark');
$saveButton.click();

sinon.assert.calledOnce(passwordConfirmationStub);

expect(fakeServer.requests.length).toEqual(1);
var request = fakeServer.requests[0];
expect(request.url).toEqual(OC.getRootPath() + '/index.php/apps/files_external/globalstorages');
Expand Down

0 comments on commit e7fa59a

Please sign in to comment.