Skip to content

Commit

Permalink
Merge pull request #232 from nextcloud/backport/231/stable27
Browse files Browse the repository at this point in the history
[stable27] groupfolder for 27
  • Loading branch information
ArtificialOwl authored Jul 28, 2023
2 parents b906ea9 + bb5f8df commit 93fa180
Show file tree
Hide file tree
Showing 9 changed files with 458 additions and 72 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/lint-info-xml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization

name: Lint
name: Lint info.xml

on:
pull_request:
Expand All @@ -16,20 +16,24 @@ on:
permissions:
contents: read

concurrency:
group: lint-info-xml-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
xml-linters:
runs-on: ubuntu-latest

name: info.xml lint
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Download schema
run: wget https://raw.githubusercontent.com/nextcloud/appstore/master/nextcloudappstore/api/v1/release/info.xsd

- name: Lint info.xml
uses: ChristophWurst/xmllint-action@v1
uses: ChristophWurst/xmllint-action@39155a91429af431d65fafc21fa52ba5c4f5cb71 # v1.1
with:
xml-file: ./appinfo/info.xml
xml-schema-file: ./info.xsd
2 changes: 1 addition & 1 deletion .github/workflows/lint-php-cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: "8.0"
coverage: none

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ["7.4", "8.0", "8.1"]
php-versions: ["8.0", "8.1"]

name: php-lint

Expand Down
100 changes: 33 additions & 67 deletions lib/Service/GroupFoldersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);


/**
* Files_FullTextSearch - Index the content of your files
*
Expand All @@ -28,105 +27,67 @@
*
*/


namespace OCA\Files_FullTextSearch\Service;

use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger;
use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Files_FullTextSearch\AppInfo\Application;
use OCA\Files_FullTextSearch\Exceptions\FileIsNotIndexableException;
use OCA\Files_FullTextSearch\Exceptions\GroupFolderNotFoundException;
use OCA\Files_FullTextSearch\Exceptions\KnownFileSourceException;
use OCA\Files_FullTextSearch\Model\FilesDocument;
use OCA\Files_FullTextSearch\Model\MountPoint;
use OCA\Files_FullTextSearch\Tools\Traits\TArrayTools;
use OCA\GroupFolders\Folder\FolderManager;
use OCP\App\IAppManager;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\Node;
use OCP\FullTextSearch\Model\IIndex;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;

