aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/dav/lib/SystemTag/SystemTagsObjectMappingCollection.php2
-rw-r--r--apps/systemtags/appinfo/routes.php28
-rw-r--r--apps/systemtags/js/admin.js6
-rw-r--r--apps/systemtags/js/systemtagsfilelist.js35
-rw-r--r--apps/systemtags/lib/Activity/Listener.php32
-rw-r--r--apps/systemtags/lib/Controller/LastUsedController.php59
-rw-r--r--core/css/systemtags.css19
-rw-r--r--core/js/systemtags/systemtagsinputfield.js31
-rw-r--r--settings/Controller/UsersController.php2
-rw-r--r--settings/ajax/disableapp.php7
-rw-r--r--settings/ajax/enableapp.php7
-rw-r--r--settings/ajax/installapp.php7
-rw-r--r--settings/ajax/uninstallapp.php7
-rw-r--r--settings/js/apps.js10
-rw-r--r--tests/Settings/Controller/UsersControllerTest.php33
15 files changed, 277 insertions, 8 deletions
diff --git a/apps/dav/lib/SystemTag/SystemTagsObjectMappingCollection.php b/apps/dav/lib/SystemTag/SystemTagsObjectMappingCollection.php
index ab0b7734258..124ed6184c1 100644
--- a/apps/dav/lib/SystemTag/SystemTagsObjectMappingCollection.php
+++ b/apps/dav/lib/SystemTag/SystemTagsObjectMappingCollection.php
@@ -192,7 +192,7 @@ class SystemTagsObjectMappingCollection implements ICollection {
*
* @param ISystemTag $tag
*
- * @return SystemTagNode
+ * @return SystemTagMappingNode
*/
private function makeNode(ISystemTag $tag) {
return new SystemTagMappingNode(
diff --git a/apps/systemtags/appinfo/routes.php b/apps/systemtags/appinfo/routes.php
new file mode 100644
index 00000000000..f39c6cdc49c
--- /dev/null
+++ b/apps/systemtags/appinfo/routes.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016, Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+return [
+ 'routes' => [
+ ['name' => 'LastUsed#getLastUsedTagIds', 'url' => '/lastused', 'verb' => 'GET'],
+ ]
+];
diff --git a/apps/systemtags/js/admin.js b/apps/systemtags/js/admin.js
index ed21f82f3ba..1388d5b2d7c 100644
--- a/apps/systemtags/js/admin.js
+++ b/apps/systemtags/js/admin.js
@@ -153,6 +153,12 @@
},
escapeMarkup: function(m) {
return m;
+ },
+ sortResults: function(results) {
+ results.sort(function(a, b) {
+ return OC.Util.naturalSortCompare(a.get('name'), b.get('name'));
+ });
+ return results;
}
}
};
diff --git a/apps/systemtags/js/systemtagsfilelist.js b/apps/systemtags/js/systemtagsfilelist.js
index 25f377785b7..c2a6f09fd9e 100644
--- a/apps/systemtags/js/systemtagsfilelist.js
+++ b/apps/systemtags/js/systemtagsfilelist.js
@@ -35,6 +35,7 @@
* @type Array.<string>
*/
_systemTagIds: [],
+ _lastUsedTags: [],
_clientSideSort: true,
_allowSelection: false,
@@ -58,6 +59,7 @@
var $controls = this.$el.find('#controls').empty();
+ _.defer(_.bind(this._getLastUsedTags, this));
this._initFilterField($controls);
},
@@ -67,7 +69,19 @@
OCA.Files.FileList.prototype.destroy.apply(this, arguments);
},
+ _getLastUsedTags: function() {
+ var self = this;
+ $.ajax({
+ type: 'GET',
+ url: OC.generateUrl('/apps/systemtags/lastused'),
+ success: function (response) {
+ self._lastUsedTags = response;
+ }
+ });
+ },
+
_initFilterField: function($container) {
+ var self = this;
this.$filterField = $('<input type="hidden" name="tags"/>');
$container.append(this.$filterField);
this.$filterField.select2({
@@ -112,6 +126,27 @@
return OC.SystemTags.getDescriptiveTag(tag)[0].outerHTML;
},
+ sortResults: function(results) {
+ results.sort(function(a, b) {
+ var aLastUsed = self._lastUsedTags.indexOf(a.id);
+ var bLastUsed = self._lastUsedTags.indexOf(b.id);
+
+ if (aLastUsed !== bLastUsed) {
+ if (bLastUsed === -1) {
+ return -1;
+ }
+ if (aLastUsed === -1) {
+ return 1;
+ }
+ return aLastUsed < bLastUsed ? -1 : 1;
+ }
+
+ // Both not found
+ return OC.Util.naturalSortCompare(a.name, b.name);
+ });
+ return results;
+ },
+
escapeMarkup: function(m) {
// prevent double markup escape
return m;
diff --git a/apps/systemtags/lib/Activity/Listener.php b/apps/systemtags/lib/Activity/Listener.php
index dbddf3c38bc..152608f7cce 100644
--- a/apps/systemtags/lib/Activity/Listener.php
+++ b/apps/systemtags/lib/Activity/Listener.php
@@ -28,6 +28,7 @@ use OCP\App\IAppManager;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
+use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
@@ -46,6 +47,8 @@ class Listener {
protected $activityManager;
/** @var IUserSession */
protected $session;
+ /** @var IConfig */
+ protected $config;
/** @var \OCP\SystemTag\ISystemTagManager */
protected $tagManager;
/** @var \OCP\App\IAppManager */
@@ -61,6 +64,7 @@ class Listener {
* @param IGroupManager $groupManager
* @param IManager $activityManager
* @param IUserSession $session
+ * @param IConfig $config
* @param ISystemTagManager $tagManager
* @param IAppManager $appManager
* @param IMountProviderCollection $mountCollection
@@ -69,6 +73,7 @@ class Listener {
public function __construct(IGroupManager $groupManager,
IManager $activityManager,
IUserSession $session,
+ IConfig $config,
ISystemTagManager $tagManager,
IAppManager $appManager,
IMountProviderCollection $mountCollection,
@@ -76,6 +81,7 @@ class Listener {
$this->groupManager = $groupManager;
$this->activityManager = $activityManager;
$this->session = $session;
+ $this->config = $config;
$this->tagManager = $tagManager;
$this->appManager = $appManager;
$this->mountCollection = $mountCollection;
@@ -126,6 +132,11 @@ class Listener {
$this->activityManager->publish($activity);
}
}
+
+
+ if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) {
+ $this->updateLastUsedTags($actor, $event->getTag());
+ }
}
/**
@@ -213,6 +224,27 @@ class Listener {
$this->activityManager->publish($activity);
}
}
+
+ if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) {
+ foreach ($tags as $tag) {
+ $this->updateLastUsedTags($actor, $tag);
+ }
+ }
+ }
+
+ /**
+ * @param string $actor
+ * @param ISystemTag $tag
+ */
+ protected function updateLastUsedTags($actor, ISystemTag $tag) {
+ $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]');
+ $lastUsedTags = json_decode($lastUsedTags, true);
+
+ array_unshift($lastUsedTags, $tag->getId());
+ array_unique($lastUsedTags);
+ $lastUsedTags = array_slice($lastUsedTags, 0, 10);
+
+ $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags));
}
/**
diff --git a/apps/systemtags/lib/Controller/LastUsedController.php b/apps/systemtags/lib/Controller/LastUsedController.php
new file mode 100644
index 00000000000..cbd149d75fb
--- /dev/null
+++ b/apps/systemtags/lib/Controller/LastUsedController.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\SystemTags\Controller;
+
+
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\IConfig;
+use OCP\IRequest;
+use OCP\IUserSession;
+
+class LastUsedController extends Controller {
+
+ /** @var IConfig */
+ protected $config;
+
+ /** @var IUserSession */
+ protected $userSession;
+
+ /**
+ * @param string $appName
+ * @param IRequest $request
+ * @param IConfig $config
+ * @param IUserSession $userSession
+ */
+ public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) {
+ parent::__construct($appName, $request);
+ $this->config = $config;
+ $this->userSession = $userSession;
+ }
+
+ /**
+ * @NoAdminRequired
+ */
+ public function getLastUsedTagIds() {
+ $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]');
+ $tagIds = json_decode($lastUsed, true);
+ return new DataResponse(array_map(function($id) { return (string) $id; }, $tagIds));
+ }
+}
diff --git a/core/css/systemtags.css b/core/css/systemtags.css
index d26f07bae8c..30c3808b51c 100644
--- a/core/css/systemtags.css
+++ b/core/css/systemtags.css
@@ -10,6 +10,9 @@
.systemtags-select2-dropdown .select2-result-label .checkmark {
visibility: hidden;
+ margin-left: -5px;
+ margin-right: 5px;
+ padding: 4px;
}
.systemtags-select2-dropdown .select2-result-label .new-item .systemtags-actions {
@@ -42,6 +45,22 @@
width: 100%;
}
+#select2-drop.systemtags-select2-dropdown .select2-results li.select2-result {
+ padding: 5px;
+}
+
+.systemtags-select2-dropdown span {
+ line-height: 25px;
+}
+
+.systemtags-select2-dropdown .systemtags-item {
+ display: inline-block;
+ height: 25px;
+}
+
+.systemtags-select2-dropdown .select2-result-label {
+ height: 25px;
+}
.systemtags-select2-container .select2-choices .select2-search-choice.select2-locked .label {
opacity: 0.5;
diff --git a/core/js/systemtags/systemtagsinputfield.js b/core/js/systemtags/systemtagsinputfield.js
index 5d986d17290..690525c0ebb 100644
--- a/core/js/systemtags/systemtagsinputfield.js
+++ b/core/js/systemtags/systemtagsinputfield.js
@@ -57,6 +57,8 @@
_newTag: null,
+ _lastUsedTags: [],
+
className: 'systemTagsInputFieldContainer',
template: function(data) {
@@ -97,6 +99,8 @@
_.defer(self._refreshSelection);
});
+ _.defer(_.bind(this._getLastUsedTags, this));
+
_.bindAll(
this,
'_refreshSelection',
@@ -108,6 +112,17 @@
);
},
+ _getLastUsedTags: function() {
+ var self = this;
+ $.ajax({
+ type: 'GET',
+ url: OC.generateUrl('/apps/systemtags/lastused'),
+ success: function (response) {
+ self._lastUsedTags = response;
+ }
+ });
+ },
+
/**
* Refreshes the selection, triggering a call to
* select2's initSelection
@@ -211,6 +226,7 @@
}, {
success: function(model) {
self._addToSelect2Selection(model.toJSON());
+ self._lastUsedTags.unshift(model.id);
self.trigger('select', model);
},
error: function(model, xhr) {
@@ -238,6 +254,7 @@
return false;
} else {
tag = this.collection.get(e.object.id);
+ this._lastUsedTags.unshift(tag.id);
}
this._newTag = null;
this.trigger('select', tag);
@@ -400,6 +417,20 @@
var aSelected = selectedItems.indexOf(a.id) >= 0;
var bSelected = selectedItems.indexOf(b.id) >= 0;
if (aSelected === bSelected) {
+ var aLastUsed = self._lastUsedTags.indexOf(a.id);
+ var bLastUsed = self._lastUsedTags.indexOf(b.id);
+
+ if (aLastUsed !== bLastUsed) {
+ if (bLastUsed === -1) {
+ return -1;
+ }
+ if (aLastUsed === -1) {
+ return 1;
+ }
+ return aLastUsed < bLastUsed ? -1 : 1;
+ }
+
+ // Both not found
return OC.Util.naturalSortCompare(a.name, b.name);
}
if (aSelected && !bSelected) {
diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php
index 20440e6d395..28b8d2648d9 100644
--- a/settings/Controller/UsersController.php
+++ b/settings/Controller/UsersController.php
@@ -605,6 +605,7 @@ class UsersController extends Controller {
// keep the user back-end up-to-date with the latest display name and email
// address
$oldDisplayName = $user->getDisplayName();
+ $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
&& $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
) {
@@ -615,6 +616,7 @@ class UsersController extends Controller {
}
$oldEmailAddress = $user->getEMailAddress();
+ $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
&& $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
) {
diff --git a/settings/ajax/disableapp.php b/settings/ajax/disableapp.php
index 1a000672e6e..8edd1c1453e 100644
--- a/settings/ajax/disableapp.php
+++ b/settings/ajax/disableapp.php
@@ -24,6 +24,13 @@
OCP\JSON::checkAdminUser();
OCP\JSON::callCheck();
+$lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
+if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
+ $l = \OC::$server->getL10N('core');
+ OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
+ exit();
+}
+
if (!array_key_exists('appid', $_POST)) {
OC_JSON::error();
exit;
diff --git a/settings/ajax/enableapp.php b/settings/ajax/enableapp.php
index cf1b7f29db5..b6d62671a63 100644
--- a/settings/ajax/enableapp.php
+++ b/settings/ajax/enableapp.php
@@ -28,6 +28,13 @@
OC_JSON::checkAdminUser();
OCP\JSON::callCheck();
+$lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
+if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
+ $l = \OC::$server->getL10N('core');
+ OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
+ exit();
+}
+
$groups = isset($_POST['groups']) ? (array)$_POST['groups'] : null;
try {
diff --git a/settings/ajax/installapp.php b/settings/ajax/installapp.php
index 75f3fea83b7..17e5eadf50e 100644
--- a/settings/ajax/installapp.php
+++ b/settings/ajax/installapp.php
@@ -24,6 +24,13 @@
OCP\JSON::checkAdminUser();
OCP\JSON::callCheck();
+$lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
+if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
+ $l = \OC::$server->getL10N('core');
+ OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
+ exit();
+}
+
if (!array_key_exists('appid', $_POST)) {
OC_JSON::error();
exit;
diff --git a/settings/ajax/uninstallapp.php b/settings/ajax/uninstallapp.php
index be8196f4b33..0e68a893ef4 100644
--- a/settings/ajax/uninstallapp.php
+++ b/settings/ajax/uninstallapp.php
@@ -24,6 +24,13 @@
OCP\JSON::checkAdminUser();
OCP\JSON::callCheck();
+$lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
+if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
+ $l = \OC::$server->getL10N('core');
+ OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
+ exit();
+}
+
if (!array_key_exists('appid', $_POST)) {
OC_JSON::error();
exit;
diff --git a/settings/js/apps.js b/settings/js/apps.js
index b52fb3d11ab..de35cd53672 100644
--- a/settings/js/apps.js
+++ b/settings/js/apps.js
@@ -262,6 +262,11 @@ OC.Settings.Apps = OC.Settings.Apps || {
},
enableApp:function(appId, active, element, groups) {
+ if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
+ OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableApp, this, appId, active, element, groups));
+ return;
+ }
+
var self = this;
OC.Settings.Apps.hideErrorMessage(appId);
groups = groups || [];
@@ -402,6 +407,11 @@ OC.Settings.Apps = OC.Settings.Apps || {
},
uninstallApp:function(appId, element) {
+ if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
+ OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.uninstallApp, this, appId, element));
+ return;
+ }
+
OC.Settings.Apps.hideErrorMessage(appId);
element.val(t('settings','Uninstalling ....'));
$.post(OC.filePath('settings','ajax','uninstallapp.php'),{appid:appId},function(result) {
diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php
index 69082a7929c..b85667740f7 100644
--- a/tests/Settings/Controller/UsersControllerTest.php
+++ b/tests/Settings/Controller/UsersControllerTest.php
@@ -2107,20 +2107,22 @@ class UsersControllerTest extends \Test\TestCase {
$user->method('getEMailAddress')->willReturn($oldEmailAddress);
$user->method('canChangeDisplayName')->willReturn(true);
- if ($data[AccountManager::PROPERTY_EMAIL]['value'] !== $oldEmailAddress) {
+ if ($data[AccountManager::PROPERTY_EMAIL]['value'] === $oldEmailAddress ||
+ $oldEmailAddress === null && $data[AccountManager::PROPERTY_EMAIL]['value'] === '') {
+ $user->expects($this->never())->method('setEMailAddress');
+ } else {
$user->expects($this->once())->method('setEMailAddress')
->with($data[AccountManager::PROPERTY_EMAIL]['value'])
->willReturn(true);
- } else {
- $user->expects($this->never())->method('setEMailAddress');
}
- if ($data[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $oldDisplayName) {
+ if ($data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ||
+ $oldDisplayName === null && $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === '') {
+ $user->expects($this->never())->method('setDisplayName');
+ } else {
$user->expects($this->once())->method('setDisplayName')
->with($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
->willReturn(true);
- } else {
- $user->expects($this->never())->method('setDisplayName');
}
$this->accountManager->expects($this->once())->method('updateUser')
@@ -2162,7 +2164,23 @@ class UsersControllerTest extends \Test\TestCase {
],
'john@example.com',
'john New doe'
- ]
+ ],
+ [
+ [
+ AccountManager::PROPERTY_EMAIL => ['value' => ''],
+ AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ null,
+ 'john New doe'
+ ],
+ [
+ [
+ AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
+ AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
+ ],
+ 'john@example.com',
+ null
+ ],
];
}
@@ -2274,6 +2292,7 @@ class UsersControllerTest extends \Test\TestCase {
->with(
$this->equalTo($mailAddress)
);
+ $user->method('getEMailAddress')->willReturn('oldEmailAddress');
$this->mailer
->expects($this->any())
->method('validateMailAddress')