Feature #1233 » adds_default_page.patch
| app/controllers/account_controller.rb | ||
|---|---|---|
|
set_autologin_cookie(user)
|
||
|
end
|
||
|
call_hook(:controller_account_success_authentication_after, {:user => user })
|
||
|
redirect_back_or_default :controller => 'my', :action => 'page'
|
||
|
if user.default_page == "top"
|
||
|
redirect_back_or_default :controller => 'welcome'
|
||
|
elsif user.default_page == "my_page"
|
||
|
redirect_back_or_default :controller => 'my', :action => 'page'
|
||
|
elsif user.default_page == "my_project"
|
||
|
redirect_back_or_default :controller => 'projects', :action => 'show', :id => user.default_project_id
|
||
|
else
|
||
|
redirect_back_or_default :controller => 'my', :action => 'page'
|
||
|
end
|
||
|
end
|
||
|
def set_autologin_cookie(user)
|
||
| app/controllers/application_controller.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def back_url
|
||
|
params[:back_url] || request.env['HTTP_REFERER']
|
||
|
end
|
||
|
def redirect_back_or_default(default)
|
||
|
back_url = CGI.unescape(params[:back_url].to_s)
|
||
|
if !back_url.blank?
|
||
| app/helpers/application_helper.rb | ||
|---|---|---|
|
end
|
||
|
def back_url_hidden_field_tag
|
||
|
back_url = params[:back_url] || request.env['HTTP_REFERER']
|
||
|
back_url = params[:back_url]
|
||
|
back_url = CGI.unescape(back_url.to_s)
|
||
|
hidden_field_tag('back_url', CGI.escape(back_url), :id => nil) unless back_url.blank?
|
||
|
end
|
||
| app/helpers/users_helper.rb | ||
|---|---|---|
|
user.valid_notification_options.collect {|o| [l(o.last), o.first]}
|
||
|
end
|
||
|
def user_default_page_options(user)
|
||
|
user.valid_default_page_options.collect {|o| [l(o.last), o.first]}
|
||
|
end
|
||
|
def change_status_link(user)
|
||
|
url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
|
||
| app/models/user.rb | ||
|---|---|---|
|
['none', :label_user_mail_option_none]
|
||
|
]
|
||
|
DEFAULT_PAGE_OPTIONS = [
|
||
|
['top', :label_user_default_page_option_top],
|
||
|
['my_page', :label_user_default_page_option_my_page],
|
||
|
['my_project', :label_user_default_page_option_my_project]
|
||
|
]
|
||
|
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
|
||
|
:after_remove => Proc.new {|user, group| group.user_removed(user)}
|
||
|
has_many :changesets, :dependent => :nullify
|
||
| ... | ... | |
|
validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true
|
||
|
validates_confirmation_of :password, :allow_nil => true
|
||
|
validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
|
||
|
validates_inclusion_of :default_page, :in => DEFAULT_PAGE_OPTIONS.collect(&:first), :allow_blank => true
|
||
|
validate :validate_password_length
|
||
|
before_create :set_mail_notification
|
||
| ... | ... | |
|
self.class.valid_notification_options(self)
|
||
|
end
|
||
|
def valid_default_page_options
|
||
|
self.class.valid_default_page_options(self)
|
||
|
end
|
||
|
# Only users that belong to more than 1 project can select projects for which they are notified
|
||
|
def self.valid_notification_options(user=nil)
|
||
|
# Note that @user.membership.size would fail since AR ignores
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def self.valid_default_page_options(user=nil)
|
||
|
if user.projects.count == 0
|
||
|
DEFAULT_PAGE_OPTIONS.reject {|option| option.first == 'my_project'}
|
||
|
else
|
||
|
DEFAULT_PAGE_OPTIONS
|
||
|
end
|
||
|
end
|
||
|
# Find a user account by matching the exact login and then a case-insensitive
|
||
|
# version. Exact matches will be given priority.
|
||
|
def self.find_by_login(login)
|
||
| ... | ... | |
|
'language',
|
||
|
'custom_field_values',
|
||
|
'custom_fields',
|
||
|
'identity_url'
|
||
|
'identity_url',
|
||
|
'default_page',
|
||
|
'default_project_id'
|
||
|
safe_attributes 'status',
|
||
|
'auth_source_id',
|
||
| app/views/my/account.html.erb | ||
|---|---|---|
|
<%= call_hook(:view_my_account, :user => @user, :form => f) %>
|
||
|
</fieldset>
|
||
|
<fieldset class="box">
|
||
|
<legend><%=l(:label_my_default_page)%></legend>
|
||
|
<%= render :partial => 'users/default_page' %>
|
||
|
</fieldset>
|
||
|
<%= submit_tag l(:button_save) %>
|
||
|
</div>
|
||
| app/views/users/_default_page.erb | ||
|---|---|---|
|
<p>
|
||
|
<%= label_tag "user_default_page", l(:description_user_default_page), :class => "hidden-for-sighted" %>
|
||
|
<%= select_tag 'user[default_page]', options_for_select(user_default_page_options(@user), @user.default_page),
|
||
|
:onchange => 'if (this.value == "my_project") {Element.show("default-projects")} else {Element.hide("default-projects")}' %>
|
||
|
</p>
|
||
|
<% if @user.projects.count > 0 %>
|
||
|
<% content_tag 'div', :id => 'default-projects', :style => (@user.default_page == 'my_project' ? '' : 'display:none;') do %>
|
||
|
<p>
|
||
|
<%= select_tag 'user[default_project_id]', options_for_select(project_tree_options_for_select(@user.projects, :selected => @user.projects.select{|p| p.id == @user.default_project_id})) %>
|
||
|
</p>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
label_my_account: My account
|
||
|
label_my_projects: My projects
|
||
|
label_my_page_block: My page block
|
||
|
label_my_default_page: My default page
|
||
|
label_administration: Administration
|
||
|
label_login: Sign in
|
||
|
label_logout: Sign out
|
||
| ... | ... | |
|
label_theme: Theme
|
||
|
label_default: Default
|
||
|
label_search_titles_only: Search titles only
|
||
|
label_user_default_page_option_top: "Top"
|
||
|
label_user_default_page_option_my_page: "My page"
|
||
|
label_user_default_page_option_my_project: "My project"
|
||
|
label_user_mail_option_all: "For any event on all my projects"
|
||
|
label_user_mail_option_selected: "For any event on the selected projects only..."
|
||
|
label_user_mail_option_none: "No events"
|
||
| ... | ... | |
|
description_query_sort_criteria_attribute: Sort attribute
|
||
|
description_query_sort_criteria_direction: Sort direction
|
||
|
description_user_mail_notification: Mail notification settings
|
||
|
description_user_default_page: Default page settings
|
||
|
description_available_columns: Available Columns
|
||
|
description_selected_columns: Selected Columns
|
||
|
description_all_columns: All Columns
|
||
| config/locales/ja.yml | ||
|---|---|---|
|
label_my_account: 個人設定
|
||
|
label_my_projects: マイプロジェクト
|
||
|
label_my_page_block: マイページパーツ
|
||
|
label_my_default_page: ログイン後のページ
|
||
|
label_administration: 管理
|
||
|
label_login: ログイン
|
||
|
label_logout: ログアウト
|
||
| ... | ... | |
|
label_theme: テーマ
|
||
|
label_default: 既定
|
||
|
label_search_titles_only: タイトルのみ
|
||
|
label_user_default_page_option_top: "トップページ"
|
||
|
label_user_default_page_option_my_page: "マイページ"
|
||
|
label_user_default_page_option_my_project: "参加しているプロジェクト"
|
||
|
label_user_mail_option_all: "参加しているプロジェクトのすべての通知"
|
||
|
label_user_mail_option_selected: "選択したプロジェクトのすべての通知..."
|
||
|
label_user_mail_option_none: "通知しない"
|
||
| ... | ... | |
|
description_project_scope: 検索範囲
|
||
|
description_filter: Filter
|
||
|
description_user_mail_notification: メール通知の設定
|
||
|
description_user_default_page: ログイン後のページの設定
|
||
|
description_date_from: 開始日
|
||
|
description_message_content: 内容
|
||
|
description_available_columns: 利用できる項目
|
||
| db/migrate/20120509070818_add_users_default_page.rb | ||
|---|---|---|
|
class AddUsersDefaultPage < ActiveRecord::Migration
|
||
|
def self.up
|
||
|
add_column :users, :default_page, :string, :default => "top"
|
||
|
add_column :users, :default_project_id, :integer, :default => 0
|
||
|
end
|
||
|
def self.down
|
||
|
remove_column :users, :default_page
|
||
|
remove_column :users, :default_project_id
|
||
|
end
|
||
|
end
|
||