Mercurial > hg > soundsoftware-site
diff app/controllers/projects_controller.rb @ 1034:ea5d9652c6f6 bug_370
Fix bug #370: Use radio buttons instead of a checkbox for project public/private selection
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Tue, 13 Nov 2012 14:00:01 +0000 |
parents | f44860e089c5 |
children | bb32da3bea34 91db8e091f10 |
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:01 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