Passed
Push — devel-3.0 ( 2fc71e...3e43d6 )
by Rubén
03:39
created

AccountService::addPresetPermissions()   B

Complexity

Conditions 7
Paths 17

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 19
nc 17
nop 1
dl 0
loc 31
rs 8.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Services\Account;
26
27
use Defuse\Crypto\Exception\CryptoException;
28
use SP\Core\Crypt\Crypt;
29
use SP\Core\Exceptions\QueryException;
30
use SP\Core\Exceptions\SPException;
31
use SP\DataModel\AccountData;
32
use SP\DataModel\AccountHistoryData;
33
use SP\DataModel\AccountPassData;
34
use SP\DataModel\AccountPermission;
35
use SP\DataModel\AccountPrivate;
36
use SP\DataModel\AccountSearchVData;
37
use SP\DataModel\Dto\AccountDetailsResponse;
38
use SP\DataModel\Dto\AccountHistoryCreateDto;
39
use SP\DataModel\ItemSearchData;
40
use SP\Repositories\Account\AccountRepository;
41
use SP\Repositories\Account\AccountToTagRepository;
42
use SP\Repositories\Account\AccountToUserGroupRepository;
43
use SP\Repositories\Account\AccountToUserRepository;
44
use SP\Repositories\NoSuchItemException;
45
use SP\Services\Config\ConfigService;
46
use SP\Services\ItemPreset\ItemPresetInterface;
47
use SP\Services\ItemPreset\ItemPresetService;
48
use SP\Services\Service;
49
use SP\Services\ServiceException;
50
use SP\Services\ServiceItemTrait;
51
use SP\Storage\Database\QueryResult;
52
53
/**
54
 * Class AccountService
55
 *
56
 * @package SP\Services\Account
57
 */
58
final class AccountService extends Service implements AccountServiceInterface
59
{
60
    use ServiceItemTrait;
61
62
    /**
63
     * @var AccountRepository
64
     */
65
    protected $accountRepository;
66
    /**
67
     * @var AccountToUserGroupRepository
68
     */
69
    protected $accountToUserGroupRepository;
70
    /**
71
     * @var AccountToUserRepository
72
     */
73
    protected $accountToUserRepository;
74
    /**
75
     * @var AccountToTagRepository
76
     */
77
    protected $accountToTagRepository;
78
    /**
79
     * @var ItemPresetService
80
     */
81
    protected $itemPresetService;
82
83
    /**
84
     * @param AccountDetailsResponse $accountDetailsResponse
85
     *
86
     * @return AccountService
87
     * @throws QueryException
88
     * @throws \SP\Core\Exceptions\ConstraintException
89
     */
90
    public function withUsersById(AccountDetailsResponse $accountDetailsResponse)
91
    {
92
        $accountDetailsResponse->setUsers($this->accountToUserRepository->getUsersByAccountId($accountDetailsResponse->getId()));
93
94
        return $this;
95
    }
96
97
    /**
98
     * @param AccountDetailsResponse $accountDetailsResponse
99
     *
100
     * @return AccountService
101
     * @throws QueryException
102
     * @throws \SP\Core\Exceptions\ConstraintException
103
     */
104
    public function withUserGroupsById(AccountDetailsResponse $accountDetailsResponse)
105
    {
106
        $accountDetailsResponse->setUserGroups($this->accountToUserGroupRepository->getUserGroupsByAccountId($accountDetailsResponse->getId())->getDataAsArray());
107
108
        return $this;
109
    }
110
111
    /**
112
     * @param AccountDetailsResponse $accountDetailsResponse
113
     *
114
     * @return AccountService
115
     * @throws QueryException
116
     * @throws \SP\Core\Exceptions\ConstraintException
117
     */
118
    public function withTagsById(AccountDetailsResponse $accountDetailsResponse)
119
    {
120
        $accountDetailsResponse->setTags($this->accountToTagRepository->getTagsByAccountId($accountDetailsResponse->getId())->getDataAsArray());
121
122
        return $this;
123
    }
124
125
    /**
126
     * @param $id
127
     *
128
     * @return bool
129
     * @throws QueryException
130
     * @throws \SP\Core\Exceptions\ConstraintException
131
     */
132
    public function incrementViewCounter($id)
133
    {
134
        return $this->accountRepository->incrementViewCounter($id);
135
    }
136
137
    /**
138
     * @param $id
139
     *
140
     * @return bool
141
     * @throws QueryException
142
     * @throws \SP\Core\Exceptions\ConstraintException
143
     */
144
    public function incrementDecryptCounter($id)
145
    {
146
        return $this->accountRepository->incrementDecryptCounter($id);
147
    }
148
149
    /**
150
     * @param $id
151
     *
152
     * @return \SP\DataModel\AccountPassData
153
     * @throws QueryException
154
     * @throws \SP\Core\Exceptions\ConstraintException
155
     * @throws NoSuchItemException
156
     */
157
    public function getPasswordForId($id)
158
    {
159
        $queryFilter = $this->dic->get(AccountFilterUser::class)->getFilter();
160
161
        $result = $this->accountRepository->getPasswordForId($id, $queryFilter);
162
163
        if ($result->getNumRows() === 0) {
164
            throw new NoSuchItemException(__u('Cuenta no encontrada'));
165
        }
166
167
        return $result->getData();
168
    }
169
170
    /**
171
     * @param AccountRequest $accountRequest
172
     *
173
     * @return int
174
     * @throws QueryException
175
     * @throws SPException
176
     * @throws \SP\Core\Exceptions\ConstraintException
177
     * @throws \SP\Core\Exceptions\NoSuchPropertyException
178
     */
179
    public function create(AccountRequest $accountRequest)
180
    {
181
        $accountRequest->changePermissions = AccountAclService::getShowPermission($this->context->getUserData(), $this->context->getUserProfile());
182
        $accountRequest->userGroupId = $accountRequest->userGroupId ?: $this->context->getUserData()->getUserGroupId();
183
184
        if (empty($accountRequest->key)) {
185
            $pass = $this->getPasswordEncrypted($accountRequest->pass);
186
187
            $accountRequest->pass = $pass['pass'];
188
            $accountRequest->key = $pass['key'];
189
        }
190
191
        $this->setPresetPrivate($accountRequest);
192
193
        $accountRequest->id = $this->accountRepository->create($accountRequest);
194
195
        $this->addItems($accountRequest);
196
197
        $this->addPresetPermissions($accountRequest->id);
198
199
        return $accountRequest->id;
200
    }
201
202
    /**
203
     * Devolver los datos de la clave encriptados
204
     *
205
     * @param string $pass
206
     * @param string $masterPass Clave maestra a utilizar
207
     *
208
     * @return array
209
     * @throws ServiceException
210
     */
211
    public function getPasswordEncrypted($pass, $masterPass = null)
212
    {
213
        try {
214
            if ($masterPass === null) {
215
                $masterPass = $this->getMasterKeyFromContext();
216
            }
217
218
            if (empty($masterPass)) {
219
                throw new ServiceException(__u('Clave maestra no establecida'));
220
            }
221
222
            $out['key'] = Crypt::makeSecuredKey($masterPass);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$out was never initialized. Although not strictly required by PHP, it is generally a good practice to add $out = array(); before regardless.
Loading history...
223
            $out['pass'] = Crypt::encrypt($pass, $out['key'], $masterPass);
224
225
            if (strlen($out['pass']) > 1000 || strlen($out['key']) > 1000) {
226
                throw new ServiceException(__u('Error interno'));
227
            }
228
229
            return $out;
230
        } catch (CryptoException $e) {
231
            throw new ServiceException(__u('Error interno'));
232
        }
233
    }
234
235
    /**
236
     * @param AccountRequest $accountRequest
237
     *
238
     * @throws QueryException
239
     * @throws \SP\Core\Exceptions\ConstraintException
240
     * @throws \SP\Core\Exceptions\NoSuchPropertyException
241
     * @throws NoSuchItemException
242
     */
243
    private function setPresetPrivate(AccountRequest $accountRequest)
244
    {
245
        $userData = $this->context->getUserData();
246
        $itemPreset = $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PRIVATE);
247
248
        if ($itemPreset !== null
249
            && $itemPreset->getFixed()
250
        ) {
251
            $accountPrivate = $itemPreset->hydrate(AccountPrivate::class);
252
253
            $userId = $accountRequest->userId;
254
255
            if ($userId === null && $accountRequest->id > 0) {
0 ignored issues
show
introduced by
The condition $userId is always false. If $userId can have other possible types, add them to lib/SP/Services/Account/AccountRequest.php:63
Loading history...
256
                $userId = $this->getById($accountRequest->id)->getAccountVData()->getUserId();
257
            }
258
259
            if ($userData->getId() === $userId) {
260
                $accountRequest->isPrivate = (int)$accountPrivate->isPrivateUser();
261
            }
262
263
            if ($userData->getUserGroupId() === $accountRequest->userGroupId) {
264
                $accountRequest->isPrivateGroup = (int)$accountPrivate->isPrivateGroup();
265
            }
266
        }
267
    }
268
269
    /**
270
     * @param int $id
271
     *
272
     * @return AccountDetailsResponse
273
     * @throws QueryException
274
     * @throws \SP\Repositories\NoSuchItemException
275
     * @throws \SP\Core\Exceptions\ConstraintException
276
     */
277
    public function getById($id)
278
    {
279
        $result = $this->accountRepository->getById($id);
280
281
        if ($result->getNumRows() === 0) {
282
            throw new NoSuchItemException(__u('La cuenta no existe'));
283
        }
284
285
        return new AccountDetailsResponse($id, $result->getData());
286
    }
287
288
    /**
289
     * Adds external items to the account
290
     *
291
     * @param AccountRequest $accountRequest
292
     */
293
    private function addItems(AccountRequest $accountRequest)
294
    {
295
        try {
296
297
            if ($accountRequest->changePermissions) {
298
                if (is_array($accountRequest->userGroupsView)
299
                    && !empty($accountRequest->userGroupsView)
300
                ) {
301
                    $this->accountToUserGroupRepository->add($accountRequest);
302
                }
303
304
                if (is_array($accountRequest->userGroupsEdit)
305
                    && !empty($accountRequest->userGroupsEdit)
306
                ) {
307
                    $this->accountToUserGroupRepository->addEdit($accountRequest);
308
                }
309
310
                if (is_array($accountRequest->usersView)
311
                    && !empty($accountRequest->usersView)
312
                ) {
313
                    $this->accountToUserRepository->add($accountRequest);
314
                }
315
316
                if (is_array($accountRequest->usersEdit)
317
                    && !empty($accountRequest->usersEdit)
318
                ) {
319
                    $this->accountToUserRepository->addEdit($accountRequest);
320
                }
321
            }
322
323
            if (is_array($accountRequest->tags)
324
                && !empty($accountRequest->tags)
325
            ) {
326
                $this->accountToTagRepository->add($accountRequest);
327
            }
328
        } catch (SPException $e) {
329
            logger($e->getMessage());
330
        }
331
    }
332
333
    /**
334
     * @param int $accountId
335
     *
336
     * @throws QueryException
337
     * @throws \SP\Core\Exceptions\ConstraintException
338
     * @throws \SP\Core\Exceptions\NoSuchPropertyException
339
     */
340
    private function addPresetPermissions(int $accountId)
341
    {
342
        $itemPresetData = $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PERMISSION);
343
344
        if ($itemPresetData !== null
345
            && $itemPresetData->getFixed()
346
        ) {
347
            $userData = $this->context->getUserData();
348
            $accountPermission = $itemPresetData->hydrate(AccountPermission::class);
349
350
            $accountRequest = new AccountRequest();
351
            $accountRequest->id = $accountId;
352
            $accountRequest->usersView = array_diff($accountPermission->getUsersView(), [$userData->getId()]);
353
            $accountRequest->usersEdit = array_diff($accountPermission->getUsersEdit(), [$userData->getId()]);
354
            $accountRequest->userGroupsView = array_diff($accountPermission->getUserGroupsView(), [$userData->getUserGroupId()]);
355
            $accountRequest->userGroupsEdit = array_diff($accountPermission->getUserGroupsEdit(), [$userData->getUserGroupId()]);
356
357
            if (!empty($accountRequest->usersView)) {
358
                $this->accountToUserRepository->add($accountRequest);
359
            }
360
361
            if (!empty($accountRequest->usersEdit)) {
362
                $this->accountToUserRepository->addEdit($accountRequest);
363
            }
364
365
            if (!empty($accountRequest->userGroupsView)) {
366
                $this->accountToUserGroupRepository->add($accountRequest);
367
            }
368
369
            if (!empty($accountRequest->userGroupsEdit)) {
370
                $this->accountToUserGroupRepository->addEdit($accountRequest);
371
            }
372
        }
