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 — user-entity ( 34b5b8...ec414b )
by Luis Ramón
02:59
created

AgreementVoter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
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\Agreement;
24
use AppBundle\Entity\User;
25
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
26
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
27
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
28
29
class AgreementVoter extends Voter
30
{
31
    const MANAGE = 'AGREEMENT_MANAGE';
32
    const ACCESS = 'AGREEMENT_ACCESS';
33
34
    private $decisionManager;
35
36
    public function __construct(AccessDecisionManagerInterface $decisionManager) {
37
        $this->decisionManager = $decisionManager;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 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...
44
    {
45
46
        if (!$subject instanceof Agreement) {
47
            return false;
48
        }
49
50
        if (!in_array($attribute, [self::MANAGE, self::ACCESS], true)) {
51
            return false;
52
        }
53
54
        return true;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
61
    {
62
        if (!$subject instanceof Agreement) {
63
            return false;
64
        }
65
        // los administradores globales siempre tienen permiso
66
        if ($this->decisionManager->decide($token, ['ROLE_ADMIN'])) {
67
            return true;
68
        }
69
70
        /** @var User $user */
71
        $user = $token->getUser();
72
73
        if (!$user instanceof User) {
74
            // si el usuario no ha entrado, denegar
75
            return false;
76
        }
77
78
        // Si es el jefe de departamento, permitir
79
        if ($user->getDirects()->contains($subject->getTraining()->getDepartment())) {
0 ignored issues
show
Bug introduced by
The method getTraining() does not seem to exist on object<AppBundle\Entity\Agreement>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
            return true;
81
        }
82
83
        // Si es el propio estudiante, tutor de grupo, tutor docente o tutor loboral, sólo acceso de lectura
84
        if ($subject->getStudent() == $user
85
            || $user->getTutorizedGroups()->contains($subject)
86
            || $subject->getEducationalTutor() == $user
87
            || $subject->getWorkTutor() == $user) {
88
89
            return $attribute == self::ACCESS;
90
        }
91
92
        // denegamos en cualquier otro caso
93
        return false;
94
    }
95
}
96