summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-04 17:03:04 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-04 17:03:04 +0000
commit21b37187445f03c9395f5fc36b5bd1a42d99d980 (patch)
treee2e8b947d3c3b453b5be0a08e5a06e4e57d5a65a /app
parent9fca4c440cbcf21a93db943b67acba68b83cf051 (diff)
downloadredmine-21b37187445f03c9395f5fc36b5bd1a42d99d980.tar.gz
redmine-21b37187445f03c9395f5fc36b5bd1a42d99d980.zip
Adds REST API for issue relations (#7366).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6176 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/issue_relations_controller.rb43
-rw-r--r--app/models/issue.rb5
-rw-r--r--app/views/issue_relations/show.api.rsb7
-rw-r--r--app/views/issues/_relations.rhtml4
-rw-r--r--app/views/issues/show.api.rsb2
5 files changed, 48 insertions, 13 deletions
diff --git a/app/controllers/issue_relations_controller.rb b/app/controllers/issue_relations_controller.rb
index b095df37a..094036768 100644
--- a/app/controllers/issue_relations_controller.rb
+++ b/app/controllers/issue_relations_controller.rb
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -17,14 +17,28 @@
class IssueRelationsController < ApplicationController
before_filter :find_issue, :find_project_from_association, :authorize
+ accept_key_auth :show, :create, :destroy
- def new
+ def show
+ @relation = @issue.find_relation(params[:id])
+
+ respond_to do |format|
+ format.html { render :nothing => true }
+ format.api
+ end
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
+ verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
+ def create
@relation = IssueRelation.new(params[:relation])
@relation.issue_from = @issue
if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/)
@relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
end
- @relation.save if request.post?
+ saved = @relation.save
+
respond_to do |format|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
format.js do
@@ -37,22 +51,31 @@ class IssueRelationsController < ApplicationController
end
end
end
+ format.api {
+ if saved
+ render :action => 'show', :status => :created, :location => issue_relation_url(@issue, @relation)
+ else
+ render_validation_errors(@relation)
+ end
+ }
end
end
+ verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
def destroy
- relation = IssueRelation.find(params[:id])
- if request.post? && @issue.relations.include?(relation)
- relation.destroy
- @issue.reload
- end
+ relation = @issue.find_relation(params[:id])
+ relation.destroy
+
respond_to do |format|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
format.js {
- @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
+ @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'}
}
+ format.api { head :ok }
end
+ rescue ActiveRecord::RecordNotFound
+ render_404
end
private
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 79c491547..5ac166270 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -501,6 +501,11 @@ class Issue < ActiveRecord::Base
def relations
(relations_from + relations_to).sort
end
+
+ # Finds an issue relation given its id.
+ def find_relation(relation_id)
+ IssueRelation.find(relation_id, :conditions => ["issue_to_id = ? OR issue_from_id = ?", id, id])
+ end
def all_dependent_issues(except=[])
except << self
diff --git a/app/views/issue_relations/show.api.rsb b/app/views/issue_relations/show.api.rsb
new file mode 100644
index 000000000..0a3e2918a
--- /dev/null
+++ b/app/views/issue_relations/show.api.rsb
@@ -0,0 +1,7 @@
+api.relation do
+ api.id @relation.id
+ api.issue_id @relation.issue_from_id
+ api.issue_to_id @relation.issue_to_id
+ api.relation_type @relation.relation_type_for(@issue)
+ api.delay @relation.delay
+end
diff --git a/app/views/issues/_relations.rhtml b/app/views/issues/_relations.rhtml
index 19ae08b04..065f8da9b 100644
--- a/app/views/issues/_relations.rhtml
+++ b/app/views/issues/_relations.rhtml
@@ -20,7 +20,7 @@
<td class="start_date"><%= format_date(relation.other_issue(@issue).start_date) %></td>
<td class="due_date"><%= format_date(relation.other_issue(@issue).due_date) %></td>
<td class="buttons"><%= link_to_remote(image_tag('link_break.png'), { :url => {:controller => 'issue_relations', :action => 'destroy', :issue_id => @issue, :id => relation},
- :method => :post
+ :method => :delete
}, :title => l(:label_relation_delete)) if authorize_for('issue_relations', 'destroy') %></td>
</tr>
<% end %>
@@ -29,7 +29,7 @@
<% end %>
<% remote_form_for(:relation, @relation,
- :url => {:controller => 'issue_relations', :action => 'new', :issue_id => @issue},
+ :url => {:controller => 'issue_relations', :action => 'create', :issue_id => @issue},
:method => :post,
:complete => "Form.Element.focus('relation_issue_to_id');",
:html => {:id => 'new-relation-form', :style => (@relation ? '' : 'display: none;')}) do |f| %>
diff --git a/app/views/issues/show.api.rsb b/app/views/issues/show.api.rsb
index 170aeb375..3493a29cd 100644
--- a/app/views/issues/show.api.rsb
+++ b/app/views/issues/show.api.rsb
@@ -27,7 +27,7 @@ api.issue do
api.array :relations do
@relations.each do |relation|
- api.relation(:id => relation.id, :issue_id => relation.other_issue(@issue).id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay)
+ api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay)
end
end if include_in_api_response?('relations') && @relations.present?