Revision 1035:4ac34b54f946 app

View differences:

app/controllers/projects_controller.rb
111 111
    end
112 112
    # end of code to be removed
113 113

  
114

  
115
    if validate_parent_id && @project.save
114
    if validate_is_public_key && validate_parent_id && @project.save
116 115
      @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
117 116
      # Add current user as a project member if he is not admin
118 117
      unless User.current.admin?
......
300 299
    render_404
301 300
  end
302 301

  
302
  def validate_is_public_key
303
    # Although is_public isn't mandatory in the project model (it gets
304
    # defaulted), it must be present in params -- it can be true or
305
    # false, but it must be there. This permits us to make forms in
306
    # which the user _has_ to select public or private (rather than
307
    # defaulting it) if we want to
308
    if params.nil? || params[:project].nil? || !params[:project].has_key?(:is_public)
309
      @project.errors.add :is_public, :public_or_private
310
      return false
311
    end
312
    true
313
  end
314

  
303 315
  # Validates parent_id param according to user's permissions
304 316
  # TODO: move it to Project model in a validation that depends on User.current
305 317
  def validate_parent_id
app/views/projects/_form.html.erb
21 21
<br />
22 22
  <em> <%= l(:text_project_homepage_info) %></em>
23 23
</p>
24
<p><%= f.check_box :is_public %>
24
<p>
25
<%= label(:project, :is_public_1, l(:field_public_or_private) + content_tag("span", " *", :class => "required")) %>
26
<%
27
   # if the project hasn't been created fully yet, then we don't
28
   # want to set either public or private (make the user decide)
29
   initialised = !@project.id.nil?
30
%>
31
  <%= f.radio_button :is_public, 1, :checked => (initialised && @project.is_public?) %>
32
  <%= l(:text_project_public_info) %>
25 33
<br />
26
  <em> <%= l(:text_project_visibility_info) %></em>
34
  <%= f.radio_button :is_public, 0, :checked => (initialised && !@project.is_public?) %> 
35
  <%= l(:text_project_private_info) %>
36
<br>
37
  <em><%= l(:text_project_visibility_info) %></em>
27 38
</p>
28 39
<%= wikitoolbar_for 'project_description' %>
29 40

  

Also available in: Unified diff