Skip to content

Commit

Permalink
OHRM5X-2177: Add claim module to admin module configurations (orangeh…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nethmin Dulsara authored May 31, 2023
1 parent 9aa281d commit 07a4dd3
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
</oxd-text>
<oxd-switch-input v-model="modules.mobile" />
</div>
<div class="orangehrm-module-field-row">
<oxd-text tag="p" class="orangehrm-module-field-label">
{{ $t('claim.claim_module') }}
</oxd-text>
<oxd-switch-input v-model="modules.claim" />
</div>
</oxd-grid>
</oxd-form-row>

Expand Down Expand Up @@ -112,6 +118,7 @@ const modulesModel = {
maintenance: false,
mobile: false,
directory: false,
claim: false,
};

export default {
Expand Down Expand Up @@ -148,6 +155,7 @@ export default {
this.modules.maintenance = data.maintenance;
this.modules.mobile = data.mobile;
this.modules.directory = data.directory;
this.modules.claim = data.claim;
})
.finally(() => {
this.isLoading = false;
Expand All @@ -166,6 +174,7 @@ export default {
maintenance: this.modules.maintenance,
mobile: this.modules.mobile,
directory: this.modules.directory,
claim: this.modules.claim,
};
this.http
.request({
Expand Down
19 changes: 15 additions & 4 deletions src/plugins/orangehrmAdminPlugin/Api/ModulesAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ModulesAPI extends Endpoint implements CrudEndpoint
public const PARAMETER_MAINTENANCE = 'maintenance';
public const PARAMETER_MOBILE = 'mobile';
public const PARAMETER_DIRECTORY = 'directory';
public const PARAMETER_CLAIM = 'claim';

/**
* @var ModuleService|null
Expand All @@ -65,6 +66,7 @@ class ModulesAPI extends Endpoint implements CrudEndpoint
self::PARAMETER_MAINTENANCE => false,
self::PARAMETER_MOBILE => false,
self::PARAMETER_DIRECTORY => false,
self::PARAMETER_CLAIM => false,
];

/**
Expand Down Expand Up @@ -100,7 +102,8 @@ public function getModuleService(): ModuleService
* @OA\Property(property="performance", type="boolean"),
* @OA\Property(property="maintenance", type="boolean"),
* @OA\Property(property="mobile", type="boolean"),
* @OA\Property(property="directory", type="boolean")
* @OA\Property(property="directory", type="boolean"),
* @OA\Property(property="claim", type="boolean"),
* ),
* example="admin: true, pim: true, leave: false, time: true,...",
* )
Expand Down Expand Up @@ -196,7 +199,8 @@ public function getValidationRuleForCreate(): ParamRuleCollection
* @OA\Property(property="performance", type="boolean"),
* @OA\Property(property="maintenance", type="boolean"),
* @OA\Property(property="mobile", type="boolean"),
* @OA\Property(property="directory", type="boolean")
* @OA\Property(property="directory", type="boolean"),
* @OA\Property(property="claim", type="boolean")
* )
* ),
* @OA\Response(response="200",
Expand All @@ -220,8 +224,9 @@ public function getValidationRuleForCreate(): ParamRuleCollection
public function update(): EndpointResourceResult
{
$modules = self::CONFIGURABLE_MODULES;
foreach ($modules as $key => $module) {
$modules[$key] = $this->getRequestParams()->getBoolean(RequestParams::PARAM_TYPE_BODY, $key, true);
foreach (self::CONFIGURABLE_MODULES as $key => $module) {
$modules[$key] = $this->getRequestParams()
->getBoolean(RequestParams::PARAM_TYPE_BODY, $key, self::CONFIGURABLE_MODULES[$key]);
}
$this->getModuleService()->updateModuleStatus($modules);
$this->getMenuService()->invalidateCachedMenuItems();
Expand Down Expand Up @@ -277,6 +282,12 @@ public function getValidationRuleForUpdate(): ParamRuleCollection
self::PARAMETER_DIRECTORY,
new Rule(Rules::BOOL_TYPE),
),
$this->getValidationDecorator()->notRequiredParamRule(
new ParamRule(
self::PARAMETER_CLAIM,
new Rule(Rules::BOOL_TYPE),
)
)
);
}

Expand Down
12 changes: 6 additions & 6 deletions src/plugins/orangehrmAdminPlugin/test/Dao/ModuleDaoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function setUp(): void
public function testGetModuleList(): void
{
$moduleList = $this->moduleDao->getModuleList();
$this->assertEquals(7, count($moduleList));
$this->assertCount(8, $moduleList);
$this->assertTrue($moduleList[0] instanceof Module);
$this->assertEquals('admin', $moduleList[0]->getName());
$this->assertEquals(1, $moduleList[0]->getStatus());
Expand All @@ -68,17 +68,17 @@ public function testUpdateModuleStatus(): void
public function testUpdateModuleStatusForReturnedValues(): void
{
$moduleUpdateArray = ['admin' => true, 'pim' => false];
$returedObjects = $this->moduleDao->updateModuleStatus($moduleUpdateArray);
$this->assertEquals(7, count($returedObjects));
$this->assertTrue($returedObjects[0]->getStatus());
$this->assertFalse($returedObjects[1]->getStatus());
$returnedObjects = $this->moduleDao->updateModuleStatus($moduleUpdateArray);
$this->assertCount(8, $returnedObjects);
$this->assertTrue($returnedObjects[0]->getStatus());
$this->assertFalse($returnedObjects[1]->getStatus());
}

public function testUpdateModuleStatusWithModulesDoesNotExists(): void
{
$moduleUpdateArray = ['admin' => true, 'pim' => false, 'test' => true];
$returedObjects = $this->moduleDao->updateModuleStatus($moduleUpdateArray);
$this->assertEquals(7, count($returedObjects));
$this->assertCount(8, $returedObjects);
foreach ($returedObjects as $returedObject) {
$this->assertTrue($returedObject->getName() != 'test');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Module:
4: {id: 5, name: 'recruitment', status: 1, displayName: 'Recruitment'}
5: {id: 6, name: 'performance', status: 1, displayName: 'Performance'}
6: {id: 7, name: 'maintenance', status: 0, displayName: 'Maintenance'}
7: {id: 9, name: 'claim', status: 1, displayName: 'Claim'}

Employee:
0: {empNumber: 1, emp_firstname: 'Devi', emp_lastname: 'DS', employee_id: 'E001'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Module:
- { id: 6, name: 'performance', status: 1, displayName: 'Performance' }
- { id: 7, name: 'directory', status: 1, displayName: 'Directory' }
- { id: 8, name: 'maintenance', status: 0, displayName: 'Maintenance' }
- { id: 9, name: 'claim', status: 1, displayName: 'Claim' }

Employee:
- { empNumber: 1, emp_firstname: 'Lynda', emp_lastname: 'Jane', employee_id: '0001' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ GetAll:
performance: true,
maintenance: false,
mobile: false,
directory: true
directory: true,
claim: true
}

'unexpected param':
Expand All @@ -37,7 +38,8 @@ Update:
performance: false,
maintenance: false,
mobile: false,
directory: false
directory: false,
claim: false
}

'all modules enabled':
Expand All @@ -55,7 +57,8 @@ Update:
performance: true,
maintenance: true,
mobile: true,
directory: true
directory: true,
claim: false
}

'all modules disabled':
Expand Down Expand Up @@ -94,7 +97,8 @@ Update:
performance: false,
maintenance: false,
mobile: false,
directory: false
directory: false,
claim: false
}

'not submitting pim module':
Expand All @@ -112,7 +116,8 @@ Update:
performance: false,
maintenance: false,
mobile: false,
directory: false
directory: false,
claim: false
}

'not submitting any not required module':
Expand Down Expand Up @@ -142,3 +147,30 @@ Update:
core.menu_service: OrangeHRM\Core\Service\MenuService
body: { admin: true, leave: 'test', time: false, recruitment: false, performance: false, maintenance: false, mobile: false, directory: false }
invalidOnly: [ leave ]

'submitting with claim module':
userId: 1
services:
core.menu_service: OrangeHRM\Core\Service\MenuService
oauth.oauth_service: OrangeHRM\OAuth\Service\OAuthService
body: { admin: true, leave: false, time: false, recruitment: false, performance: false, maintenance: false, mobile: false, directory: false, claim: true }
data: {
admin: true,
pim: true,
leave: false,
time: false,
recruitment: false,
performance: false,
maintenance: false,
mobile: false,
directory: false,
claim: true
}

'submitting with invalid data for claim module':
userId: 1
services:
core.menu_service: OrangeHRM\Core\Service\MenuService
oauth.oauth_service: OrangeHRM\OAuth\Service\OAuthService
body: { admin: true, leave: false, time: false, recruitment: false, performance: false, maintenance: false, mobile: false, directory: false, claim: 1 }
invalidOnly: [ claim ]

0 comments on commit 07a4dd3

Please sign in to comment.