Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

full uppercase const #39276

Merged
merged 2 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/files_external/lib/Command/Applicable.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Response::HTTP_NOT_FOUND;
}

if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAL) {
$output->writeln('<error>Can\'t change applicables on personal mounts</error>');
return self::FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/lib/Config/ConfigAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
throw new \InvalidArgumentException('Invalid object store');
}
$storage->setBackendOption('objectstore', new $objectClass($objectStore));

Check failure on line 75 in apps/files_external/lib/Config/ConfigAdapter.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-security

TaintedCallable

apps/files_external/lib/Config/ConfigAdapter.php:75:50: TaintedCallable: Detected tainted text (see https://psalm.dev/243)
}

$storage->getAuthMechanism()->manipulateStorageConfig($storage, $user);
Expand Down Expand Up @@ -140,7 +140,7 @@
}, $storages, $storageConfigs);

$mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAL) {
return new PersonalMount(
$this->userStoragesService,
$storageConfig,
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/lib/Controller/StoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function show($id, $testOnly = true) {

$data = $storage->jsonSerialize(true);
$isAdmin = $this->groupManager->isAdmin($this->userSession->getUser()->getUID());
$data['can_edit'] = $storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAl || $isAdmin;
$data['can_edit'] = $storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAL || $isAdmin;

return new DataResponse(
$data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function show($id, $testOnly = true) {

$data = $storage->jsonSerialize(true);
$isAdmin = $this->groupManager->isAdmin($this->userSession->getUser()->getUID());
$data['can_edit'] = $storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAl || $isAdmin;
$data['can_edit'] = $storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAL || $isAdmin;

return new DataResponse(
$data,
Expand Down
8 changes: 5 additions & 3 deletions apps/files_external/lib/Lib/StorageConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
*/
class StorageConfig implements \JsonSerializable {
public const MOUNT_TYPE_ADMIN = 1;
public const MOUNT_TYPE_PERSONAL = 2;
/** @deprecated use MOUNT_TYPE_PERSONAL (full uppercase) instead */
public const MOUNT_TYPE_PERSONAl = 2;
ArtificialOwl marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand Down Expand Up @@ -384,14 +386,14 @@ public function setStatus($status, $message = null) {
}

/**
* @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl
* @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
*/
public function getType() {
return $this->type;
}

/**
* @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl
* @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
*/
public function setType($type) {
$this->type = $type;
Expand Down Expand Up @@ -435,7 +437,7 @@ public function jsonSerialize(bool $obfuscate = false): array {
$result['statusMessage'] = $this->statusMessage;
}
$result['userProvided'] = $this->authMechanism instanceof IUserProvided;
$result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system';
$result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAL) ? 'personal': 'system';
return $result;
}

Expand Down
4 changes: 3 additions & 1 deletion apps/files_external/lib/Service/DBConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*/
class DBConfigService {
public const MOUNT_TYPE_ADMIN = 1;
public const MOUNT_TYPE_PERSONAL = 2;
/** @deprecated use MOUNT_TYPE_PERSONAL (full uppercase) instead */
public const MOUNT_TYPE_PERSONAl = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@icewind1991 should we merge or we keep both (DBConfigService and StorageConfig) definition ?


public const APPLICABLE_TYPE_GLOBAL = 1;
Expand Down Expand Up @@ -234,7 +236,7 @@ public function getAdminMountsForMultiple($type, array $values) {
public function getUserMountsFor($type, $value) {
$builder = $this->connection->getQueryBuilder();
$query = $this->getForQuery($builder, $type, $value);
$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT)));
$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAL, IQueryBuilder::PARAM_INT)));

return $this->getMountsFromQuery($query);
}
Expand Down
5 changes: 2 additions & 3 deletions apps/files_external/lib/Service/UserStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use OC\Files\Filesystem;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException;

use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
use OCP\IUserSession;
Expand Down Expand Up @@ -103,7 +102,7 @@
}

protected function getType() {
return DBConfigService::MOUNT_TYPE_PERSONAl;
return DBConfigService::MOUNT_TYPE_PERSONAL;
}

/**
Expand Down Expand Up @@ -144,7 +143,7 @@
}

protected function isApplicable(StorageConfig $config) {
return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl;
return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAL;

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getUID on possibly null value
}

public function removeStorage($id) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/tests/Auth/Password/GlobalAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testNoCredentialsPersonal() {
$this->credentialsManager->expects($this->never())
->method('retrieve');

$storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_PERSONAl);
$storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_PERSONAL);

$this->instance->manipulateStorageConfig($storage);
$this->assertEquals([], $storage->getBackendOptions());
Expand Down
10 changes: 5 additions & 5 deletions apps/files_external/tests/Service/DBConfigServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function testGetMountsFor() {

public function testGetAdminMounts() {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAl);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);

$mounts = $this->dbConfig->getAdminMounts();
$this->assertCount(1, $mounts);
Expand All @@ -208,7 +208,7 @@ public function testGetAdminMounts() {
public function testGetAdminMountsFor() {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAl);
$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);

$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test');
$this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test');
Expand All @@ -221,8 +221,8 @@ public function testGetAdminMountsFor() {

public function testGetUserMountsFor() {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAl);
$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAl);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);

$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test');
$this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test');
Expand Down Expand Up @@ -285,7 +285,7 @@ public function testGetMountsForDuplicateByGroup() {

public function testGetAllMounts() {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAl);
$id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);

$mounts = $this->dbConfig->getAllMounts();
$this->assertCount(2, $mounts);
Expand Down
Loading