|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
|
8
|
|
|
|
|
9
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
13
|
|
|
|
|
14
|
|
|
use App\Entity\Organization; |
|
15
|
|
|
use App\Entity\User\ProductOwner; |
|
16
|
|
|
|
|
17
|
|
|
use App\Manager\OrganizationManager; |
|
18
|
|
|
use App\Manager\UserManager; |
|
19
|
|
|
|
|
20
|
|
|
use App\Security\Authentication\AuthenticationManager; |
|
21
|
|
|
|
|
22
|
|
|
use App\Manager\Project\{ |
|
23
|
|
|
DetailsManager, |
|
24
|
|
|
NewsManager, |
|
25
|
|
|
PollManager, |
|
26
|
|
|
ProjectManager |
|
27
|
|
|
}; |
|
28
|
|
|
use App\Registry\ProjectRegistry; |
|
29
|
|
|
|
|
30
|
|
|
class ProjectController extends Controller |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @Route("/projects", name="projects_list", methods={"GET"}) |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function getListAction(ProjectManager $projectManager, ProjectRegistry $projectRegistry) |
|
36
|
|
|
{ |
|
37
|
1 |
|
$projectRegistry->store($projectManager->getAll()); |
|
38
|
1 |
|
return $this->render('projects/list.html.twig', [ |
|
39
|
1 |
|
'projects' => $projectRegistry->getItems() |
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @Route("/projects/new", name="new_project", methods={"GET"}) |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function newAction($form = null) |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
1 |
|
return $this->render('projects/new.html.twig', [ |
|
49
|
1 |
|
'organization_types' => Organization::getTypes() |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @Route("/projects", name="project_creation", methods={"POST"}) |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function createAction(Request $request, ProjectManager $projectManager, AuthenticationManager $authenticationManager, UserManager $userManager, OrganizationManager $organizationManager) |
|
57
|
|
|
{ |
|
58
|
1 |
|
$connection = $this->getDoctrine()->getManager()->getConnection(); |
|
59
|
1 |
|
$connection->beginTransaction(); |
|
60
|
|
|
try { |
|
61
|
1 |
|
if (($organization = $request->request->get('organization')) !== null) { |
|
62
|
1 |
|
$organization = $organizationManager->createOrganization($organization); |
|
63
|
|
|
} |
|
64
|
1 |
|
if (($productOwnerData = $request->request->get('product_owner')) === null && !$this->isGranted('ROLE_USER')) { |
|
65
|
|
|
throw new BadRequestHttpException('projects.missing_product_owner'); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
1 |
|
$productOwner = ($productOwnerData !== null) ? $userManager->createUser( |
|
68
|
1 |
|
$request->request->get('product_owner'), |
|
69
|
1 |
|
ProductOwner::TYPE_PRODUCT_OWNER, |
|
70
|
1 |
|
$organization |
|
71
|
1 |
|
) : $this->getUser(); |
|
72
|
1 |
|
$project = $projectManager->createProject( |
|
73
|
1 |
|
$request->request->get('project')['name'], |
|
74
|
1 |
|
$request->request->get('project')['description'], |
|
75
|
1 |
|
$productOwner, |
|
|
|
|
|
|
76
|
1 |
|
$organization |
|
77
|
|
|
); |
|
78
|
1 |
|
if ($organization !== null && !$productOwner->hasOrganization($organization)) { |
|
79
|
|
|
$productOwner->addOrganization($organization); |
|
80
|
|
|
} |
|
81
|
1 |
|
$projectManager->joinProject($project, $productOwner, false); |
|
82
|
1 |
|
$authenticationManager->authenticate($request, $productOwner); |
|
83
|
1 |
|
$connection->commit(); |
|
84
|
1 |
|
return new JsonResponse($project, 201); |
|
85
|
|
|
} catch (\Exception $ex) { |
|
86
|
|
|
$connection->rollback(); |
|
87
|
|
|
throw $ex; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @Route("/projects/{slug}", name="project_page", methods={"GET"}) |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getAction(Request $request, ProjectManager $projectManager, NewsManager $newsManager) |
|
95
|
|
|
{ |
|
96
|
|
|
$project = $projectManager->get($request->attributes->get('slug')); |
|
97
|
|
|
|
|
98
|
|
|
return $this->render('projects/details.html.twig', [ |
|
99
|
|
|
'project' => $project, |
|
100
|
|
|
'news' => $newsManager->getProjectNews($project), |
|
101
|
|
|
'members' => $projectManager->getProjectMembers($project), |
|
102
|
|
|
'membership' => ($this->isGranted('ROLE_USER')) ? $projectManager->getProjectMember($project, $this->getUser()) : null |
|
103
|
|
|
]); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @Route("/projects/{slug}/workspace", name="project_workspace", methods={"GET"}) |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function getWorkspaceAction(Request $request, ProjectManager $projectManager, DetailsManager $detailsManager, PollManager $pollManager) |
|
110
|
|
|
{ |
|
111
|
1 |
|
$project = $projectManager->get($request->attributes->get('slug')); |
|
112
|
1 |
|
return $this->render('projects/workspace.html.twig', [ |
|
113
|
1 |
|
'project' => $project, |
|
114
|
1 |
|
'details' => $detailsManager->getCurrentProjectDetails($project), |
|
115
|
1 |
|
'poll' => $pollManager->getCurrentProjectPoll($project), |
|
116
|
|
|
]); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @Route("/projects/{slug}/details", name="project_details", methods={"GET"}) |
|
121
|
|
|
*/ |
|
122
|
1 |
|
public function getDetailsAction(Request $request, ProjectManager $projectManager, DetailsManager $detailsManager) |
|
123
|
|
|
{ |
|
124
|
1 |
|
$this->denyAccessUnlessGranted('ROLE_USER'); |
|
125
|
1 |
|
$project = $projectManager->get($request->attributes->get('slug')); |
|
126
|
1 |
|
$user = $this->getUser(); |
|
127
|
1 |
|
if (!$user->getProjects()->contains($project)) { |
|
128
|
1 |
|
throw new AccessDeniedHttpException('projects.access_denied'); |
|
129
|
|
|
} |
|
130
|
1 |
|
return $this->render('projects/details_edition.html.twig', [ |
|
131
|
1 |
|
'project' => $project, |
|
132
|
1 |
|
'details' => $detailsManager->getCurrentProjectDetails($project) |
|
133
|
|
|
]); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @Route("/projects/{slug}/details", name="put_project_details", methods={"PUT"}) |
|
138
|
|
|
*/ |
|
139
|
1 |
|
public function putDetailsAction(Request $request, ProjectManager $projectManager, DetailsManager $detailsManager) |
|
140
|
|
|
{ |
|
141
|
1 |
|
$this->denyAccessUnlessGranted('ROLE_USER'); |
|
142
|
1 |
|
$project = $projectManager->get($request->attributes->get('slug')); |
|
143
|
1 |
|
$user = $this->getUser(); |
|
144
|
1 |
|
if (!$user->getProjects()->contains($project)) { |
|
145
|
1 |
|
throw new AccessDeniedHttpException('projects.access_denied'); |
|
146
|
|
|
} |
|
147
|
1 |
|
$details = $detailsManager->putProjectDetails($project, $request->request->all()); |
|
148
|
1 |
|
return new JsonResponse($details, ($details->getCreatedAt() === $details->getUpdatedAt()) ? 201 : 200); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @Route("/projects/{slug}/join", name="project_join", methods={"POST"}) |
|
153
|
|
|
*/ |
|
154
|
|
|
public function joinAction(Request $request, ProjectManager $projectManager) |
|
155
|
|
|
{ |
|
156
|
|
|
$this->denyAccessUnlessGranted('ROLE_USER'); |
|
157
|
|
|
$project = $projectManager->get($request->attributes->get('slug')); |
|
158
|
|
|
|
|
159
|
|
|
$membership = $projectManager->joinProject($project, $this->getUser()); |
|
160
|
|
|
|
|
161
|
|
|
return new JsonResponse($membership, 201); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.