diff --git a/src/app/Http/Controllers/API/V4/Admin/GroupsController.php b/src/app/Http/Controllers/API/V4/Admin/GroupsController.php new file mode 100644 --- /dev/null +++ b/src/app/Http/Controllers/API/V4/Admin/GroupsController.php @@ -0,0 +1,118 @@ +input('search')); + $owner = trim(request()->input('owner')); + $result = collect([]); + + if ($owner) { + if ($owner = User::find($owner)) { + foreach ($owner->wallets as $wallet) { + $wallet->entitlements()->where('entitleable_type', Group::class)->get() + ->each(function ($entitlement) use ($result) { + $result->push($entitlement->entitleable); + }); + } + + $result = $result->sortBy('namespace')->values(); + } + } elseif (!empty($search)) { + if ($group = Group::where('email', $search)->first()) { + $result->push($group); + } + } + + // Process the result + $result = $result->map(function ($group) { + $data = [ + 'id' => $group->id, + 'email' => $group->email, + ]; + + $data = array_merge($data, self::groupStatuses($group)); + return $data; + }); + + $result = [ + 'list' => $result, + 'count' => count($result), + 'message' => \trans('app.search-foundxdistlists', ['x' => count($result)]), + ]; + + return response()->json($result); + } + + /** + * Create a new group. + * + * @param \Illuminate\Http\Request $request The API request. + * + * @return \Illuminate\Http\JsonResponse The response + */ + public function store(Request $request) + { + return $this->errorResponse(404); + } + + /** + * Suspend a group + * + * @param \Illuminate\Http\Request $request The API request. + * @param string $id Group identifier + * + * @return \Illuminate\Http\JsonResponse The response + */ + public function suspend(Request $request, $id) + { + $group = Group::find($id); + + if (empty($group)) { + return $this->errorResponse(404); + } + + $group->suspend(); + + return response()->json([ + 'status' => 'success', + 'message' => __('app.distlist-suspend-success'), + ]); + } + + /** + * Un-Suspend a group + * + * @param \Illuminate\Http\Request $request The API request. + * @param string $id Group identifier + * + * @return \Illuminate\Http\JsonResponse The response + */ + public function unsuspend(Request $request, $id) + { + $group = Group::find($id); + + if (empty($group)) { + return $this->errorResponse(404); + } + + $group->unsuspend(); + + return response()->json([ + 'status' => 'success', + 'message' => __('app.distlist-unsuspend-success'), + ]); + } +} diff --git a/src/app/Http/Controllers/API/V4/Admin/UsersController.php b/src/app/Http/Controllers/API/V4/Admin/UsersController.php --- a/src/app/Http/Controllers/API/V4/Admin/UsersController.php +++ b/src/app/Http/Controllers/API/V4/Admin/UsersController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\API\V4\Admin; use App\Domain; +use App\Group; use App\Sku; use App\User; use App\UserAlias; @@ -42,6 +43,11 @@ $user_ids = $user_ids->merge($ext_user_ids)->unique(); + // Search by a distribution list email + if ($group = Group::withTrashed()->where('email', $search)->first()) { + $user_ids = $user_ids->merge([$group->wallet()->user_id])->unique(); + } + if (!$user_ids->isEmpty()) { $result = User::withTrashed()->whereIn('id', $user_ids) ->orderBy('email')->get(); diff --git a/src/app/Jobs/Group/UpdateJob.php b/src/app/Jobs/Group/UpdateJob.php --- a/src/app/Jobs/Group/UpdateJob.php +++ b/src/app/Jobs/Group/UpdateJob.php @@ -2,6 +2,7 @@ namespace App\Jobs\Group; +use App\Backends\LDAP; use App\Jobs\GroupJob; class UpdateJob extends GroupJob @@ -19,11 +20,29 @@ return; } - if (!$group->isLdapReady()) { + // Cancel the update if the group is deleted or not yet in LDAP + if (!$group->isLdapReady() || $group->isDeleted()) { $this->delete(); return; } - \App\Backends\LDAP::updateGroup($group); + LDAP::connect(); + + // Groups does not have an attribute for the status, therefore + // we remove suspended groups from LDAP. + // We do not remove STATUS_LDAP_READY flag because it is part of the + // setup process. + + $inLdap = !empty(LDAP::getGroup($group->email)); + + if ($group->isSuspended() && $inLdap) { + LDAP::deleteGroup($group); + } elseif (!$group->isSuspended() && !$inLdap) { + LDAP::createGroup($group); + } else { + LDAP::updateGroup($group); + } + + LDAP::disconnect(); } } diff --git a/src/resources/js/routes-admin.js b/src/resources/js/routes-admin.js --- a/src/resources/js/routes-admin.js +++ b/src/resources/js/routes-admin.js @@ -1,4 +1,5 @@ import DashboardComponent from '../vue/Admin/Dashboard' +import DistlistComponent from '../vue/Admin/Distlist' import DomainComponent from '../vue/Admin/Domain' import LoginComponent from '../vue/Login' import LogoutComponent from '../vue/Logout' @@ -18,6 +19,12 @@ meta: { requiresAuth: true } }, { + path: '/distlist/:list', + name: 'distlist', + component: DistlistComponent, + meta: { requiresAuth: true } + }, + { path: '/domain/:domain', name: 'domain', component: DomainComponent, diff --git a/src/resources/lang/en/app.php b/src/resources/lang/en/app.php --- a/src/resources/lang/en/app.php +++ b/src/resources/lang/en/app.php @@ -38,6 +38,8 @@ 'distlist-update-success' => 'Distribution list updated successfully.', 'distlist-create-success' => 'Distribution list created successfully.', 'distlist-delete-success' => 'Distribution list deleted successfully.', + 'distlist-suspend-success' => 'Distribution list suspended successfully.', + 'distlist-unsuspend-success' => 'Distribution list unsuspended successfully.', 'domain-verify-success' => 'Domain verified successfully.', 'domain-verify-error' => 'Domain ownership verification failed.', @@ -52,6 +54,7 @@ 'user-reset-2fa-success' => '2-Factor authentication reset successfully.', 'search-foundxdomains' => ':x domains have been found.', + 'search-foundxgroups' => ':x distribution lists have been found.', 'search-foundxusers' => ':x user accounts have been found.', 'support-request-success' => 'Support request submitted successfully.', diff --git a/src/resources/vue/Admin/Distlist.vue b/src/resources/vue/Admin/Distlist.vue new file mode 100644 --- /dev/null +++ b/src/resources/vue/Admin/Distlist.vue @@ -0,0 +1,79 @@ + + + diff --git a/src/resources/vue/Admin/Domain.vue b/src/resources/vue/Admin/Domain.vue --- a/src/resources/vue/Admin/Domain.vue +++ b/src/resources/vue/Admin/Domain.vue @@ -4,8 +4,8 @@
{{ domain.namespace }}
-
-
+ +
@@ -13,7 +13,7 @@
-
+
diff --git a/src/resources/vue/Admin/User.vue b/src/resources/vue/Admin/User.vue --- a/src/resources/vue/Admin/User.vue +++ b/src/resources/vue/Admin/User.vue @@ -108,6 +108,11 @@ Users ({{ users.length }}) +
@@ -259,6 +264,32 @@
+
+
+
+ + + + + + + + + + + + + + + + +
Email address
+ + {{ list.email }} +
There are no distribution lists in this account.
+
+
+