diff --git a/src/app/Http/Controllers/RelationController.php b/src/app/Http/Controllers/RelationController.php --- a/src/app/Http/Controllers/RelationController.php +++ b/src/app/Http/Controllers/RelationController.php @@ -106,6 +106,21 @@ } } + $with_imap = \config('app.with_imap'); + $with_ldap = \config('app.with_ldap'); + + $state['isReady'] = (!$with_imap || !isset($state['isImapReady']) || $state['isImapReady']) + && (!$with_ldap || !isset($state['isLdapReady']) || $state['isLdapReady']) + && (!isset($state['isVerified']) || $state['isVerified']) + && (!isset($state['isConfirmed']) || $state['isConfirmed']); + + if (!$with_imap) { + unset($state['isImapReady']); + } + if (!$with_ldap) { + unset($state['isLdapReady']); + } + if (empty($state['isDeleted']) && method_exists($resource, 'trashed')) { $state['isDeleted'] = $resource->trashed(); } diff --git a/src/resources/js/app.js b/src/resources/js/app.js --- a/src/resources/js/app.js +++ b/src/resources/js/app.js @@ -296,7 +296,7 @@ return 'text-warning' } - if (obj.isImapReady === false || obj.isLdapReady === false || obj.isVerified === false || obj.isConfirmed === false) { + if (!obj.isReady) { return 'text-danger' } @@ -315,7 +315,7 @@ return this.$t('status.suspended') } - if (obj.isImapReady === false || obj.isLdapReady === false || obj.isVerified === false || obj.isConfirmed === false) { + if (!obj.isReady) { return this.$t('status.notready') } diff --git a/src/tests/Feature/Controller/DomainsTest.php b/src/tests/Feature/Controller/DomainsTest.php --- a/src/tests/Feature/Controller/DomainsTest.php +++ b/src/tests/Feature/Controller/DomainsTest.php @@ -210,7 +210,12 @@ $this->assertArrayHasKey('isVerified', $json['list'][0]); $this->assertArrayHasKey('isSuspended', $json['list'][0]); $this->assertArrayHasKey('isActive', $json['list'][0]); - $this->assertArrayHasKey('isLdapReady', $json['list'][0]); + if (\config('app.with_ldap')) { + $this->assertArrayHasKey('isLdapReady', $json['list'][0]); + } else { + $this->assertArrayNotHasKey('isLdapReady', $json['list'][0]); + } + $this->assertArrayHasKey('isReady', $json['list'][0]); $response = $this->actingAs($ned)->get("api/v4/domains"); $response->assertStatus(200); @@ -346,7 +351,12 @@ $this->assertArrayHasKey('isVerified', $json); $this->assertArrayHasKey('isSuspended', $json); $this->assertArrayHasKey('isActive', $json); - $this->assertArrayHasKey('isLdapReady', $json); + if (\config('app.with_ldap')) { + $this->assertArrayHasKey('isLdapReady', $json); + } else { + $this->assertArrayNotHasKey('isLdapReady', $json); + } + $this->assertArrayHasKey('isReady', $json); $this->assertCount(1, $json['skus']); $this->assertSame(1, $json['skus'][$sku_domain->id]['count']); $this->assertSame([0], $json['skus'][$sku_domain->id]['costs']); diff --git a/src/tests/Feature/Controller/UsersTest.php b/src/tests/Feature/Controller/UsersTest.php --- a/src/tests/Feature/Controller/UsersTest.php +++ b/src/tests/Feature/Controller/UsersTest.php @@ -228,8 +228,13 @@ $this->assertArrayHasKey('isAccountDegraded', $json['list'][0]); $this->assertArrayHasKey('isSuspended', $json['list'][0]); $this->assertArrayHasKey('isActive', $json['list'][0]); - $this->assertArrayHasKey('isLdapReady', $json['list'][0]); - $this->assertArrayHasKey('isImapReady', $json['list'][0]); + $this->assertArrayHasKey('isReady', $json['list'][0]); + if (\config('app.with_ldap')) { + $this->assertArrayHasKey('isLdapReady', $json['list'][0]); + } + if (\config('app.with_imap')) { + $this->assertArrayHasKey('isImapReady', $json['list'][0]); + } $response = $this->actingAs($ned)->get("/api/v4/users"); $response->assertStatus(200); @@ -307,8 +312,13 @@ $this->assertArrayHasKey('isAccountDegraded', $json); $this->assertArrayHasKey('isSuspended', $json); $this->assertArrayHasKey('isActive', $json); - $this->assertArrayHasKey('isLdapReady', $json); - $this->assertArrayHasKey('isImapReady', $json); + $this->assertArrayHasKey('isReady', $json); + if (\config('app.with_ldap')) { + $this->assertArrayHasKey('isLdapReady', $json); + } + if (\config('app.with_imap')) { + $this->assertArrayHasKey('isImapReady', $json); + } $john = $this->getTestUser('john@kolab.org'); $jack = $this->getTestUser('jack@kolab.org'); @@ -471,10 +481,9 @@ $response = $this->actingAs($jack)->get("/api/v4/users/{$john->id}/status"); $response->assertStatus(403); - if ($john->isImapReady()) { - $john->status ^= User::STATUS_IMAP_READY; - $john->save(); - } + $john->status &= ~User::STATUS_IMAP_READY; + $john->status &= ~User::STATUS_LDAP_READY; + $john->save(); // Get user status $response = $this->actingAs($john)->get("/api/v4/users/{$john->id}/status"); @@ -482,14 +491,20 @@ $json = $response->json(); - $this->assertFalse($json['isImapReady']); $this->assertFalse($json['isReady']); + + if (\config('app.with_ldap')) { + $this->assertFalse($json['isLdapReady']); + } else { + $this->assertArrayNotHasKey('isLdapReady', $json); + } + if (\config('app.with_imap')) { - $this->assertCount(6, $json['process']); + $this->assertFalse($json['isImapReady']); $this->assertSame('user-imap-ready', $json['process'][2]['label']); - $this->assertSame(false, $json['process'][2]['state']); + $this->assertFalse($json['process'][2]['state']); } else { - $this->assertCount(7, $json['process']); + $this->assertArrayNotHasKey('isImapReady', $json); } $this->assertTrue(empty($json['status'])); $this->assertTrue(empty($json['message'])); @@ -507,13 +522,11 @@ $json = $response->json(); $this->assertFalse($json['isImapReady']); + $this->assertFalse($json['isLdapReady']); $this->assertFalse($json['isReady']); if (\config('app.with_imap')) { - $this->assertCount(7, $json['process']); $this->assertSame('user-imap-ready', $json['process'][2]['label']); $this->assertSame(false, $json['process'][2]['state']); - } else { - $this->assertCount(6, $json['process']); } $this->assertSame('success', $json['status']); $this->assertSame('Setup process has been pushed. Please wait.', $json['message']);