Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge branch 'pu/pm/HRFreeTimeStatusTypeAcl' into '2022.11'
Browse files Browse the repository at this point in the history
tweak(HR FreeTime) update status/type/acls

See merge request tine20/tine20!1891
  • Loading branch information
paulmhh committed Mar 16, 2022
2 parents dd39084 + 23582f2 commit db6ddf1
Show file tree
Hide file tree
Showing 54 changed files with 1,540 additions and 616 deletions.
1 change: 1 addition & 0 deletions tests/tine20/HumanResources/Controller/ContractTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testUpdateContract()
'status' => 'ACCEPTED',
'employee_id' => $employee->getId(),
'account_id' => $myAccount->getId(),
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_REQUESTED,
'type' => 'vacation',
'freedays' => array(
array('date' => $firstDayDate, 'duration' => 1)
Expand Down
2 changes: 2 additions & 0 deletions tests/tine20/HumanResources/Controller/DailyWTReportTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public function testCalculateReportsForEmployeeVacation()
'employee_id' => $this->employee->getId(),
'account_id' => $this->employee->account_id,
'type' => HumanResources_Model_FreeTimeType::ID_VACATION,
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'freedays' => [
['date' => '2018-08-01']
]
Expand Down Expand Up @@ -307,6 +308,7 @@ public function testCalculateReportsForEmployeeSickness()
'employee_id' => $this->employee->getId(),
'account_id' => $this->employee->account_id,
'type' => HumanResources_Model_FreeTimeType::ID_SICKNESS,
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'freedays' => [
['date' => '2018-08-01']
]
Expand Down
48 changes: 47 additions & 1 deletion tests/tine20/HumanResources/Controller/FreeTimeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package HumanResources
* @license http://www.gnu.org/licenses/agpl.html
* @copyright Copyright (c) 2018-2021 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2018-2022 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Cornelius Weiss <c.weiss@metaways.de>
*/

Expand Down Expand Up @@ -40,6 +40,7 @@ protected function _createFreeTime($user = null)
'employee_id' => $this->employee->getId(),
'account_id' => $accountId,
'type' => HumanResources_Model_FreeTimeType::ID_VACATION,
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'freedays' => [
['date' => '2018-08-01'],
['date' => '2018-08-02']
Expand Down Expand Up @@ -136,4 +137,49 @@ public function testAccessOwnDataGrant()
['field' => 'account_id', 'operator' => 'equals', 'value' => $freeTime->account_id],
]))->count());
}

