-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
N°3366 - Multiple target state on approbal-extended #7
base: master
Are you sure you want to change the base?
Changes from 8 commits
6d401f7
9504f28
892f8ad
0b0075a
616e46b
b30b9b3
8e55292
6786112
51f29c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,16 @@ | |
* @author Denis Flaven <[email protected]> | ||
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL | ||
*/ | ||
|
||
class ApprovalConfiguration | ||
{ | ||
const DEFAULT_TARGET = [ | ||
'UserRequest' => [ | ||
'target_states' => ['new'], | ||
'bypass_profiles' => 'Service Manager', | ||
'reuse_previous_answers' => true, | ||
accognet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
]; | ||
} | ||
class ApprovalComputeWorkingHours implements iWorkingTimeComputer | ||
{ | ||
public static function GetDescription() | ||
|
@@ -51,17 +60,22 @@ class HideButtonsPlugin implements iApplicationUIExtension | |
{ | ||
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false) | ||
{ | ||
if ( (get_class($oObject) == 'UserRequest' ) && ( $oObject->IsNew()) ) | ||
$aAllowedClasses = MetaModel::GetConfig()->GetModuleSetting('combodo-approval-extended', 'targets',ApprovalConfiguration::DEFAULT_TARGET); | ||
if (array_key_exists(get_class($oObject), $aAllowedClasses) && MetaModel::HasLifecycle(get_class($oObject))) | ||
{ | ||
$oSet = new DBObjectSet(new DBObjectSearch('ApprovalRule')); | ||
$iCount = $oSet->Count(); | ||
if ($iCount > 0) | ||
{ | ||
$oPage->add_ready_script( | ||
<<<EOF | ||
$('button.action[name="next_action"]').hide(); | ||
EOF | ||
); | ||
$sStateAttCode = MetaModel::GetStateAttributeCode(get_class($oObject)); | ||
$sTargetState = $oObject->Get($sStateAttCode); | ||
|
||
if (in_array($sTargetState, $aAllowedClasses[get_class($oObject)][ 'target_states']) ) { | ||
$sOQL = 'SELECT ApprovalRule AS ar JOIN ServiceSubcategory AS sc ON sc.approvalrule_id = ar.id WHERE ar.target_class = :target_class AND ar.target_class_state = :target_state'; | ||
$oApprovalRuleSet = new DBObjectSet( DBObjectSearch::FromOQL($sOQL), [], ['target_class' => get_class($oObject), 'target_states' => $sTargetState]); | ||
if ($oApprovalRuleSet->Count() > 0) { | ||
$oPage->add_ready_script( | ||
<<<JS | ||
$('button.action[name="next_action"]').hide(); | ||
JS | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,7 +16,7 @@ | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
SetupWebPage::AddModule( | ||||||||||||||||||||||||||||||
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file | ||||||||||||||||||||||||||||||
'combodo-approval-extended/1.4.2', | ||||||||||||||||||||||||||||||
'combodo-approval-extended/1.5.0-dev', | ||||||||||||||||||||||||||||||
array( | ||||||||||||||||||||||||||||||
// Identification | ||||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||||
|
@@ -56,12 +56,17 @@ | |||||||||||||||||||||||||||||
'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any | ||||||||||||||||||||||||||||||
'doc.more_information' => '', // hyperlink to more information, if any | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
'settings' => array( | ||||||||||||||||||||||||||||||
// Module specific settings go here, if any | ||||||||||||||||||||||||||||||
'target_state' => 'new', | ||||||||||||||||||||||||||||||
'bypass_profiles' => 'Administrator, Service Manager', | ||||||||||||||||||||||||||||||
'reuse_previous_answers' => true | ||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||
'settings' => | ||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||
'targets' => [ | ||||||||||||||||||||||||||||||
'UserRequest' => | ||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||
'target_states' => ['new'], | ||||||||||||||||||||||||||||||
'bypass_profiles' => 'Service Manager', | ||||||||||||||||||||||||||||||
'reuse_previous_answers' => true, | ||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
@@ -73,7 +78,28 @@ class ApprovalExtendedInstaller extends ModuleInstallerAPI | |||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
public static function BeforeWritingConfig(Config $oConfiguration) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
// If you want to override/force some configuration values, do it here | ||||||||||||||||||||||||||||||
if (empty(utils::GetConfig()->GetModuleSetting('combodo-approval-extended', 'targets', null)) | ||||||||||||||||||||||||||||||
&& !empty(utils::GetConfig()->GetModuleSetting('combodo-approval-extended', 'target_states', null) )) { | ||||||||||||||||||||||||||||||
// Migration of the old configuration to the new one | ||||||||||||||||||||||||||||||
$newConfiguration = [ | ||||||||||||||||||||||||||||||
'UserRequest' => [ | ||||||||||||||||||||||||||||||
'target_states' => [$oConfiguration->GetModuleSetting('combodo-approval-extended', 'target_states', null) ], | ||||||||||||||||||||||||||||||
'bypass_profiles' =>$oConfiguration->GetModuleSetting('combodo-approval-extended', 'bypass_profiles', 'Service Manager') , | ||||||||||||||||||||||||||||||
'reuse_previous_answers' => $oConfiguration->GetModuleSetting('combodo-approval-extended', 'reuse_previous_answers', true) , | ||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||
Comment on lines
+84
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still some indentation problem, a typo and to keep backward compatibility, the admin profile should also be included when migrating.
Suggested change
|
||||||||||||||||||||||||||||||
$oConfiguration->SetModuleSetting('combodo-approval-extended', 'targets', $newConfiguration); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
// Replacing old conf parameters value to indicate that it is obsolete | ||||||||||||||||||||||||||||||
$aParamsToRemove = array('target_states', 'bypass_profiles', 'reuse_previous_answers'); | ||||||||||||||||||||||||||||||
foreach($aParamsToRemove as $sParamToRemove) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
$sParamCurrentValue = $oConfiguration->GetModuleSetting('combodo-approval-extended', $sParamToRemove, null); | ||||||||||||||||||||||||||||||
if(!empty($sParamCurrentValue)) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
$oConfiguration->SetModuleSetting('combodo-approval-extended', $sParamToRemove, 'No longer used, you can remove this parameter.'); | ||||||||||||||||||||||||||||||
accognet marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+93
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this section, since you said this: https://github.com/Combodo/combodo-approval-extended/pull/7/files#r1763440755 |
||||||||||||||||||||||||||||||
return $oConfiguration; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make more sense later in the code when this var is named differently..