Commit 04d1b412 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'tasks' into 'master'

Add Todos

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/2425

Tasks:

-  Prepare database
 - [X] Create a new table (`todos`)
- Tasks Queue view
 - [X] Add a number icon showing the number of todos on the top right next to the new and logout button that will redirect the user to the todos page
 - [X] Add a chronological list of todos, with the 'Todos' tab active by default
 - [X] Add a 'Done' button to each todo
 - [x] Add filters (project, author, type, and action)
- Todos generation
 - [X] When user issue/mr is assgined to someone
 - [x] When user is mentioned on (issues/mr's/comments)
- Mark todo as `done`
 - [X] When clicks on the 'Done' button
 - [X] When edit issue/mr
 - [X] When left/edit a comment
 - [X] When reassign issue/mr
 - [X] When add/remove labels to issue/mr
 - [X] When issue/mr is closed
 - [X] When mr is merged
 - [X] When added an emoji
 - [X] When changed the issue/mr milestone

* Screenshot:

![Screenshot_2016-02-20_12.45.57](/uploads/4b2554b1bde25aed3347e1ae41e8e0c0/Screenshot_2016-02-20_12.45.57.png)

See merge request !2817
parents 28f9b543 2ef1ea50
......@@ -67,7 +67,7 @@ v 8.5.0 (unreleased)
- Fix broken link to project in build notification emails
- Ability to see and sort on vote count from Issues and MR lists
- Fix builds scheduler when first build in stage was allowed to fail
- User project limit is reached notice is hidden if the projects limit is zero
- User project limit is reached notice is hidden if the projects limit is zero
- Add API support for managing runners and project's runners
- Allow SAML users to login with no previous account without having to allow
all Omniauth providers to do so.
......@@ -77,6 +77,7 @@ v 8.5.0 (unreleased)
- Emoji comment on diffs are not award emoji
- Add label description (Nuttanart Pornprasitsakul)
- Show label row when filtering issues or merge requests by label (Nuttanart Pornprasitsakul)
- Add Todos
v 8.4.4
- Update omniauth-saml gem to 1.4.2
......
/**
* Dashboard Todos
*
*/
.navbar-nav {
li {
.badge.todos-pending-count {
background-color: #7f8fa4;
margin-top: -5px;
}
}
}
.todos {
.panel {
border-top: none;
margin-bottom: 0;
}
}
.todo-item {
font-size: $gl-font-size;
padding: $gl-padding-top 0 $gl-padding-top ($gl-avatar-size + $gl-padding-top);
border-bottom: 1px solid $table-border-color;
color: #7f8fa4;
&.todo-inline {
.avatar {
position: relative;
top: -2px;
}
.todo-title {
line-height: 40px;
}
}
a {
color: #4c4e54;
}
.avatar {
margin-left: -($gl-avatar-size + $gl-padding-top);
}
.todo-title {
@include str-truncated(calc(100% - 174px));
font-weight: 600;
.author_name {
color: #333;
}
}
.todo-body {
margin-right: 174px;
.todo-note {
word-wrap: break-word;
.md {
color: #7f8fa4;
font-size: $gl-font-size;
p {
color: #5c5d5e;
}
}
pre {
border: none;
background: #f9f9f9;
border-radius: 0;
color: #777;
margin: 0 20px;
overflow: hidden;
}
.note-image-attach {
margin-top: 4px;
margin-left: 0px;
max-width: 200px;
float: none;
}
p:last-child {
margin-bottom: 0;
}
}
.todo-note-icon {
color: #777;
float: left;
font-size: $gl-font-size;
line-height: 16px;
margin-right: 5px;
}
}
&:last-child { border:none }
}
@media (max-width: $screen-xs-max) {
.todo-item {
padding-left: $gl-padding;
.todo-title {
white-space: normal;
overflow: visible;
max-width: 100%;
}
.avatar {
display: none;
}
.todo-body {
margin: 0;
border-left: 2px solid #DDD;
padding-left: 10px;
}
}
}
class Dashboard::TodosController < Dashboard::ApplicationController
before_action :find_todos, only: [:index, :destroy_all]
def index
@todos = @todos.page(params[:page]).per(PER_PAGE)
end
def destroy
todo.done!
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' }
format.js { render nothing: true }
end
end
def destroy_all
@todos.each(&:done)
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
format.js { render nothing: true }
end
end
private
def todo
@todo ||= current_user.todos.find(params[:id])
end
def find_todos
@todos = TodosFinder.new(current_user, params).execute
end
end
......@@ -181,6 +181,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
return
end
TodoService.new.merge_merge_request(merge_request, current_user)
@merge_request.update(merge_error: nil)
if params[:merge_when_build_succeeds].present? && @merge_request.ci_commit && @merge_request.ci_commit.active?
......
# TodosFinder
#
# Used to filter Todos by set of params
#
# Arguments:
# current_user - which user use
# params:
# action_id: integer
# author_id: integer
# project_id; integer
# state: 'pending' or 'done'
# type: 'Issue' or 'MergeRequest'
#
class TodosFinder
NONE = '0'
attr_accessor :current_user, :params
def initialize(current_user, params)
@current_user = current_user
@params = params
end
def execute
items = current_user.todos
items = by_action_id(items)
items = by_author(items)
items = by_project(items)
items = by_state(items)
items = by_type(items)
items
end
private
def action_id?
action_id.present? && [Todo::ASSIGNED, Todo::MENTIONED].include?(action_id.to_i)
end
def action_id
params[:action_id]
end
def author?
params[:author_id].present?
end
def author
return @author if defined?(@author)
@author =
if author? && params[:author_id] != NONE
User.find(params[:author_id])
else
nil
end
end
def project?
params[:project_id].present?
end
def project
return @project if defined?(@project)
if project?
@project = Project.find(params[:project_id])
unless Ability.abilities.allowed?(current_user, :read_project, @project)
@project = nil
end
else
@project = nil
end
@project
end
def type?
type.present? && ['Issue', 'MergeRequest'].include?(type)
end
def type
params[:type]
end
def by_action_id(items)
if action_id?
items = items.where(action: action_id)
end
items
end
def by_author(items)
if author?
items = items.where(author_id: author.try(:id))
end
items
end
def by_project(items)
if project?
items = items.where(project: project)
end
items
end
def by_state(items)
case params[:state]
when 'done'
items.done
else
items.pending
end
end
def by_type(items)
if type?
items = items.where(target_type: type)
end
items
end
end
module TodosHelper
def todos_pending_count
current_user.todos.pending.count
end
def todos_done_count
current_user.todos.done.count
end
def todo_action_name(todo)
case todo.action
when Todo::ASSIGNED then 'assigned you'
when Todo::MENTIONED then 'mentioned you on'
end
end
def todo_target_link(todo)
target = todo.target_type.titleize.downcase
link_to "#{target} #{todo.target.to_reference}", todo_target_path(todo)
end
def todo_target_path(todo)
anchor = dom_id(todo.note) if todo.note.present?
polymorphic_path([todo.project.namespace.becomes(Namespace),
todo.project, todo.target], anchor: anchor)
end
def todos_filter_params
{
state: params[:state],
project_id: params[:project_id],
author_id: params[:author_id],
type: params[:type],
action_id: params[:action_id],
}
end
def todos_filter_path(options = {})
without = options.delete(:without)
options = todos_filter_params.merge(options)
if without.present?
without.each do |key|
options.delete(key)
end
end
path = request.path
path << "?#{options.to_param}"
path
end
def todo_actions_options
actions = [
OpenStruct.new(id: '', title: 'Any Action'),
OpenStruct.new(id: Todo::ASSIGNED, title: 'Assigned'),
OpenStruct.new(id: Todo::MENTIONED, title: 'Mentioned')
]
options_from_collection_for_select(actions, 'id', 'title', params[:action_id])
end
def todo_projects_options
projects = current_user.authorized_projects.sorted_by_activity.non_archived
projects = projects.includes(:namespace)
projects = projects.map do |project|
OpenStruct.new(id: project.id, title: project.name_with_namespace)
end
projects.unshift(OpenStruct.new(id: '', title: 'Any Project'))
options_from_collection_for_select(projects, 'id', 'title', params[:project_id])
end
def todo_types_options
types = [
OpenStruct.new(title: 'Any Type', name: ''),
OpenStruct.new(title: 'Issue', name: 'Issue'),
OpenStruct.new(title: 'Merge Request', name: 'MergeRequest')
]
options_from_collection_for_select(types, 'name', 'title', params[:type])
end
end
......@@ -37,6 +37,8 @@ class Note < ActiveRecord::Base
belongs_to :author, class_name: "User"
belongs_to :updated_by, class_name: "User"
has_many :todos, dependent: :destroy
delegate :name, to: :project, prefix: true
delegate :name, :email, to: :author, prefix: true
......
# == Schema Information
#
# Table name: todos
#
# id :integer not null, primary key
# user_id :integer not null
# project_id :integer not null
# target_id :integer not null
# target_type :string not null
# author_id :integer
# note_id :integer
# action :integer not null
# state :string not null
# created_at :datetime
# updated_at :datetime
#
class Todo < ActiveRecord::Base
ASSIGNED = 1
MENTIONED = 2
belongs_to :author, class_name: "User"
belongs_to :note
belongs_to :project
belongs_to :target, polymorphic: true, touch: true
belongs_to :user
delegate :name, :email, to: :author, prefix: true, allow_nil: true
validates :action, :project, :target, :user, presence: true
default_scope { reorder(id: :desc) }
scope :pending, -> { with_state(:pending) }
scope :done, -> { with_state(:done) }
state_machine :state, initial: :pending do
event :done do
transition pending: :done
end
state :pending
state :done
end
def body
if note.present?
note.note
else
target.title
end
end
end
......@@ -140,7 +140,7 @@ class User < ActiveRecord::Base
has_one :abuse_report, dependent: :destroy
has_many :spam_logs, dependent: :destroy
has_many :builds, dependent: :nullify, class_name: 'Ci::Build'
has_many :todos, dependent: :destroy
#
# Validations
......
......@@ -23,6 +23,10 @@ class BaseService
EventCreateService.new
end
def todo_service
TodoService.new
end
def log_info(message)
Gitlab::AppLogger.info message
end
......
......@@ -54,7 +54,7 @@ class IssuableBaseService < BaseService
if params.present? && issuable.update_attributes(params.merge(updated_by: current_user))
issuable.reset_events_cache
handle_common_system_notes(issuable, old_labels: old_labels)
handle_changes(issuable)
handle_changes(issuable, old_labels: old_labels)
issuable.create_new_cross_references!(current_user)
execute_hooks(issuable, 'update')
end
......@@ -71,6 +71,19 @@ class IssuableBaseService < BaseService
end
end
def has_changes?(issuable, options = {})
valid_attrs = [:title, :description, :assignee_id, :milestone_id, :target_branch]
attrs_changed = valid_attrs.any? do |attr|
issuable.previous_changes.include?(attr.to_s)
end
old_labels = options[:old_labels]
labels_changed = old_labels && issuable.labels != old_labels
attrs_changed || labels_changed
end
def handle_common_system_notes(issuable, options = {})
if issuable.previous_changes.include?('title')
create_title_change_note(issuable, issuable.previous_changes['title'].first)
......
......@@ -3,6 +3,7 @@ module Issues
def execute(issue, commit = nil)
if project.jira_tracker? && project.jira_service.active
project.jira_service.execute(commit, issue)
todo_service.close_issue(issue, current_user)
return issue
end
......@@ -10,6 +11,7 @@ module Issues
event_service.close_issue(issue, current_user)
create_note(issue, commit)
notification_service.close_issue(issue, current_user)
todo_service.close_issue(issue, current_user)
execute_hooks(issue, 'close')
end
......
......@@ -9,6 +9,7 @@ module Issues
if issue.save
issue.update_attributes(label_ids: label_params)
notification_service.new_issue(issue, current_user)
todo_service.new_issue(issue, current_user)
event_service.open_issue(issue, current_user)
issue.create_cross_references!(current_user)
execute_hooks(issue, 'open')
......
......@@ -4,7 +4,16 @@ module Issues
update(issue)
end
def handle_changes(issue)
def handle_changes(issue, options = {})
if has_changes?(issue, options)
todo_service.mark_pending_todos_as_done(issue, current_user)
end
if issue.previous_changes.include?('title') ||
issue.previous_changes.include?('description')
todo_service.update_issue(issue, current_user)
end
if issue.previous_changes.include?('milestone_id')
create_milestone_note(issue)
end
......@@ -12,6 +21,7 @@ module Issues
if issue.previous_changes.include?('assignee_id')
create_assignee_note(issue)
notification_service.reassigned_issue(issue, current_user)
todo_service.reassigned_issue(issue, current_user)
end
end
......
......@@ -9,6 +9,7 @@ module MergeRequests
event_service.close_mr(merge_request, current_user)
create_note(merge_request)
notification_service.close_mr(merge_request, current_user)
todo_service.close_merge_request(merge_request, current_user)
execute_hooks(merge_request, 'close')
end
......
......@@ -2,7 +2,7 @@ module MergeRequests
class CreateService < MergeRequests::BaseService
def execute
# @project is used to determine whether the user can set the merge request's
# assignee, milestone and labels. Whether they can depends on their
# assignee, milestone and labels. Whether they can depends on their
# permissions on the target project.
source_project = @project
@project = Project.find(params[:target_project_id]) if params[:target_project_id]
......@@ -18,6 +18,7 @@ module MergeRequests
merge_request.update_attributes(label_ids: label_params)
event_service.open_mr(merge_request, current_user)
notification_service.new_merge_request(merge_request, current_user)
todo_service.new_merge_request(merge_request, current_user)
merge_request.create_cross_references!(current_user)
execute_hooks(merge_request)
end
......
......@@ -14,7 +14,16 @@ module MergeRequests
update(merge_request)
end
def handle_changes(merge_request)
def handle_changes(merge_request, options = {})
if has_changes?(merge_request, options)
todo_service.mark_pending_todos_as_done(merge_request, current_user)
end
if merge_request.previous_changes.include?('title') ||
merge_request.previous_changes.include?('description')
todo_service.update_merge_request(merge_request, current_user)
end
if merge_request.previous_changes.include?('target_branch')
create_branch_change_note(merge_request, 'target',
merge_request.previous_changes['target_branch'].first,
......@@ -28,6 +37,7 @@ module MergeRequests
if merge_request.previous_changes.include?('assignee_id')
create_assignee_note(merge_request)
notification_service.reassigned_merge_request(merge_request, current_user)
todo_service.reassigned_merge_request(merge_request, current_user)
end
if merge_request.previous_changes.include?('target_branch') ||
......
......@@ -8,6 +8,7 @@ module Notes
if note.save
# Finish the harder work in the background
NewNoteWorker.perform_in(2.seconds, note.id, params)
TodoService.new.new_note(note, current_user)
end
note
......
module Notes
class PostProcessService
attr_accessor :note
def initialize(note)
......@@ -25,6 +24,5 @@ module Notes
@note.project.execute_hooks(note_data, :note_hooks)
@note.project.execute_services(note_data, :note_hooks)
end
end
end
......@@ -7,6 +7,10 @@ module Notes
note.create_new_cross_references!(current_user)
note.reset_events_cache
if note.previous_changes.include?('note')
TodoService.new.update_note(note, current_user)
end
note
end
end
......
# TodoService class
#
# Used for creating todos after certain user actions
#
# Ex.
# TodoService.new.new_issue(issue, current_user)
#
class TodoService
# When create an issue we should:
#
# * create a todo for assignee if issue is assigned
# * create a todo for each mentioned user on issue
#
def new_issue(issue, current_user)
new_issuable(issue, current_user)
end
# When update an issue we should:
#
# * mark all pending todos related to the issue for the current user as done
#
def update_issue(issue, current_user)
create_mention_todos(issue.project, issue, current_user)
end
# When close an issue we should:
#
# * mark all pending todos related to the target for the current user as done
#
def close_issue(issue, current_user)
mark_pending_todos_as_done(issue, current_user)
end
# When we reassign an issue we should:
#
# * create a pending todo for new assignee if issue is assigned
#
def reassigned_issue(issue, current_user)
create_assignment_todo(issue, current_user)
end
# When create a merge request we should:
#
# * creates a pending todo for assignee if merge request is assigned
# * create a todo for each mentioned user on merge request
#
def new_merge_request(merge_request, current_user)
new_issuable(merge_request, current_user)
end
# When update a merge request we should:
#
# * create a todo for each mentioned user on merge request
#
def update_merge_request(merge_request, current_user)
create_mention_todos(merge_request.project, merge_request, current_user)
end
# When close a merge request we should:
#
# * mark all pending todos related to the target for the current user as done
#
def close_merge_request(merge_request, current_user)
mark_pending_todos_as_done(merge_request, current_user)
end
# When we reassign a merge request we should:
#
# * creates a pending todo for new assignee if merge request is assigned
#
def reassigned_merge_request(merge_request, current_user)
create_assignment_todo(merge_request, current_user)
end
# When merge a merge request we should:
#
# * mark all pending todos related to the target for the current user as done
#
def merge_merge_request(merge_request, current_user)
mark_pending_todos_as_done(merge_request, current_user)
end
# When create a note we should:
#
# * mark all pending todos related to the noteable for the note author as done
# * create a todo for each mentioned user on note
#
def new_note(note, current_user)
handle_note(note, current_user)
end
# When update a note we should:
#
# * mark all pending todos related to the noteable for the current user as done
# * create a todo for each new user mentioned on note
#
def update_note(note, current_user)
handle_note(note, current_user)
end
# When marking pending todos as done we should:
#
# * mark all pending todos related to the target for the current user as done
#
def mark_pending_todos_as_done(target, user)
pending_todos(user, target.project, target).update_all(state: :done)
end
private
def create_todos(project, target, author, users, action, note = nil)
Array(users).each do |user|
next if pending_todos(user, project, target).exists?
Todo.create(
project: project,
user_id: user.id,
author_id: author.id,
target_id: target.id,
target_type: target.class.name,
action: action,
note: note
)
end
end
def new_issuable(issuable, author)
create_assignment_todo(issuable, author)
create_mention_todos(issuable.project, issuable, author)
end
def handle_note(note, author)
# Skip system notes, like status changes and cross-references
return if note.system
project = note.project
target = note.noteable
mark_pending_todos_as_done(target, author)
create_mention_todos(project, target, author, note)
end
def create_assignment_todo(issuable, author)
if issuable.assignee && issuable.assignee != author
create_todos(issuable.project, issuable, author, issuable.assignee, Todo::ASSIGNED)
end
end
def create_mention_todos(project, issuable, author, note = nil)
mentioned_users = filter_mentioned_users(project, note || issuable, author)
create_todos(project, issuable, author, mentioned_users, Todo::MENTIONED, note)
end
def filter_mentioned_users(project, target, author)
mentioned_users = target.mentioned_users.select do |user|
user.can?(:read_project, project)
end
mentioned_users.delete(author)
mentioned_users.uniq
end
def pending_todos(user, project, target)
user.todos.pending.where(
project_id: project.id,
target_id: target.id,
target_type: target.class.name
)
end
end
%li{class: "todo todo-#{todo.done? ? 'done' : 'pending'}", id: dom_id(todo) }
.todo-item{class: 'todo-block'}
= image_tag avatar_icon(todo.author_email, 40), class: 'avatar s40', alt:''
.todo-title
%span.author_name
= link_to_author todo
%span.todo_label
= todo_action_name(todo)
= todo_target_link(todo)
&middot; #{time_ago_with_tooltip(todo.created_at)}
- if todo.pending?
.todo-actions.pull-right
= link_to 'Done', [:dashboard, todo], method: :delete, class: 'btn'
.todo-body
.todo-note
.md
= event_note(todo.body, project: todo.project)
- page_title "Todos"
- header_title "Todos", dashboard_todos_path
.top-area
%ul.nav-links
%li{class: ('active' if params[:state].blank? || params[:state] == 'pending')}
= link_to todos_filter_path(state: 'pending') do
%span
To do
%span{class: 'badge'}
= todos_pending_count
%li{class: ('active' if params[:state] == 'done')}
= link_to todos_filter_path(state: 'done') do
%span
Done
%span{class: 'badge'}
= todos_done_count
.nav-controls
- if @todos.any?(&:pending?)
= link_to 'Mark all as done', destroy_all_dashboard_todos_path(todos_filter_params), class: 'btn', method: :delete
.todos-filters
.gray-content-block.second-block
= form_tag todos_filter_path(without: [:project_id, :author_id, :type, :action_id]), method: :get, class: 'filter-form' do
.filter-item.inline
= select_tag('project_id', todo_projects_options,
class: 'select2 trigger-submit', include_blank: true,
data: {placeholder: 'Project'})
.filter-item.inline
= users_select_tag(:author_id, selected: params[:author_id],
placeholder: 'Author', class: 'trigger-submit', any_user: "Any Author", first_user: true, current_user: true)
.filter-item.inline
= select_tag('type', todo_types_options,
class: 'select2 trigger-submit', include_blank: true,
data: {placeholder: 'Type'})
.filter-item.inline.actions-filter
= select_tag('action_id', todo_actions_options,
class: 'select2 trigger-submit', include_blank: true,
data: {placeholder: 'Action'})
.prepend-top-default
- if @todos.any?
- @todos.group_by(&:project).each do |group|
.panel.panel-default.panel-small
- project = group[0]
.panel-heading
= link_to project.name_with_namespace, namespace_project_path(project.namespace, project)
%ul.well-list.todos-list
= render group[1]
= paginate @todos, theme: "gitlab"
- else
.nothing-here-block You're all done!
:javascript
new UsersSelect();
$('form.filter-form').on('submit', function (event) {
event.preventDefault();
Turbolinks.visit(this.action + '&' + $(this).serialize());
});
......@@ -21,6 +21,10 @@
%li
= link_to admin_root_path, title: 'Admin Area', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do
= icon('wrench fw')
%li
= link_to dashboard_todos_path, title: 'Todos', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do
%span.badge.todos-pending-count
= todos_pending_count
- if current_user.can_create_project?
%li
= link_to new_project_path, title: 'New project', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do
......@@ -39,4 +43,4 @@
= render 'shared/outdated_browser'
- if @project && !@project.empty_repo?
:javascript
var findFileURL = "#{namespace_project_find_file_path(@project.namespace, @project, @ref || @project.repository.root_ref)}";
\ No newline at end of file
var findFileURL = "#{namespace_project_find_file_path(@project.namespace, @project, @ref || @project.repository.root_ref)}";
......@@ -4,6 +4,12 @@
= icon('home fw')
%span
Projects
= nav_link(controller: :todos) do
= link_to dashboard_todos_path, title: 'Todos' do
= icon('bell fw')
%span
Todos
%span.count= number_with_delimiter(todos_pending_count)
= nav_link(path: 'dashboard#activity') do
= link_to activity_dashboard_path, class: 'shortcuts-activity', title: 'Activity' do
= icon('dashboard fw')
......@@ -25,12 +31,12 @@
%span
Issues
%span.count= number_with_delimiter(current_user.assigned_issues.opened.count)
= nav_link(path: 'dashboard#merge_requests') do
= link_to assigned_mrs_dashboard_path, title: 'Merge Requests', class: 'shortcuts-merge_requests' do
= icon('tasks fw')
%span
Merge Requests
%span.count= number_with_delimiter(current_user.assigned_merge_requests.opened.count)
= nav_link(path: 'dashboard#merge_requests') do
= link_to assigned_mrs_dashboard_path, title: 'Merge Requests', class: 'shortcuts-merge_requests' do
= icon('tasks fw')
%span
Merge Requests
%span.count= number_with_delimiter(current_user.assigned_merge_requests.opened.count)
= nav_link(controller: :snippets) do
= link_to dashboard_snippets_path, title: 'Snippets' do
= icon('clipboard fw')
......
......@@ -334,6 +334,12 @@ Rails.application.routes.draw do
resources :groups, only: [:index]
resources :snippets, only: [:index]
resources :todos, only: [:index, :destroy] do
collection do
delete :destroy_all
end
end
resources :projects, only: [:index] do
collection do
get :starred
......
class CreateTasks < ActiveRecord::Migration
def change
create_table :tasks do |t|
t.references :user, null: false, index: true
t.references :project, null: false, index: true
t.references :target, polymorphic: true, null: false, index: true
t.integer :author_id, index: true
t.integer :action, null: false
t.string :state, null: false, index: true
t.timestamps
end
end
end
class AddNoteToTasks < ActiveRecord::Migration
def change
add_reference :tasks, :note, index: true
end
end
class RenameTasksToTodos < ActiveRecord::Migration
def change
rename_table :tasks, :todos
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160217100506) do
ActiveRecord::Schema.define(version: 20160220123949) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -824,6 +824,26 @@ ActiveRecord::Schema.define(version: 20160217100506) do
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
create_table "todos", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "project_id", null: false
t.integer "target_id", null: false
t.string "target_type", null: false
t.integer "author_id"
t.integer "action", null: false
t.string "state", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "note_id"
end
add_index "todos", ["author_id"], name: "index_todos_on_author_id", using: :btree
add_index "todos", ["note_id"], name: "index_todos_on_note_id", using: :btree
add_index "todos", ["project_id"], name: "index_todos_on_project_id", using: :btree
add_index "todos", ["state"], name: "index_todos_on_state", using: :btree
add_index "todos", ["target_type", "target_id"], name: "index_todos_on_target_type_and_target_id", using: :btree
add_index "todos", ["user_id"], name: "index_todos_on_user_id", using: :btree
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
......
@dashboard
Feature: Dashboard Todos
Background:
Given I sign in as a user
And I own project "Shop"
And "John Doe" is a developer of project "Shop"
And "Mary Jane" is a developer of project "Shop"
And "Mary Jane" owns private project "Enterprise"
And I am a developer of project "Enterprise"
And I have todos
And I visit dashboard todos page
@javascript
Scenario: I mark todos as done
Then I should see todos assigned to me
And I mark the todo as done
And I click on the "Done" tab
Then I should see all todos marked as done
@javascript
Scenario: I filter by project
Given I filter by "Enterprise"
Then I should not see todos
@javascript
Scenario: I filter by author
Given I filter by "John Doe"
Then I should not see todos related to "Mary Jane" in the list
@javascript
Scenario: I filter by type
Given I filter by "Issue"
Then I should not see todos related to "Merge Requests" in the list
@javascript
Scenario: I filter by action
Given I filter by "Mentioned"
Then I should not see todos related to "Assignments" in the list
class Spinach::Features::DashboardTodos < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedProject
include SharedUser
include Select2Helper
step '"John Doe" is a developer of project "Shop"' do
project.team << [john_doe, :developer]
end
step 'I am a developer of project "Enterprise"' do
enterprise.team << [current_user, :developer]
end
step '"Mary Jane" is a developer of project "Shop"' do
project.team << [john_doe, :developer]
end
step 'I have todos' do
create(:todo, user: current_user, project: project, author: mary_jane, target: issue, action: Todo::MENTIONED)
create(:todo, user: current_user, project: project, author: john_doe, target: issue, action: Todo::ASSIGNED)
note = create(:note, author: john_doe, noteable: issue, note: "#{current_user.to_reference} Wdyt?")
create(:todo, user: current_user, project: project, author: john_doe, target: issue, action: Todo::MENTIONED, note: note)
create(:todo, user: current_user, project: project, author: john_doe, target: merge_request, action: Todo::ASSIGNED)
end
step 'I should see todos assigned to me' do
expect(page).to have_content 'To do 4'
expect(page).to have_content 'Done 0'
expect(page).to have_link project.name_with_namespace
should_see_todo(1, "John Doe assigned you merge request !#{merge_request.iid}", merge_request.title)
should_see_todo(2, "John Doe mentioned you on issue ##{issue.iid}", "#{current_user.to_reference} Wdyt?")
should_see_todo(3, "John Doe assigned you issue ##{issue.iid}", issue.title)
should_see_todo(4, "Mary Jane mentioned you on issue ##{issue.iid}", issue.title)
end
step 'I mark the todo as done' do
page.within('.todo:nth-child(1)') do
click_link 'Done'
end
expect(page).to have_content 'Todo was successfully marked as done.'
expect(page).to have_content 'To do 3'
expect(page).to have_content 'Done 1'
should_not_see_todo "John Doe assigned you merge request !#{merge_request.iid}"
end
step 'I click on the "Done" tab' do
click_link 'Done 1'
end
step 'I should see all todos marked as done' do
expect(page).to have_link project.name_with_namespace
should_see_todo(1, "John Doe assigned you merge request !#{merge_request.iid}", merge_request.title, false)
end
step 'I filter by "Enterprise"' do
select2(enterprise.id, from: "#project_id")
end
step 'I filter by "John Doe"' do
select2(john_doe.id, from: "#author_id")
end
step 'I filter by "Issue"' do
select2('Issue', from: "#type")
end
step 'I filter by "Mentioned"' do
select2("#{Todo::MENTIONED}", from: '#action_id')
end
step 'I should not see todos' do
expect(page).to have_content "You're all done!"
end
step 'I should not see todos related to "Mary Jane" in the list' do
should_not_see_todo "Mary Jane mentioned you on issue ##{issue.iid}"
end
step 'I should not see todos related to "Merge Requests" in the list' do
should_not_see_todo "John Doe assigned you merge request !#{merge_request.iid}"
end
step 'I should not see todos related to "Assignments" in the list' do
should_not_see_todo "John Doe assigned you merge request !#{merge_request.iid}"
should_not_see_todo "John Doe assigned you issue ##{issue.iid}"
end
def should_see_todo(position, title, body, pending = true)
page.within(".todo:nth-child(#{position})") do
expect(page).to have_content title
expect(page).to have_content body
if pending
expect(page).to have_link 'Done'
else
expect(page).to_not have_link 'Done'
end
end
end
def should_not_see_todo(title)
expect(page).not_to have_content title
end
def john_doe
@john_doe ||= user_exists("John Doe", { username: "john_doe" })
end
def mary_jane
@mary_jane ||= user_exists("Mary Jane", { username: "mary_jane" })
end
def enterprise
@enterprise ||= Project.find_by(name: 'Enterprise')
end
def issue
@issue ||= create(:issue, assignee: current_user, project: project)
end
def merge_request
@merge_request ||= create(:merge_request, assignee: current_user, source_project: project)
end
end
......@@ -103,6 +103,10 @@ module SharedPaths
visit dashboard_groups_path
end
step 'I visit dashboard todos page' do
visit dashboard_todos_path
end
step 'I should be redirected to the dashboard groups page' do
expect(current_path).to eq dashboard_groups_path
end
......
# == Schema Information
#
# Table name: todos
#
# id :integer not null, primary key
# user_id :integer not null
# project_id :integer not null
# target_id :integer not null
# target_type :string not null
# author_id :integer
# note_id :integer
# action :integer not null
# state :string not null
# created_at :datetime
# updated_at :datetime
#
FactoryGirl.define do
factory :todo do
project
author
user
target factory: :issue
action { Todo::ASSIGNED }
trait :assigned do
action { Todo::ASSIGNED }
end
trait :mentioned do
action { Todo::MENTIONED }
end
end
end
......@@ -26,6 +26,8 @@ describe Note, models: true do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:noteable) }
it { is_expected.to belong_to(:author).class_name('User') }
it { is_expected.to have_many(:todos).dependent(:destroy) }
end
describe 'validation' do
......
# == Schema Information
#
# Table name: todos
#
# id :integer not null, primary key
# user_id :integer not null
# project_id :integer not null
# target_id :integer not null
# target_type :string not null
# author_id :integer
# note_id :integer
# action :integer not null
# state :string not null
# created_at :datetime
# updated_at :datetime
#
require 'spec_helper'
describe Todo, models: true do
describe 'relationships' do
it { is_expected.to belong_to(:author).class_name("User") }
it { is_expected.to belong_to(:note) }
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:target).touch(true) }
it { is_expected.to belong_to(:user) }
end
describe 'respond to' do
it { is_expected.to respond_to(:author_name) }
it { is_expected.to respond_to(:author_email) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:action) }
it { is_expected.to validate_presence_of(:target) }
it { is_expected.to validate_presence_of(:user) }
end
describe '#action_name' do
it 'returns proper message when action is an assigment' do
subject.action = Todo::ASSIGNED
expect(subject.action_name).to eq 'assigned'
end
it 'returns proper message when action is a mention' do
subject.action = Todo::MENTIONED
expect(subject.action_name).to eq 'mentioned you on'
end
end
describe '#body' do
before do
subject.target = build(:issue, title: 'Bugfix')
end
it 'returns target title when note is blank' do
subject.note = nil
expect(subject.body).to eq 'Bugfix'
end
it 'returns note when note is present' do
subject.note = build(:note, note: 'quick fix')
expect(subject.body).to eq 'quick fix'
end
end
describe '#target_iid' do
let(:issue) { build(:issue, id: 1, iid: 5) }
before do
subject.target = issue
end
it 'returns target.iid when target respond to iid' do
expect(subject.target_iid).to eq 5
end
it 'returns target_id when target does not respond to iid' do
allow(issue).to receive(:respond_to?).with(:iid).and_return(false)
expect(subject.target_iid).to eq 1
end
end
end
......@@ -92,6 +92,7 @@ describe User, models: true do
it { is_expected.to have_many(:identities).dependent(:destroy) }
it { is_expected.to have_one(:abuse_report) }
it { is_expected.to have_many(:spam_logs).dependent(:destroy) }
it { is_expected.to have_many(:todos).dependent(:destroy) }
end
describe 'validations' do
......
......@@ -5,6 +5,7 @@ describe Issues::CloseService, services: true do
let(:user2) { create(:user) }
let(:issue) { create(:issue, assignee: user2) }
let(:project) { issue.project }
let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
before do
project.team << [user, :master]
......@@ -32,6 +33,10 @@ describe Issues::CloseService, services: true do
note = @issue.notes.last
expect(note.note).to include "Status changed to closed"
end
it 'marks todos as done' do
expect(todo.reload).to be_done
end
end
context "external issue tracker" do
......@@ -42,6 +47,7 @@ describe Issues::CloseService, services: true do
it { expect(@issue).to be_valid }
it { expect(@issue).to be_opened }
it { expect(todo.reload).to be_pending }
end
end
end
......@@ -3,14 +3,18 @@ require 'spec_helper'
describe Issues::CreateService, services: true do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:assignee) { create(:user) }
describe :execute do
context "valid params" do
context 'valid params' do
before do
project.team << [user, :master]
project.team << [assignee, :master]
opts = {
title: 'Awesome issue',
description: 'please fix'
description: 'please fix',
assignee: assignee
}
@issue = Issues::CreateService.new(project, user, opts).execute
......@@ -18,6 +22,21 @@ describe Issues::CreateService, services: true do
it { expect(@issue).to be_valid }
it { expect(@issue.title).to eq('Awesome issue') }
it { expect(@issue.assignee).to eq assignee }
it 'creates a pending todo for new assignee' do
attributes = {
project: project,
author: user,
user: assignee,
target_id: @issue.id,
target_type: @issue.class.name,
action: Todo::ASSIGNED,
state: :pending
}
expect(Todo.where(attributes).count).to eq 1
end
end
end
end
......@@ -80,6 +80,74 @@ describe Issues::UpdateService, services: true do
end
end
context 'todos' do
let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
context 'when the title change' do
before do
update_issue({ title: 'New title' })
end
it 'marks pending todos as done' do
expect(todo.reload.done?).to eq true
end
end
context 'when the description change' do
before do
update_issue({ description: 'Also please fix' })
end
it 'marks todos as done' do
expect(todo.reload.done?).to eq true
end
end
context 'when is reassigned' do
before do
update_issue({ assignee: user2 })
end
it 'marks previous assignee todos as done' do
expect(todo.reload.done?).to eq true
end
it 'creates a todo for new assignee' do
attributes = {
project: project,
author: user,
user: user2,
target_id: issue.id,
target_type: issue.class.name,
action: Todo::ASSIGNED,
state: :pending
}
expect(Todo.where(attributes).count).to eq 1
end
end
context 'when the milestone change' do
before do
update_issue({ milestone: create(:milestone) })
end
it 'marks todos as done' do
expect(todo.reload.done?).to eq true
end
end
context 'when the labels change' do
before do
update_issue({ label_ids: [label.id] })
end
it 'marks todos as done' do
expect(todo.reload.done?).to eq true
end
end
end
context 'when Issue has tasks' do
before { update_issue({ description: "- [ ] Task 1\n- [ ] Task 2" }) }
......@@ -144,6 +212,5 @@ describe Issues::UpdateService, services: true do
end
end
end
end
end
......@@ -5,6 +5,7 @@ describe MergeRequests::CloseService, services: true do
let(:user2) { create(:user) }
let(:merge_request) { create(:merge_request, assignee: user2) }
let(:project) { merge_request.project }
let!(:todo) { create(:todo, :assigned, user: user, project: project, target: merge_request, author: user2) }
before do
project.team << [user, :master]
......@@ -41,6 +42,10 @@ describe MergeRequests::CloseService, services: true do
note = @merge_request.notes.last
expect(note.note).to include 'Status changed to closed'
end
it 'marks todos as done' do
expect(todo.reload).to be_done
end
end
end
end
......@@ -3,6 +3,7 @@ require 'spec_helper'
describe MergeRequests::CreateService, services: true do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:assignee) { create(:user) }
describe :execute do
context 'valid params' do
......@@ -14,10 +15,12 @@ describe MergeRequests::CreateService, services: true do
target_branch: 'master'
}
end
let(:service) { MergeRequests::CreateService.new(project, user, opts) }
before do
project.team << [user, :master]
project.team << [assignee, :developer]
allow(service).to receive(:execute_hooks)
@merge_request = service.execute
......@@ -25,10 +28,49 @@ describe MergeRequests::CreateService, services: true do
it { expect(@merge_request).to be_valid }
it { expect(@merge_request.title).to eq('Awesome merge_request') }
it { expect(@merge_request.assignee).to be_nil }
it 'should execute hooks with default action' do
expect(service).to have_received(:execute_hooks).with(@merge_request)
end
it 'does not creates todos' do
attributes = {
project: project,
target_id: @merge_request.id,
target_type: @merge_request.class.name
}
expect(Todo.where(attributes).count).to be_zero
end
context 'when merge request is assigned to someone' do
let(:opts) do
{
title: 'Awesome merge_request',
description: 'please fix',
source_branch: 'feature',
target_branch: 'master',
assignee: assignee
}
end
it { expect(@merge_request.assignee).to eq assignee }
it 'creates a todo for new assignee' do
attributes = {
project: project,
author: user,
user: assignee,
target_id: @merge_request.id,
target_type: @merge_request.class.name,
action: Todo::ASSIGNED,
state: :pending
}
expect(Todo.where(attributes).count).to eq 1
end
end
end
end
end
......@@ -98,6 +98,84 @@ describe MergeRequests::UpdateService, services: true do
end
end
context 'todos' do
let!(:pending_todo) { create(:todo, :assigned, user: user, project: project, target: merge_request, author: user2) }
context 'when the title change' do
before do
update_merge_request({ title: 'New title' })
end
it 'marks pending todos as done' do
expect(pending_todo.reload).to be_done
end
end
context 'when the description change' do
before do
update_merge_request({ description: 'Also please fix' })
end
it 'marks pending todos as done' do
expect(pending_todo.reload).to be_done
end
end
context 'when is reassigned' do
before do
update_merge_request({ assignee: user2 })
end
it 'marks previous assignee pending todos as done' do
expect(pending_todo.reload).to be_done
end
it 'creates a pending todo for new assignee' do
attributes = {
project: project,
author: user,
user: user2,
target_id: merge_request.id,
target_type: merge_request.class.name,
action: Todo::ASSIGNED,
state: :pending
}
expect(Todo.where(attributes).count).to eq 1
end
end
context 'when the milestone change' do
before do
update_merge_request({ milestone: create(:milestone) })
end
it 'marks pending todos as done' do
expect(pending_todo.reload).to be_done
end
end
context 'when the labels change' do
before do
update_merge_request({ label_ids: [label.id] })
end
it 'marks pending todos as done' do
expect(pending_todo.reload).to be_done
end
end
context 'when the target branch change' do
before do
update_merge_request({ target_branch: 'target' })
end
it 'marks pending todos as done' do
expect(pending_todo.reload).to be_done
end
end
end
context 'when MergeRequest has tasks' do
before { update_merge_request({ description: "- [ ] Task 1\n- [ ] Task 2" }) }
......@@ -130,6 +208,5 @@ describe MergeRequests::UpdateService, services: true do
end
end
end
end
end
......@@ -20,6 +20,7 @@ describe Notes::PostProcessService, services: true do
it do
expect(project).to receive(:execute_hooks)
expect(project).to receive(:execute_services)
Notes::PostProcessService.new(@note).execute
end
end
......
require 'spec_helper'
describe Notes::UpdateService, services: true do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:note) { create(:note, project: project, noteable: issue, author: user, note: 'Old note') }
before do
project.team << [user, :master]
project.team << [user2, :developer]
end
describe '#execute' do
def update_note(opts)
@note = Notes::UpdateService.new(project, user, opts).execute(note)
@note.reload
end
context 'todos' do
let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
context 'when the note change' do
before do
update_note({ note: 'New note' })
end
it 'marks todos as done' do
expect(todo.reload).to be_done
end
end
context 'when the note does not change' do
before do
update_note({ note: 'Old note' })
end
it 'keep todos' do
expect(todo.reload).to be_pending
end
end
end
end
end
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment