Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
- fix psalm errors

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian Steffens committed Sep 12, 2023
1 parent cea1d3a commit ba5ba99
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/Db/TableMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function search(string $term = null, ?string $userId = null, ?int $limit

// get table ids, that are shared with the given user
// only makes sense if a user is given, otherwise will always get all shares doubled
if ($userId !== null && $userId !== '') {
if ($userId) {
$shareQueryTablesSharedViaUser->selectDistinct('node_id')
->from('tables_shares')
->andWhere($qb->expr()->eq('node_type', $qb->createNamedParameter('table', IQueryBuilder::PARAM_STR)))
Expand All @@ -94,7 +94,7 @@ public function search(string $term = null, ?string $userId = null, ?int $limit
$qb->select('*')
->from($this->table);

if ($userId !== null && $userId !== '') {
if ($userId) {
$qb->andWhere($qb->expr()->eq('ownership', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)));
$qb->orWhere($shareQueryTablesSharedViaUser->expr()->in('id', $qb->createFunction($shareQueryTablesSharedViaUser->getSQL()), IQueryBuilder::PARAM_INT_ARRAY));
if($userGroups) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/ViewMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function search(string $term = null, ?string $userId = null, ?int $limit

// get view ids, that are shared with the given user
// only makes sense if a user is given, otherwise will always get all shares doubled
if ($userId !== null && $userId !== '') {
if ($userId) {
$shareQueryViewsSharedViaUser->selectDistinct('node_id')
->from('tables_shares')
->andWhere($qb->expr()->eq('node_type', $qb->createNamedParameter('view', IQueryBuilder::PARAM_STR)))
Expand All @@ -108,7 +108,7 @@ public function search(string $term = null, ?string $userId = null, ?int $limit
->from($this->table, 'v')
->leftJoin('v', 'tables_tables', 't', 't.id = v.table_id');

if ($userId !== null && $userId !== '') {
if ($userId) {
$qb->where($qb->expr()->eq('ownership', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)))
->orWhere($shareQueryViewsSharedViaUser->expr()->in('v.id', $qb->createFunction($shareQueryViewsSharedViaUser->getSQL()), IQueryBuilder::PARAM_INT_ARRAY));
if($userGroups) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Helper/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace OCA\Tables\Helper;

use OC\Group\Group;
use OCA\Tables\Errors\InternalError;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
Expand Down Expand Up @@ -43,7 +43,7 @@ private function getUser(string $userId): IUser {

/**
* @param string $userId
* @return Group[]
* @return IGroup[]
* @throws InternalError
*/
public function getGroupsForUser(string $userId): array {
Expand Down
6 changes: 3 additions & 3 deletions lib/Search/SearchTablesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$appIconUrl,
$table->getEmoji() .' '. $table->getTitle(),
($table->getOwnerDisplayName() ?? $table->getOwnership()) . ', ' . $this->l10n->n('%n row', '%n rows', $table->getRowsCount()).', '.$this->l10n->t('table'),
$this->getInternalLink('table', $table->getId()),
$this->getInternalLink($table->getId(), 'table'),
'',
false
);
Expand All @@ -123,7 +123,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$viewIconUrl,
$view->getEmoji() .' '. $view->getTitle(),
($view->getOwnerDisplayName() ?? $view->getOwnership()) . ', ' . $this->l10n->n('%n row', '%n rows', $view->getRowsCount()).', '.$this->l10n->t('table view'),
$this->getInternalLink('view', $view->getId()),
$this->getInternalLink($view->getId(), 'view'),
'',
false
);
Expand All @@ -141,7 +141,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
* @param int $nodeId
* @return string
*/
protected function getInternalLink(string $nodeType = 'table', int $nodeId): string {
protected function getInternalLink(int $nodeId, string $nodeType = 'table'): string {
$allowedNodeTypes = ['table', 'view'];
if(in_array($nodeType, $allowedNodeTypes)) {
return $this->urlGenerator->linkToRouteAbsolute(Application::APP_ID . '.page.index')
Expand Down
7 changes: 7 additions & 0 deletions lib/Service/PermissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ public function getSharedPermissionsIfSharedWithMe(int $elementId, ?string $elem

// private methods ==========================================================================

/**
* @param mixed $element
* @param string $nodeType
* @param string $permission
* @param string|null $userId
* @return bool
*/
private function checkPermission($element, string $nodeType, string $permission, ?string $userId = null): bool {
if($this->basisCheck($element, $nodeType, $userId)) {
return true;
Expand Down

0 comments on commit ba5ba99

Please sign in to comment.