summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-11-07 14:15:01 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-11-07 14:15:01 +0000
commit475530e59f65f3e8d24623383512e092b2d02521 (patch)
tree76e9b403b548ee62b3f5b05fcf9a0c7554add13d
parent3b01ea9fa42cec01a17664a64de6f8157d363bec (diff)
downloadredmine-475530e59f65f3e8d24623383512e092b2d02521.tar.gz
redmine-475530e59f65f3e8d24623383512e092b2d02521.zip
Adds a "visible" option on User and Project custom fields (#1738).
If set to false, the custom field won't be display on user profile/project overview. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4382 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/users_controller.rb1
-rw-r--r--app/models/custom_value.rb4
-rw-r--r--app/views/custom_fields/_form.rhtml2
-rw-r--r--app/views/projects/index.xml.builder2
-rw-r--r--app/views/projects/show.rhtml2
-rw-r--r--app/views/projects/show.xml.builder2
-rw-r--r--app/views/users/show.rhtml2
-rw-r--r--config/locales/en.yml1
-rw-r--r--config/locales/fr.yml2
-rw-r--r--db/migrate/20101107130441_add_custom_fields_visible.rb9
-rw-r--r--test/fixtures/custom_values.yml2
-rw-r--r--test/functional/projects_controller_test.rb12
-rw-r--r--test/functional/users_controller_test.rb15
-rw-r--r--test/integration/api_test/projects_test.rb9
-rw-r--r--vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb4
15 files changed, 62 insertions, 7 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 66979d5e2..bf38f87fd 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -51,7 +51,6 @@ class UsersController < ApplicationController
def show
@user = User.find(params[:id])
- @custom_values = @user.custom_values
# show projects based on current user visibility
@memberships = @user.memberships.all(:conditions => Project.visible_by(User.current))
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 39ba59994..97bd47f94 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -34,6 +34,10 @@ class CustomValue < ActiveRecord::Base
custom_field.editable?
end
+ def visible?
+ custom_field.visible?
+ end
+
def required?
custom_field.is_required?
end
diff --git a/app/views/custom_fields/_form.rhtml b/app/views/custom_fields/_form.rhtml
index 9871567f7..a71df87aa 100644
--- a/app/views/custom_fields/_form.rhtml
+++ b/app/views/custom_fields/_form.rhtml
@@ -86,10 +86,12 @@ when "IssueCustomField" %>
<% when "UserCustomField" %>
<p><%= f.check_box :is_required %></p>
+ <p><%= f.check_box :visible %></p>
<p><%= f.check_box :editable %></p>
<% when "ProjectCustomField" %>
<p><%= f.check_box :is_required %></p>
+ <p><%= f.check_box :visible %></p>
<p><%= f.check_box :searchable %></p>
<% when "TimeEntryCustomField" %>
diff --git a/app/views/projects/index.xml.builder b/app/views/projects/index.xml.builder
index d5200f620..6ea2a3aa7 100644
--- a/app/views/projects/index.xml.builder
+++ b/app/views/projects/index.xml.builder
@@ -8,7 +8,7 @@ xml.projects :type => 'array' do
xml.description project.description
xml.parent(:id => project.parent_id, :name => project.parent.name) unless project.parent.nil?
xml.custom_fields do
- project.custom_field_values.each do |custom_value|
+ project.visible_custom_field_values.each do |custom_value|
xml.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
end
end unless project.custom_field_values.empty?
diff --git a/app/views/projects/show.rhtml b/app/views/projects/show.rhtml
index 9651651ac..414358aca 100644
--- a/app/views/projects/show.rhtml
+++ b/app/views/projects/show.rhtml
@@ -16,7 +16,7 @@
<li><%=l(:label_subproject_plural)%>:
<%= @subprojects.collect{|p| link_to(h(p), :action => 'show', :id => p)}.join(", ") %></li>
<% end %>
- <% @project.custom_values.each do |custom_value| %>
+ <% @project.visible_custom_field_values.each do |custom_value| %>
<% if !custom_value.value.blank? %>
<li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
<% end %>
diff --git a/app/views/projects/show.xml.builder b/app/views/projects/show.xml.builder
index f49d7ee10..d99db8b56 100644
--- a/app/views/projects/show.xml.builder
+++ b/app/views/projects/show.xml.builder
@@ -7,7 +7,7 @@ xml.project do
xml.homepage @project.homepage
xml.custom_fields do
- @project.custom_field_values.each do |custom_value|
+ @project.visible_custom_field_values.each do |custom_value|
xml.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
end
end unless @project.custom_field_values.empty?
diff --git a/app/views/users/show.rhtml b/app/views/users/show.rhtml
index afab71110..c100e6ebd 100644
--- a/app/views/users/show.rhtml
+++ b/app/views/users/show.rhtml
@@ -9,7 +9,7 @@
<% unless @user.pref.hide_mail %>
<li><%=l(:field_mail)%>: <%= mail_to(h(@user.mail), nil, :encode => 'javascript') %></li>
<% end %>
- <% for custom_value in @custom_values %>
+ <% @user.visible_custom_field_values.each do |custom_value| %>
<% if !custom_value.value.blank? %>
<li><%=h custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 3b4b80258..78654b1fb 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -297,6 +297,7 @@ en:
field_member_of_group: "Assignee's group"
field_assigned_to_role: "Assignee's role"
field_text: Text field
+ field_visible: Visible
setting_app_title: Application title
setting_app_subtitle: Application subtitle
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index 44e048722..350c38dbd 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -303,6 +303,7 @@ fr:
field_sharing: Partage
field_active: Actif
field_parent_issue: Tâche parente
+ field_visible: Visible
setting_app_title: Titre de l'application
setting_app_subtitle: Sous-titre de l'application
@@ -943,3 +944,4 @@ fr:
field_member_of_group: Groupe de l'assigné
field_assigned_to_role: Rôle de l'assigné
field_start_date: Start date
+ setting_emails_header: Emails header
diff --git a/db/migrate/20101107130441_add_custom_fields_visible.rb b/db/migrate/20101107130441_add_custom_fields_visible.rb
new file mode 100644
index 000000000..25ef44662
--- /dev/null
+++ b/db/migrate/20101107130441_add_custom_fields_visible.rb
@@ -0,0 +1,9 @@
+class AddCustomFieldsVisible < ActiveRecord::Migration
+ def self.up
+ add_column :custom_fields, :visible, :boolean, :null => false, :default => true
+ end
+
+ def self.down
+ remove_column :custom_fields, :visible
+ end
+end
diff --git a/test/fixtures/custom_values.yml b/test/fixtures/custom_values.yml
index 76ce067a7..58288b39f 100644
--- a/test/fixtures/custom_values.yml
+++ b/test/fixtures/custom_values.yml
@@ -28,7 +28,7 @@ custom_values_003:
custom_field_id: 4
customized_id: 2
id: 3
- value: ""
+ value: "01 42 50 00 00"
custom_values_004:
customized_type: Issue
custom_field_id: 2
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
index 7122f89e2..59d6286a1 100644
--- a/test/functional/projects_controller_test.rb
+++ b/test/functional/projects_controller_test.rb
@@ -284,6 +284,18 @@ class ProjectsControllerTest < ActionController::TestCase
assert_template 'show'
assert_not_nil assigns(:project)
assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
+
+ assert_tag 'li', :content => /Development status/
+ end
+
+ def test_show_should_not_display_hidden_custom_fields
+ ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
+ get :show, :id => 'ecookbook'
+ assert_response :success
+ assert_template 'show'
+ assert_not_nil assigns(:project)
+
+ assert_no_tag 'li', :content => /Development status/
end
def test_show_should_not_fail_when_custom_values_are_nil
diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb
index 5e288d445..100ec8ded 100644
--- a/test/functional/users_controller_test.rb
+++ b/test/functional/users_controller_test.rb
@@ -24,7 +24,7 @@ class UsersController; def rescue_action(e) raise e end; end
class UsersControllerTest < ActionController::TestCase
include Redmine::I18n
- fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources
+ fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values
def setup
@controller = UsersController.new
@@ -65,6 +65,19 @@ class UsersControllerTest < ActionController::TestCase
assert_response :success
assert_template 'show'
assert_not_nil assigns(:user)
+
+ assert_tag 'li', :content => /Phone number/
+ end
+
+ def test_show_should_not_display_hidden_custom_fields
+ @request.session[:user_id] = nil
+ UserCustomField.find_by_name('Phone number').update_attribute :visible, false
+ get :show, :id => 2
+ assert_response :success
+ assert_template 'show'
+ assert_not_nil assigns(:user)
+
+ assert_no_tag 'li', :content => /Phone number/
end
def test_show_should_not_fail_when_custom_values_are_nil
diff --git a/test/integration/api_test/projects_test.rb b/test/integration/api_test/projects_test.rb
index 7c090a925..de84daa08 100644
--- a/test/integration/api_test/projects_test.rb
+++ b/test/integration/api_test/projects_test.rb
@@ -36,6 +36,15 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest
get '/projects/1.xml'
assert_response :success
assert_equal 'application/xml', @response.content_type
+ assert_tag 'custom_field', :attributes => {:name => 'Development status'}, :content => 'Stable'
+ end
+
+ def test_show_should_not_display_hidden_custom_fields
+ ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
+ get '/projects/1.xml'
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_no_tag 'custom_field', :attributes => {:name => 'Development status'}
end
def test_create
diff --git a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index 01a61bf48..03b36f698 100644
--- a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -62,6 +62,10 @@ module Redmine
@custom_field_values ||= available_custom_fields.collect { |x| custom_values.detect { |v| v.custom_field == x } || custom_values.build(:custom_field => x, :value => nil) }
end
+ def visible_custom_field_values
+ custom_field_values.select(&:visible?)
+ end
+
def custom_field_values_changed?
@custom_field_values_changed == true
end