Skip to content

Commit 39a3433

Browse files
Merge pull request #889 from nextcloud/backport/886/stable32
[stable32] fix(teamfolder): Fix mimetype detection in teamfolder trashbin
2 parents ce53004 + 41249a1 commit 39a3433

File tree

13 files changed

+452
-61
lines changed

13 files changed

+452
-61
lines changed

.github/workflows/integration.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
databases: ['sqlite', 'mysql', 'pgsql']
2828
server-versions: ['stable32']
2929
richdocuments-versions: ['stable32']
30+
groupfolders-versions: ['stable32']
3031
primary-storage: ['local', 'minio']
3132

3233
name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}-${{ matrix.primary-storage}}
@@ -79,6 +80,14 @@ jobs:
7980
repository: nextcloud/richdocuments
8081
ref: ${{ matrix.richdocuments-versions }}
8182

83+
- name: Checkout app (groupfolders)
84+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
85+
with:
86+
persist-credentials: false
87+
path: apps/groupfolders
88+
repository: nextcloud/groupfolders
89+
ref: ${{ matrix.groupfolders-versions }}
90+
8291
- name: Set up php ${{ matrix.php-versions }}
8392
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
8493
with:
@@ -104,6 +113,10 @@ jobs:
104113
working-directory: apps/richdocuments
105114
run: composer i --no-dev
106115

116+
- name: Set up dependencies (groupfolders)
117+
working-directory: apps/groupfolders
118+
run: composer i --no-dev
119+
107120
- name: Set up Nextcloud for S3 primary storage
108121
if: matrix.primary-storage == 'minio'
109122
run: |

.github/workflows/phpunit-mariadb.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
7373
mariadb-versions: ['10.6', '11.4']
7474
richdocuments-versions: ['stable32']
75+
groupfolders-versions: ['stable32']
7576

7677
name: MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
7778

@@ -113,6 +114,14 @@ jobs:
113114
repository: nextcloud/richdocuments
114115
ref: ${{ matrix.richdocuments-versions }}
115116

117+
- name: Checkout app (groupfolders)
118+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
119+
with:
120+
persist-credentials: false
121+
path: apps/groupfolders
122+
repository: nextcloud/groupfolders
123+
ref: ${{ matrix.groupfolders-versions }}
124+
116125
- name: Set up php ${{ matrix.php-versions }}
117126
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
118127
with:
@@ -149,6 +158,10 @@ jobs:
149158
working-directory: apps/richdocuments
150159
run: composer i --no-dev
151160

161+
- name: Set up dependencies (groupfolders)
162+
working-directory: apps/groupfolders
163+
run: composer i --no-dev
164+
152165
- name: Set up Nextcloud
153166
env:
154167
DB_PORT: 4444

.github/workflows/phpunit-mysql.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
id: versions
3333
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1
3434
with:
35-
matrix: '{"mysql-versions": ["8.4"], "richdocuments-versions": ["stable32"]}'
35+
matrix: '{"mysql-versions": ["8.4"], "richdocuments-versions": ["stable32"], "groupfolders-versions": ["stable32"]}'
3636

3737
changes:
3838
runs-on: ubuntu-latest-low
@@ -110,6 +110,14 @@ jobs:
110110
repository: nextcloud/richdocuments
111111
ref: ${{ matrix.richdocuments-versions }}
112112

113+
- name: Checkout app (groupfolders)
114+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
115+
with:
116+
persist-credentials: false
117+
path: apps/groupfolders
118+
repository: nextcloud/groupfolders
119+
ref: ${{ matrix.groupfolders-versions }}
120+
113121
- name: Set up php ${{ matrix.php-versions }}
114122
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
115123
with:
@@ -146,6 +154,10 @@ jobs:
146154
working-directory: apps/richdocuments
147155
run: composer i --no-dev
148156

157+
- name: Set up dependencies (groupfolders)
158+
working-directory: apps/groupfolders
159+
run: composer i --no-dev
160+
149161
- name: Set up Nextcloud
150162
env:
151163
DB_PORT: 4444

.github/workflows/phpunit-oci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
7272
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
7373
richdocuments-versions: ['stable32']
74+
groupfolders-versions: ['stable32']
7475
oci-versions: ['18', '21', '23']
7576

