Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #161 from FrostyX/develop
Browse files Browse the repository at this point in the history
Email notifications support
  • Loading branch information
mikelbring committed Nov 22, 2013
2 parents 6c04173 + def40b3 commit 8b9e91b
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 16 deletions.
106 changes: 96 additions & 10 deletions app/application/models/project/issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,7 +135,7 @@ public function activity($activity_limit = 5)
'user' => $users[$row->user_id],
'activity' => $row
));

break;


Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -400,4 +486,4 @@ public static function count_issues()
);
}

}
}
19 changes: 17 additions & 2 deletions app/application/models/project/issue/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -96,6 +111,6 @@ public static function delete_comment($comment)
*/
public static function format($body)
{
return \Sparkdown\Markdown($body);
return \Sparkdown\Markdown($body);
}
}
}
4 changes: 4 additions & 0 deletions app/application/views/email/change_status_issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>Issue "<?php echo $issue->title; ?>" in "<?php echo $project->name; ?>" project was <?php echo $verb; ?>.</p>

<p><?php echo ucfirst($verb); ?> by: <?php echo $actor; ?><br />
URL: <a href="<?php echo $issue->to(); ?>"><?php echo $issue->to(); ?></a></p>
4 changes: 4 additions & 0 deletions app/application/views/email/commented_issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>Issue "<?php echo $issue->title; ?>" in "<?php echo $project->name; ?>" project has a new comment.</p>

<p>Submitted by: <?php echo $actor; ?><br />
URL: <a href="<?php echo $issue->to(); ?>"><?php echo $issue->to(); ?></a></p>
4 changes: 4 additions & 0 deletions app/application/views/email/new_assigned_issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>New issue "<?php echo $issue->title; ?>" was submitted to "<?php echo $project->name; ?>" project and assigned to you.</p>

<p>Created by: <?php echo $issue->user->firstname . ' ' . $issue->user->lastname; ?><br />
URL: <a href="<?php echo $issue->to(); ?>"><?php echo $issue->to(); ?></a></p>
4 changes: 4 additions & 0 deletions app/application/views/email/new_issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>New issue "<?php echo $issue->title; ?>" was submitted to "<?php echo $project->name; ?>" project.</p>

<p>Submitted by: <?php echo $issue->user->firstname . ' ' . $issue->user->lastname; ?><br />
URL: <a href="<?php echo $issue->to(); ?>"><?php echo $issue->to(); ?></a></p>
4 changes: 4 additions & 0 deletions app/application/views/email/reassigned_issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>Issue "<?php echo $issue->title; ?>" in "<?php echo $project->name; ?>" project was reassigned to you.</p>

<p>Reassigned by: <?php echo $actor; ?><br />
URL: <a href="<?php echo $issue->to(); ?>"><?php echo $issue->to(); ?></a></p>
4 changes: 4 additions & 0 deletions app/application/views/email/update_issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>Issue "<?php echo $issue->title; ?>" in "<?php echo $project->name; ?>" project was updated.</p>

<p>Updated by: <?php echo $actor; ?><br />
URL: <a href="<?php echo $issue->to(); ?>"><?php echo $issue->to(); ?></a></p>
17 changes: 13 additions & 4 deletions app/application/views/project/index/issues.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
<div class="info">
<?php echo __('tinyissue.created_by'); ?>
<strong><?php echo $row->user->firstname . ' ' . $row->user->lastname; ?></strong>
<?php echo Time::age(strtotime($row->created_at)); ?>
<?php if(is_null($row->updated_by)): ?>
<?php echo Time::age(strtotime($row->created_at)); ?>
<?php endif; ?>

<?php if(!is_null($row->updated_by)): ?>
- <?php __('tinyissue.updated_by'); ?> <strong><?php echo $row->updated->firstname . ' ' . $row->updated->lastname; ?></strong>
<?php echo Time::age(strtotime($row->updated_at)); ?>
- <?php echo __('tinyissue.updated_by'); ?>
<strong><?php echo $row->updated->firstname . ' ' . $row->updated->lastname; ?></strong>
<?php echo Time::age(strtotime($row->updated_at)); ?>
<?php endif; ?>

<?php if($row->assigned_to != 0): ?>
- <?php echo __('tinyissue.assigned_to'); ?>
<strong><?php echo $row->assigned->firstname . ' ' . $row->assigned->lastname; ?></strong>
<?php endif; ?>

</div>
</div>
</li>
Expand All @@ -28,4 +37,4 @@
<?php endif; ?>

</div>
</div>
</div>

0 comments on commit 8b9e91b

Please sign in to comment.