Page MenuHomePhorge

D5205.1775412044.diff
No OneTemporary

Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None

D5205.1775412044.diff

diff --git a/src/app/Http/Controllers/API/V4/ConfigController.php b/src/app/Http/Controllers/API/V4/ConfigController.php
new file mode 100644
--- /dev/null
+++ b/src/app/Http/Controllers/API/V4/ConfigController.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace App\Http\Controllers\API\V4;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Http\Request;
+
+class ConfigController extends Controller
+{
+ /**
+ * Get the per-user webmail configuration.
+ *
+ * @return \Illuminate\Http\JsonResponse The response
+ */
+ public function webmail(Request $request)
+ {
+ $user = $this->guard()->user();
+
+ if (!$this->checkTenant($user)) {
+ return $this->errorResponse(404);
+ }
+
+ $config = [
+ 'plugins' => [],
+ ];
+
+ $skus = $user->skuTitles();
+
+ if (in_array('activesync', $skus)) {
+ $config['plugins'][] = 'kolab_activesync';
+ }
+
+ if (in_array('2fa', $skus)) {
+ $config['plugins'][] = 'kolab_2fa';
+ }
+
+ if (in_array('groupware', $skus)) {
+ $config['plugins'][] = 'calendar';
+ $config['plugins'][] = 'kolab_files';
+ $config['plugins'][] = 'kolab_addressbook';
+ $config['plugins'][] = 'kolab_tags';
+ // $config['plugins'][] = 'kolab_notes';
+ $config['plugins'][] = 'tasklist';
+ } else {
+ // disable groupware plugins in case they are enabled by default
+ $config['calendar_disabled'] = true;
+ $config['kolab_files_disabled'] = true;
+ // $config['kolab_addressbook_disabled'] = true;
+ // $config['kolab_notes_disabled'] = true;
+ $config['kolab_tags_disabled'] = true;
+ $config['tasklist_disabled'] = true;
+ }
+
+ return response()->json($config);
+ }
+}
diff --git a/src/app/Http/Controllers/API/V4/UsersController.php b/src/app/Http/Controllers/API/V4/UsersController.php
--- a/src/app/Http/Controllers/API/V4/UsersController.php
+++ b/src/app/Http/Controllers/API/V4/UsersController.php
@@ -229,14 +229,7 @@
$plan = $isController ? $wallet->plan() : null;
$allSkus = Sku::withObjectTenantContext($user)->pluck('title')->all();
-
- // Get user's entitlements titles
- $skus = $user->entitlements()->distinct()
- ->join('skus', 'skus.id', '=', 'entitlements.sku_id')
- ->pluck('title')
- ->sort()
- ->values()
- ->all();
+ $skus = $user->skuTitles();
$hasBeta = in_array('beta', $skus) || !in_array('beta', $allSkus);
$hasMeet = !$isDegraded && \config('app.with_meet') && in_array('room', $allSkus);
diff --git a/src/app/Traits/EntitleableTrait.php b/src/app/Traits/EntitleableTrait.php
--- a/src/app/Traits/EntitleableTrait.php
+++ b/src/app/Traits/EntitleableTrait.php
@@ -266,6 +266,21 @@
return Sku::withObjectTenantContext($this)->where('title', $title)->first();
}
+ /**
+ * Get all SKU titles for this object.
+ *
+ * @return array<string>
+ */
+ public function skuTitles(): array
+ {
+ return $this->entitlements()->distinct()
+ ->join('skus', 'skus.id', '=', 'entitlements.sku_id')
+ ->pluck('title')
+ ->sort()
+ ->values()
+ ->all();
+ }
+
/**
* Returns entitleable object title (e.g. email or domain name).
*
diff --git a/src/routes/api.php b/src/routes/api.php
--- a/src/routes/api.php
+++ b/src/routes/api.php
@@ -117,6 +117,8 @@
// to prevent an attacker from pairing a new device with a stolen token.
Route::get('companions/{id}/pairing', [API\V4\CompanionAppsController::class, 'pairing']);
+ Route::get('config/webmail', [API\V4\ConfigController::class, 'webmail']);
+
Route::apiResource('domains', API\V4\DomainsController::class);
Route::get('domains/{id}/confirm', [API\V4\DomainsController::class, 'confirm']);
Route::get('domains/{id}/skus', [API\V4\DomainsController::class, 'skus']);
diff --git a/src/tests/Feature/Controller/ConfigTest.php b/src/tests/Feature/Controller/ConfigTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Controller/ConfigTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Tests\Feature\Controller;
+
+use Tests\TestCase;
+
+class ConfigTest extends TestCase
+{
+ /**
+ * Test webmail configuration (GET /api/v4/config/webmail)
+ */
+ public function testWebmail(): void
+ {
+ $john = $this->getTestUser('john@kolab.org');
+ $joe = $this->getTestUser('joe@kolab.org');
+ $ned = $this->getTestUser('ned@kolab.org');
+
+ $response = $this->get('api/v4/config/webmail');
+ $response->assertStatus(401);
+
+ $response = $this->actingAs($john)->get('api/v4/config/webmail');
+ $response->assertStatus(200);
+
+ $json = $response->json();
+
+ $this->assertContains('kolab_files', $json['plugins']);
+ $this->assertContains('kolab_tags', $json['plugins']);
+ $this->assertContains('calendar', $json['plugins']);
+ $this->assertContains('tasklist', $json['plugins']);
+
+ $response = $this->actingAs($ned)->get('api/v4/config/webmail');
+ $response->assertStatus(200);
+
+ $json = $response->json();
+
+ $this->assertContains('kolab_2fa', $json['plugins']);
+ $this->assertContains('kolab_activesync', $json['plugins']);
+ $this->assertContains('kolab_files', $json['plugins']);
+ $this->assertContains('kolab_tags', $json['plugins']);
+ $this->assertContains('calendar', $json['plugins']);
+ $this->assertContains('tasklist', $json['plugins']);
+
+ $response = $this->actingAs($joe)->get('api/v4/config/webmail');
+ $response->assertStatus(200);
+
+ $json = $response->json();
+
+ $this->assertSame([], $json['plugins']);
+ $this->assertSame(true, $json['calendar_disabled']);
+ $this->assertSame(true, $json['kolab_files_disabled']);
+ $this->assertSame(true, $json['kolab_tags_disabled']);
+ $this->assertSame(true, $json['tasklist_disabled']);
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 5, 6:00 PM (36 m, 58 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18834096
Default Alt Text
D5205.1775412044.diff (6 KB)

Event Timeline