diff --git a/app/application/models/project/issue.php b/app/application/models/project/issue.php index 763899097..7508c1c68 100644 --- a/app/application/models/project/issue.php +++ b/app/application/models/project/issue.php @@ -40,16 +40,16 @@ public function closer() { return $this->belongs_to('\User', 'closed_by'); } - + public function activity($activity_limit = 5) { - - $users = $comments = $activity_type = array(); + + $users = $comments = $activity_type = array(); $issue = $this; $project_id = $this->project_id; $project = \Project::find($project_id); - + foreach(\Activity::all() as $row) { $activity_type[$row->id] = $row; @@ -135,7 +135,7 @@ public function activity($activity_limit = 5) 'user' => $users[$row->user_id], 'activity' => $row )); - + break; @@ -165,17 +165,17 @@ public function activity($activity_limit = 5) } return $return; - + } - - + + public function comments() { return $this->has_many('Project\Issue\Comment', 'issue_id') ->order_by('created_at', 'ASC'); } - + public function comment_count() { return $this->has_many('Project\Issue\Comment', 'issue_id')->count(); @@ -205,9 +205,27 @@ public function to($url = '') */ public function reassign($user_id) { + $old_assignee = $this->assigned_to; + $this->assigned_to = $user_id; $this->save(); + /* Notify the person being assigned to unless that person is doing the actual assignment */ + if($this->assigned_to && $this->assigned_to != \Auth::user()->id) + { + $project_id = $this->project_id; + $project = \Project::find($project_id); + + $subject = 'Issue "' . $this->title . '" in "' . $project->name . '" project was reassigned to you'; + $text = \View::make('email.reassigned_issue', array( + 'actor' => \Auth::user()->firstname . ' ' . \Auth::user()->lastname, + 'project' => $project, + 'issue' => $this, + )); + + \Mail::send_email($text, $this->assigned->email, $subject); + } + \User\Activity::add(5, $this->project_id, $this->id, $user_id, null, $user_id); } @@ -235,6 +253,23 @@ public function change_status($status) $this->status = $status; $this->save(); + + /* Notify the person to whom the issue is currently assigned, unless that person is the one changing the status */ + if($this->assigned_to && $this->assigned_to != \Auth::user()->id) + { + $project = \Project::current(); + $verb = ($this->status == 0 ? 'closed' : 'reopened'); + + $subject = 'Issue "' . $this->title . '" in "' . $project->name . '" project was ' . $verb; + $text = \View::make('email.change_status_issue', array( + 'actor' => \Auth::user()->firstname . ' ' . \Auth::user()->lastname, + 'project' => $project, + 'issue' => $this, + 'verb' => $verb + )); + + \Mail::send_email($text, $this->assigned->email, $subject); + } } /** @@ -274,6 +309,21 @@ public function update_issue($input) $this->fill($fill); $this->save(); + + /* Notify the person to whom the issue is currently assigned, unless that person is the one making the update */ + if($this->assigned_to && $this->assigned_to != \Auth::user()->id) + { + $project = \Project::current(); + + $subject = 'Issue "' . $this->title . '" in "' . $project->name . '" project was updated'; + $text = \View::make('email.update_issue', array( + 'actor' => \Auth::user()->firstname . ' ' . \Auth::user()->lastname, + 'project' => $project, + 'issue' => $this, + )); + + \Mail::send_email($text, $this->assigned->email, $subject); + } return array( 'success' => true @@ -360,6 +410,42 @@ public static function create_issue($input, $project) /* Add attachments to issue */ \DB::table('projects_issues_attachments')->where('upload_token', '=', $input['token'])->where('uploaded_by', '=', \Auth::user()->id)->update(array('issue_id' => $issue->id)); + /* Notify the person being assigned to. */ + /* If no one is assigned, notify all users who are assigned to this project and who have permission to modify the issue. */ + /* Do not notify the person creating the issue. */ + if($issue->assigned_to) + { + if($issue->assigned_to != \Auth::user()->id) + { + $project = \Project::current(); + + $subject = 'New issue "' . $issue->title . '" was submitted to "' . $project->name . '" project and assigned to you'; + $text = \View::make('email.new_assigned_issue', array( + 'project' => $project, + 'issue' => $issue, + )); + + \Mail::send_email($text, $issue->assigned->email, $subject); + } + } + else + { + $project = \Project::current(); + foreach($project->users()->get() as $row) + { + if($row->id != \Auth::user()->id && $row->permission('project-modify')) + { + $subject = 'New issue "' . $issue->title . '" was submitted to "' . $project->name . '" project'; + $text = \View::make('email.new_issue', array( + 'project' => $project, + 'issue' => $issue, + )); + + \Mail::send_email($text, $row->email, $subject); + } + } + } + /* Return success and issue object */ return array( 'success' => true, @@ -400,4 +486,4 @@ public static function count_issues() ); } -} \ No newline at end of file +} diff --git a/app/application/models/project/issue/comment.php b/app/application/models/project/issue/comment.php index b889fbc4b..18ae559e8 100644 --- a/app/application/models/project/issue/comment.php +++ b/app/application/models/project/issue/comment.php @@ -50,6 +50,21 @@ public static function create_comment($input, $project, $issue) $issue->updated_at = date('Y-m-d H:i:s'); $issue->updated_by = \Auth::user()->id; $issue->save(); + + /* Notify the person to whom the issue is currently assigned, unless that person is the one making the comment */ + if($issue->assigned_to && $issue->assigned_to != \Auth::user()->id) + { + $project = \Project::current(); + + $subject = 'Issue "' . $issue->title . '" in "' . $project->name . '" project has a new comment'; + $text = \View::make('email.commented_issue', array( + 'actor' => \Auth::user()->firstname . ' ' . \Auth::user()->lastname, + 'project' => $project, + 'issue' => $issue, + )); + + \Mail::send_email($text, $issue->assigned->email, $subject); + } return $comment; } @@ -96,6 +111,6 @@ public static function delete_comment($comment) */ public static function format($body) { - return \Sparkdown\Markdown($body); + return \Sparkdown\Markdown($body); } -} \ No newline at end of file +} diff --git a/app/application/views/email/change_status_issue.php b/app/application/views/email/change_status_issue.php new file mode 100644 index 000000000..9f9674550 --- /dev/null +++ b/app/application/views/email/change_status_issue.php @@ -0,0 +1,4 @@ +

