Mercurial > hg > soundsoftware-site
diff app/controllers/projects_controller.rb @ 1040:ff783f2cc500 live
Merge from branch cannam
author | Chris Cannam |
---|---|
date | Tue, 13 Nov 2012 15:08:34 +0000 |
parents | ea5d9652c6f6 |
children | bb32da3bea34 91db8e091f10 |
line wrap: on
line diff
--- a/app/controllers/projects_controller.rb Mon Nov 12 15:17:47 2012 +0000 +++ b/app/controllers/projects_controller.rb Tue Nov 13 15:08:34 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