mirror of
https://github.com/freescout-helpdesk/freescout.git
synced 2024-11-24 03:12:46 +01:00
Hide admins from Assign list - closes #456
This commit is contained in:
parent
726d78d4f8
commit
c0893aa500
@ -1313,14 +1313,14 @@ class ConversationsController extends Controller
|
|||||||
$response['msg'] .= __('Action not authorized');
|
$response['msg'] .= __('Action not authorized');
|
||||||
}
|
}
|
||||||
if (!$response['msg']) {
|
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) {
|
if (!$mailbox_user) {
|
||||||
// Admin may not be connected to the mailbox yet
|
// Admin may not be connected to the mailbox yet
|
||||||
$user->mailboxes()->attach($request->mailbox_id);
|
$user->mailboxes()->attach($request->mailbox_id);
|
||||||
// $mailbox_user = new MailboxUser();
|
// $mailbox_user = new MailboxUser();
|
||||||
// $mailbox_user->mailbox_id = $mailbox->id;
|
// $mailbox_user->mailbox_id = $mailbox->id;
|
||||||
// $mailbox_user->user_id = $user->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->after_send = $request->value;
|
||||||
$mailbox_user->settings->save();
|
$mailbox_user->settings->save();
|
||||||
|
@ -156,7 +156,21 @@ class MailboxesController extends Controller
|
|||||||
$users = User::nonDeleted()->where('role', '!=', User::ROLE_ADMIN)->get();
|
$users = User::nonDeleted()->where('role', '!=', User::ROLE_ADMIN)->get();
|
||||||
$users = User::sortUsers($users);
|
$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->users()->sync($request->users);
|
||||||
$mailbox->syncPersonalFolders($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!'));
|
\Session::flash('flash_success_floating', __('Mailbox permissions saved!'));
|
||||||
|
|
||||||
return redirect()->route('mailboxes.permissions', ['id' => $id]);
|
return redirect()->route('mailboxes.permissions', ['id' => $id]);
|
||||||
|
@ -150,7 +150,12 @@ class Mailbox extends Model
|
|||||||
*/
|
*/
|
||||||
public function users()
|
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();
|
$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).
|
// Exclude deleted users (better to do it in PHP).
|
||||||
foreach ($users as $i => $user) {
|
foreach ($users as $i => $user) {
|
||||||
@ -374,14 +379,46 @@ class Mailbox extends Model
|
|||||||
|
|
||||||
// Sort by full name
|
// Sort by full name
|
||||||
if ($sort) {
|
if ($sort) {
|
||||||
$users = $users->sortBy(function ($value, $key) {
|
$users = User::sortUsers($users);
|
||||||
return $value->getFullName();
|
|
||||||
}, SORT_STRING | SORT_FLAG_CASE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $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.
|
* Get users IDs who have access to the mailbox.
|
||||||
*/
|
*/
|
||||||
@ -498,7 +535,7 @@ class Mailbox extends Model
|
|||||||
*/
|
*/
|
||||||
public function getUserSettings($user_id)
|
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) {
|
if ($mailbox_user) {
|
||||||
return $mailbox_user->settings;
|
return $mailbox_user->settings;
|
||||||
} else {
|
} else {
|
||||||
@ -506,6 +543,7 @@ class Mailbox extends Model
|
|||||||
// Create dummy object with default parameters
|
// Create dummy object with default parameters
|
||||||
$settings = new \StdClass();
|
$settings = new \StdClass();
|
||||||
$settings->after_send = MailboxUser::AFTER_SEND_NEXT;
|
$settings->after_send = MailboxUser::AFTER_SEND_NEXT;
|
||||||
|
$settings->hide = false;
|
||||||
|
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,12 @@ class User extends Authenticatable
|
|||||||
*/
|
*/
|
||||||
public function mailboxes()
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddHideColumnToMailboxUserTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('mailbox_user', function (Blueprint $table) {
|
||||||
|
// Hide admin from Assign list.
|
||||||
|
$table->boolean('hide')->default(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('mailbox_user', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('hide');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
4
public/css/style.css
vendored
4
public/css/style.css
vendored
@ -2850,6 +2850,10 @@ ul.sidebar-block-list {
|
|||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
padding-bottom: 4px;
|
padding-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
.table-header-nb td,
|
||||||
|
.table-header-nb th {
|
||||||
|
border-top: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modal
|
* Modal
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
($conversation->user_id == Auth::user()->id && $mailbox->ticket_assignee != App\Mailbox::TICKET_ASSIGNEE_ANYONE)
|
($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)
|
|| (!$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') }}</option>
|
|| $mailbox->ticket_assignee == App\Mailbox::TICKET_ASSIGNEE_REPLYING)data-default="true" selected="selected"@endif>{{ __('Me') }}</option>
|
||||||
@foreach ($mailbox->usersHavingAccess() as $user)
|
@foreach ($mailbox->usersAssignable() as $user)
|
||||||
@if ($user->id != Auth::user()->id)
|
@if ($user->id != Auth::user()->id)
|
||||||
<option value="{{ $user->id }}" @if ($conversation->user_id == $user->id && !in_array($mailbox->ticket_assignee, [ App\Mailbox::TICKET_ASSIGNEE_REPLYING, App\Mailbox::TICKET_ASSIGNEE_ANYONE]))data-default="true" selected="selected"@endif>{{ $user->getFullName() }}</option>
|
<option value="{{ $user->id }}" @if ($conversation->user_id == $user->id && !in_array($mailbox->ticket_assignee, [ App\Mailbox::TICKET_ASSIGNEE_REPLYING, App\Mailbox::TICKET_ASSIGNEE_ANYONE]))data-default="true" selected="selected"@endif>{{ $user->getFullName() }}</option>
|
||||||
@endif
|
@endif
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
<ul class="dropdown-menu conv-user">
|
<ul class="dropdown-menu conv-user">
|
||||||
<li @if (!$conversation->user_id) class="active" @endif><a href="#" data-user_id="-1">{{ __("Anyone") }}</a></li>
|
<li @if (!$conversation->user_id) class="active" @endif><a href="#" data-user_id="-1">{{ __("Anyone") }}</a></li>
|
||||||
<li @if ($conversation->user_id == Auth::user()->id) class="active" @endif><a href="#" data-user_id="{{ Auth::user()->id }}">{{ __("Me") }}</a></li>
|
<li @if ($conversation->user_id == Auth::user()->id) class="active" @endif><a href="#" data-user_id="{{ Auth::user()->id }}">{{ __("Me") }}</a></li>
|
||||||
@foreach ($mailbox->usersHavingAccess(true) as $user)
|
@foreach ($mailbox->usersAssignable() as $user)
|
||||||
@if ($user->id != Auth::user()->id)
|
@if ($user->id != Auth::user()->id)
|
||||||
<li @if ($conversation->user_id == $user->id) class="active" @endif><a href="#" data-user_id="{{ $user->id }}">{{ $user->getFullName() }}</a></li>
|
<li @if ($conversation->user_id == $user->id) class="active" @endif><a href="#" data-user_id="{{ $user->id }}">{{ $user->getFullName() }}</a></li>
|
||||||
@endif
|
@endif
|
||||||
|
@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
<div class="container form-container">
|
<div class="container form-container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<form method="POST" action="">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<h3> {{ __('Selected Users have access to this mailbox:') }}</h3>
|
<h3> {{ __('Selected Users have access to this mailbox:') }}</h3>
|
||||||
<p class="block-help">{{ __('Administrators have access to all mailboxes and are not listed here.') }}</p>
|
<p class="block-help">{{ __('Administrators have access to all mailboxes and are not listed here.') }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<form method="POST" action="">
|
|
||||||
{{ csrf_field() }}
|
{{ csrf_field() }}
|
||||||
|
|
||||||
<p><a href="javascript:void(0)" class="sel-all">{{ __('all') }}</a> / <a href="javascript:void(0)" class="sel-none">{{ __('none') }}</a></p>
|
<p><a href="javascript:void(0)" class="sel-all">{{ __('all') }}</a> / <a href="javascript:void(0)" class="sel-none">{{ __('none') }}</a></p>
|
||||||
@ -37,6 +38,28 @@
|
|||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-xs-12 margin-top">
|
||||||
|
<h3> {{ __('Administrators') }}:</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-11 col-lg-9">
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<tr class="table-header-nb">
|
||||||
|
<th> </th>
|
||||||
|
<th class="text-center">{{ __('Hide from Assign list') }}</th>
|
||||||
|
</tr>
|
||||||
|
<fieldset id="permissions-fields">
|
||||||
|
@foreach ($admins as $admin)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $admin->getFullName() }}</td>
|
||||||
|
<td class="text-center"><input type="checkbox" name="admins[{{ $admin->id }}][hide]" value="1" @if (!empty($admin->hide)) checked="checked" @endif></td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</fieldset>
|
||||||
|
</table>
|
||||||
<div class="form-group margin-top">
|
<div class="form-group margin-top">
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">
|
<button type="submit" class="btn btn-primary">
|
||||||
@ -44,8 +67,8 @@
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
Loading…
Reference in New Issue
Block a user