Commit 959b503c authored by Sean McGivern's avatar Sean McGivern Committed by Alejandro Rodríguez

Merge branch 'ee-870-backport' into 'master'

Backport some changes done from Time Tracking feature in EE.

See merge request !7604
parent 15d156fa
...@@ -12,7 +12,7 @@ module IssuableActions ...@@ -12,7 +12,7 @@ module IssuableActions
destroy_method = "destroy_#{issuable.class.name.underscore}".to_sym destroy_method = "destroy_#{issuable.class.name.underscore}".to_sym
TodoService.new.public_send(destroy_method, issuable, current_user) TodoService.new.public_send(destroy_method, issuable, current_user)
name = issuable.class.name.titleize.downcase name = issuable.human_class_name
flash[:notice] = "The #{name} was successfully deleted." flash[:notice] = "The #{name} was successfully deleted."
redirect_to polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable.class]) redirect_to polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable.class])
end end
......
...@@ -69,7 +69,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -69,7 +69,7 @@ class Projects::IssuesController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
render json: @issue.to_json(include: [:milestone, :labels]) render json: IssueSerializer.new.represent(@issue)
end end
end end
end end
......
...@@ -60,7 +60,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -60,7 +60,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
format.html { define_discussion_vars } format.html { define_discussion_vars }
format.json do format.json do
render json: @merge_request render json: MergeRequestSerializer.new.represent(@merge_request)
end end
format.patch do format.patch do
......
...@@ -146,24 +146,26 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -146,24 +146,26 @@ class Projects::NotesController < Projects::ApplicationController
end end
def note_json(note) def note_json(note)
attrs = {
award: false,
id: note.id
}
if note.is_a?(AwardEmoji) if note.is_a?(AwardEmoji)
{ attrs.merge!(
valid: note.valid?, valid: note.valid?,
award: true, award: true,
id: note.id,
name: note.name name: note.name
} )
elsif note.persisted? elsif note.persisted?
Banzai::NoteRenderer.render([note], @project, current_user) Banzai::NoteRenderer.render([note], @project, current_user)
attrs = { attrs.merge!(
valid: true, valid: true,
id: note.id,
discussion_id: note.discussion_id, discussion_id: note.discussion_id,
html: note_html(note), html: note_html(note),
award: false,
note: note.note note: note.note
} )
if note.diff_note? if note.diff_note?
discussion = note.to_discussion discussion = note.to_discussion
...@@ -188,15 +190,14 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -188,15 +190,14 @@ class Projects::NotesController < Projects::ApplicationController
attrs[:original_discussion_id] = note.original_discussion_id attrs[:original_discussion_id] = note.original_discussion_id
end end
end end
attrs
else else
{ attrs.merge!(
valid: false, valid: false,
award: false,
errors: note.errors errors: note.errors
} )
end end
attrs
end end
def authorize_admin_note! def authorize_admin_note!
......
...@@ -251,6 +251,17 @@ module Issuable ...@@ -251,6 +251,17 @@ module Issuable
self.class.to_ability_name self.class.to_ability_name
end end
# Convert this Issuable class name to a format usable by notifications.
#
# Examples:
#
# issuable.class # => MergeRequest
# issuable.human_class_name # => "merge request"
def human_class_name
@human_class_name ||= self.class.name.titleize.downcase
end
# Returns a Hash of attributes to be used for Twitter card metadata # Returns a Hash of attributes to be used for Twitter card metadata
def card_attributes def card_attributes
{ {
......
class IssuableEntity < Grape::Entity
expose :id
expose :iid
expose :assignee_id
expose :author_id
expose :description
expose :lock_version
expose :milestone_id
expose :position
expose :state
expose :title
expose :updated_by_id
expose :created_at
expose :updated_at
expose :deleted_at
end
class IssueEntity < IssuableEntity
expose :branch_name
expose :confidential
expose :due_date
expose :moved_to_id
expose :project_id
expose :milestone, using: API::Entities::Milestone
expose :labels, using: LabelEntity
end
class IssueSerializer < BaseSerializer
entity IssueEntity
end
class LabelEntity < Grape::Entity
expose :id
expose :title
expose :color
expose :description
expose :group_id
expose :project_id
expose :template
expose :created_at
expose :updated_at
end
class MergeRequestEntity < IssuableEntity
expose :in_progress_merge_commit_sha
expose :locked_at
expose :merge_commit_sha
expose :merge_error
expose :merge_params
expose :merge_status
expose :merge_user_id
expose :merge_when_build_succeeds
expose :source_branch
expose :source_project_id
expose :target_branch
expose :target_project_id
end
class MergeRequestSerializer < BaseSerializer
entity MergeRequestEntity
end
...@@ -35,7 +35,7 @@ module Notes ...@@ -35,7 +35,7 @@ module Notes
todo_service.new_note(note, current_user) todo_service.new_note(note, current_user)
end end
if command_params && command_params.any? if command_params.present?
slash_commands_service.execute(command_params, note) slash_commands_service.execute(command_params, note)
# We must add the error after we call #save because errors are reset # We must add the error after we call #save because errors are reset
......
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
- else - else
.pull-right .pull-right
- if can?(current_user, :"destroy_#{issuable.to_ability_name}", @project) - if can?(current_user, :"destroy_#{issuable.to_ability_name}", @project)
= link_to 'Delete', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), data: { confirm: "#{issuable.class.name.titleize} will be removed! Are you sure?" }, = link_to 'Delete', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), data: { confirm: "#{issuable.human_class_name} will be removed! Are you sure?" },
method: :delete, class: 'btn btn-danger btn-grouped' method: :delete, class: 'btn btn-danger btn-grouped'
= link_to 'Cancel', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), class: 'btn btn-grouped btn-cancel' = link_to 'Cancel', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), class: 'btn btn-grouped btn-cancel'
......
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