functional_renaming_rss_to_atom.diff

rename all methods and give deprecation warnings - Daniel Felix, 2013-03-13 11:37

Download (26.9 KB)

View differences:

app/controllers/application_controller.rb
100 100
        user = autologin_user
101 101
      elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
102 102
        # RSS key authentication does not start a session
103
        user = User.find_by_rss_key(params[:key])
103
        user = User.find_by_atom_key(params[:key])
104 104
      end
105 105
    end
106 106
    if user.nil? && Setting.rest_api_enabled? && accept_api_auth?
app/controllers/my_controller.rb
105 105
  end
106 106

  
107 107
  # Create a new feeds key
108
  def reset_rss_key
108
  def reset_atom_key
109 109
    if request.post?
110
      if User.current.rss_token
111
        User.current.rss_token.destroy
110
      if User.current.atom_token
111
        User.current.atom_token.destroy
112 112
        User.current.reload
113 113
      end
114
      User.current.rss_key
114
      User.current.atom_key
115 115
      flash[:notice] = l(:notice_feeds_access_key_reseted)
116 116
    end
117 117
    redirect_to my_account_path
118 118
  end
119
  
120
  # TODO: remove in Redmine 3.0
121
  def reset_rss_key
122
    ActiveSupport::Deprecation.warn "My#reset_rss_key is deprecated and will be removed in Redmine 3.0. Please use #reset_atom_key instead."
123
    reset_atom_key
124
  end
125

  
119 126

  
120 127
  # Create a new API key
121 128
  def reset_api_key
app/controllers/projects_controller.rb
158 158
      @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
159 159
    end
160 160

  
161
    @key = User.current.rss_key
161
    @key = User.current.atom_key
162 162

  
163 163
    respond_to do |format|
164 164
      format.html
app/models/user.rb
72 72
                                   :after_remove => Proc.new {|user, group| group.user_removed(user)}
73 73
  has_many :changesets, :dependent => :nullify
74 74
  has_one :preference, :dependent => :destroy, :class_name => 'UserPreference'
75
  has_one :rss_token, :class_name => 'Token', :conditions => "action='feeds'"
75
  has_one :atom_token, :class_name => 'Token', :conditions => "action='feeds'"
76 76
  has_one :api_token, :class_name => 'Token', :conditions => "action='api'"
77 77
  belongs_to :auth_source
78 78

  
......
303 303
    self.pref[:comments_sorting] == 'desc'
304 304
  end
305 305

  
306
  # Return user's RSS key (a 40 chars long string), used to access feeds
307
  def rss_key
308
    if rss_token.nil?
309
      create_rss_token(:action => 'feeds')
306
  # Return user's ATOM key (a 40 chars long string), used to access feeds
307
  def atom_key
308
    if atom_token.nil?
309
      create_atom_token(:action => 'feeds')
310 310
    end
311
    rss_token.value
311
    atom_token.value
312
  end
313
  
314
  # TODO: remove in Redmine 3.0
315
  def rss_key
316
    ActiveSupport::Deprecation.warn "User.rss_key is deprecated and will be removed in Redmine 3.0. Please use User.atom_key instead."
317
    atom_key
312 318
  end
313 319

  
314 320
  # Return user's API key (a 40 chars long string), used to access the API
......
361 367
    end
362 368
  end
363 369

  
364
  def self.find_by_rss_key(key)
370
  def self.find_by_atom_key(key)
365 371
    Token.find_active_user('feeds', key)
366 372
  end
367 373

  
374
  # TODO: remove in Redmine 3.0
375
  def self.find_by_rss_key(key)
376
    ActiveSupport::Deprecation.warn "User.find_by_rss_key is deprecated and will be removed in Redmine 3.0. Please use User.find_by_atom_key instead."
377
    self.find_by_atom_key(key)
378
  end
379

  
368 380
  def self.find_by_api_key(key)
369 381
    Token.find_active_user('api', key)
370 382
  end
......
698 710
  def name(*args); I18n.t(:label_user_anonymous) end
699 711
  def mail; nil end
700 712
  def time_zone; nil end
701
  def rss_key; nil end
713
  def atom_key; nil end
702 714

  
703 715
  def pref
704 716
    UserPreference.new(:user => self)
