Add data required for note form

This commit is contained in:
Douwe Maan 2017-06-23 17:10:05 -05:00 committed by Fatih Acet
parent e57093ff62
commit ebf9155113
6 changed files with 36 additions and 5 deletions

View file

@ -92,7 +92,7 @@ class Projects::IssuesController < Projects::ApplicationController
respond_to do |format|
format.html
format.json do
render json: IssueSerializer.new.represent(@issue)
render json: serializer.represent(@issue)
end
end
end
@ -152,7 +152,7 @@ class Projects::IssuesController < Projects::ApplicationController
format.json do
if @issue.valid?
render json: IssueSerializer.new.represent(@issue)
render json: serializer.represent(@issue)
else
render json: { errors: @issue.errors.full_messages }, status: :unprocessable_entity
end
@ -308,4 +308,8 @@ class Projects::IssuesController < Projects::ApplicationController
redirect_to new_user_session_path, notice: notice
end
def serializer
IssueSerializer.new(current_user: current_user, project: issue.project)
end
end

View file

@ -35,7 +35,7 @@ module IssuablesHelper
def serialize_issuable(issuable)
case issuable
when Issue
IssueSerializer.new.represent(issuable).to_json
IssueSerializer.new(current_user: current_user, project: issuable.project).represent(issuable).to_json
when MergeRequest
MergeRequestSerializer
.new(current_user: current_user, project: issuable.project)

View file

@ -15,4 +15,6 @@ class IssuableEntity < Grape::Entity
expose :total_time_spent
expose :human_time_estimate
expose :human_total_time_spent
expose :milestone, using: API::Entities::Milestone
expose :labels, using: LabelEntity
end

View file

@ -7,10 +7,26 @@ class IssueEntity < IssuableEntity
expose :due_date
expose :moved_to_id
expose :project_id
expose :milestone, using: API::Entities::Milestone
expose :labels, using: LabelEntity
expose :web_url do |issue|
project_issue_path(issue.project, issue)
end
expose :current_user do
expose :can_create_note do |issue|
can?(request.current_user, :create_note, issue.project)
end
expose :can_update do |issue|
can?(request.current_user, :update_issue, issue)
end
end
expose :create_note_path do |issue|
namespace_project_notes_path(issue.project.namespace, issue.project, noteable_type: 'Issue', noteable_id: issue.id, target_type: 'issue', target_id: issue.id)
end
expose :preview_note_path do |issue|
preview_markdown_path(issue.project, quick_actions_target_type: 'Issue', quick_actions_target_id: issue.id)
end
end

View file

@ -0,0 +1,3 @@
class UserSerializer < BaseSerializer
entity UserEntity
end

View file

@ -12,3 +12,9 @@
/ #notes{style: "margin-top: 150px"}
/ = render 'shared/notes/notes_with_form', :autocomplete => true
:javascript
window.gl.issueData = #{serialize_issuable(@issue)};
window.gl.currentUserData = #{UserSerializer.new.represent(current_user).to_json};
%section#note-form{ data: { new_session_path: new_session_path(:user, redirect_to_referer: 'yes') } }