/**
* Class GroupFoldersService
*
* @package OCA\Files_FullTextSearch\Service
*/
class GroupFoldersService {
use TNC22Logger;
use TArrayTools;


/** @var IManager */
private $shareManager;

/** @var IGroupManager */
private $groupManager;

/** @var FolderManager */
private $folderManager;

/** @var LocalFilesService */
private $localFilesService;

/** @var ConfigService */
private $configService;

/** @var MiscService */
private $miscService;


private ?FolderManager $folderManager = null;
/** @var MountPoint[] */
private $groupFolders = [];

private array $groupFolders = [];

/**
* GroupFoldersService constructor.
*
* @param string $userId
* @param IDBConnection $dbConnection
* @param IAppManager $appManager
* @param IManager $shareManager
* @param IGroupManager $groupManager
* @param LocalFilesService $localFilesService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
IDBConnection $dbConnection, IAppManager $appManager, IManager $shareManager,
IGroupManager $groupManager, LocalFilesService $localFilesService,
ConfigService $configService, MiscService $miscService
IDBConnection $dbConnection,
IAppManager $appManager,
IMimeTypeLoader $mimeTypeLoader,
private IGroupManager $groupManager,
private LocalFilesService $localFilesService,
ConfigService $configService,
private LoggerInterface $logger
) {
if ($configService->getAppValue(ConfigService::FILES_GROUP_FOLDERS) === '1'
&& $appManager->isEnabledForUser('groupfolders')) {
try {
$this->folderManager = new FolderManager($dbConnection);
$this->folderManager = new FolderManager(
$dbConnection,
$groupManager,
$mimeTypeLoader,
$logger
);
} catch (Exception $e) {
return;
}
}

$this->shareManager = $shareManager;
$this->groupManager = $groupManager;
$this->localFilesService = $localFilesService;
$this->configService = $configService;
$this->miscService = $miscService;
$this->setup('app', Application::APP_ID);
}


/**
* @param string $userId
*/
public function initGroupSharesForUser(string $userId) {
public function initGroupSharesForUser(string $userId): void {
if ($this->folderManager === null) {
return;
}

$this->debug('initGroupSharesForUser request', ['userId' => $userId]);
$this->logger->debug('initGroupSharesForUser request', ['userId' => $userId]);
$this->groupFolders = $this->getMountPoints($userId);
$this->debug('initGroupSharesForUser result', ['groupFolders' => $this->groupFolders]);
$this->logger->debug('initGroupSharesForUser result', ['groupFolders' => $this->groupFolders]);
}


Expand All @@ -136,7 +97,7 @@ public function initGroupSharesForUser(string $userId) {
*
* @throws KnownFileSourceException
*/
public function getFileSource(Node $file, string &$source) {
public function getFileSource(Node $file, string &$source): void {
if ($file->getMountPoint()
->getMountType() !== 'group'
|| $this->folderManager === null) {
Expand All @@ -158,7 +119,7 @@ public function getFileSource(Node $file, string &$source) {
* @param FilesDocument $document
* @param Node $file
*/
public function updateDocumentAccess(FilesDocument &$document, Node $file) {
public function updateDocumentAccess(FilesDocument $document, Node $file): void {
if ($document->getSource() !== ConfigService::FILES_GROUP_FOLDERS) {
return;
}
Expand All @@ -169,9 +130,14 @@ public function updateDocumentAccess(FilesDocument &$document, Node $file) {
return;
}


$access = $document->getAccess();
$access->addGroups($mount->getGroups());
foreach ($mount->getGroups() as $group) {
if ($this->groupManager->get($group) === null) {
$access->addCircle($group);
} else {
$access->addGroup($group);
}
}

$document->getIndex()
->addOptionInt('group_folder_id', $mount->getId());
Expand All @@ -183,7 +149,7 @@ public function updateDocumentAccess(FilesDocument &$document, Node $file) {
* @param FilesDocument $document
* @param array $users
*/
public function getShareUsers(FilesDocument $document, array &$users) {
public function getShareUsers(FilesDocument $document, array &$users): void {
if ($document->getSource() !== ConfigService::FILES_GROUP_FOLDERS) {
return;
}
Expand All @@ -200,7 +166,7 @@ public function getShareUsers(FilesDocument $document, array &$users) {
*/
private function getMountPoint(Node $file): MountPoint {
foreach ($this->groupFolders as $mount) {
if (strpos($file->getPath(), $mount->getPath()) === 0) {
if (str_starts_with($file->getPath(), $mount->getPath())) {
return $mount;
}
}
Expand Down Expand Up @@ -233,7 +199,7 @@ private function getMountPoints(string $userId): array {
/**
* @param IIndex $index
*/
public function impersonateOwner(IIndex $index) {
public function impersonateOwner(IIndex $index): void {
if ($index->getSource() !== ConfigService::FILES_GROUP_FOLDERS) {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/Tools/Exceptions/ArrayNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace OCA\Files_FullTextSearch\Tools\Exceptions;

use Exception;

class ArrayNotFoundException extends Exception {
}
10 changes: 10 additions & 0 deletions lib/Tools/Exceptions/ItemNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace OCA\Files_FullTextSearch\Tools\Exceptions;

use Exception;

class ItemNotFoundException extends Exception {
}
10 changes: 10 additions & 0 deletions lib/Tools/Exceptions/MalformedArrayException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace OCA\Files_FullTextSearch\Tools\Exceptions;

use Exception;

class MalformedArrayException extends Exception {
}
10 changes: 10 additions & 0 deletions lib/Tools/Exceptions/UnknownTypeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace OCA\Files_FullTextSearch\Tools\Exceptions;

use Exception;

class UnknownTypeException extends Exception {
}
Loading

0 comments on commit 93fa180

Please sign in to comment.