Issue "title; ?>" in "name; ?>" project was .

+ +

by:
+URL: to(); ?>

\ No newline at end of file diff --git a/app/application/views/email/commented_issue.php b/app/application/views/email/commented_issue.php new file mode 100644 index 000000000..90b6d04e4 --- /dev/null +++ b/app/application/views/email/commented_issue.php @@ -0,0 +1,4 @@ +

Issue "title; ?>" in "name; ?>" project has a new comment.

+ +

Submitted by:
+URL: to(); ?>

\ No newline at end of file diff --git a/app/application/views/email/new_assigned_issue.php b/app/application/views/email/new_assigned_issue.php new file mode 100644 index 000000000..571df0a2b --- /dev/null +++ b/app/application/views/email/new_assigned_issue.php @@ -0,0 +1,4 @@ +

New issue "title; ?>" was submitted to "name; ?>" project and assigned to you.

+ +

Created by: user->firstname . ' ' . $issue->user->lastname; ?>
+URL: to(); ?>

\ No newline at end of file diff --git a/app/application/views/email/new_issue.php b/app/application/views/email/new_issue.php new file mode 100644 index 000000000..cbec15542 --- /dev/null +++ b/app/application/views/email/new_issue.php @@ -0,0 +1,4 @@ +

New issue "title; ?>" was submitted to "name; ?>" project.

+ +

Submitted by: user->firstname . ' ' . $issue->user->lastname; ?>
+URL: to(); ?>

\ No newline at end of file diff --git a/app/application/views/email/reassigned_issue.php b/app/application/views/email/reassigned_issue.php new file mode 100644 index 000000000..82d69a15b --- /dev/null +++ b/app/application/views/email/reassigned_issue.php @@ -0,0 +1,4 @@ +

Issue "title; ?>" in "name; ?>" project was reassigned to you.

+ +

Reassigned by:
+URL: to(); ?>

\ No newline at end of file diff --git a/app/application/views/email/update_issue.php b/app/application/views/email/update_issue.php new file mode 100644 index 000000000..59924bf3d --- /dev/null +++ b/app/application/views/email/update_issue.php @@ -0,0 +1,4 @@ +

Issue "title; ?>" in "name; ?>" project was updated.

+ +

Updated by:
+URL: to(); ?>

\ No newline at end of file diff --git a/app/application/views/project/index/issues.php b/app/application/views/project/index/issues.php index 67333b157..13014d2f6 100644 --- a/app/application/views/project/index/issues.php +++ b/app/application/views/project/index/issues.php @@ -14,12 +14,21 @@
user->firstname . ' ' . $row->user->lastname; ?> - created_at)); ?> + updated_by)): ?> + created_at)); ?> + updated_by)): ?> - - updated->firstname . ' ' . $row->updated->lastname; ?> - updated_at)); ?> + - + updated->firstname . ' ' . $row->updated->lastname; ?> + updated_at)); ?> + + + assigned_to != 0): ?> + - + assigned->firstname . ' ' . $row->assigned->lastname; ?> +
@@ -28,4 +37,4 @@ - \ No newline at end of file +