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

Make Applications visible by default in the app navigation bar #1250

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Have a good time and manage whatever you want.
<nextcloud min-version="27" max-version="30"/>
</dependencies>
<repair-steps>
<pre-migration>
<step>OCA\Tables\Migration\FixContextsDefaults</step>
</pre-migration>
<post-migration>
<step>OCA\Tables\Migration\NewDbStructureRepairStep</step>
<step>OCA\Tables\Migration\DbRowSleeveSequence</step>
Expand Down
34 changes: 30 additions & 4 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ public function indexTableShares(int $tableId): DataResponse {
* @param bool $permissionUpdate Permission if receiver can update data
* @param bool $permissionDelete Permission if receiver can delete data
* @param bool $permissionManage Permission if receiver can manage node
* @param int $displayMode context shares only, whether it should appear in nav bar. 0: no, 1: recipients, 2: all
* @param int $displayMode context shares only, whether it should appear in nav bar. 0: no, 1: recipients, 2: all (default). Cf. Application::NAV_ENTRY_MODE_*.
* @psalm-param int<0, 2> $displayMode
* @return DataResponse<Http::STATUS_OK, TablesShare, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: Share returned
Expand All @@ -536,10 +537,22 @@ public function createShare(
bool $permissionUpdate = false,
bool $permissionDelete = false,
bool $permissionManage = false,
int $displayMode = 0,
int $displayMode = 2,
): DataResponse {
try {
return new DataResponse($this->shareService->create($nodeId, $nodeType, $receiver, $receiverType, $permissionRead, $permissionCreate, $permissionUpdate, $permissionDelete, $permissionManage, $displayMode)->jsonSerialize());
return new DataResponse(
$this->shareService->create(
$nodeId,
$nodeType,
$receiver,
$receiverType,
$permissionRead,
$permissionCreate,
$permissionUpdate,
$permissionDelete,
$permissionManage,
$displayMode
)->jsonSerialize());
} catch (PermissionError $e) {
$this->logger->warning('A permission error occurred: '.$e->getMessage());
$message = ['message' => $e->getMessage()];
Expand Down Expand Up @@ -1401,7 +1414,20 @@ public function importInView(int $viewId, string $path, bool $createMissingColum
#[RequirePermission(permission: Application::PERMISSION_MANAGE, type: Application::NODE_TYPE_TABLE, idParam: 'tableId')]
public function createTableShare(int $tableId, string $receiver, string $receiverType, bool $permissionRead, bool $permissionCreate, bool $permissionUpdate, bool $permissionDelete, bool $permissionManage): DataResponse {
try {
return new DataResponse($this->shareService->create($tableId, 'table', $receiver, $receiverType, $permissionRead, $permissionCreate, $permissionUpdate, $permissionDelete, $permissionManage, 0)->jsonSerialize());
return new DataResponse(
$this->shareService->create(
$tableId,
'table',
$receiver,
$receiverType,
$permissionRead,
$permissionCreate,
$permissionUpdate,
$permissionDelete,
$permissionManage,
Application::NAV_ENTRY_MODE_ALL
Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW it is not really applicable here (table share…), but have the same default may lead to less confusion in the future us's.

)->jsonSerialize()
);
} catch (PermissionError $e) {
$this->logger->warning('A permission error occurred: '.$e->getMessage());
$message = ['message' => $e->getMessage()];
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function create(
bool $permissionUpdate = false,
bool $permissionDelete = false,
bool $permissionManage = false,
int $displayMode = 0,
int $displayMode = Application::NAV_ENTRY_MODE_ALL,
): DataResponse {
return $this->handleError(function () use ($nodeId, $nodeType, $receiver, $receiverType, $permissionRead, $permissionCreate, $permissionUpdate, $permissionDelete, $permissionManage, $displayMode) {
return $this->service->create($nodeId, $nodeType, $receiver, $receiverType, $permissionRead, $permissionCreate, $permissionUpdate, $permissionDelete, $permissionManage, $displayMode);
Expand Down
46 changes: 46 additions & 0 deletions lib/Migration/FixContextsDefaults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types = 1);

namespace OCA\Tables\Migration;

use OCA\Tables\AppInfo\Application;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class FixContextsDefaults implements IRepairStep {

public function __construct(
protected IConfig $config,
protected IDBConnection $dbc,
) {
}

/**
* @inheritDoc
*/
public function getName() {
return 'Fix navigation bar default of existing contexts to show for all';
}

/**
* @inheritDoc
*/
public function run(IOutput $output) {
$appVersion = $this->config->getAppValue(Application::APP_ID, 'installed_version', '0.0');
if (\version_compare($appVersion, '0.8.0-beta.1', '>')) {
$output->info('Not applicable, skipping.');
return;
}

$qb = $this->dbc->getQueryBuilder();
$qb->update('tables_contexts_navigation')
->set('display_mode', $qb->createNamedParameter(Application::NAV_ENTRY_MODE_ALL, IQueryBuilder::PARAM_INT))
->where($qb->expr()->eq('display_mode', $qb->createNamedParameter(Application::NAV_ENTRY_MODE_HIDDEN, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter('', IQueryBuilder::PARAM_STR)))
->executeStatement();
}
}
6 changes: 4 additions & 2 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2496,8 +2496,10 @@
"displayMode": {
"type": "integer",
"format": "int64",
"default": 0,
"description": "context shares only, whether it should appear in nav bar. 0: no, 1: recipients, 2: all"
"default": 2,
"description": "context shares only, whether it should appear in nav bar. 0: no, 1: recipients, 2: all (default). Cf. Application::NAV_ENTRY_MODE_*.",
"minimum": 0,
"maximum": 2
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1903,8 +1903,8 @@ export interface operations {
readonly permissionManage?: boolean;
/**
* Format: int64
* @description context shares only, whether it should appear in nav bar. 0: no, 1: recipients, 2: all
* @default 0
* @description context shares only, whether it should appear in nav bar. 0: no, 1: recipients, 2: all (default). Cf. Application::NAV_ENTRY_MODE_*.
* @default 2
*/
readonly displayMode?: number;
};
Expand Down
Loading