app/views/activities/index.html.erb
33 33
</div>
34 34
&nbsp;
35 35
<% other_formats_links do |f| %>
36
  <%= f.link_to 'Atom', :url => params.merge(:from => nil, :key => User.current.rss_key) %>
36
  <%= f.link_to 'Atom', :url => params.merge(:from => nil, :key => User.current.atom_key) %>
37 37
<% end %>
38 38

  
39 39
<% content_for :header_tags do %>
40
<%= auto_discovery_link_tag(:atom, params.merge(:format => 'atom', :from => nil, :key => User.current.rss_key)) %>
40
<%= auto_discovery_link_tag(:atom, params.merge(:format => 'atom', :from => nil, :key => User.current.atom_key)) %>
41 41
<% end %>
42 42

  
43 43
<% content_for :sidebar do %>
app/views/boards/index.html.erb
28 28
</table>
29 29

  
30 30
<% other_formats_links do |f| %>
31
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_messages => 1, :key => User.current.rss_key} %>
31
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_messages => 1, :key => User.current.atom_key} %>
32 32
<% end %>
33 33

  
34 34
<% content_for :header_tags do %>
35
  <%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :id => @project, :format => 'atom', :show_messages => 1, :key => User.current.rss_key}) %>
35
  <%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :id => @project, :format => 'atom', :show_messages => 1, :key => User.current.atom_key}) %>
36 36
<% end %>
37 37

  
38 38
<% html_title l(:label_board_plural) %>
app/views/boards/show.html.erb
56 56
<% end %>
57 57

  
58 58
<% other_formats_links do |f| %>
59
  <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
59
  <%= f.link_to 'Atom', :url => {:key => User.current.atom_key} %>
60 60
<% end %>
61 61

  
62 62
<% html_title @board.name %>
63 63

  
64 64
<% content_for :header_tags do %>
65
    <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@project}: #{@board}") %>
65
    <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.atom_key}, :title => "#{@project}: #{@board}") %>
66 66
<% end %>
app/views/issues/index.html.erb
64 64
<% end %>
65 65

  
66 66
<% other_formats_links do |f| %>
67
  <%= f.link_to 'Atom', :url => params.merge(:key => User.current.rss_key) %>
67
  <%= f.link_to 'Atom', :url => params.merge(:key => User.current.atom_key) %>
68 68
  <%= f.link_to 'CSV', :url => params, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
69 69
  <%= f.link_to 'PDF', :url => params %>
70 70
<% end %>
......
96 96
<% content_for :header_tags do %>
97 97
    <%= auto_discovery_link_tag(:atom,
98 98
                                {:query_id => @query, :format => 'atom',
99
                                 :page => nil, :key => User.current.rss_key},
99
                                 :page => nil, :key => User.current.atom_key},
100 100
                                :title => l(:label_issue_plural)) %>
101 101
    <%= auto_discovery_link_tag(:atom,
102 102
                                {:controller => 'journals', :action => 'index',
103 103
                                 :query_id => @query, :format => 'atom',
104
                                 :page => nil, :key => User.current.rss_key},
104
                                 :page => nil, :key => User.current.atom_key},
105 105
                                :title => l(:label_changes_details)) %>
106 106
<% end %>
107 107

  
app/views/issues/show.html.erb
134 134
<% end %>
135 135

  
136 136
<% other_formats_links do |f| %>
137
  <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
137
  <%= f.link_to 'Atom', :url => {:key => User.current.atom_key} %>
138 138
  <%= f.link_to 'PDF' %>
139 139
<% end %>
140 140

  
......
152 152
<% end %>
153 153

  
154 154
<% content_for :header_tags do %>
155
    <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %>
155
    <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.atom_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %>
156 156
<% end %>
157 157

  
158 158
<%= context_menu issues_context_menu_path %>
app/views/journals/index.builder
1 1
xml.instruct!
2 2
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3 3
  xml.title   @title
4
  xml.link    "rel" => "self", "href" => url_for(:format => 'atom', :key => User.current.rss_key, :only_path => false)
4
  xml.link    "rel" => "self", "href" => url_for(:format => 'atom', :key => User.current.atom_key, :only_path => false)
5 5
  xml.link    "rel" => "alternate", "href" => home_url(:only_path => false)
6 6
  xml.id      url_for(:controller => 'welcome', :only_path => false)
7 7
  xml.updated((@journals.first ? @journals.first.event_datetime : Time.now).xmlschema)
