Project API and globalActivities flag (#3564)
* expose globalActivities setting in project entity * fix globalActivities being true by default if created via API
This commit is contained in:
@@ -257,6 +257,9 @@ class Project implements EntityWithMetaFields, EntityWithBudget
|
|||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*
|
*
|
||||||
|
* @Serializer\Expose()
|
||||||
|
* @Serializer\Groups({"Default"})
|
||||||
|
*
|
||||||
* @ORM\Column(name="global_activities", type="boolean", nullable=false, options={"default": true})
|
* @ORM\Column(name="global_activities", type="boolean", nullable=false, options={"default": true})
|
||||||
* @Assert\NotNull()
|
* @Assert\NotNull()
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
namespace App\Form\API;
|
namespace App\Form\API;
|
||||||
|
|
||||||
use App\Form\ProjectEditForm;
|
use App\Form\ProjectEditForm;
|
||||||
|
use App\Form\Type\APITrueFalseType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
@@ -23,6 +24,11 @@ class ProjectApiEditForm extends ProjectEditForm
|
|||||||
parent::buildForm($builder, $options);
|
parent::buildForm($builder, $options);
|
||||||
|
|
||||||
$builder->remove('metaFields');
|
$builder->remove('metaFields');
|
||||||
|
$builder->remove('globalActivities');
|
||||||
|
$builder->add('globalActivities', APITrueFalseType::class, [
|
||||||
|
'label' => 'label.globalActivities',
|
||||||
|
'empty_data' => '1',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
30
src/Form/Type/APITrueFalseType.php
Normal file
30
src/Form/Type/APITrueFalseType.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Kimai time-tracking app.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Form\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class APITrueFalseType extends AbstractType
|
||||||
|
{
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'false_values' => [0, '0', false],
|
||||||
|
'required' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParent(): string
|
||||||
|
{
|
||||||
|
return CheckboxType::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -433,6 +433,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
|||||||
'billable' => 'bool',
|
'billable' => 'bool',
|
||||||
'color' => '@string',
|
'color' => '@string',
|
||||||
'customer' => 'int',
|
'customer' => 'int',
|
||||||
|
'globalActivities' => 'bool',
|
||||||
'comment' => '@string',
|
'comment' => '@string',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -445,6 +446,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
|||||||
'billable' => 'bool',
|
'billable' => 'bool',
|
||||||
'color' => '@string',
|
'color' => '@string',
|
||||||
'customer' => ['result' => 'object', 'type' => 'Customer'],
|
'customer' => ['result' => 'object', 'type' => 'Customer'],
|
||||||
|
'globalActivities' => 'bool',
|
||||||
'comment' => '@string',
|
'comment' => '@string',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -461,6 +463,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
|||||||
'parentTitle' => 'string',
|
'parentTitle' => 'string',
|
||||||
'start' => '@datetime',
|
'start' => '@datetime',
|
||||||
'end' => '@datetime',
|
'end' => '@datetime',
|
||||||
|
'globalActivities' => 'bool',
|
||||||
'teams' => ['result' => 'array', 'type' => 'Team'],
|
'teams' => ['result' => 'array', 'type' => 'Team'],
|
||||||
'comment' => '@string',
|
'comment' => '@string',
|
||||||
];
|
];
|
||||||
@@ -478,6 +481,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
|
|||||||
'parentTitle' => 'string',
|
'parentTitle' => 'string',
|
||||||
'start' => '@datetime',
|
'start' => '@datetime',
|
||||||
'end' => '@datetime',
|
'end' => '@datetime',
|
||||||
|
'globalActivities' => 'bool',
|
||||||
'teams' => ['result' => 'array', 'type' => 'Team'],
|
'teams' => ['result' => 'array', 'type' => 'Team'],
|
||||||
'comment' => '@string',
|
'comment' => '@string',
|
||||||
'budget' => 'float',
|
'budget' => 'float',
|
||||||
|
|||||||
@@ -298,12 +298,51 @@ class ProjectControllerTest extends APIControllerBaseTest
|
|||||||
$this->assertIsArray($result);
|
$this->assertIsArray($result);
|
||||||
self::assertApiResponseTypeStructure('ProjectEntity', $result);
|
self::assertApiResponseTypeStructure('ProjectEntity', $result);
|
||||||
$this->assertNotEmpty($result['id']);
|
$this->assertNotEmpty($result['id']);
|
||||||
|
self::assertTrue($result['globalActivities']);
|
||||||
self::assertEquals('2018-02-08T13:02:54+0000', $result['orderDate']);
|
self::assertEquals('2018-02-08T13:02:54+0000', $result['orderDate']);
|
||||||
self::assertEquals('2019-02-01T19:32:17+0000', $result['start']);
|
self::assertEquals('2019-02-01T19:32:17+0000', $result['start']);
|
||||||
self::assertEquals('2020-02-08T21:11:42+0000', $result['end']);
|
self::assertEquals('2020-02-08T21:11:42+0000', $result['end']);
|
||||||
self::assertEquals('1234567890/WXYZ/SUBPROJECT/1234/CONTRACT/EMPLOYEE1', $result['orderNumber']);
|
self::assertEquals('1234567890/WXYZ/SUBPROJECT/1234/CONTRACT/EMPLOYEE1', $result['orderNumber']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPostActionWithOtherFields()
|
||||||
|
{
|
||||||
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||||
|
$data = [
|
||||||
|
'name' => 'foo',
|
||||||
|
'customer' => 1,
|
||||||
|
'globalActivities' => '0',
|
||||||
|
];
|
||||||
|
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
|
||||||
|
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||||
|
|
||||||
|
$result = json_decode($client->getResponse()->getContent(), true);
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
self::assertApiResponseTypeStructure('ProjectEntity', $result);
|
||||||
|
$this->assertNotEmpty($result['id']);
|
||||||
|
self::assertEquals('foo', $result['name']);
|
||||||
|
self::assertFalse($result['globalActivities']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostActionWithOtherFields2()
|
||||||
|
{
|
||||||
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||||
|
$data = [
|
||||||
|
'name' => 'foo',
|
||||||
|
'customer' => 1,
|
||||||
|
'globalActivities' => '1',
|
||||||
|
];
|
||||||
|
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
|
||||||
|
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||||
|
|
||||||
|
$result = json_decode($client->getResponse()->getContent(), true);
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
self::assertApiResponseTypeStructure('ProjectEntity', $result);
|
||||||
|
$this->assertNotEmpty($result['id']);
|
||||||
|
self::assertEquals('foo', $result['name']);
|
||||||
|
self::assertTrue($result['globalActivities']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testPostActionWithLeastFields()
|
public function testPostActionWithLeastFields()
|
||||||
{
|
{
|
||||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||||
|
|||||||
Reference in New Issue
Block a user