Project

General

Profile

Feature #664 » feature-664.patch

Mizuki ISHIKAWA, 2022-02-08 05:54

View differences:

app/controllers/account_controller.rb
19 19

  
20 20
class AccountController < ApplicationController
21 21
  helper :custom_fields
22
  helper :account
22 23
  include CustomFieldsHelper
24
  include AccountHelper
23 25

  
24 26
  self.main_menu = false
25 27

  
......
33 35
      authenticate_user
34 36
    else
35 37
      if User.current.logged?
36
        redirect_back_or_default home_url, :referer => true
38
        redirect_back_or_default start_page_url, :referer => true
37 39
      end
38 40
    end
39 41
  rescue AuthSourceException => e
app/helpers/account_helper.rb
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
module AccountHelper
21
  def start_page_url
22
    start_page_candidates = {
23
      'home' => home_path,
24
      'my_page' => my_page_path,
25
      'projects' => projects_path
26
    }
27
    start_page_candidates[Setting.start_page] || home_path
28
  end
21 29
end
app/helpers/application_helper.rb
1539 1539
    hidden_field_tag('back_url', url, :id => nil) unless url.blank?
1540 1540
  end
1541 1541

  
1542
  def back_url_after_login_hidden_field_tag
1543
    url = validate_back_url(back_url)
1544
    url = validate_back_url(start_page_url) if url == validate_back_url(home_url)
1545

  
1546
    hidden_field_tag('back_url', url, :id => nil) unless url.blank?
1547
  end
1548

  
1542 1549
  def cancel_button_tag(fallback_url)
1543 1550
    url = validate_back_url(back_url) || fallback_url
1544 1551
    link_to l(:button_cancel), url
app/views/account/login.html.erb
2 2

  
3 3
<div id="login-form">
4 4
  <%= form_tag(signin_path, onsubmit: 'return keepAnchorOnSignIn(this);') do %>
5
  <%= back_url_hidden_field_tag %>
6
  
5
  <%= back_url_after_login_hidden_field_tag %>
6

  
7 7
  <label for="username"><%=l(:field_login)%></label>
8 8
  <%= text_field_tag 'username', params[:username], :tabindex => '1' %>
9 9
  
app/views/settings/_general.html.erb
6 6
<p><%= setting_text_area :welcome_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %></p>
7 7
<%= wikitoolbar_for 'settings_welcome_text' %>
8 8

  
9
<p><%= setting_select :start_page, [[l(:label_home), 'home'], [l(:label_my_page), 'my_page'], [l(:label_project_plural), 'projects']] %></p>
9 10

  
10 11
<p><%= setting_text_field :per_page_options, :size => 20 %>
11 12
<em class="info"><%= l(:text_comma_separated) %></em></p>
config/locales/en.yml
413 413

  
414 414
  setting_app_title: Application title
415 415
  setting_welcome_text: Welcome text
416
  setting_start_page: Start page
416 417
  setting_default_language: Default language
417 418
  setting_login_required: Authentication required
418 419
  setting_self_registration: Self-registration
config/settings.yml
23 23
  default: Redmine
24 24
welcome_text:
25 25
  default:
26
start_page:
27
  default: home
26 28
login_required:
27 29
  default: 0
28 30
  security_notifications: 1
test/functional/account_controller_test.rb
37 37
  def test_get_login_while_logged_in_should_redirect_to_back_url_if_present
38 38
    @request.session[:user_id] = 2
39 39
    @request.env["HTTP_REFERER"] = 'http://test.host/issues/show/1'
40
    get(
41
      :login,
42
      :params => {
43
        :back_url => 'http://test.host/issues/show/1'
44
      }
45
    )
40
    with_settings :start_page => 'projects' do
41
      get(
42
        :login,
43
        :params => {
44
          :back_url => 'http://test.host/issues/show/1'
45
        }
46
      )
47
    end
46 48
    assert_redirected_to '/issues/show/1'
47 49
    assert_equal 2, @request.session[:user_id]
48 50
  end
......
51 53
    @request.session[:user_id] = 2
52 54
    @request.env["HTTP_REFERER"] = 'http://test.host/issues/show/1'