373
    }
374
375
    /**
376
     * @param AccountHistoryData $data
377
     *
378
     * @return int
379
     * @throws QueryException
380
     * @throws \SP\Core\Exceptions\ConstraintException
381
     */
382
    public function createFromHistory(AccountHistoryData $data)
383
    {
384
        $accountRequest = new AccountRequest();
385
        $accountRequest->name = $data->getName();
386
        $accountRequest->categoryId = $data->getCategoryId();
387
        $accountRequest->clientId = $data->getClientId();
388
        $accountRequest->url = $data->getUrl();
389
        $accountRequest->login = $data->getLogin();
390
        $accountRequest->pass = $data->getPass();
391
        $accountRequest->key = $data->getKey();
392
        $accountRequest->notes = $data->getNotes();
393
        $accountRequest->userId = $data->getUserId();
394
        $accountRequest->userGroupId = $data->getUserGroupId();
395
        $accountRequest->passDateChange = $data->getPassDateChange();
396
        $accountRequest->parentId = $data->getParentId();
397
        $accountRequest->isPrivate = $data->getIsPrivate();
398
        $accountRequest->isPrivateGroup = $data->getIsPrivateGroup();
399
400
        return $this->accountRepository->create($accountRequest);
401
    }
402
403
    /**
404
     * Updates external items for the account
405
     *
406
     * @param AccountRequest $accountRequest
407
     *
408
     * @throws \Exception
409
     */
410
    public function update(AccountRequest $accountRequest)
411
    {
412
        $this->transactionAware(function () use ($accountRequest) {
413
            $accountRequest->changePermissions = AccountAclService::getShowPermission($this->context->getUserData(), $this->context->getUserProfile());
414
415
            // Cambiar el grupo principal si el usuario es Admin
416
            $accountRequest->changeUserGroup = ($accountRequest->userGroupId > 0
417
                && ($this->context->getUserData()->getIsAdminApp() || $this->context->getUserData()->getIsAdminAcc()));
418
419
            $this->addHistory($accountRequest->id);
420
421
            $this->setPresetPrivate($accountRequest);
422
423
            $this->accountRepository->update($accountRequest);
424
425
            $this->updateItems($accountRequest);
426
427
            $this->addPresetPermissions($accountRequest->id);
428
        });
429
    }
430
431
    /**
432
     * @param int  $accountId
433
     * @param bool $isDelete
434
     *
435
     * @return bool
436
     * @throws NoSuchItemException
437
     * @throws QueryException
438
     * @throws ServiceException
439
     * @throws \SP\Core\Exceptions\ConstraintException
440
     */
441
    private function addHistory($accountId, $isDelete = false)
442
    {
443
        $accountHistoryRepository = $this->dic->get(AccountHistoryService::class);
444
        $configService = $this->dic->get(ConfigService::class);
445
446
        return $accountHistoryRepository->create(
447
            new AccountHistoryCreateDto(
448
                $accountId,
449
                !$isDelete,
450
                $isDelete,
451
                $configService->getByParam('masterPwd'))
452
        );
453
    }
454
455
    /**
456
     * Updates external items for the account
457
     *
458
     * @param AccountRequest $accountRequest
459
     *
460
     * @throws QueryException
461
     * @throws \SP\Core\Exceptions\ConstraintException
462
     */
463
    private function updateItems(AccountRequest $accountRequest)
464
    {
465
        if ($accountRequest->changePermissions) {
466
            if ($accountRequest->updateUserGroupPermissions) {
467
                if (!empty($accountRequest->userGroupsView)) {
468
                    $this->accountToUserGroupRepository->update($accountRequest);
469
                } else {
470
                    $this->accountToUserGroupRepository->deleteByAccountId($accountRequest->id);
471
                }
472
473
                if (!empty($accountRequest->userGroupsEdit)) {
474
                    $this->accountToUserGroupRepository->updateEdit($accountRequest);
475
                } else {
476
                    $this->accountToUserGroupRepository->deleteEditByAccountId($accountRequest->id);
477
                }
478
            }
479
480
            if ($accountRequest->updateUserPermissions) {
481
                if (!empty($accountRequest->usersView)) {
482
                    $this->accountToUserRepository->update($accountRequest);
483
                } else {
484
                    $this->accountToUserRepository->deleteByAccountId($accountRequest->id);
485
                }
486
487
                if (!empty($accountRequest->usersEdit)) {
488
                    $this->accountToUserRepository->updateEdit($accountRequest);
489
                } else {
490
                    $this->accountToUserRepository->deleteEditByAccountId($accountRequest->id);
491
                }
492
            }
493
        }
494
495
        if ($accountRequest->updateTags) {
496
            if (!empty($accountRequest->tags)) {
497
                $this->accountToTagRepository->update($accountRequest);
498
            } else {
499
                $this->accountToTagRepository->deleteByAccountId($accountRequest->id);
500
            }
501
        }
502
    }