app/views/my/_sidebar.html.erb
10 10
<h4><%= l(:label_feeds_access_key) %></h4>
11 11

  
12 12
<p>
13
<% if @user.rss_token %>
14
<%= l(:label_feeds_access_key_created_on, distance_of_time_in_words(Time.now, @user.rss_token.created_on)) %>
13
<% if @user.atom_token %>
14
<%= l(:label_feeds_access_key_created_on, distance_of_time_in_words(Time.now, @user.atom_token.created_on)) %>
15 15
<% else %>
16 16
<%= l(:label_missing_feeds_access_key) %>
17 17
<% end %>
18
(<%= link_to l(:button_reset), {:action => 'reset_rss_key'}, :method => :post %>)
18
(<%= link_to l(:button_reset), {:action => 'reset_atom_key'}, :method => :post %>)
19 19
</p>
20 20

  
21 21
<% if Setting.rest_api_enabled? %>
app/views/my/blocks/_issuesassignedtome.html.erb
13 13
<% content_for :header_tags do %>
14 14
<%= auto_discovery_link_tag(:atom,
15 15
                            {:controller => 'issues', :action => 'index', :set_filter => 1,
16
                             :assigned_to_id => 'me', :format => 'atom', :key => User.current.rss_key},
16
                             :assigned_to_id => 'me', :format => 'atom', :key => User.current.atom_key},
17 17
                            {:title => l(:label_assigned_to_me_issues)}) %>
18 18
<% end %>
app/views/my/blocks/_issuesreportedbyme.html.erb
14 14
<% content_for :header_tags do %>
15 15
<%= auto_discovery_link_tag(:atom,
16 16
                            {:controller => 'issues', :action => 'index', :set_filter => 1,
17
                             :author_id => 'me', :format => 'atom', :key => User.current.rss_key},
17
                             :author_id => 'me', :format => 'atom', :key => User.current.atom_key},
18 18
                            {:title => l(:label_reported_issues)}) %>
19 19
<% end %>
app/views/news/index.html.erb
35 35
<p class="pagination"><%= pagination_links_full @news_pages %></p>
36 36

  
37 37
<% other_formats_links do |f| %>
38
  <%= f.link_to 'Atom', :url => {:project_id => @project, :key => User.current.rss_key} %>
38
  <%= f.link_to 'Atom', :url => {:project_id => @project, :key => User.current.atom_key} %>
39 39
<% end %>
40 40

  
41 41
<% content_for :header_tags do %>
42
  <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
42
  <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.atom_key})) %>
43 43
  <%= stylesheet_link_tag 'scm' %>
44 44
<% end %>
45 45

  
app/views/projects/index.html.erb
1 1
<% content_for :header_tags do %>
2
    <%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %>
2
    <%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.atom_key}) %>
3 3
<% end %>
4 4

  
5 5
<div class="contextual">
......
24 24
<% end %>
25 25

  
26 26
<% other_formats_links do |f| %>
27
  <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
27
  <%= f.link_to 'Atom', :url => {:key => User.current.atom_key} %>
28 28
<% end %>
29 29

  
30 30
<% content_for :sidebar do %>
app/views/projects/show.html.erb
91 91
<% end %>
92 92

  
93 93
<% content_for :header_tags do %>
94
<%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :id => @project, :format => 'atom', :key => User.current.rss_key}) %>
94
<%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :id => @project, :format => 'atom', :key => User.current.atom_key}) %>
95 95
<% end %>
96 96

  
97 97
<% html_title(l(:label_overview)) -%>
app/views/repositories/revisions.html.erb
24 24
  <%= auto_discovery_link_tag(
25 25
               :atom,
26 26
               params.merge(
27
                 {:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
27
                 {:format => 'atom', :page => nil, :key => User.current.atom_key})) %>
28 28
<% end %>
29 29

  
30 30
<% other_formats_links do |f| %>
31
  <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
31
  <%= f.link_to 'Atom', :url => {:key => User.current.atom_key} %>
32 32
<% end %>
33 33

  
34 34
<% html_title(l(:label_revision_plural)) -%>
app/views/repositories/show.html.erb
44 44
      <%= auto_discovery_link_tag(
45 45
                   :atom, params.merge(
46 46
                      {:format => 'atom', :action => 'revisions',
47
                       :id => @project, :page => nil, :key => User.current.rss_key})) %>
47
                       :id => @project, :page => nil, :key => User.current.atom_key})) %>