7677
name: OCI ${{ matrix.oci-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
@@ -123,6 +124,14 @@ jobs:
123124
repository: nextcloud/richdocuments
124125
ref: ${{ matrix.richdocuments-versions }}
125126

127+
- name: Checkout app (groupfolders)
128+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
129+
with:
130+
persist-credentials: false
131+
path: apps/groupfolders
132+
repository: nextcloud/groupfolders
133+
ref: ${{ matrix.groupfolders-versions }}
134+
126135
- name: Set up php ${{ matrix.php-versions }}
127136
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
128137
with:
@@ -154,6 +163,10 @@ jobs:
154163
working-directory: apps/richdocuments
155164
run: composer i --no-dev
156165

166+
- name: Set up dependencies (groupfolders)
167+
working-directory: apps/groupfolders
168+
run: composer i --no-dev
169+
157170
- name: Set up Nextcloud
158171
env:
159172
DB_PORT: 1521

.github/workflows/phpunit-pgsql.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
7272
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
7373
richdocuments-versions: ['stable32']
74+
groupfolders-versions: ['stable32']
7475

7576
name: PostgreSQL PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
7677

@@ -114,6 +115,14 @@ jobs:
114115
repository: nextcloud/richdocuments
115116
ref: ${{ matrix.richdocuments-versions }}
116117

118+
- name: Checkout app (groupfolders)
119+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
120+
with:
121+
persist-credentials: false
122+
path: apps/groupfolders
123+
repository: nextcloud/groupfolders
124+
ref: ${{ matrix.groupfolders-versions }}
125+
117126
- name: Set up php ${{ matrix.php-versions }}
118127
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
119128
with:
@@ -145,6 +154,10 @@ jobs:
145154
working-directory: apps/richdocuments
146155
run: composer i --no-dev
147156

157+
- name: Set up dependencies (groupfolders)
158+
working-directory: apps/groupfolders
159+
run: composer i --no-dev
160+
148161
- name: Set up Nextcloud
149162
env:
150163
DB_PORT: 4444

.github/workflows/phpunit-sqlite.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
7272
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
7373
richdocuments-versions: ['stable32']
74+
groupfolders-versions: ['stable32']
7475

7576
name: SQLite PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
7677

@@ -103,6 +104,14 @@ jobs:
103104
repository: nextcloud/richdocuments
104105
ref: ${{ matrix.richdocuments-versions }}
105106

107+
- name: Checkout app (groupfolders)
108+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
109+
with:
110+
persist-credentials: false
111+
path: apps/groupfolders
112+
repository: nextcloud/groupfolders
113+
ref: ${{ matrix.groupfolders-versions }}
114+
106115
- name: Set up php ${{ matrix.php-versions }}
107116
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
108117
with:
@@ -134,6 +143,10 @@ jobs:
134143
working-directory: apps/richdocuments
135144
run: composer i --no-dev
136145

146+
- name: Set up dependencies (groupfolders)
147+
working-directory: apps/groupfolders
148+
run: composer i --no-dev
149+
137150
- name: Set up Nextcloud
138151
env:
139152
DB_PORT: 4444

lib/Operation.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OC\Files\FileInfo;
1313
use OC\Files\Node\Folder;
1414
use OC\Files\View;
15+
use OCA\GroupFolders\Mount\GroupMountPoint;
1516
use OCA\WorkflowEngine\Entity\File;
1617
use OCP\EventDispatcher\Event;
1718
use OCP\Files\Cache\ICacheEntry;
@@ -62,7 +63,7 @@ public function checkFileAccess(string $path, IMountPoint $mountPoint, bool $isD
6263

6364
$this->nestingLevel++;
6465

65-
$filePath = $this->translatePath($storage, $path);
66+
$filePath = $this->translatePath($mountPoint, $storage, $path);
6667
$ruleMatcher = $this->manager->getRuleMatcher();
6768
$ruleMatcher->setFileInfo($storage, $filePath, $isDir);
6869
$node = $this->getNode($path, $mountPoint, $cacheEntry);
@@ -119,8 +120,31 @@ protected function isBlockablePath(IMountPoint $mountPoint, string $path): bool
119120
/**
120121
* For thumbnails and versions we want to check the tags of the original file
121122
*/
122-
protected function translatePath(IStorage $storage, string $path): string {
123-
if (substr_count($path, '/') < 1) {
123+
protected function translatePath(IMountPoint $mountPoint, IStorage $storage, string $path): string {
124+
if ($mountPoint instanceof GroupMountPoint) {
125+
/**
126+
* Case | Mount point path | Path ($path)
127+
* --------+---------------------------------------+--------------------------------
128+
* Files | /user/files/$folderName/ | Subfolder/File.txt
129+
* Trash | /user/files_trashbin/groupfolder/$id/ | Subfolder/File.txt.v{timestamp}
130+
* Version | /user/files_versions/groupfolder/$id/ | Subfolder/File.txt.d{timestamp}
131+
*/
132+
$mountPath = $mountPoint->getMountPoint();
133+
if (substr_count($mountPath, '/') >= 3) {
134+
[,, $folder] = explode('/', $mountPath);
135+
if ($folder === 'files_versions' && preg_match('/.+\.v\d{10}$/', basename($path))) {
136+
// Remove trailing ".v{timestamp}"
137+
return substr($path, 0, -12);
138+
}
139+
if ($folder === 'files_trashbin' && preg_match('/.+\.d\d{10}$/', basename($path))) {
140+
// Remove trailing ".d{timestamp}"
141+
return substr($path, 0, -12);
142+
}
143+
}
144+
return $path;
145+
}
146+
147+
if (substr_count($path, '/') === 0) {
124148
return $path;
125149
}
126150

@@ -138,7 +162,7 @@ protected function translatePath(IStorage $storage, string $path): string {
138162
// 'versions', 'path/to/file.txt'
139163
$segments = explode('/', $innerPath, 2);
140164
if (isset($segments[1])) {
141-
$innerPath = $segments[1];
165+
[$folder, $innerPath] = $segments;
142166
}
143167

144168
if (preg_match('/.+\.d\d{10}$/', basename($innerPath))) {
@@ -176,6 +200,10 @@ protected function isCreatingSkeletonFiles(): bool {
176200
&& isset($step['function']) && $step['function'] === 'tryLogin') {
177201
return true;
178202
}
203+
if (isset($step['class']) && $step['class'] === \OCA\GroupFolders\Trash\TrashBackend::class
204+
&& isset($step['function']) && $step['function'] === 'setupTrashFolder') {
205+
return true;
206+
}
179207
}
180208

181209
return false;

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<file name="tests/stubs/oc_files_cache_wrapper_cachewrapper.php" />
3232
<file name="tests/stubs/oc_files_storage_wrapper_wrapper.php" />
3333
<file name="tests/stubs/oc_files_storage_wrapper_jail.php" />
34+
<file name="tests/stubs/oca_groupfolders.php" />
3435
</stubs>
3536
</psalm>

0 commit comments

Comments
 (0)