Mercurial > hg > soundsoftware-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
1033:13a8e4ac88d5 | 1034:ea5d9652c6f6 |
---|---|
109 | 109 |
110 @project.tag_list = ActionController::Base.helpers.strip_tags(new_tags) | 110 @project.tag_list = ActionController::Base.helpers.strip_tags(new_tags) |
111 end | 111 end |
112 # end of code to be removed | 112 # end of code to be removed |
113 | 113 |
114 | 114 if validate_is_public_key && validate_parent_id && @project.save |
115 if validate_parent_id && @project.save | |
116 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 115 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
117 # Add current user as a project member if he is not admin | 116 # Add current user as a project member if he is not admin |
118 unless User.current.admin? | 117 unless User.current.admin? |
119 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first | 118 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first |
120 m = Member.new(:user => User.current, :roles => [r]) | 119 m = Member.new(:user => User.current, :roles => [r]) |
298 authorize | 297 authorize |
299 rescue ActiveRecord::RecordNotFound | 298 rescue ActiveRecord::RecordNotFound |
300 render_404 | 299 render_404 |
301 end | 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 # Validates parent_id param according to user's permissions | 315 # Validates parent_id param according to user's permissions |
304 # TODO: move it to Project model in a validation that depends on User.current | 316 # TODO: move it to Project model in a validation that depends on User.current |
305 def validate_parent_id | 317 def validate_parent_id |
306 return true if User.current.admin? | 318 return true if User.current.admin? |
307 parent_id = params[:project] && params[:project][:parent_id] | 319 parent_id = params[:project] && params[:project][:parent_id] |