48 48
   <% end %>
49 49

  
50 50
   <% other_formats_links do |f| %>
51 51
    <%= f.link_to 'Atom',
52 52
                  :url => {:action => 'revisions', :id => @project,
53 53
                           :repository_id => @repository.identifier_param,
54
                           :key => User.current.rss_key} %>
54
                           :key => User.current.atom_key} %>
55 55
    <% end %>
56 56
  <% end %>
57 57
<% end %>
app/views/timelog/index.html.erb
21 21
<p class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></p>
22 22

  
23 23
<% other_formats_links do |f| %>
24
  <%= f.link_to 'Atom', :url => params.merge({:issue_id => @issue, :key => User.current.rss_key}) %>
24
  <%= f.link_to 'Atom', :url => params.merge({:issue_id => @issue, :key => User.current.atom_key}) %>
25 25
  <%= f.link_to 'CSV', :url => params, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
26 26
<% end %>
27 27

  
......
43 43
<% html_title l(:label_spent_time), l(:label_details) %>
44 44

  
45 45
<% content_for :header_tags do %>
46
    <%= auto_discovery_link_tag(:atom, {:issue_id => @issue, :format => 'atom', :key => User.current.rss_key}, :title => l(:label_spent_time)) %>
46
    <%= auto_discovery_link_tag(:atom, {:issue_id => @issue, :format => 'atom', :key => User.current.atom_key}, :title => l(:label_spent_time)) %>
47 47
<% end %>
app/views/users/show.html.erb
59 59
</div>
60 60

  
61 61
<% other_formats_links do |f| %>
62
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => nil, :user_id => @user, :key => User.current.rss_key} %>
62
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => nil, :user_id => @user, :key => User.current.atom_key} %>
63 63
<% end %>
64 64

  
65 65
<% content_for :header_tags do %>
66
  <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :user_id => @user, :format => :atom, :key => User.current.rss_key) %>
66
  <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :user_id => @user, :format => :atom, :key => User.current.atom_key) %>
67 67
<% end %>
68 68
<% end %>
69 69
<%= call_hook :view_account_right_bottom, :user => @user %>
app/views/welcome/index.html.erb
32 32
</div>
33 33

  
34 34
<% content_for :header_tags do %>
35
<%= auto_discovery_link_tag(:atom, {:controller => 'news', :action => 'index', :key => User.current.rss_key, :format => 'atom'},
35
<%= auto_discovery_link_tag(:atom, {:controller => 'news', :action => 'index', :key => User.current.atom_key, :format => 'atom'},
36 36
                                   :title => "#{Setting.app_title}: #{l(:label_news_latest)}") %>
37
<%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :key => User.current.rss_key, :format => 'atom'},
37
<%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :key => User.current.atom_key, :format => 'atom'},
38 38
                                   :title => "#{Setting.app_title}: #{l(:label_activity)}") %>
39 39
<% end %>
app/views/wiki/date_index.html.erb
23 23

  
24 24
<% unless @pages.empty? %>
25 25
<% other_formats_links do |f| %>
26
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
26
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.atom_key} %>
27 27
  <% if User.current.allowed_to?(:export_wiki_pages, @project) %>
28 28
  <%= f.link_to('PDF', :url => {:action => 'export', :format => 'pdf'}) %>
29 29
  <%= f.link_to('HTML', :url => {:action => 'export'}) %>
......
32 32
<% end %>
33 33

  
34 34
<% content_for :header_tags do %>
35
<%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
35
<%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.atom_key) %>
36 36
<% end %>
app/views/wiki/index.html.erb
19 19
  <%= f.link_to 'Atom',
20 20
                :url => {:controller => 'activities', :action => 'index',
21 21
                         :id => @project, :show_wiki_edits => 1,
22
                         :key => User.current.rss_key} %>
22
                         :key => User.current.atom_key} %>
23 23
  <% if User.current.allowed_to?(:export_wiki_pages, @project) %>
24 24
  <%= f.link_to('PDF', :url => {:action => 'export', :format => 'pdf'}) %>
25 25
  <%= f.link_to('HTML', :url => {:action => 'export'}) %>
