summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorNala Ginrut <nalaginrut@gmail.com>2014-06-19 15:18:13 +0800
committerNala Ginrut <nalaginrut@gmail.com>2014-06-19 15:18:13 +0800
commitbfd1db41367f7931016931a94cf1b67396481c79 (patch)
tree2d696f2d8eca9ed2e4561c61c16584952d9f7b0b /app/Model
parentd0944e682d5a3491f72c5b566248b87fbaff032a (diff)
parentefdc959c555872677e599d2ff12e1263d719f3f2 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php1
-rw-r--r--app/Model/Action.php6
-rw-r--r--app/Model/Base.php20
-rw-r--r--app/Model/Config.php7
-rw-r--r--app/Model/File.php21
-rw-r--r--app/Model/Project.php3
-rw-r--r--app/Model/RememberMe.php8
-rw-r--r--app/Model/SubTask.php179
-rw-r--r--app/Model/Task.php15
-rw-r--r--app/Model/User.php5
10 files changed, 228 insertions, 37 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php
index c6ed8686..035fd7c3 100644
--- a/app/Model/Acl.php
+++ b/app/Model/Acl.php
@@ -36,6 +36,7 @@ class Acl extends Base
'config' => array('index', 'removeremembermetoken'),
'comment' => array('create', 'save', 'confirm', 'remove', 'update', 'edit', 'forbidden'),
'file' => array('create', 'save', 'download', 'confirm', 'remove', 'open', 'image'),
+ 'subtask' => array('create', 'save', 'edit', 'update', 'confirm', 'remove'),
'task' => array(
'show',
'create',
diff --git a/app/Model/Action.php b/app/Model/Action.php
index 7cd917e9..0e3aee71 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -42,7 +42,8 @@ class Action extends Base
'TaskAssignCurrentUser' => t('Assign the task to the person who does the action'),
'TaskDuplicateAnotherProject' => t('Duplicate the task to another project'),
'TaskAssignColorUser' => t('Assign a color to a specific user'),
- 'TaskAssignColorCategory' => t('Assign a color to a specific category'),
+ 'TaskAssignColorCategory' => t('Assign automatically a color based on a category'),
+ 'TaskAssignCategoryColor' => t('Assign automatically a category based on a color'),
);
}
@@ -237,6 +238,9 @@ class Action extends Base
case 'TaskAssignColorCategory':
$className = '\Action\TaskAssignColorCategory';
return new $className($project_id, new Task($this->db, $this->event));
+ case 'TaskAssignCategoryColor':
+ $className = '\Action\TaskAssignCategoryColor';
+ return new $className($project_id, new Task($this->db, $this->event));
default:
throw new LogicException('Action not found: '.$name);
}
diff --git a/app/Model/Base.php b/app/Model/Base.php
index e95296bb..66185aeb 100644
--- a/app/Model/Base.php
+++ b/app/Model/Base.php
@@ -14,6 +14,7 @@ require __DIR__.'/../../vendor/SimpleValidator/Validators/AlphaNumeric.php';
require __DIR__.'/../../vendor/SimpleValidator/Validators/GreaterThan.php';
require __DIR__.'/../../vendor/SimpleValidator/Validators/Date.php';
require __DIR__.'/../../vendor/SimpleValidator/Validators/Email.php';
+require __DIR__.'/../../vendor/SimpleValidator/Validators/Numeric.php';
use Core\Event;
use PicoDb\Database;
@@ -54,23 +55,4 @@ abstract class Base
$this->db = $db;
$this->event = $event;
}
-
- /**
- * Generate a random token with different methods: openssl or /dev/urandom or fallback to uniqid()
- *
- * @static
- * @access public
- * @return string Random token
- */
- public static function generateToken()
- {
- if (function_exists('openssl_random_pseudo_bytes')) {
- return bin2hex(\openssl_random_pseudo_bytes(16));
- }
- else if (ini_get('open_basedir') === '' && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
- return hash('sha256', file_get_contents('/dev/urandom', false, null, 0, 30));
- }
-
- return hash('sha256', uniqid(mt_rand(), true));
- }
}
diff --git a/app/Model/Config.php b/app/Model/Config.php
index 23abd8b5..469e6447 100644
--- a/app/Model/Config.php
+++ b/app/Model/Config.php
@@ -5,6 +5,7 @@ namespace Model;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
use Core\Translator;
+use Core\Security;
/**
* Config model
@@ -29,7 +30,7 @@ class Config extends Base
*/
public function getTimezones()
{
- $timezones = \timezone_identifiers_list();
+ $timezones = timezone_identifiers_list();
return array_combine(array_values($timezones), $timezones);
}
@@ -171,12 +172,12 @@ class Config extends Base
*/
public function regenerateTokens()
{
- $this->db->table(self::TABLE)->update(array('webhooks_token' => $this->generateToken()));
+ $this->db->table(self::TABLE)->update(array('webhooks_token' => Security::generateToken()));
$projects = $this->db->table(Project::TABLE)->findAllByColumn('id');
foreach ($projects as $project_id) {
- $this->db->table(Project::TABLE)->eq('id', $project_id)->update(array('token' => $this->generateToken()));
+ $this->db->table(Project::TABLE)->eq('id', $project_id)->update(array('token' => Security::generateToken()));
}
}
}
diff --git a/app/Model/File.php b/app/Model/File.php
index 41ecfba1..e5aa527e 100644
--- a/app/Model/File.php
+++ b/app/Model/File.php
@@ -55,6 +55,22 @@ class File extends Base
}
/**
+ * Remove all files for a given task
+ *
+ * @access public
+ * @param integer $task_id Task id
+ * @return bool
+ */
+ public function removeAll($task_id)
+ {
+ $files = $this->getAll($task_id);
+
+ foreach ($files as $file) {
+ $this->remove($file['id']);
+ }
+ }
+
+ /**
* Create a file entry in the database
*
* @access public
@@ -144,6 +160,7 @@ class File extends Base
public function upload($project_id, $task_id, $form_name)
{
$this->setup();
+ $result = array();
if (! empty($_FILES[$form_name])) {
@@ -159,7 +176,7 @@ class File extends Base
if (@move_uploaded_file($uploaded_filename, self::BASE_PATH.$destination_filename)) {
- $this->create(
+ $result[] = $this->create(
$task_id,
$original_filename,
$destination_filename,
@@ -169,5 +186,7 @@ class File extends Base
}
}
}
+
+ return count(array_unique($result)) === 1;
}
}
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 9fbb0806..e1465012 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -5,6 +5,7 @@ namespace Model;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
use Event\TaskModification;
+use Core\Security;
/**
* Project model
@@ -363,7 +364,7 @@ class Project extends Base
{
$this->db->startTransaction();
- $values['token'] = self::generateToken();
+ $values['token'] = Security::generateToken();
if (! $this->db->table(self::TABLE)->save($values)) {
$this->db->cancelTransaction();
diff --git a/app/Model/RememberMe.php b/app/Model/RememberMe.php
index 1494b14a..c9ef819f 100644
--- a/app/Model/RememberMe.php
+++ b/app/Model/RememberMe.php
@@ -2,6 +2,8 @@
namespace Model;
+use Core\Security;
+
/**
* RememberMe model
*
@@ -174,8 +176,8 @@ class RememberMe extends Base
*/
public function create($user_id, $ip, $user_agent)
{
- $token = hash('sha256', $user_id.$user_agent.$ip.$this->generateToken());
- $sequence = $this->generateToken();
+ $token = hash('sha256', $user_id.$user_agent.$ip.Security::generateToken());
+ $sequence = Security::generateToken();
$expiration = time() + self::EXPIRATION;
$this->cleanup($user_id);
@@ -225,7 +227,7 @@ class RememberMe extends Base
*/
public function update($token, $sequence)
{
- $new_sequence = $this->generateToken();
+ $new_sequence = Security::generateToken();
$this->db
->table(self::TABLE)
diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php
new file mode 100644
index 00000000..21ccdaac
--- /dev/null
+++ b/app/Model/SubTask.php
@@ -0,0 +1,179 @@
+<?php
+
+namespace Model;
+
+use SimpleValidator\Validator;
+use SimpleValidator\Validators;
+
+/**
+ * Subtask model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class SubTask extends Base
+{
+ /**
+ * SQL table name
+ *
+ * @var string
+ */
+ const TABLE = 'task_has_subtasks';
+
+ /**
+ * Task "done" status
+ *
+ * @var integer
+ */
+ const STATUS_DONE = 2;
+
+ /**
+ * Task "in progress" status
+ *
+ * @var integer
+ */
+ const STATUS_INPROGRESS = 1;
+
+ /**
+ * Task "todo" status
+ *
+ * @var integer
+ */
+ const STATUS_TODO = 0;
+
+ /**
+ * Get available status
+ *
+ * @access public
+ * @return array
+ */
+ public function getStatusList()
+ {
+ $status = array(
+ self::STATUS_TODO => t('Todo'),
+ self::STATUS_INPROGRESS => t('In progress'),
+ self::STATUS_DONE => t('Done'),
+ );
+
+ asort($status);
+
+ return $status;
+ }
+
+ /**
+ * Get all subtasks for a given task
+ *
+ * @access public
+ * @param integer $task_id Task id
+ * @return array
+ */
+ public function getAll($task_id)
+ {
+ $status = $this->getStatusList();
+ $subtasks = $this->db->table(self::TABLE)
+ ->eq('task_id', $task_id)
+ ->columns(self::TABLE.'.*', User::TABLE.'.username')
+ ->join(User::TABLE, 'id', 'user_id')
+ ->findAll();
+
+ foreach ($subtasks as &$subtask) {
+ $subtask['status_name'] = $status[$subtask['status']];
+ }
+
+ return $subtasks;
+ }
+
+ /**
+ * Get a subtask by the id
+ *
+ * @access public
+ * @param integer $subtask_id Subtask id
+ * @return array
+ */
+ public function getById($subtask_id)
+ {
+ return $this->db->table(self::TABLE)->eq('id', $subtask_id)->findOne();
+ }
+
+ /**
+ * Create
+ *
+ * @access public
+ * @param array $values Form values
+ * @return bool
+ */
+ public function create(array $values)
+ {
+ if (isset($values['another_subtask'])) {
+ unset($values['another_subtask']);
+ }
+
+ if (isset($values['time_estimated']) && empty($values['time_estimated'])) {
+ $values['time_estimated'] = 0;
+ }
+
+ if (isset($values['time_spent']) && empty($values['time_spent'])) {
+ $values['time_spent'] = 0;
+ }
+
+ return $this->db->table(self::TABLE)->save($values);
+ }
+
+ /**
+ * Update
+ *
+ * @access public
+ * @param array $values Form values
+ * @return bool
+ */
+ public function update(array $values)
+ {
+ if (isset($values['time_estimated']) && empty($values['time_estimated'])) {
+ $values['time_estimated'] = 0;
+ }
+
+ if (isset($values['time_spent']) && empty($values['time_spent'])) {
+ $values['time_spent'] = 0;
+ }
+
+ return $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
+ }
+
+ /**
+ * Remove
+ *
+ * @access public
+ * @param integer $subtask_id Subtask id
+ * @return bool
+ */
+ public function remove($subtask_id)
+ {
+ return $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove();
+ }
+
+ /**
+ * Validate creation/modification
+ *
+ * @access public
+ * @param array $values Form values
+ * @return array $valid, $errors [0] = Success or not, [1] = List of errors
+ */
+ public function validate(array $values)
+ {
+ $v = new Validator($values, array(
+ new Validators\Required('task_id', t('The task id is required')),
+ new Validators\Integer('task_id', t('The task id must be an integer')),
+ new Validators\Required('title', t('The title is required')),
+ new Validators\MaxLength('title', t('The maximum length is %d characters', 100), 100),
+ new Validators\Integer('user_id', t('The user id must be an integer')),
+ new Validators\Integer('status', t('The status must be an integer')),
+ new Validators\Numeric('time_estimated', t('The time must be a numeric value')),
+ new Validators\Numeric('time_spent', t('The time must be a numeric value')),
+ ));
+
+ return array(
+ $v->execute(),
+ $v->getErrors()
+ );
+ }
+}
diff --git a/app/Model/Task.php b/app/Model/Task.php
index faa33ca9..70f1404c 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -359,12 +359,10 @@ class Task extends Base
// Trigger events
if ($result) {
- $events = array();
-
- if (! in_array($this->event->getLastTriggeredEvent(), array(self::EVENT_CREATE_UPDATE))) {
- $events[] = self::EVENT_CREATE_UPDATE;
- $events[] = self::EVENT_UPDATE;
- }
+ $events = array(
+ self::EVENT_CREATE_UPDATE,
+ self::EVENT_UPDATE,
+ );
if (isset($values['column_id']) && $original_task['column_id'] != $values['column_id']) {
$events[] = self::EVENT_MOVE_COLUMN;
@@ -441,6 +439,9 @@ class Task extends Base
*/
public function remove($task_id)
{
+ $file = new File($this->db, $this->event);
+ $file->removeAll($task_id);
+
return $this->db->table(self::TABLE)->eq('id', $task_id)->remove();
}
@@ -455,6 +456,8 @@ class Task extends Base
*/
public function move($task_id, $column_id, $position)
{
+ $this->event->clearTriggeredEvents();
+
return $this->update(array(
'id' => $task_id,
'column_id' => $column_id,
diff --git a/app/Model/User.php b/app/Model/User.php
index bce717a7..6804d765 100644
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -203,7 +203,7 @@ class User extends Base
new Validators\Required('password', t('The password is required')),
new Validators\MinLength('password', t('The minimum length is %d characters', 6), 6),
new Validators\Required('confirmation', t('The confirmation is required')),
- new Validators\Equals('password', 'confirmation', t('Passwords doesn\'t matches')),
+ new Validators\Equals('password', 'confirmation', t('Passwords don\'t match')),
new Validators\Integer('default_project_id', t('This value must be an integer')),
new Validators\Integer('is_admin', t('This value must be an integer')),
new Validators\Email('email', t('Email address invalid')),
@@ -264,7 +264,7 @@ class User extends Base
new Validators\Required('password', t('The password is required')),
new Validators\MinLength('password', t('The minimum length is %d characters', 6), 6),
new Validators\Required('confirmation', t('The confirmation is required')),
- new Validators\Equals('password', 'confirmation', t('Passwords doesn\'t matches')),
+ new Validators\Equals('password', 'confirmation', t('Passwords don\'t match')),
new Validators\Integer('default_project_id', t('This value must be an integer')),
new Validators\Integer('is_admin', t('This value must be an integer')),
new Validators\Email('email', t('Email address invalid')),
@@ -359,7 +359,6 @@ class User extends Base
// LDAP authentication
if (! $authenticated && LDAP_AUTH) {
- require __DIR__.'/ldap.php';
$ldap = new Ldap($this->db, $this->event);
$authenticated = $ldap->authenticate($username, $password);
$method = LastLogin::AUTH_LDAP;