Add interface INamedToken
Remove $token instanceof DefaultToken || $token instanceof PublicKeyToken Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
parent
db49e0fdae
commit
34e849d702
4 changed files with 47 additions and 7 deletions
|
@ -30,7 +30,6 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method void setId(int $id)
|
||||
* @method void setUid(string $uid);
|
||||
* @method void setLoginName(string $loginname)
|
||||
* @method void setName(string $name)
|
||||
* @method string getToken()
|
||||
* @method void setType(int $type)
|
||||
* @method int getType()
|
||||
|
@ -39,7 +38,7 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method int getLastActivity()
|
||||
* @method void setVersion(int $version)
|
||||
*/
|
||||
class DefaultToken extends Entity implements IToken {
|
||||
class DefaultToken extends Entity implements INamedToken {
|
||||
|
||||
const VERSION = 1;
|
||||
|
||||
|
@ -179,6 +178,10 @@ class DefaultToken extends Entity implements IToken {
|
|||
return parent::getName();
|
||||
}
|
||||
|
||||
public function setName(string $name): void {
|
||||
parent::setName($name);
|
||||
}
|
||||
|
||||
public function getRemember(): int {
|
||||
return parent::getRemember();
|
||||
}
|
||||
|
|
34
lib/private/Authentication/Token/INamedToken.php
Normal file
34
lib/private/Authentication/Token/INamedToken.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2019, Daniel Kesselberg (mail@danielkesselberg.de)
|
||||
*
|
||||
* @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 OC\Authentication\Token;
|
||||
|
||||
|
||||
interface INamedToken extends IToken {
|
||||
/**
|
||||
* Set token name
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name): void;
|
||||
}
|
|
@ -31,7 +31,6 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method void setId(int $id)
|
||||
* @method void setUid(string $uid);
|
||||
* @method void setLoginName(string $loginname)
|
||||
* @method void setName(string $name)
|
||||
* @method string getToken()
|
||||
* @method void setType(int $type)
|
||||
* @method int getType()
|
||||
|
@ -45,7 +44,7 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method void setVersion(int $version)
|
||||
* @method bool getPasswordInvalid()
|
||||
*/
|
||||
class PublicKeyToken extends Entity implements IToken {
|
||||
class PublicKeyToken extends Entity implements INamedToken {
|
||||
|
||||
const VERSION = 2;
|
||||
|
||||
|
@ -197,6 +196,10 @@ class PublicKeyToken extends Entity implements IToken {
|
|||
return parent::getName();
|
||||
}
|
||||
|
||||
public function setName(string $name): void {
|
||||
parent::setName($name);
|
||||
}
|
||||
|
||||
public function getRemember(): int {
|
||||
return parent::getRemember();
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ use BadMethodCallException;
|
|||
use OC\AppFramework\Http;
|
||||
use OC\Authentication\Exceptions\InvalidTokenException;
|
||||
use OC\Authentication\Exceptions\PasswordlessTokenException;
|
||||
use OC\Authentication\Token\DefaultToken;
|
||||
use OC\Authentication\Token\INamedToken;
|
||||
use OC\Authentication\Token\IProvider;
|
||||
use OC\Authentication\Token\IToken;
|
||||
use OC\Settings\Activity\Provider;
|
||||
|
@ -115,7 +115,7 @@ class AuthSettingsController extends Controller {
|
|||
return array_map(function (IToken $token) use ($sessionToken) {
|
||||
$data = $token->jsonSerialize();
|
||||
$data['canDelete'] = true;
|
||||
$data['canRename'] = $token instanceof DefaultToken || $token instanceof PublicKeyToken;
|
||||
$data['canRename'] = $token instanceof INamedToken;
|
||||
if ($sessionToken->getId() === $token->getId()) {
|
||||
$data['canDelete'] = false;
|
||||
$data['canRename'] = false;
|
||||
|
@ -231,7 +231,7 @@ class AuthSettingsController extends Controller {
|
|||
]);
|
||||
|
||||
|
||||
if ($token instanceof DefaultToken || $token instanceof PublicKeyToken) {
|
||||
if ($token instanceof INamedToken) {
|
||||
$token->setName($name);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue