• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

heimrichhannot / contao-utils-bundle / 10366099093

13 Aug 2024 08:14AM UTC coverage: 23.297% (-0.01%) from 23.309%
10366099093

push

github

ericges
fix user hasAccessToField

0 of 5 new or added lines in 1 file covered. (0.0%)

1320 of 5666 relevant lines covered (23.3%)

1.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.0
/src/User/UserUtil.php
1
<?php
2

3
/*
4
 * Copyright (c) 2022 Heimrich & Hannot GmbH
5
 *
6
 * @license LGPL-3.0-or-later
7
 */
8

9
namespace HeimrichHannot\UtilsBundle\User;
10

11
use Contao\BackendUser;
12
use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
13
use Contao\System;
14
use Contao\UserModel;
15
use HeimrichHannot\UtilsBundle\Model\ModelUtil;
16
use HeimrichHannot\UtilsBundle\Traits\PersonTrait;
17

18
/**
19
 * Class UserUtil.
20
 */
21
class UserUtil
22
{
23
    use PersonTrait;
24

25
    const TABLE = 'tl_user';
26

27
    /**
28
     * @var ContaoFrameworkInterface
29
     */
30
    protected $framework;
31
    /**
32
     * @var ModelUtil
33
     */
34
    protected $modelUtil;
35

36
    public function __construct(
37
        ContaoFrameworkInterface $framework,
38
        ModelUtil $modelUtil
39
    ) {
40
        $this->framework = $framework;
2✔
41
        $this->modelUtil = $modelUtil;
2✔
42
    }
43

44
    /**
45
     * @return UserModel|UserModel[]|\Contao\Model\Collection|null
46
     *
47
     * @deprecated use Utils service instead
48
     */
49
    public function findActiveByGroups(array $groups, array $options = [])
50
    {
51
        if (empty($groups)) {
×
52
            return null;
×
53
        }
54

55
        /** @var $adapter UserModel */
56
        if (null === $adapter = $this->framework->getAdapter(UserModel::class)) {
×
57
            return null;
×
58
        }
59

60
        $t = $adapter->getTable();
×
61
        $time = \Date::floorToMinute();
×
62
        $values = [];
×
63

64
        $columns = ["($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'".($time + 60)."') AND $t.disable=''"];
×
65

66
        if (!empty(array_filter($groups))) {
×
67
            [$columns[], $tmpValues] = System::getContainer()->get('huh.utils.database')->createWhereForSerializedBlob('groups', array_filter($groups));
×
68
            $values = array_merge(array_values($values), array_values($tmpValues));
×
69
        }
70

71
        return $adapter->findBy($columns, $values, $options);
×
72
    }
73

74
    public function hasAccessToField($table, $field): bool
75
    {
76
        $user = $this->framework->createInstance(BackendUser::class);
×
77

NEW
78
        if ($user === null) {
×
79
            return false;
×
80
        }
81

NEW
82
        if ($user->isAdmin) {
×
NEW
83
            return true;
×
84
        }
85

NEW
86
        return \is_array($user->alexf)
×
NEW
87
            && \in_array("$table::$field", $user->alexf);
×
88
    }
89

90
    public function isAdmin(): bool
91
    {
92
        $user = $this->framework->createInstance(BackendUser::class);
×
93

94
        if (null === $user || !\is_array($user->alexf)) {
×
95
            return false;
×
96
        }
97

98
        return $user->isAdmin;
×
99
    }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc