From 0ccf0428b2484255f5016b1b5cc151eeba17ef79 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 30 Dec 2015 13:17:06 +0000 Subject: [PATCH] added Issue::isCreatedBy() --- codepot/src/codepot/controllers/issue.php | 9 +++----- codepot/src/codepot/models/issuemodel.php | 26 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/codepot/src/codepot/controllers/issue.php b/codepot/src/codepot/controllers/issue.php index c77a9773..7c3319cb 100644 --- a/codepot/src/codepot/controllers/issue.php +++ b/codepot/src/codepot/controllers/issue.php @@ -661,8 +661,7 @@ DEPRECATED // TODO: add a project option to accept an issue from anonymous users, logged-in users or just members. else if (!$login['sysadmin?'] && $this->projects->projectHasMember($projectid, $login['id']) === FALSE && - ($issue = $this->issues->get ($login['id'], $project, $issueid)) !== FALSE && - $login['id'] != $issue->createdby) + $this->issues->isCreatedBy($projectid, $issueid, $login['id']) === FALSE) { $status = "error - not a member nor a creator - {$login['id']}"; } @@ -793,8 +792,7 @@ DEPRECATED // TODO: add a project option to accept an issue from anonymous users, logged-in users or just members. else if (!$login['sysadmin?'] && $this->projects->projectHasMember($projectid, $login['id']) === FALSE && - ($issue = $this->issues->get ($login['id'], $project, $issueid)) !== FALSE && - $login['id'] != $issue->createdby) + $this->issues->isCreatedBy($projectid, $issueid, $login['id']) === FALSE) { $status = "error - not a member nor a creator - {$login['id']}"; } @@ -875,8 +873,7 @@ DEPRECATED // TODO: add a project option to accept an issue from anonymous users, logged-in users or just members. else if (!$login['sysadmin?'] && $this->projects->projectHasMember($projectid, $login['id']) === FALSE && - ($issue = $this->issues->get ($login['id'], $project, $issueid)) !== FALSE && - $login['id'] != $issue->createdby) + $this->issues->isCreatedBy($projectid, $issueid, $login['id']) === FALSE) { $status = "error - not a member nor a creator - {$login['id']}"; } diff --git a/codepot/src/codepot/models/issuemodel.php b/codepot/src/codepot/models/issuemodel.php index 7bd704e9..2c11dbae 100644 --- a/codepot/src/codepot/models/issuemodel.php +++ b/codepot/src/codepot/models/issuemodel.php @@ -899,6 +899,32 @@ class IssueModel extends Model restore_error_handler (); return $x; } + + function isCreatedBy ($projectid, $issueid, $userid) + { + $this->db->trans_begin (); // manual transaction. not using trans_start(). + + $this->db->where ('projectid', $projectod); + $this->db->where ('id', $issueid); + $query = $this->db->get ('issue'); + if ($this->db->trans_status() === FALSE) + { + $this->db->trans_rollback (); + return FALSE; + } + + $result = $query->result (); + if (empty($result)) + { + $this->db->trans_commit (); + return FALSE; + } + + $this->db->trans_commit (); + + $issue = &$result[0]; + return ($issue->created_by == $userid); + } } ?>