diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index da7259da16..e1fc76cb41 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -23,13 +23,13 @@ class ProjectsController < ApplicationController
menu_item :projects, :only => [:index, :new, :copy, :create]
before_action :find_project,
- :except => [:index, :autocomplete, :list, :new, :create, :copy]
+ :except => [:index, :autocomplete, :list, :new, :create]
before_action :authorize,
- :except => [:index, :autocomplete, :list, :new, :create, :copy,
+ :except => [:index, :autocomplete, :list, :new, :create,
:archive, :unarchive,
:destroy]
before_action :authorize_global, :only => [:new, :create]
- before_action :require_admin, :only => [:copy, :archive, :unarchive]
+ before_action :require_admin, :only => [:archive, :unarchive]
accept_atom_auth :index
accept_api_auth :index, :show, :create, :update, :destroy, :archive, :unarchive, :close, :reopen
require_sudo_mode :destroy
@@ -140,6 +140,7 @@ class ProjectsController < ApplicationController
end
def copy
+ @project = nil # Reset because source project was set in @project for authorize.
@issue_custom_fields = IssueCustomField.sorted.to_a
@trackers = Tracker.sorted.to_a
@source_project = Project.find(params[:id])
diff --git a/app/models/role.rb b/app/models/role.rb
index 790d09f271..b6130b77b0 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -80,6 +80,8 @@ class Role < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name, :case_sensitive => true
validates_length_of :name, :maximum => 255
+ validate :check_the_prerequisites_for_copy_project_permission
+
validates_inclusion_of(
:issues_visibility,
:in => ISSUES_VISIBILITY_OPTIONS.collect(&:first),
@@ -318,4 +320,12 @@ class Role < ActiveRecord::Base
role
end
private_class_method :find_or_create_system_role
+
+ def check_the_prerequisites_for_copy_project_permission
+ if self.permissions.include?(:copy_project) &&
+ self.permissions.exclude?(:add_project) &&
+ self.permissions.exclude?(:add_subprojects)
+ errors.add(:base, l(:error_cannot_have_copy_project_permission))
+ end
+ end
end
diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb
index 5c7ef440c2..53fa3f3c5c 100644
--- a/app/views/projects/show.html.erb
+++ b/app/views/projects/show.html.erb
@@ -5,6 +5,9 @@
<% if User.current.allowed_to?(:add_subprojects, @project) %>
<%= link_to l(:label_subproject_new), new_project_path(:parent_id => @project), :class => 'icon icon-add' %>
<% end %>
+ <% if User.current.allowed_to?(:copy_project, @project) %>
+ <%= link_to(l(:button_copy), copy_project_path(@project), :class => 'icon icon-copy') %>
+ <% end %>
<% if User.current.allowed_to?(:close_project, @project) %>
<% if @project.active? %>
<%= link_to l(:button_close), close_project_path(@project), :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock' %>
diff --git a/app/views/roles/_form.html.erb b/app/views/roles/_form.html.erb
index e149b0011e..1140962897 100644
--- a/app/views/roles/_form.html.erb
+++ b/app/views/roles/_form.html.erb
@@ -54,9 +54,10 @@