......
31 31
<%= auto_discovery_link_tag(
32 32
      :atom, :controller => 'activities', :action => 'index',
33 33
      :id => @project, :show_wiki_edits => 1, :format => 'atom',
34
      :key => User.current.rss_key) %>
34
      :key => User.current.atom_key) %>
35 35
<% end %>
config/routes.rb
64 64
  match 'my/account/destroy', :controller => 'my', :action => 'destroy', :via => [:get, :post]
65 65
  match 'my/page', :controller => 'my', :action => 'page', :via => :get
66 66
  match 'my', :controller => 'my', :action => 'index', :via => :get # Redirects to my/page
67
  match 'my/reset_rss_key', :controller => 'my', :action => 'reset_rss_key', :via => :post
67
  match 'my/reset_atom_key', :controller => 'my', :action => 'reset_atom_key', :via => :post
68 68
  match 'my/reset_api_key', :controller => 'my', :action => 'reset_api_key', :via => :post
69 69
  match 'my/password', :controller => 'my', :action => 'password', :via => [:get, :post]
70 70
  match 'my/page_layout', :controller => 'my', :action => 'page_layout', :via => :get
test/functional/my_controller_test.rb
208 208
    assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
209 209
  end
210 210

  
211
  def test_reset_rss_key_with_existing_key
212
    @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
213
    post :reset_rss_key
211
  def test_reset_atom_key_with_existing_key
212
    @previous_token_value = User.find(2).atom_key # Will generate one if it's missing
213
    post :reset_atom_key
214 214

  
215
    assert_not_equal @previous_token_value, User.find(2).rss_key
216
    assert User.find(2).rss_token
215
    assert_not_equal @previous_token_value, User.find(2).atom_key
216
    assert User.find(2).atom_token
217 217
    assert_match /reset/, flash[:notice]
218 218
    assert_redirected_to '/my/account'
219 219
  end
220 220

  
221
  def test_reset_rss_key_without_existing_key
222
    assert_nil User.find(2).rss_token
223
    post :reset_rss_key
221
  def test_reset_atom_key_without_existing_key
222
    assert_nil User.find(2).atom_token
223
    post :reset_atom_key
224 224

  
225
    assert User.find(2).rss_token
225
    assert User.find(2).atom_token
226 226
    assert_match /reset/, flash[:notice]
227 227
    assert_redirected_to '/my/account'
228 228
  end
test/integration/application_test.rb
54 54
    get 'issues/4.atom'
55 55
    assert_response 302
56 56

  
57
    rss_key = User.find(2).rss_key
58
    get "issues/4.atom?key=#{rss_key}"
57
    atom_key = User.find(2).atom_key
58
    get "issues/4.atom?key=#{atom_key}"
59 59
    assert_response 200
60 60
    assert_nil session[:user_id]
61 61
  end
test/integration/routing/my_test.rb
40 40
        { :controller => 'my', :action => 'index' }
41 41
      )
42 42
    assert_routing(
43
        { :method => 'post', :path => "/my/reset_rss_key" },
44
        { :controller => 'my', :action => 'reset_rss_key' }
43
        { :method => 'post', :path => "/my/reset_atom_key" },
44
        { :controller => 'my', :action => 'reset_atom_key' }
45 45
      )
46 46
    assert_routing(
47 47
        { :method => 'post', :path => "/my/reset_api_key" },
test/unit/user_test.rb
659 659
    assert_equal 1, anon2.errors.count
660 660
  end
661 661

  
662
  def test_rss_key
663
    assert_nil @jsmith.rss_token
664
    key = @jsmith.rss_key
662
  def test_atom_key
663
    assert_nil @jsmith.atom_token
664
    key = @jsmith.atom_key
665 665
    assert_equal 40, key.length
666 666

  
667 667
    @jsmith.reload
668
    assert_equal key, @jsmith.rss_key
668
    assert_equal key, @jsmith.atom_key
669 669
  end
670 670

  
671
  def test_rss_key_should_not_be_generated_twice
671
  def test_atom_key_should_not_be_generated_twice
672 672
    assert_difference 'Token.count', 1 do
673
      key1 = @jsmith.rss_key
674
      key2 = @jsmith.rss_key
673
      key1 = @jsmith.atom_key
674
      key2 = @jsmith.atom_key
675 675
      assert_equal key1, key2
676 676
    end
677 677
  end