$ts = new Timetracker_Model_Timesheet($data, TRUE);
if ($_forceCreation) {
- $tsRec = $this->_json->saveTimesheet($ts->toArray(), $_forceCreation);
+ $tsRec = $this->_json->saveTimesheet($ts->toArray());
$this->_lastCreatedRecord = $tsRec;
}
$timesheet = $this->_getTimesheet(array(
'timeaccount_id' => $timeaccount['id'],
));
- $timesheetData = $this->_json->saveTimesheet($timesheet->toArray());
+ $timesheetData = $this->_json->saveTimesheet($timesheet->toArray(), array('skipClosedCheck' => true));
Timetracker_ControllerTest::removeManageAllRight();
- $this->setExpectedException('Tinebase_Exception_AccessDenied');
+ $this->setExpectedException('Timetracker_Exception_ClosedTimeaccount');
// update Timesheet
$timesheetData['description'] = "blubbblubb";
*/
protected function _checkGrant($_record, $_action, $_throw = TRUE, $_errorMessage = 'No Permission.', $_oldRecord = NULL)
{
+ $isAdmin = false;
// users with MANAGE_TIMEACCOUNTS have all grants here
if ( $this->checkRight(Timetracker_Acl_Rights::MANAGE_TIMEACCOUNTS, FALSE)
- || Timetracker_Model_TimeaccountGrants::hasGrant($_record->timeaccount_id, Tinebase_Model_Grants::GRANT_ADMIN)) {
- return TRUE;
+ || Timetracker_Model_TimeaccountGrants::hasGrant($_record->timeaccount_id, Tinebase_Model_Grants::GRANT_ADMIN)) {
+ $isAdmin = true;
}
-
- // only TA managers are allowed to alter TS of closed TAs
+
+ // only TA managers are allowed to alter TS of closed TAs, but they have to confirm first that they really want to do it
if ($_action != 'get') {
$timeaccount = Timetracker_Controller_Timeaccount::getInstance()->get($_record->timeaccount_id);
if (! $timeaccount->is_open) {
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
. ' This Timeaccount is already closed!');
+
+ if ($isAdmin === true) {
+ if (is_array($this->_requestContext) && isset($this->_requestContext['skipClosedCheck']) && $this->_requestContext['skipClosedCheck']) {
+ return true;
+ }
+ }
+
if ($_throw) {
- throw new Tinebase_Exception_AccessDenied('This Timeaccount is already closed!');
+ throw new Timetracker_Exception_ClosedTimeaccount();
}
return FALSE;
}
$this->_fieldGrants['is_billable']['requiredGrant'] = Tinebase_Model_Grants::GRANT_ADMIN;
}
}
+
+ if ($isAdmin === true) {
+ return true;
+ }
+
$hasGrant = FALSE;
--- /dev/null
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package Timetracker
+ * @subpackage Exception
+ * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @copyright Copyright (c) 2016 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author Paul Mehrer <p.mehrer@metaways.de>
+ *
+ */
+
+/**
+ * Deadline exception
+ *
+ * @package Timetracker
+ * @subpackage Exception
+ */
+class Timetracker_Exception_ClosedTimeaccount extends Tinebase_Exception_AccessDenied
+{
+ /**
+ * create new Deadline exception
+ *
+ * @param string $_message
+ * @param integer $_code
+ * @return void
+ */
+ public function __construct($_message = 'This Timeaccount is already closed!', $_code = 403) {
+ parent::__construct($_message, $_code);
+ }
+}
* creates/updates a record
*
* @param array $recordData
+ * @param array $context
* @return array created/updated record
*/
- public function saveTimesheet($recordData)
+ public function saveTimesheet($recordData, array $context = array())
{
+ $this->_timesheetController->setRequestContext($context);
return $this->_save($recordData, $this->_timesheetController, 'Timesheet');
}
evalGrants: false,
useInvoice: false,
displayNotes: true,
+ context: { 'skipClosedCheck': false },
/**
* overwrite update toolbars function (we don't have record grants yet)
},
/**
+ * returns additional save params
+ *
+ * @returns {{checkBusyConflicts: boolean}}
+ */
+ getAdditionalSaveParams: function() {
+ return {
+ context: this.context
+ };
+ },
+
+ /**
* show error if request fails
*
* @param {} response
String.format(this.app.i18n._('Could not save {0}.'), this.i18nRecordName)
+ ' ( ' + this.app.i18n._('Booking deadline for this Timeaccount has been exceeded.') /* + ' ' + response.message */ + ')'
);
+ } else if (response.code && response.code == 403) {
+ //Time Account is closed
+ console.warn(this.grants);
+ if(Tine.Tinebase.common.hasRight('manage', 'Timetracker', 'timeaccounts')) {
+ this.onClosedWarning.apply(this, arguments);
+ } else {
+ Ext.MessageBox.alert(
+ this.app.i18n._('Closed Timeaccount Warning!'),
+ String.format(this.app.i18n._('The selected Time Account is already closed.'))
+ );
+ }
} else {
// call default exception handler
Tine.Tinebase.ExceptionHandler.handleRequestException(response);
}
this.loadMask.hide();
+ },
+
+ onClosedWarning: function() {
+ Ext.Msg.confirm(this.app.i18n._('Closed Timeaccount Warning!'),
+ this.app.i18n._('The selected Time Account is already closed. Do you wish to continue anyway?'),
+ function(btn) {
+ if (btn == 'yes') {
+ this.context = { 'skipClosedCheck': true };
+ this.onApplyChanges(true);
+ }
+ }, this);
}
});
* @var array|null
*/
protected $_modelsUsingPath = null;
+
+ /**
+ * request context information
+ *
+ * @var array|null
+ */
+ protected $_requestContext = null;
+
+ public function setRequestContext(array $context)
+ {
+ $this->_requestContext = $context;
+ }
+
+ /**
+ * @return array|null
+ */
+ public function getRequestContext()
+ {
+ return $this->_requestContext;
+ }
/**
* generic check admin rights function