/** * @param Project $project * @param User $user * @return bool */ private function canRead(Project $project, User $user) : bool { $visibility = $project->getVisibility(); switch ($visibility) { case 0: return $this->canEdit($project, $user); case 1: return $user instanceof User; case 2: return true; } }
/** * @param Project $project * @return User */ public function addProject(Project $project) { $project->setUser($this); $this->projects[] = $project; return $this; }
/** * @param Project $project * @return JsonResponse * * @Route("/secured/users/{slug}/projects/{projectSlug}/config/edit", name="user_project_configuration_edition") * @Method({"POST"}) * @Security("is_granted('edit', project)") */ public function editProjectConfigurationAction(Request $request, Project $project) { $configurationFactory = $this->get('app.project.factory.configuration'); $configuration = $configurationFactory->create(); $form = $this->createNamedForm('', ConfigurationType::class, $configuration); $form->handleRequest($request); if (!$form->isValid()) { return new JsonResponse(['error' => $this->getFormErrors($form)], 400); } $project->setConfiguration($configuration); $this->persistAndFlush($project); return ['id' => $project->getId(), 'slug' => $project->getSlug(), 'configuration' => $project->getConfiguration()]; }