Project

General

Profile

Patch #8451 ยป redmine-1.1.2-rest-usability-enhancement.patch

redmine-1.1.2-rest-usability-enhancement for Net::Redmine::API::REST - Christophe Nowicki, 2011-05-27 14:46

View differences:

./app/controllers/enumerations_controller.rb 2011-05-27 09:15:09.600031476 +0200
18 18
class EnumerationsController < ApplicationController
19 19
  layout 'admin'
20 20
  
21
  before_filter :require_admin
21
  before_filter :require_admin, :except => [:index, :show]
22
  before_filter :find_enumerations, :only => [:show]
22 23

  
23 24
  helper :custom_fields
24 25
  include CustomFieldsHelper
25 26
  
26 27
  def index
27
    list
28
    render :action => 'list'
28
    @enumerations_pages, @enumerations = paginate :enumerations, :per_page => 10, :order => 'position'
29
    render :action => 'list' if request.xhr?
30
    respond_to do |format|
31
      format.html if User.current.admin?
32
      format.html { render_403 } unless User.current.admin?
33
      format.api
34
    end
29 35
  end
30 36

  
31 37
  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
......
35 41
  def list
36 42
  end
37 43

  
44
  def show
45
    respond_to do |format|
46
      format.html { render_404 }
47
      format.api
48
    end
49
  end
50

  
38 51
  def new
39 52
    begin
40 53
      @enumeration = params[:type].constantize.new
......
86 99
  #  flash[:error] = 'Unable to delete enumeration'
87 100
  #  redirect_to :action => 'index'
88 101
  end
102

  
103
private
104
  def find_enumerations
105
    begin
106
      @enumeration = Enumeration.find(params[:id])
107
    rescue ActiveRecord::RecordNotFound
108
      @enumeration = Enumeration.find_by_name(params[:id])
109
      if @enumeration.nil?
110
        render_404
111
      end
112
    end
113
  end
89 114
end
./app/controllers/issue_categories_controller.rb 2011-05-27 09:15:12.160055868 +0200
18 18
class IssueCategoriesController < ApplicationController
19 19
  menu_item :settings
20 20
  model_object IssueCategory
21
  before_filter :find_model_object, :except => :new
22
  before_filter :find_project_from_association, :except => :new
21
  before_filter :find_issue_categories, :only => :show
22
  before_filter :find_model_object, :except => [:new, :index]
23
  before_filter :find_project_from_association, :except => [:new, :index]
23 24
  before_filter :find_project, :only => :new
24
  before_filter :authorize
25
  before_filter :authorize, :except => [:index, :show]
25 26
  
26 27
  verify :method => :post, :only => :destroy
27 28

  
29
  def index
30
    @issue_categories_pages, @issue_categories = paginate :issue_categories, :per_page => 25, :order => "name"
31
    render :action => "index", :layout => false if request.xhr?
32
    respond_to do |format|
33
      format.html if User.current.admin?
34
      format.html { render_403 } unless User.current.admin?
35
      format.api
36
    end
37
  end
38
  
39

  
28 40
  def new
29 41
    @category = @project.issue_categories.build(params[:category])
30 42
    if request.post?
......
51 63
      end
52 64
    end
53 65
  end
66

  
67
  def show
68
    respond_to do |format|
69
      format.html { render_404 }
70
      format.api
71
    end
72
  end
54 73
  
55 74
  def edit
56 75
    if request.post? and @category.update_attributes(params[:category])
......
86 105
  rescue ActiveRecord::RecordNotFound
87 106
    render_404
88 107
  end
108

  
109
  def find_issue_categories
110
    begin
111
      @issue_categories = IssueCategories.find(params[:id])
112
    rescue ActiveRecord::RecordNotFound
113
      @issue_categories = IssueCategories.find_by_name(params[:id])
114
      if @status.nil?
115
        render_404
116
      end
117
    end
118
  end
89 119
end
./app/controllers/issue_statuses_controller.rb 2011-05-27 09:15:12.948062250 +0200
18 18
class IssueStatusesController < ApplicationController
19 19
  layout 'admin'
20 20
  
21
  before_filter :require_admin
21
  before_filter :require_admin, :except => [:index, :show]
22
  before_filter :find_status, :only => [:show]
22 23

  
23 24
  verify :method => :post, :only => [ :destroy, :create, :update, :move, :update_issue_done_ratio ],
24 25
         :redirect_to => { :action => :index }
......
26 27
  def index
27 28
    @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
28 29
    render :action => "index", :layout => false if request.xhr?
30
    respond_to do |format|
31
      format.html if User.current.admin?
32
      format.html { render_403 } unless User.current.admin?
33
      format.api
34
    end
29 35
  end
30 36

  
31 37
  def new
......
42 48
    end
43 49
  end
44 50

  
51
  def show
52
    respond_to do |format|
