diff --git a/app/Http/Controllers/ConversationsController.php b/app/Http/Controllers/ConversationsController.php index e491b21e..ccfac361 100644 --- a/app/Http/Controllers/ConversationsController.php +++ b/app/Http/Controllers/ConversationsController.php @@ -1313,14 +1313,14 @@ class ConversationsController extends Controller $response['msg'] .= __('Action not authorized'); } if (!$response['msg']) { - $mailbox_user = $user->mailboxes()->where('mailbox_id', $request->mailbox_id)->first(); + $mailbox_user = $user->mailboxesWithSettings()->where('mailbox_id', $request->mailbox_id)->first(); if (!$mailbox_user) { // Admin may not be connected to the mailbox yet $user->mailboxes()->attach($request->mailbox_id); // $mailbox_user = new MailboxUser(); // $mailbox_user->mailbox_id = $mailbox->id; // $mailbox_user->user_id = $user->id; - $mailbox_user = $user->mailboxes()->where('mailbox_id', $request->mailbox_id)->first(); + $mailbox_user = $user->mailboxesWithSettings()->where('mailbox_id', $request->mailbox_id)->first(); } $mailbox_user->settings->after_send = $request->value; $mailbox_user->settings->save(); diff --git a/app/Http/Controllers/MailboxesController.php b/app/Http/Controllers/MailboxesController.php index 50b4c11a..98adee87 100644 --- a/app/Http/Controllers/MailboxesController.php +++ b/app/Http/Controllers/MailboxesController.php @@ -156,7 +156,21 @@ class MailboxesController extends Controller $users = User::nonDeleted()->where('role', '!=', User::ROLE_ADMIN)->get(); $users = User::sortUsers($users); - return view('mailboxes/permissions', ['mailbox' => $mailbox, 'users' => $users, 'mailbox_users' => $mailbox->users]); + $admins = User::nonDeleted() + ->select(['users.*', 'mailbox_user.hide']) + ->leftJoin('mailbox_user', function ($join) use ($mailbox) { + $join->on('mailbox_user.user_id', '=', 'users.id'); + $join->where('mailbox_user.mailbox_id', $mailbox->id); + }) + ->where('role', User::ROLE_ADMIN)->get(); + $admins = User::sortUsers($admins); + + return view('mailboxes/permissions', [ + 'mailbox' => $mailbox, + 'users' => $users, + 'admins' => $admins, + 'mailbox_users' => $mailbox->users, + ]); } /** @@ -173,6 +187,19 @@ class MailboxesController extends Controller $mailbox->users()->sync($request->users); $mailbox->syncPersonalFolders($request->users); + // Save admins settings. + $admins = User::nonDeleted()->where('role', User::ROLE_ADMIN)->get(); + foreach ($admins as $admin) { + $mailbox_user = $admin->mailboxesWithSettings()->where('mailbox_id', $id)->first(); + if (!$mailbox_user) { + // Admin may not be connected to the mailbox yet + $admin->mailboxes()->attach($id); + $mailbox_user = $admin->mailboxesWithSettings()->where('mailbox_id', $id)->first(); + } + $mailbox_user->settings->hide = (isset($request->admins[$admin->id]['hide']) ? (int)$request->admins[$admin->id]['hide'] : false); + $mailbox_user->settings->save(); + } + \Session::flash('flash_success_floating', __('Mailbox permissions saved!')); return redirect()->route('mailboxes.permissions', ['id' => $id]); diff --git a/app/Mailbox.php b/app/Mailbox.php index 2b05053d..fdabbd8b 100644 --- a/app/Mailbox.php +++ b/app/Mailbox.php @@ -150,7 +150,12 @@ class Mailbox extends Model */ public function users() { - return $this->belongsToMany('App\User')->as('settings')->withPivot('after_send'); + return $this->belongsToMany('App\User'); + } + + public function usersWithSettings() + { + return $this->belongsToMany('App\User')->as('settings')->withPivot('after_send')->withPivot('hide'); } /** @@ -363,7 +368,7 @@ class Mailbox extends Model { $admins = User::where('role', User::ROLE_ADMIN)->select($fields)->remember(\Helper::cacheTime($cache))->get(); - $users = $this->users()->select($fields)->rememberForever()->get()->merge($admins)->unique(); + $users = $this->users()->select($fields)->remember(\Helper::cacheTime($cache))->get()->merge($admins)->unique(); // Exclude deleted users (better to do it in PHP). foreach ($users as $i => $user) { @@ -374,14 +379,46 @@ class Mailbox extends Model // Sort by full name if ($sort) { - $users = $users->sortBy(function ($value, $key) { - return $value->getFullName(); - }, SORT_STRING | SORT_FLAG_CASE); + $users = User::sortUsers($users); } return $users; } + public function usersAssignable($cache = true) + { + // Exclude hidden admins. + $mailbox_id = $this->id; + $admins = User::select(['users.*', 'mailbox_user.hide']) + ->leftJoin('mailbox_user', function ($join) use ($mailbox_id) { + $join->on('mailbox_user.user_id', '=', 'users.id'); + $join->where('mailbox_user.mailbox_id', $mailbox_id); + }) + ->where('role', User::ROLE_ADMIN) + ->remember(\Helper::cacheTime($cache)) + ->get(); + + $users = $this->users()->select('users.*')->remember(\Helper::cacheTime($cache))->get()->merge($admins)->unique(); + + foreach ($users as $i => $user) { + if (!empty($user->hide)) { + $users->forget($i); + } + } + + // Exclude deleted users (better to do it in PHP). + foreach ($users as $i => $user) { + if ($user->isDeleted()) { + $users->forget($i); + } + } + + // Sort by full name + $users = User::sortUsers($users); + + return $users; + } + /** * Get users IDs who have access to the mailbox. */ @@ -498,7 +535,7 @@ class Mailbox extends Model */ public function getUserSettings($user_id) { - $mailbox_user = $this->users()->where('users.id', $user_id)->first(); + $mailbox_user = $this->usersWithSettings()->where('users.id', $user_id)->first(); if ($mailbox_user) { return $mailbox_user->settings; } else { @@ -506,6 +543,7 @@ class Mailbox extends Model // Create dummy object with default parameters $settings = new \StdClass(); $settings->after_send = MailboxUser::AFTER_SEND_NEXT; + $settings->hide = false; return $settings; } diff --git a/app/User.php b/app/User.php index d2aa3222..909aedea 100644 --- a/app/User.php +++ b/app/User.php @@ -124,7 +124,12 @@ class User extends Authenticatable */ public function mailboxes() { - return $this->belongsToMany('App\Mailbox')->as('settings')->withPivot('after_send'); + return $this->belongsToMany('App\Mailbox'); + } + + public function mailboxesWithSettings() + { + return $this->belongsToMany('App\Mailbox')->as('settings')->withPivot('after_send')->withPivot('hide'); } /** diff --git a/database/migrations/2020_02_06_103815_add_hide_column_to_mailbox_user_table.php b/database/migrations/2020_02_06_103815_add_hide_column_to_mailbox_user_table.php new file mode 100644 index 00000000..add8e8d8 --- /dev/null +++ b/database/migrations/2020_02_06_103815_add_hide_column_to_mailbox_user_table.php @@ -0,0 +1,33 @@ +boolean('hide')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('mailbox_user', function (Blueprint $table) { + $table->dropColumn('hide'); + }); + } +} diff --git a/public/css/style.css b/public/css/style.css index cce3b387..f3685c21 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -2850,6 +2850,10 @@ ul.sidebar-block-list { padding-top: 4px; padding-bottom: 4px; } +.table-header-nb td, +.table-header-nb th { + border-top: none !important; +} /** * Modal diff --git a/resources/views/conversations/editor_bottom_toolbar.blade.php b/resources/views/conversations/editor_bottom_toolbar.blade.php index f01adf43..a612bc8b 100644 --- a/resources/views/conversations/editor_bottom_toolbar.blade.php +++ b/resources/views/conversations/editor_bottom_toolbar.blade.php @@ -22,7 +22,7 @@ ($conversation->user_id == Auth::user()->id && $mailbox->ticket_assignee != App\Mailbox::TICKET_ASSIGNEE_ANYONE) || (!$conversation->user_id && $mailbox->ticket_assignee == App\Mailbox::TICKET_ASSIGNEE_REPLYING_UNASSIGNED) || $mailbox->ticket_assignee == App\Mailbox::TICKET_ASSIGNEE_REPLYING)data-default="true" selected="selected"@endif>{{ __('Me') }} - @foreach ($mailbox->usersHavingAccess() as $user) + @foreach ($mailbox->usersAssignable() as $user) @if ($user->id != Auth::user()->id) @endif diff --git a/resources/views/conversations/view.blade.php b/resources/views/conversations/view.blade.php index b2c73c26..58a0e819 100644 --- a/resources/views/conversations/view.blade.php +++ b/resources/views/conversations/view.blade.php @@ -64,7 +64,7 @@