|
18 | 18 | use App\Http\Requests\User\UpdateUserRequest;
|
19 | 19 | use App\Http\Requests\User\StoreUserRequest;
|
20 | 20 | use Ramsey\Uuid\Uuid;
|
21 |
| -use App\Repositories\Task\TaskRepositoryContract; |
22 |
| -use App\Repositories\Lead\LeadRepositoryContract; |
23 | 21 |
|
24 | 22 | class UsersController extends Controller
|
25 | 23 | {
|
26 | 24 | protected $users;
|
27 | 25 | protected $roles;
|
28 | 26 |
|
29 |
| - public function __construct( |
30 |
| - TaskRepositoryContract $tasks, |
31 |
| - LeadRepositoryContract $leads |
32 |
| - ) { |
33 |
| - $this->tasks = $tasks; |
34 |
| - $this->leads = $leads; |
| 27 | + public function __construct() |
| 28 | + { |
35 | 29 | $this->middleware('user.create', ['only' => ['create']]);
|
36 | 30 | }
|
37 | 31 |
|
@@ -221,15 +215,18 @@ public function store(StoreUserRequest $request)
|
221 | 215 | */
|
222 | 216 | public function show($external_id)
|
223 | 217 | {
|
| 218 | + /** @var User $user */ |
| 219 | + $user = $this->findByExternalId($external_id); |
224 | 220 | return view('users.show')
|
225 |
| - ->withUser($this->findByExternalId($external_id)) |
| 221 | + ->withUser($user) |
226 | 222 | ->withCompanyname(Setting::first()->company)
|
227 |
| - ->with('task_statistics', $this->tasks->totalOpenAndClosedTasks($external_id)) |
228 |
| - ->with('lead_statistics', $this->leads->totalOpenAndClosedLeads($external_id)) |
| 223 | + ->with('task_statistics', $user->totalOpenAndClosedTasks($external_id)) |
| 224 | + ->with('lead_statistics', $user->totalOpenAndClosedLeads($external_id)) |
229 | 225 | ->with('lead_statuses', Status::typeOfLead()->get())
|
230 | 226 | ->with('task_statuses', Status::typeOfTask()->get());
|
231 | 227 | }
|
232 | 228 |
|
| 229 | + |
233 | 230 | /**
|
234 | 231 | * @param $external_id
|
235 | 232 | * @return mixed
|
@@ -279,11 +276,10 @@ public function update($external_id, UpdateUserRequest $request)
|
279 | 276 |
|
280 | 277 | $user->fill($input)->save();
|
281 | 278 | $role = $user->roles->first();
|
282 |
| - if ($request->roles == (int)$role->id) { |
283 |
| - } elseif ($role->first()->name == Role::OWNER_ROLE && $owners->count() <= 1 && $role) { |
| 279 | + if ($role && $role->name == Role::OWNER_ROLE && $owners->count() <= 1) { |
284 | 280 | Session()->flash('flash_message_warning', __('Not able to change owner role, please choose a new owner first'));
|
285 | 281 | } else {
|
286 |
| - $user->roles()->sync([$role]); |
| 282 | + $user->roles()->sync([$request->roles]); |
287 | 283 | }
|
288 | 284 | $user->department()->sync([$department]);
|
289 | 285 |
|
|
0 commit comments