Feature #2963 » 04-parent_project_set_by_manager-0.4.0.patch
| app/controllers/projects_controller.rb | ||
|---|---|---|
|
else
|
||
|
@project.enabled_module_names = params[:enabled_modules]
|
||
|
if @project.save
|
||
|
@project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
|
||
|
@project.set_parent!(params[:project]['parent_id']) if user_allowed_to_change_parent?(@project) && params[:project].has_key?('parent_id')
|
||
|
# Add current user as a project member if he is not admin
|
||
|
unless User.current.admin?
|
||
|
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||
| ... | ... | |
|
if request.post?
|
||
|
@project.attributes = params[:project]
|
||
|
if @project.save
|
||
|
@project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
|
||
|
@project.set_parent!(params[:project]['parent_id']) if user_allowed_to_change_parent?(@project) && params[:project].has_key?('parent_id')
|
||
|
flash[:notice] = l(:notice_successful_update)
|
||
|
redirect_to :action => 'settings', :id => @project
|
||
|
else
|
||
| app/helpers/projects_helper.rb | ||
|---|---|---|
|
end
|
||
|
s
|
||
|
end
|
||
|
def user_allowed_to_change_parent?(project)
|
||
|
if project.id == nil
|
||
|
return User.current.allowed_to?(:add_project, nil, :global => true)
|
||
|
end
|
||
|
User.current.allowed_to?(:add_project, project) && (!project.parent || User.current.allowed_to?(:add_project, project.parent))
|
||
|
end
|
||
|
end
|
||
| app/models/project.rb | ||
|---|---|---|
|
|
||
|
# Returns an array of projects the project can be moved to
|
||
|
def possible_parents
|
||
|
@possible_parents ||= (Project.active.find(:all) - self_and_descendants)
|
||
|
@possible_parents ||= (find_allowed_projects - self_and_descendants)
|
||
|
end
|
||
|
|
||
|
# Sets the parent of the project
|
||
| ... | ... | |
|
def allowed_actions
|
||
|
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
|
||
|
end
|
||
|
def find_allowed_projects
|
||
|
Project.active.find(:all).find_all { |p| User.current.allowed_to?(:add_project, p) }
|
||
|
end
|
||
|
end
|
||
| app/views/projects/_form.rhtml | ||
|---|---|---|
|
<!--[form:project]-->
|
||
|
<p><%= f.text_field :name, :required => true %><br /><em><%= l(:text_caracters_maximum, 30) %></em></p>
|
||
|
<% if User.current.admin? && !@project.possible_parents.empty? %>
|
||
|
<% if user_allowed_to_change_parent?(@project) && !@project.possible_parents.empty? %>
|
||
|
<p><label><%= l(:field_parent) %></label><%= parent_project_select_tag(@project) %></p>
|
||
|
<% end %>
|
||
- « Previous
- 1
- 2
- Next »