53 55

  
54
    get :login
56
    with_settings :start_page => 'projects' do
57
      get :login
58
    end
55 59
    assert_redirected_to '/issues/show/1'
56 60
    assert_equal 2, @request.session[:user_id]
57 61
  end
58 62

  
59
  def test_get_login_while_logged_in_should_redirect_to_home_by_default
63
  def test_get_login_while_logged_in_should_redirect_to_start_page_by_default
60 64
    @request.session[:user_id] = 2
65
    start_pages = { 'projects' => '/projects', 'home' => '/', 'my_page' => '/my/page' }
61 66

  
62
    get :login
63
    assert_redirected_to '/'
64
    assert_equal 2, @request.session[:user_id]
67
    start_pages.each do |name, path|
68
      with_settings :start_page => name do
69
        get :login
70
        assert_redirected_to path
71
        assert_equal 2, @request.session[:user_id]
72
      end
73
    end
65 74
  end
66 75

  
67 76
  def test_login_should_redirect_to_back_url_param
......
71 80
      'http://test.host/',
72 81
      '/'
73 82
    ]
74
    back_urls.each do |back_url|
75
      post(
76
        :login,
77
        :params => {
78
          :username => 'jsmith',
79
          :password => 'jsmith',
80
          :back_url => back_url
81
        }
82
      )
83
      assert_redirected_to back_url
83
    with_settings :start_page => 'projects' do
84
      back_urls.each do |back_url|
85
        post(
86
          :login,
87
          :params => {
88
            :username => 'jsmith',
89
            :password => 'jsmith',
90
            :back_url => back_url
91
          }
92
        )
93
        assert_redirected_to back_url
94
      end
84 95
    end
85 96
  end
86 97

  
......
92 103
      'http://test.host/redmine/issues/show/1',
93 104
      '/redmine'
94 105
    ]
95
    back_urls.each do |back_url|
96
      post(
97
        :login,
98
        :params => {
99
          :username => 'jsmith',
100
          :password => 'jsmith',
101
          :back_url => back_url
102
        }
103
      )
104
      assert_redirected_to back_url
106
    with_settings :start_page => 'projects' do
107
      back_urls.each do |back_url|
108
        post(
109
          :login,
110
          :params => {
111
            :username => 'jsmith',
112
            :password => 'jsmith',
113
            :back_url => back_url
114
          }
115
        )
116
        assert_redirected_to back_url
117
      end
105 118
    end
106 119
  ensure
107 120
    Redmine::Utils.relative_url_root = @relative_url_root
......
112 125
      'http://test.foo/fake',
113 126
      '//test.foo/fake'
114 127
    ]
115
    back_urls.each do |back_url|
116
      post(
117
        :login, :params => {
118
          :username => 'jsmith',
119
          :password => 'jsmith',
120
          :back_url => back_url
121
        }
122
      )
123
      assert_redirected_to '/my/page'
128
    with_settings :start_page => 'projects' do
129
      back_urls.each do |back_url|
130
        post(
131
          :login, :params => {
132
            :username => 'jsmith',
133
            :password => 'jsmith',
134
            :back_url => back_url
135
          }
136
        )
137
        assert_redirected_to '/my/page'
138
      end
124 139
    end
125 140
  end
126 141

  
......
144 159
      'fake@test.foo',
145 160
      '.test.foo'
146 161
    ]
147
    back_urls.each do |back_url|
148
      post(
149
        :login,
150
        :params => {
151
          :username => 'jsmith',
152
          :password => 'jsmith',
153
          :back_url => back_url
154
        }
155
      )
156
      assert_redirected_to '/my/page'
162
    with_settings :start_page => 'projects' do
163
      back_urls.each do |back_url|
164
        post(
165
          :login,
166
          :params => {
167
            :username => 'jsmith',
168
            :password => 'jsmith',
169
            :back_url => back_url
170
          }
171
        )
172
        assert_redirected_to '/my/page'
173
      end
157 174
    end
158 175
  ensure
159 176
    Redmine::Utils.relative_url_root = @relative_url_root
(1-1/2)