changeset 1035:4ac34b54f946 cannam

Merge
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 13 Nov 2012 14:00:16 +0000
parents 13a8e4ac88d5 (current diff) ea5d9652c6f6 (diff)
children 8526d7436527
files
diffstat 3 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/projects_controller.rb	Tue Nov 13 12:10:20 2012 +0000
+++ b/app/controllers/projects_controller.rb	Tue Nov 13 14:00:16 2012 +0000
@@ -111,8 +111,7 @@
     end
     # end of code to be removed
 
-
-    if validate_parent_id && @project.save
+    if validate_is_public_key && validate_parent_id && @project.save
       @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
       # Add current user as a project member if he is not admin
       unless User.current.admin?
@@ -300,6 +299,19 @@
     render_404
   end
 
+  def validate_is_public_key
+    # Although is_public isn't mandatory in the project model (it gets
+    # defaulted), it must be present in params -- it can be true or
+    # false, but it must be there. This permits us to make forms in
+    # which the user _has_ to select public or private (rather than
+    # defaulting it) if we want to
+    if params.nil? || params[:project].nil? || !params[:project].has_key?(:is_public)
+      @project.errors.add :is_public, :public_or_private
+      return false
+    end
+    true
+  end
+
   # Validates parent_id param according to user's permissions
   # TODO: move it to Project model in a validation that depends on User.current
   def validate_parent_id
--- a/app/views/projects/_form.html.erb	Tue Nov 13 12:10:20 2012 +0000
+++ b/app/views/projects/_form.html.erb	Tue Nov 13 14:00:16 2012 +0000
@@ -21,9 +21,20 @@
 <br />
   <em> <%= l(:text_project_homepage_info) %></em>
 </p>
-<p><%= f.check_box :is_public %>
+<p>
+<%= label(:project, :is_public_1, l(:field_public_or_private) + content_tag("span", " *", :class => "required")) %>
+<%
+   # if the project hasn't been created fully yet, then we don't
+   # want to set either public or private (make the user decide)
+   initialised = !@project.id.nil?
+%>
+  <%= f.radio_button :is_public, 1, :checked => (initialised && @project.is_public?) %>
+  <%= l(:text_project_public_info) %>
 <br />
-  <em> <%= l(:text_project_visibility_info) %></em>
+  <%= f.radio_button :is_public, 0, :checked => (initialised && !@project.is_public?) %> 
+  <%= l(:text_project_private_info) %>
+<br>
+  <em><%= l(:text_project_visibility_info) %></em>
 </p>
 <%= wikitoolbar_for 'project_description' %>
 
--- a/config/locales/en.yml	Tue Nov 13 12:10:20 2012 +0000
+++ b/config/locales/en.yml	Tue Nov 13 14:00:16 2012 +0000
@@ -130,6 +130,7 @@
         circular_dependency: "This relation would create a circular dependency"
         cant_link_an_issue_with_a_descendant: "An issue cannot be linked to one of its subtasks"
         must_accept_terms_and_conditions: "You must accept the Terms and Conditions"        
+        public_or_private: "You must select either public or private"
 
   actionview_instancetag_blank_option: Please select
 
@@ -328,6 +329,7 @@
   field_root_directory: Root directory
   field_cvsroot: CVSROOT
   field_cvs_module: Module
+  field_public_or_private: "Public or Private?"
 
   setting_external_repository: "Select this if the project's main repository is hosted somewhere else"
   setting_external_repository_url: "The URL of the existing external repository. Must be publicly accessible without a password"
@@ -966,7 +968,9 @@
   text_caracters_minimum: "Must be at least %{count} characters long."
   text_length_between: "Length between %{min} and %{max} characters."
   text_project_name_info: "This will be the name of your project as it appears throughout this site.<br /> You can change it at any time, in the project's settings."
-  text_project_visibility_info: "If your project is not public, it will be visible only to you and to users that you have added as project members.<br/>You can change this later if you wish."
+  text_project_public_info: "Public: visible to anybody browsing the site."
+  text_project_private_info: "Private: visible only to you, and to users you have added as project members."
+  text_project_visibility_info: "You can change whether your project is public or private later if you wish."
   text_user_ssamr_description_info: 'Please describe your current research or development interests.<br/>This information will be used at registration to determine that you are a real person &ndash; so please be descriptive, or your application may be delayed or rejected.<br/>After registration, the description is publicly visible in your profile and you can edit it at any time.'
   text_issue_parent_issue_info: 'If this is a subtask, please insert its parent task number or write the main task name.'