diff --git app/controllers/account_controller.rb app/controllers/account_controller.rb index fa53008..5701545 100644 --- app/controllers/account_controller.rb +++ app/controllers/account_controller.rb @@ -201,7 +201,15 @@ class AccountController < ApplicationController 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) diff --git app/controllers/application_controller.rb app/controllers/application_controller.rb index 0cb6aa7..79d30f9 100644 --- app/controllers/application_controller.rb +++ app/controllers/application_controller.rb @@ -259,10 +259,6 @@ class ApplicationController < ActionController::Base 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? diff --git app/helpers/application_helper.rb app/helpers/application_helper.rb index 02b8be6..eef7f4e 100644 --- app/helpers/application_helper.rb +++ app/helpers/application_helper.rb @@ -967,7 +967,7 @@ module ApplicationHelper 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 diff --git app/helpers/users_helper.rb app/helpers/users_helper.rb index a264854..065c5d1 100644 --- app/helpers/users_helper.rb +++ app/helpers/users_helper.rb @@ -39,6 +39,10 @@ module UsersHelper 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} diff --git app/models/user.rb app/models/user.rb index e59c752..3de8be1 100644 --- app/models/user.rb +++ app/models/user.rb @@ -44,6 +44,12 @@ class User < Principal ['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 @@ -78,6 +84,7 @@ class User < Principal 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 @@ -314,6 +321,10 @@ class User < Principal 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 @@ -325,6 +336,14 @@ class User < Principal 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) @@ -500,7 +519,9 @@ class User < Principal 'language', 'custom_field_values', 'custom_fields', - 'identity_url' + 'identity_url', + 'default_page', + 'default_project_id' safe_attributes 'status', 'auth_source_id', diff --git app/views/my/account.html.erb app/views/my/account.html.erb index 47e9459..afb7560 100644 --- app/views/my/account.html.erb +++ app/views/my/account.html.erb @@ -27,6 +27,11 @@ <%= call_hook(:view_my_account, :user => @user, :form => f) %> +
+ <%=l(:label_my_default_page)%> + <%= render :partial => 'users/default_page' %> +
+ <%= submit_tag l(:button_save) %> diff --git app/views/users/_default_page.erb app/views/users/_default_page.erb new file mode 100644 index 0000000..a88366a --- /dev/null +++ app/views/users/_default_page.erb @@ -0,0 +1,12 @@ +

+<%= 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")}' %> +

+<% if @user.projects.count > 0 %> +<% content_tag 'div', :id => 'default-projects', :style => (@user.default_page == 'my_project' ? '' : 'display:none;') do %> +

+<%= 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})) %> +

+<% end %> +<% end %> \ No newline at end of file diff --git config/locales/en.yml config/locales/en.yml index 9536cf9..1b3702c 100644 --- config/locales/en.yml +++ config/locales/en.yml @@ -518,6 +518,7 @@ en: 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 @@ -776,6 +777,9 @@ en: 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" @@ -1018,6 +1022,7 @@ en: 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 diff --git config/locales/ja.yml config/locales/ja.yml index c65cdec..d0caefb 100644 --- config/locales/ja.yml +++ config/locales/ja.yml @@ -526,6 +526,7 @@ ja: label_my_account: 個人設定 label_my_projects: マイプロジェクト label_my_page_block: マイページパーツ + label_my_default_page: ログイン後のページ label_administration: 管理 label_login: ログイン label_logout: ログアウト @@ -777,6 +778,9 @@ ja: 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: "通知しない" @@ -1015,6 +1019,7 @@ ja: description_project_scope: 検索範囲 description_filter: Filter description_user_mail_notification: メール通知の設定 + description_user_default_page: ログイン後のページの設定 description_date_from: 開始日 description_message_content: 内容 description_available_columns: 利用できる項目 diff --git db/migrate/20120509070818_add_users_default_page.rb db/migrate/20120509070818_add_users_default_page.rb new file mode 100644 index 0000000..f973aa6 --- /dev/null +++ db/migrate/20120509070818_add_users_default_page.rb @@ -0,0 +1,11 @@ +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 \ No newline at end of file