This commit is contained in:
Kevin Papst
2021-09-16 17:06:32 +02:00
committed by GitHub
parent 2536105ad0
commit f2eec4f315
9 changed files with 140 additions and 62 deletions

View File

@@ -93,7 +93,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Returns one team entity",
* @SWG\Schema(ref="#/definitions/TeamEntity"),
* @SWG\Schema(ref="#/definitions/Team"),
* )
*
* @Security("is_granted('view_team')")
@@ -160,7 +160,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Returns the new created team",
* @SWG\Schema(ref="#/definitions/TeamEntity"),
* @SWG\Schema(ref="#/definitions/Team"),
* )
* )
* @SWG\Parameter(
@@ -205,7 +205,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Returns the updated team",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(
@@ -277,7 +277,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Adds a new user to a team.",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(
@@ -336,7 +336,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Removes a user from the team. The teamlead cannot be removed.",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(
@@ -399,7 +399,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Adds a new customer to a team.",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(
@@ -458,7 +458,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Removes a customer from the team.",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(
@@ -517,7 +517,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Adds a new project to a team.",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(
@@ -576,7 +576,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Removes a project from the team.",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(
@@ -635,7 +635,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Adds a new activity to a team.",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(
@@ -694,7 +694,7 @@ final class TeamController extends BaseApiController
* @SWG\Response(
* response=200,
* description="Removes a activity from the team.",
* @SWG\Schema(ref="#/definitions/TeamEntity")
* @SWG\Schema(ref="#/definitions/Team")
* )
* )
* @SWG\Parameter(

View File

@@ -421,7 +421,6 @@ final class ActivityController extends AbstractController
'action' => $url,
'method' => 'POST',
'currency' => $currency,
'customer' => true,
'include_budget' => $this->isGranted('budget', $activity)
]);
}

View File

@@ -349,7 +349,7 @@ class Team
* @Serializer\VirtualProperty
* @Serializer\SerializedName("users"),
* @Serializer\Groups({"Team_Entity"})
* @SWG\Property(ref="#/definitions/User")
* @SWG\Property(type="array", @SWG\Items(ref="#/definitions/User"))
*
* @return User[]
*/

View File

@@ -51,7 +51,7 @@ class TeamMember
*
* @Serializer\Expose()
* @Serializer\Groups({"Default", "Entity", "User_Entity"})
* @SWG\Property(ref="#/definitions/TeamEntity")
* @SWG\Property(ref="#/definitions/Team")
*
* @ORM\ManyToOne(targetEntity="App\Entity\Team", inversedBy="members")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)

View File

@@ -173,6 +173,8 @@ class User implements UserInterface, EquatableInterface, \Serializable
*/
private $preferences;
/**
* List of all team memberships.
*
* @var TeamMember[]|ArrayCollection<TeamMember>
*
* @Serializer\Expose()
@@ -273,6 +275,8 @@ class User implements UserInterface, EquatableInterface, \Serializable
*/
private $passwordRequestedAt;
/**
* List of all role names
*
* @Serializer\Expose()
* @Serializer\Groups({"User_Entity"})
* @Serializer\Type("array<string>")
@@ -625,10 +629,12 @@ class User implements UserInterface, EquatableInterface, \Serializable
}
/**
* List of all teams, this user is part of
*
* @Serializer\VirtualProperty
* @Serializer\SerializedName("teams"),
* @Serializer\Groups({"User_Entity"})
* @SWG\Property(ref="#/definitions/TeamEntity")
* @SWG\Property(type="array", @SWG\Items(ref="#/definitions/Team"))
*
* @return Team[]
*/

View File

@@ -11,18 +11,13 @@ namespace App\Form;
use App\Entity\Activity;
use App\Entity\Customer;
use App\Form\Type\CustomerType;
use App\Form\Type\ProjectType;
use App\Repository\CustomerRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\CustomerFormTypeQuery;
use App\Repository\Query\ProjectFormTypeQuery;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ActivityEditForm extends AbstractType
@@ -37,6 +32,7 @@ class ActivityEditForm extends AbstractType
$project = null;
$customer = null;
$new = true;
$isGlobal = false;
if (isset($options['data'])) {
/** @var Activity $entry */
@@ -46,6 +42,8 @@ class ActivityEditForm extends AbstractType
$project = $entry->getProject();
$customer = $project->getCustomer();
$options['currency'] = $customer->getCurrency();
} else {
$isGlobal = null === $entry->getProject();
}
$new = $entry->getId() === null;
@@ -64,23 +62,7 @@ class ActivityEditForm extends AbstractType
])
;
if ($new) {
if ($options['customer']) {
$builder
->add('customer', CustomerType::class, [
'query_builder' => function (CustomerRepository $repo) use ($builder, $customer) {
$query = new CustomerFormTypeQuery($customer);
$query->setUser($builder->getOption('user'));
return $repo->getQueryBuilderForFormType($query);
},
'data' => $customer ? $customer : null,
'required' => false,
'mapped' => false,
'project_enabled' => true,
]);
}
if ($new || !$isGlobal) {
$builder
->add('project', ProjectType::class, [
'required' => false,
@@ -92,28 +74,6 @@ class ActivityEditForm extends AbstractType
return $repo->getQueryBuilderForFormType($query);
},
]);
// replaces the project select after submission, to make sure only projects for the selected customer are displayed
$builder->addEventListener(
FormEvents::PRE_SUBMIT,
function (FormEvent $event) use ($builder, $project) {
$data = $event->getData();
if (!isset($data['customer']) || empty($data['customer'])) {
return;
}
$event->getForm()->add('project', ProjectType::class, [
'group_by' => null,
'query_builder' => function (ProjectRepository $repo) use ($builder, $data, $project) {
$query = new ProjectFormTypeQuery($project, $data['customer']);
$query->setUser($builder->getOption('user'));
$query->setIgnoreDate(true);
return $repo->getQueryBuilderForFormType($query);
},
]);
}
);
}
$this->addCommonFields($builder, $options);
@@ -129,6 +89,7 @@ class ActivityEditForm extends AbstractType
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_activity_edit',
// @deprecated not supported since 1.15, which removed the customer select completely
'customer' => false,
'currency' => Customer::DEFAULT_CURRENCY,
'include_budget' => false,