53
      format.html { render_404 }
54
      format.api
55
    end
56
  end
57

  
45 58
  def edit
46 59
    @issue_status = IssueStatus.find(params[:id])
47 60
  end
......
72 85
    end
73 86
    redirect_to :action => 'index'
74 87
  end
88

  
89
private
90

  
91
def find_status
92
    begin
93
      @status = IssueStatus.find(params[:id])
94
    rescue ActiveRecord::RecordNotFound
95
      @status = IssueStatus.find_by_name(params[:id])
96
      if @status.nil?
97
        render_404
98
      end
99
    end
100
  end
75 101
end
./app/controllers/trackers_controller.rb 2011-05-27 09:15:08.760030676 +0200
17 17

  
18 18
class TrackersController < ApplicationController
19 19
  layout 'admin'
20
  
21
  before_filter :require_admin
20

  
21
  before_filter :require_admin, :except => [:index, :show]
22
  before_filter :find_trackers, :only => [:show]
22 23

  
23 24
  verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
24 25

  
25 26
  def index
26 27
    @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
27 28
    render :action => "index", :layout => false if request.xhr?
29
    respond_to do |format|
30
      format.html if User.current.admin?
31
      format.html { render_403 } unless User.current.admin?
32
      format.api
33
    end
28 34
  end
29 35

  
30 36
  def new
......
42 48
    @projects = Project.find(:all)
43 49
  end
44 50

  
51
  def show
52
    respond_to do |format|
53
      format.html { render_404 }
54
      format.api
55
    end
56
  end
57

  
45 58
  def edit
46 59
    @tracker = Tracker.find(params[:id])
47 60
    if request.post? and @tracker.update_attributes(params[:tracker])
......
61 74
    end
62 75
    redirect_to :action => 'index'
63 76
  end  
77

  
78
private
79
  def find_trackers
80
    begin
81
      @tracker = Tracker.find(params[:id])
82
    rescue ActiveRecord::RecordNotFound
83
      @tracker = Tracker.find_by_name(params[:id])
84
      if @tracker.nil?
85
        render_404
86
      end
87
    end
88
  end
89

  
64 90
end
./app/views/enumerations/index.api.rsb 2011-05-27 09:15:29.812057409 +0200
1
api.array :enumerations do
2
	@enumerations.each do |enumeration|
3
		api.enumeration do
4
			api.type enumeration.type
5
			api.name enumeration.name
6
			api.id enumeration.id
7
		end
8
	end
9
end
./app/views/enumerations/show.api.rsb 2011-05-27 09:15:29.892266085 +0200
1
api.enumerations do
2
  api.type @enumeration.type
3
  api.name @enumeration.name
4
  api.id @enumeration.id
5
end
./app/views/issue_categories/index.api.rsb 2011-05-27 09:15:34.108031357 +0200
1
api.array :issue_categories do
2
	@issue_categories.each do |category|
3
		api.category do
4
			api.name category.name
5
			api.id category.id
6
		end
7
	end
8
end
./app/views/issue_categories/show.api.rsb 2011-05-27 09:15:34.252782323 +0200
1
api.issue_category do
2
  api.name @issue_category.name
3
  api.id @issue_category.id
4
end
./app/views/issue_statuses/index.api.rsb 2011-05-27 09:15:28.031987862 +0200
1
api.array :issue_statuses do
2
	@issue_statuses.each do |status|
3
		api.status do
4
			api.name status.name
5
			api.id status.id
6
		end	
7
	end
8
end
./app/views/issue_statuses/show.api.rsb 2011-05-27 09:15:28.107988399 +0200
1
api.issue_status do
2
  api.name  @status.name
3
  api.id    @status.id
4
end
./app/views/trackers/index.api.rsb 2011-05-27 09:15:25.606214785 +0200
1
api.array :trackers do
2
	@trackers.each do |tracker|
3
		api.tracker do
4
			api.name tracker.name
5
			api.id tracker.id
6
		end
7
	end
8
end
./app/views/trackers/show.api.rsb 2011-05-27 09:15:25.704003712 +0200
1
api.trackers do
2
  api.name  @tracker.name
3
  api.id    @tracker.id
4
end
./config/routes.rb 2011-05-27 09:20:40.667987762 +0200
90 90
    reports.connect 'projects/:id/issues/report/:detail', :action => 'issue_report_details'
91 91
  end
92 92

  
93
  map.resources :issue_statuses, :only => [:index, :show]
94
  map.resources :issue_categories, :only => [:index, :show]
95
  map.resources :trackers, :only => [:index, :show]
96
  map.resources :enumerations, :only => [:index, :show]
97

  
93 98
  # Following two routes conflict with the resources because #index allows POST
94 99
  map.connect '/issues', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
95 100
  map.connect '/issues/create', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
    (1-1/1)