503
504
    /**
505
     * @param AccountRequest $accountRequest
506
     *
507
     * @throws \Exception
508
     */
509
    public function editPassword(AccountRequest $accountRequest)
510
    {
511
        $this->transactionAware(function () use ($accountRequest) {
512
            $this->addHistory($accountRequest->id);
513
514
            $pass = $this->getPasswordEncrypted($accountRequest->pass);
515
516
            $accountRequest->pass = $pass['pass'];
517
            $accountRequest->key = $pass['key'];
518
519
            $this->accountRepository->editPassword($accountRequest);
520
        });
521
    }
522
523
    /**
524
     * Updates an already encrypted password data from a master password changing action
525
     *
526
     * @param AccountPasswordRequest $accountRequest
527
     *
528
     * @return bool
529
     * @throws \SP\Core\Exceptions\ConstraintException
530
     * @throws QueryException
531
     */
532
    public function updatePasswordMasterPass(AccountPasswordRequest $accountRequest)
533
    {
534
        return $this->accountRepository->updatePassword($accountRequest);
535
    }
536
537
    /**
538
     * @param $historyId
539
     * @param $accountId
540
     *
541
     * @throws \Exception
542
     */
543
    public function editRestore($historyId, $accountId)
544
    {
545
        $this->transactionAware(function () use ($historyId, $accountId) {
546
            $this->addHistory($accountId);
547
548
            if (!$this->accountRepository->editRestore($historyId, $this->context->getUserData()->getId())) {
549
                throw new ServiceException(__u('Error al restaurar cuenta'));
550
            }
551
        });
552
    }
553
554
    /**
555
     * @param $id
556
     *
557
     * @return AccountService
558
     * @throws ServiceException
559
     */
560
    public function delete($id)
561
    {
562
        $this->transactionAware(function () use ($id) {
563
            $this->addHistory($id, 1);
564
565
            if ($this->accountRepository->delete($id) === 0) {
566
                throw new NoSuchItemException(__u('Cuenta no encontrada'));
567
            }
568
        });
569
570
        return $this;
571
    }
572
573
    /**
574
     * @param array $ids
575
     *
576
     * @return AccountService
577
     * @throws SPException
578
     * @throws ServiceException
579
     */
580
    public function deleteByIdBatch(array $ids)
581
    {
582
        if ($this->accountRepository->deleteByIdBatch($ids) === 0) {
583
            throw new ServiceException(__u('Error al eliminar las cuentas'));
584
        }
585
586
        return $this;
587
    }
588
589
    /**
590
     * @param $accountId
591
     *
592
     * @return array
593
     * @throws QueryException
594
     * @throws \SP\Core\Exceptions\ConstraintException
595
     */
596
    public function getForUser($accountId = null)
597
    {
598
        $queryFilter = $this->dic->get(AccountFilterUser::class)->getFilter();
599
600
        if (null !== $accountId) {
601
            $queryFilter->addFilter('Account.id <> ? AND (Account.parentId = 0 OR Account.parentId IS NULL)', [$accountId]);
602
        }
603
604
        return $this->accountRepository->getForUser($queryFilter)->getDataAsArray();
605
    }
606
607
    /**
608
     * @param $accountId
609
     *
610
     * @return array
611
     * @throws QueryException
612
     * @throws \SP\Core\Exceptions\ConstraintException
613
     */
614
    public function getLinked($accountId)
615
    {
616
        $queryFilter = $this->dic->get(AccountFilterUser::class)->getFilter();
617
618
        $queryFilter->addFilter('Account.parentId = ?', [$accountId]);
619
620
        return $this->accountRepository->getLinked($queryFilter)->getDataAsArray();
621
    }
