User custom fields can now be set as editable so that users can edit them on 'My account'.
For existing user custom fields, this new attribute is set to false by default to preserve the prior behaviour (it can turned on by editing the custom field in admin area). Note: on the registration form, *required* custom fields will be displayed even if they are not defined as editable so that the account can be created. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2276 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
99c2e98975
commit
12792d8068
|
@ -19,6 +19,7 @@ class MyController < ApplicationController
|
|||
before_filter :require_login
|
||||
|
||||
helper :issues
|
||||
helper :custom_fields
|
||||
|
||||
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||||
'issuesreportedbyme' => :label_reported_issues,
|
||||
|
|
|
@ -30,6 +30,14 @@ class CustomValue < ActiveRecord::Base
|
|||
self.value == '1'
|
||||
end
|
||||
|
||||
def editable?
|
||||
custom_field.editable?
|
||||
end
|
||||
|
||||
def required?
|
||||
custom_field.is_required?
|
||||
end
|
||||
|
||||
def to_s
|
||||
value.to_s
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<p><label for="user_language"><%=l(:field_language)%></label>
|
||||
<%= select("user", "language", lang_options_for_select) %></p>
|
||||
|
||||
<% @user.custom_field_values.each do |value| %>
|
||||
<% @user.custom_field_values.select {|v| v.editable? || v.required?}.each do |value| %>
|
||||
<p><%= custom_field_tag_with_label :user, value %></p>
|
||||
<% end %>
|
||||
<!--[eoform:user]-->
|
||||
|
|
|
@ -84,6 +84,7 @@ when "IssueCustomField" %>
|
|||
|
||||
<% when "UserCustomField" %>
|
||||
<p><%= f.check_box :is_required %></p>
|
||||
<p><%= f.check_box :editable %></p>
|
||||
|
||||
<% when "ProjectCustomField" %>
|
||||
<p><%= f.check_box :is_required %></p>
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
<p><%= f.text_field :lastname, :required => true %></p>
|
||||
<p><%= f.text_field :mail, :required => true %></p>
|
||||
<p><%= f.select :language, lang_options_for_select %></p>
|
||||
|
||||
<% @user.custom_field_values.select(&:editable?).each do |value| %>
|
||||
<p><%= custom_field_tag_with_label :user, value %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag l(:button_save) %>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class AddCustomFieldsEditable < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :custom_fields, :editable, :boolean, :default => true
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :custom_fields, :editable
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
class SetCustomFieldsEditable < ActiveRecord::Migration
|
||||
def self.up
|
||||
UserCustomField.update_all('editable = false')
|
||||
end
|
||||
|
||||
def self.down
|
||||
UserCustomField.update_all('editable = true')
|
||||
end
|
||||
end
|
|
@ -701,3 +701,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -706,3 +706,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -703,3 +703,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -186,6 +186,7 @@ field_searchable: Searchable
|
|||
field_default_value: Default value
|
||||
field_comments_sorting: Display comments
|
||||
field_parent_title: Parent page
|
||||
field_editable: Editable
|
||||
|
||||
setting_app_title: Application title
|
||||
setting_app_subtitle: Application subtitle
|
||||
|
|
|
@ -686,3 +686,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -701,3 +701,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -186,6 +186,7 @@ field_searchable: Utilisé pour les recherches
|
|||
field_default_value: Valeur par défaut
|
||||
field_comments_sorting: Afficher les commentaires
|
||||
field_parent_title: Page parent
|
||||
field_editable: Modifiable
|
||||
|
||||
setting_app_title: Titre de l'application
|
||||
setting_app_subtitle: Sous-titre de l'application
|
||||
|
|
|
@ -701,3 +701,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -701,3 +701,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -701,3 +701,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -703,3 +703,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -703,3 +703,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -720,3 +720,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -703,3 +703,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -701,3 +701,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -735,3 +735,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -707,3 +707,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -704,3 +704,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -702,3 +702,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -703,3 +703,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -704,3 +704,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -703,3 +703,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -703,3 +703,4 @@ warning_attachments_not_saved: "%d file(s) could not be saved."
|
|||
button_create_and_continue: Create and continue
|
||||
text_custom_field_possible_values_info: 'One line for each value'
|
||||
label_display: Display
|
||||
field_editable: Editable
|
||||
|
|
|
@ -15,6 +15,7 @@ custom_fields_001:
|
|||
is_required: false
|
||||
field_format: list
|
||||
default_value: ""
|
||||
editable: true
|
||||
custom_fields_002:
|
||||
name: Searchable field
|
||||
min_length: 1
|
||||
|
@ -28,6 +29,7 @@ custom_fields_002:
|
|||
field_format: string
|
||||
searchable: true
|
||||
default_value: "Default string"
|
||||
editable: true
|
||||
custom_fields_003:
|
||||
name: Development status
|
||||
min_length: 0
|
||||
|
@ -45,6 +47,7 @@ custom_fields_003:
|
|||
is_required: true
|
||||
field_format: list
|
||||
default_value: ""
|
||||
editable: true
|
||||
custom_fields_004:
|
||||
name: Phone number
|
||||
min_length: 0
|
||||
|
@ -57,6 +60,7 @@ custom_fields_004:
|
|||
is_required: false
|
||||
field_format: string
|
||||
default_value: ""
|
||||
editable: true
|
||||
custom_fields_005:
|
||||
name: Money
|
||||
min_length: 0
|
||||
|
@ -69,6 +73,7 @@ custom_fields_005:
|
|||
is_required: false
|
||||
field_format: float
|
||||
default_value: ""
|
||||
editable: true
|
||||
custom_fields_006:
|
||||
name: Float field
|
||||
min_length: 0
|
||||
|
@ -81,4 +86,5 @@ custom_fields_006:
|
|||
is_required: false
|
||||
field_format: float
|
||||
default_value: ""
|
||||
editable: true
|
||||
|
|
@ -22,7 +22,7 @@ require 'my_controller'
|
|||
class MyController; def rescue_action(e) raise e end; end
|
||||
|
||||
class MyControllerTest < Test::Unit::TestCase
|
||||
fixtures :users, :issues, :issue_statuses, :trackers, :enumerations
|
||||
fixtures :users, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields
|
||||
|
||||
def setup
|
||||
@controller = MyController.new
|
||||
|
@ -43,20 +43,37 @@ class MyControllerTest < Test::Unit::TestCase
|
|||
assert_template 'page'
|
||||
end
|
||||
|
||||
def test_get_account
|
||||
def test_my_account_should_show_editable_custom_fields
|
||||
get :account
|
||||
assert_response :success
|
||||
assert_template 'account'
|
||||
assert_equal User.find(2), assigns(:user)
|
||||
|
||||
assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
|
||||
end
|
||||
|
||||
def test_my_account_should_not_show_non_editable_custom_fields
|
||||
UserCustomField.find(4).update_attribute :editable, false
|
||||
|
||||
get :account
|
||||
assert_response :success
|
||||
assert_template 'account'
|
||||
assert_equal User.find(2), assigns(:user)
|
||||
|
||||
assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
|
||||
end
|
||||
|
||||
def test_update_account
|
||||
post :account, :user => {:firstname => "Joe", :login => "root", :admin => 1}
|
||||
post :account, :user => {:firstname => "Joe",
|
||||
:login => "root",
|
||||
:admin => 1,
|
||||
:custom_field_values => {"4" => "0100562500"}}
|
||||
assert_redirected_to 'my/account'
|
||||
user = User.find(2)
|
||||
assert_equal user, assigns(:user)
|
||||
assert_equal "Joe", user.firstname
|
||||
assert_equal "jsmith", user.login
|
||||
assert_equal "0100562500", user.custom_value_for(4).value
|
||||
assert !user.admin?
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue