GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 946e53...2c9141 )
by Luis Ramón
16:58
created

EducationalTutorVoter::voteOnAttribute()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 40
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 40
rs 6.7272
cc 7
eloc 16
nc 7
nop 3
1
<?php
2
/*
3
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2016: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Security;
22
23
use AppBundle\Entity\User;
24
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
25
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
26
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
27
28
class EducationalTutorVoter extends Voter
29
{
30
    const VISIT_TRACK = 'USER_VISIT_TRACK';
31
    const MANAGE = 'USER_MANAGE';
32
33
    private $decisionManager;
34
35
    public function __construct(AccessDecisionManagerInterface $decisionManager) {
36
        $this->decisionManager = $decisionManager;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 View Code Duplication
    protected function supports($attribute, $subject)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        if (!$subject instanceof User) {
45
            return false;
46
        }
47
48
        if (!in_array($attribute, [self::MANAGE, self::VISIT_TRACK], true)) {
49
            return false;
50
        }
51
52
        return true;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
59
    {
60
        if (!$subject instanceof User) {
61
            return false;
62
        }
63
64
        /** @var User $user */
65
        $user = $token->getUser();
66
67
        // si el usuario no ha entrado, denegar
68
        if (!$user instanceof User) {
69
            return false;
70
        }
71
72
        $user = $token->getUser();
73
74
        // si no es tutor docente, denegar
75
        if ($subject->getEducationalTutorAgreements()->isEmpty()) {
76
            return false;
77
        }
78
79
        // los administradores globales siempre tienen permiso
80
        if ($this->decisionManager->decide($token, ['ROLE_ADMIN'])) {
81
            return true;
82
        }
83
84
        // los jefes de departamento de los grupos a los que pertenece un tutor laboral
85
        // tienen permisos de seguimiento
86
        if ($subject->getEducationalTutorAgreements()->first()->getStudent()->getStudentGroup()->getTraining()->getDepartment()->getHead() === $user) {
87
            return $attribute != self::MANAGE;
88
        }
89
90
        // el propio tutor puede seguir sus visitas
91
        if ($subject == $user) {
92
            return $attribute === self::VISIT_TRACK;
93
        }
94
        
95
        // denegar en cualquier otro caso
96
        return false;
97
    }
98
}
99