622
623
    /**
624
     * @param $id
625
     *
626
     * @return AccountPassData
627
     * @throws QueryException
628
     * @throws \SP\Core\Exceptions\ConstraintException
629
     * @throws NoSuchItemException
630
     */
631
    public function getPasswordHistoryForId($id)
632
    {
633
        $queryFilter = $this->dic->get(AccountFilterUser::class)->getFilterHistory();
634
        $queryFilter->addFilter('AccountHistory.id = ?', [$id]);
635
636
        $result = $this->accountRepository->getPasswordHistoryForId($queryFilter);
637
638
        if ($result->getNumRows() === 0) {
639
            throw new NoSuchItemException(__u('La cuenta no existe'));
640
        }
641
642
        return $result->getData();
643
    }
644
645
    /**
646
     * @return AccountData[]
647
     * @throws QueryException
648
     * @throws \SP\Core\Exceptions\ConstraintException
649
     */
650
    public function getAllBasic()
651
    {
652
        return $this->accountRepository->getAll()->getDataAsArray();
653
    }
654
655
    /**
656
     * @param ItemSearchData $itemSearchData
657
     *
658
     * @return QueryResult
659
     * @throws QueryException
660
     * @throws \SP\Core\Exceptions\ConstraintException
661
     */
662
    public function search(ItemSearchData $itemSearchData)
663
    {
664
        return $this->accountRepository->search($itemSearchData);
665
    }
666
667
    /**
668
     * Devolver el número total de cuentas
669
     *
670
     * @return \stdClass
671
     * @throws QueryException
672
     * @throws \SP\Core\Exceptions\ConstraintException
673
     */
674
    public function getTotalNumAccounts()
675
    {
676
        return $this->accountRepository->getTotalNumAccounts()->num;
677
    }
678
679
    /**
680
     * Obtener los datos de una cuenta.
681
     *
682
     * @param $id
683
     *
684
     * @return \SP\DataModel\AccountExtData
685
     * @throws QueryException
686
     * @throws \SP\Repositories\NoSuchItemException
687
     * @throws \SP\Core\Exceptions\ConstraintException
688
     */
689
    public function getDataForLink($id)
690
    {
691
        $result = $this->accountRepository->getDataForLink($id);
692
693
        if ($result->getNumRows() === 0) {
694
            throw new NoSuchItemException(__u('La cuenta no existe'));
695
        }
696
697
        return $result->getData();
698
    }
699
700
    /**
701
     * Obtener los datos relativos a la clave de todas las cuentas.
702
     *
703
     * @return array Con los datos de la clave
704
     * @throws QueryException
705
     * @throws \SP\Core\Exceptions\ConstraintException
706
     */
707
    public function getAccountsPassData()
708
    {
709
        return $this->accountRepository->getAccountsPassData();
710
    }
711
712
    /**
713
     * Obtener las cuentas de una búsqueda.
714
     *
715
     * @param AccountSearchFilter $accountSearchFilter
716
     *
717
     * @return AccountSearchVData[]
718
     * @throws QueryException
719
     * @throws SPException
720
     * @throws \SP\Core\Exceptions\ConstraintException
721
     */
722
    public function getByFilter(AccountSearchFilter $accountSearchFilter)
723
    {
724
        $accountFilterUser = $this->dic->get(AccountFilterUser::class);
725
726
        return $this->accountRepository->getByFilter(
727
            $accountSearchFilter,
728
            $accountFilterUser->getFilter($accountSearchFilter->getGlobalSearch())
729
        )->getDataAsArray();
730
    }
731
732
    /**
733
     * @throws \Psr\Container\ContainerExceptionInterface
734
     * @throws \Psr\Container\NotFoundExceptionInterface
735
     */
736
    protected function initialize()
737
    {
738
        $this->accountRepository = $this->dic->get(AccountRepository::class);
739
        $this->accountToUserRepository = $this->dic->get(AccountToUserRepository::class);
740
        $this->accountToUserGroupRepository = $this->dic->get(AccountToUserGroupRepository::class);
741
        $this->accountToTagRepository = $this->dic->get(AccountToTagRepository::class);
742
        $this->itemPresetService = $this->dic->get(ItemPresetService::class);
743
    }
744
}