summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-12-24 16:18:15 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-12-24 16:18:15 +0000
commit62c83bdd2e1b06fcd873ba6d638c0bf59e390958 (patch)
treecfff2b493b317d0b870ce1499725e008f1b85ff1 /app
parent24fde6f1096074cc596a3fbab0165f682a554e82 (diff)
downloadredmine-62c83bdd2e1b06fcd873ba6d638c0bf59e390958.tar.gz
redmine-62c83bdd2e1b06fcd873ba6d638c0bf59e390958.zip
Adds a 'Add subprojects' permission.
* 'Add project' permission will let user create a root project * 'Add subprojects' permission will let project members create subprojects git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3238 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects_controller.rb21
-rw-r--r--app/helpers/projects_helper.rb11
-rw-r--r--app/models/project.rb6
-rw-r--r--app/views/projects/_form.rhtml2
-rw-r--r--app/views/projects/show.rhtml6
5 files changed, 40 insertions, 6 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 386807f55..722893798 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -73,7 +73,7 @@ class ProjectsController < ApplicationController
@project.enabled_module_names = Setting.default_projects_modules
else
@project.enabled_module_names = params[:enabled_modules]
- if @project.save
+ if 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?
@@ -104,7 +104,7 @@ class ProjectsController < ApplicationController
else
@project = Project.new(params[:project])
@project.enabled_module_names = params[:enabled_modules]
- if @project.copy(@source_project, :only => params[:only])
+ if validate_parent_id && @project.copy(@source_project, :only => params[:only])
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'admin', :action => 'projects'
@@ -156,7 +156,7 @@ class ProjectsController < ApplicationController
def edit
if request.post?
@project.attributes = params[:project]
- if @project.save
+ if validate_parent_id && @project.save
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'settings', :id => @project
@@ -395,4 +395,19 @@ private
@selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
end
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
+ return true if User.current.admin?
+ parent_id = params[:project] && params[:project][:parent_id]
+ if parent_id || @project.new_record?
+ parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
+ unless @project.allowed_parents.include?(parent)
+ @project.errors.add :parent_id, :invalid
+ return false
+ end
+ end
+ true
+ end
end
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 7ab0186d5..a44d2fb82 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -36,7 +36,16 @@ module ProjectsHelper
end
def parent_project_select_tag(project)
- options = '<option></option>' + project_tree_options_for_select(project.allowed_parents, :selected => project.parent)
+ selected = project.parent
+ # retrieve the requested parent project
+ parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
+ if parent_id
+ selected = (parent_id.blank? ? nil : Project.find(parent_id))
+ end
+
+ options = ''
+ options << "<option value=''></option>" if project.allowed_parents.include?(nil)
+ options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
content_tag('select', options, :name => 'project[parent_id]')
end
diff --git a/app/models/project.rb b/app/models/project.rb
index d6526100f..3f34393b3 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -246,7 +246,11 @@ class Project < ActiveRecord::Base
# by the current user
def allowed_parents
return @allowed_parents if @allowed_parents
- @allowed_parents = (Project.find(:all, :conditions => Project.allowed_to_condition(User.current, :add_project, :member => true)) - self_and_descendants)
+ @allowed_parents = Project.find(:all, :conditions => Project.allowed_to_condition(User.current, :add_subprojects))
+ @allowed_parents = @allowed_parents - self_and_descendants
+ if User.current.allowed_to?(:add_project, nil, :global => true)
+ @allowed_parents << nil
+ end
unless parent.nil? || @allowed_parents.empty? || @allowed_parents.include?(parent)
@allowed_parents << parent
end
diff --git a/app/views/projects/_form.rhtml b/app/views/projects/_form.rhtml
index 0e286fcae..ef2a18855 100644
--- a/app/views/projects/_form.rhtml
+++ b/app/views/projects/_form.rhtml
@@ -4,7 +4,7 @@
<!--[form:project]-->
<p><%= f.text_field :name, :required => true %><br /><em><%= l(:text_caracters_maximum, 30) %></em></p>
-<% unless @project.allowed_parents.empty? %>
+<% unless @project.allowed_parents.compact.empty? %>
<p><label><%= l(:field_parent) %></label><%= parent_project_select_tag(@project) %></p>
<% end %>
diff --git a/app/views/projects/show.rhtml b/app/views/projects/show.rhtml
index a59c329c3..7d5412af0 100644
--- a/app/views/projects/show.rhtml
+++ b/app/views/projects/show.rhtml
@@ -1,3 +1,9 @@
+<div class="contextual">
+ <% if User.current.allowed_to?(:add_subprojects, @project) %>
+ <%= link_to l(:label_subproject_new), {:controller => 'projects', :action => 'add', :parent_id => @project}, :class => 'icon icon-add' %>
+ <% end %>
+</div>
+
<h2><%=l(:label_overview)%></h2>
<div class="splitcontentleft">