public function testCreateChangeRequestGrant()
{
Tinebase_TransactionManager::getInstance()->unitTestForceSkipRollBack(true);

$freeTime = $this->_createFreeTime('pwulf');

Tinebase_Core::setUser($this->_personas['jsmith']);

try {
HumanResources_Controller_FreeTime::getInstance()->get($freeTime->getId());
$this->fail('pwulf should not see jsmith data');
} catch (Tinebase_Exception_AccessDenied $tead) {}

try {
HumanResources_Controller_Account::getInstance()->get($freeTime->account_id);
$this->fail('pwulf should not see jsmith data');
} catch (Tinebase_Exception_AccessDenied $tead) {}

try {
HumanResources_Controller_Employee::getInstance()->get($freeTime->employee_id);
$this->fail('pwulf should not see jsmith data');
} catch (Tinebase_Exception_AccessDenied $tead) {}

$grants = Tinebase_Container::getInstance()->getGrantsOfContainer(
($d = HumanResources_Controller_Division::getInstance()->get($this->employee->division_id))->container_id,
true);
$grants->addRecord(new HumanResources_Model_DivisionGrants([
'record_id' => $d->container_id,
'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER,
'account_id' => $this->_personas['jsmith']->getId(),
HumanResources_Model_DivisionGrants::CREATE_CHANGE_REQUEST => true,
]));
Tinebase_Container::getInstance()->setGrants($d->container_id, $grants, true, false);


HumanResources_Controller_FreeTime::getInstance()->get($freeTime->getId());
HumanResources_Controller_Account::getInstance()->get($freeTime->account_id);
HumanResources_Controller_Employee::getInstance()->get($freeTime->employee_id);
$contracts = HumanResources_Controller_Contract::getInstance()->search(
Tinebase_Model_Filter_FilterGroup::getFilterForModel(HumanResources_Model_Contract::class, [
['field' => 'employee_id', 'operator' => 'equals', 'value' => $freeTime->getIdFromProperty('employee_id')],
]));
$this->assertSame(1, $contracts->count());
}
}
26 changes: 15 additions & 11 deletions tests/tine20/HumanResources/JsonTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function testGetFeastAndFreeDaysWithGrants()
'employee_id' => $savedEmployee['id'],
'account_id' => $myAccount->getId(),
'type' => 'vacation',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_REQUESTED,
'freedays' => array(
array('date' => $date->getClone()->addDay(60), 'duration' => 1),
)
Expand Down Expand Up @@ -165,6 +166,7 @@ public function testEmployee()
'employee_id' => $savedEmployee['id'],
'account_id' => $myAccount->getId(),
'type' => 'vacation',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_REQUESTED,
'freedays' => array(
array('date' => $firstDayDate, 'duration' => 1),
array('date' => $firstDayDate->getClone()->addDay(1), 'duration' => 1),
Expand Down Expand Up @@ -685,7 +687,7 @@ public function testCalculation()
'account_id' => $accountId2013,
'employee_id' => $employee->getId(),
'type' => 'vacation',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'firstday_date' => $yesterday->subWeek(1)->toString()
);
$nd = $referenceDate->subMonth(2);
Expand Down Expand Up @@ -726,7 +728,7 @@ public function testCalculation()
'account_id' => $accountId2014,
'employee_id' => $employee->getId(),
'type' => 'vacation',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'firstday_date' => $refdate,
'lastday_date' => $refdate->addDay(3)->toString(),
'days_count' => 3
Expand Down Expand Up @@ -768,7 +770,7 @@ public function testCalculation()
'account_id' => $accountId2013,
'employee_id' => $employee->getId(),
'type' => 'vacation',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'firstday_date' => $day->toString()
);

Expand All @@ -793,7 +795,7 @@ public function testCalculation()
'account_id' => $accountId2013,
'employee_id' => $employee->getId(),
'type' => 'sickness',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'firstday_date' => $day->toString()
);

Expand Down Expand Up @@ -869,7 +871,7 @@ public function testFirstAndLastDayOfFreetime()
'account_id' => $accountId2013,
'employee_id' => $employee->getId(),
'type' => 'vacation',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
);

$newFreeTime['freedays'] = array(
Expand Down Expand Up @@ -1104,7 +1106,7 @@ public function testAddContract()
'employee_id' => $employeeJson['id'],
'account_id' => $account->getId(),
'type' => 'vacation',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'freedays' => [['duration' => '1', 'date' => '2013-01-11 00:00:00']],
]));

Expand Down Expand Up @@ -1245,7 +1247,7 @@ public function testAlternatingContracts()
'account_id' => $account['id'],
'employee_id' => $recordData['id'],
'type' => 'vacation',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'firstday_date' => $day->toString()
);

Expand All @@ -1265,7 +1267,7 @@ public function testAlternatingContracts()
'account_id' => $account['id'],
'employee_id' => $recordData['id'],
'type' => 'vacation',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'firstday_date' => $day->toString()
);

Expand All @@ -1288,7 +1290,7 @@ public function testAlternatingContracts()
'account_id' => $account['id'],
'employee_id' => $recordData['id'],
'type' => 'vacation',
'status' => 'ACCEPTED',
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
'firstday_date' => $day->toString()
);

Expand All @@ -1311,7 +1313,8 @@ public function testAlternatingContracts()
'account_id' => $account['id'],
'employee_id' => $recordData['id'],
'type' => 'sickness',
'status' => "EXCUSED",
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
HumanResources_Model_FreeTime::FLD_TYPE_STATUS => HumanResources_Config::FREE_TIME_TYPE_STATUS_EXCUSED,
'firstday_date' => $day->toString()
);

Expand Down Expand Up @@ -1349,7 +1352,8 @@ public function testAlternatingContracts()
'account_id' => $account['id'],
'employee_id' => $recordData['id'],
'type' => 'sickness',
'status' => "UNEXCUSED",
HumanResources_Model_FreeTime::FLD_PROCESS_STATUS => HumanResources_Config::FREE_TIME_PROCESS_STATUS_ACCEPTED,
HumanResources_Model_FreeTime::FLD_TYPE_STATUS => HumanResources_Config::FREE_TIME_TYPE_STATUS_UNEXCUSED,
'firstday_date' => $day->toString()
);

Expand Down
11 changes: 11 additions & 0 deletions tests/tine20/HumanResources/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ protected function setUp(): void
parent::setUp();
}

protected function tearDown(): void
{
$this->_feast_calendar = null;
$this->_department = null;
$this->_40hoursWorkingTimeScheme = null;
$this->employee = null;
$this->division = null;

parent::tearDown();
}


protected function _createBasicData($account = null)
{
Expand Down
1 change: 1 addition & 0 deletions tests/tine20/Tinebase/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ public function testGetModelsOfAllApplications()
HumanResources_Model_StreamModalReport::class,
HumanResources_Model_WageType::class,
HumanResources_Model_WorkingTimeScheme::class,
HumanResources_Model_WTRCorrection::class,
),
'Inventory' => array(
Inventory_Model_InventoryItem::class,
Expand Down
72 changes: 44 additions & 28 deletions tine20/HumanResources/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ class HumanResources_Config extends Tinebase_Config_Abstract
{
const APP_NAME = 'HumanResources';

/**
* Vacation Status
* @var string
*/
const VACATION_STATUS = 'vacationStatus';
const FREE_TIME_TYPE_STATUS = 'freeTimeTypeStatus';
const FREE_TIME_TYPE_STATUS_EXCUSED = 'EXCUSED';
const FREE_TIME_TYPE_STATUS_UNEXCUSED = 'UNEXCUSED';
const FREE_TIME_PROCESS_STATUS = 'freeTimeProcessStatus';
const FREE_TIME_PROCESS_STATUS_REQUESTED = 'REQUESTED';
const FREE_TIME_PROCESS_STATUS_ACCEPTED = 'ACCEPTED';
const FREE_TIME_PROCESS_STATUS_DECLINED = 'DECLINED';

const WTR_CORRECTION_STATUS = 'wtrCorrectionStatus';
const WTR_CORRECTION_STATUS_REQUESTED = 'REQUESTED';
const WTR_CORRECTION_STATUS_ACCEPTED = 'ACCEPTED';
const WTR_CORRECTION_STATUS_DECLINED = 'DECLINED';

/**
* Sickness Status
* @var string
*/
const SICKNESS_STATUS = 'sicknessStatus';

/**
* Default Feast Calendar (used for tailoring datepicker)
* @var string
Expand Down Expand Up @@ -90,40 +91,55 @@ class HumanResources_Config extends Tinebase_Config_Abstract
* @see tine20/Tinebase/Config/Definition::$_properties
*/
protected static $_properties = array(
self::VACATION_STATUS => array(
self::FREE_TIME_TYPE_STATUS => array(
//_('Sickness Status')
'label' => 'Sickness Status',
//_('Possible sickness status definitions')
'description' => 'Possible sickness status definitions',
'type' => 'keyFieldConfig',
'options' => array('recordModel' => HumanResources_Model_FreeTimeStatus::class),
'clientRegistryInclude' => TRUE,
'default' => array(
'records' => array(
array('id' => self::FREE_TIME_TYPE_STATUS_EXCUSED, 'value' => 'Excused', 'icon' => 'images/icon-set/icon_ok.svg', 'system' => TRUE), //_('Excused')
array('id' => self::FREE_TIME_TYPE_STATUS_UNEXCUSED, 'value' => 'Unexcused', 'icon' => 'images/icon-set/icon_stop.svg', 'system' => TRUE), //_('Unexcused')

),
'default' => 'EXCUSED'
)
),
self::FREE_TIME_PROCESS_STATUS => array(
//_('Vacation Status')
'label' => 'Vacation Status',
//_('Possible vacation status definitions')
'description' => 'Possible vacation status definitions',
'type' => 'keyFieldConfig',
'options' => array('recordModel' => 'HumanResources_Model_FreeTimeStatus'),
'options' => array('recordModel' => HumanResources_Model_FreeTimeStatus::class),
'clientRegistryInclude' => TRUE,
'default' => array(
'records' => array(
array('id' => 'REQUESTED', 'value' => 'Requested', 'icon' => 'images/icon-set/icon_invite.svg', 'system' => TRUE), //_('Requested')
array('id' => 'IN-PROCESS', 'value' => 'In process', 'icon' => 'images/icon-set/icon_reload.svg', 'system' => TRUE), //_('In process')
array('id' => 'ACCEPTED', 'value' => 'Accepted', 'icon' => 'images/icon-set/icon_ok.svg', 'system' => TRUE), //_('Accepted')
array('id' => 'DECLINED', 'value' => 'Declined', 'icon' => 'images/icon-set/icon_stop.svg', 'system' => TRUE), //_('Declined')
array('id' => self::FREE_TIME_PROCESS_STATUS_REQUESTED, 'value' => 'Requested', 'icon' => 'images/icon-set/icon_invite.svg', 'system' => TRUE), //_('Requested')
array('id' => self::FREE_TIME_PROCESS_STATUS_ACCEPTED, 'value' => 'Accepted', 'icon' => 'images/icon-set/icon_ok.svg', 'system' => TRUE), //_('Accepted')
array('id' => self::FREE_TIME_PROCESS_STATUS_DECLINED, 'value' => 'Declined', 'icon' => 'images/icon-set/icon_stop.svg', 'system' => TRUE), //_('Declined')

),
'default' => 'REQUESTED'
'default' => self::FREE_TIME_PROCESS_STATUS_REQUESTED
)
),
self::SICKNESS_STATUS => array(
//_('Sickness Status')
'label' => 'Sickness Status',
//_('Possible sickness status definitions')
'description' => 'Possible sickness status definitions',
self::WTR_CORRECTION_STATUS => array(
//_('Working Time Correction Status')
'label' => 'Working Time Correction Status',
//_('Working Time Correction Status')
'description' => 'Working Time Correction Status',
'type' => 'keyFieldConfig',
'options' => array('recordModel' => 'HumanResources_Model_FreeTimeStatus'),
'clientRegistryInclude' => TRUE,
'default' => array(
'records' => array(
array('id' => 'EXCUSED', 'value' => 'Excused', 'icon' => 'images/icon-set/icon_ok.svg', 'system' => TRUE), //_('Excused')
array('id' => 'UNEXCUSED', 'value' => 'Unexcused', 'icon' => 'images/icon-set/icon_stop.svg', 'system' => TRUE), //_('Unexcused')

array('id' => self::WTR_CORRECTION_STATUS_REQUESTED, 'value' => 'Requested', 'icon' => 'images/icon-set/icon_invite.svg', 'system' => TRUE), //_('Requested')
array('id' => self::WTR_CORRECTION_STATUS_ACCEPTED, 'value' => 'Accepted', 'icon' => 'images/icon-set/icon_ok.svg', 'system' => TRUE), //_('Accepted')
array('id' => self::WTR_CORRECTION_STATUS_DECLINED, 'value' => 'Declined', 'icon' => 'images/icon-set/icon_stop.svg', 'system' => TRUE), //_('Declined')
),
'default' => 'EXCUSED'
'default' => self::WTR_CORRECTION_STATUS_REQUESTED,
)
),
self::DEFAULT_FEAST_CALENDAR => array(
Expand Down

0 comments on commit db6ddf1

Please sign in to comment.