Project

General

Profile

Actions

Feature #18835

open

Copy projects - Templating projects

Added by Thibaut Comte almost 10 years ago. Updated over 4 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Projects
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:

Description

Hi guys

I'd like to share with you what i did to allow users to copy projects for non-admin user.

I started with what Christian wrote a while ago on this issue #13373

So i modified 3 files :

In app/view/projects/show.html.erb
line 12 :

<% if @project.is_public? %>
<%= link_to(l(:button_copy), { :controller => 'projects', :action => 'copy', :id => @project }, :class => 'icon icon-copy') %>
<% end %>

This add a copy button in each project near "add subproject, close project".

This means that in every project i can copy it into another project.
But i can't really do that because i don't have the right to copy a project if i'm not admin.

So in app/controllers/projects_controller.rb
somewhere between line 20 and 30 i removed :copy from a before_filter like in the issue #13373

before_filter :authorize_global, :only => [:new, :create ]
before_filter :require_admin, :only => [ :archive, :unarchive, :destroy ]

Now, the problem is that everyone can copy every project even if non member, because i just have to write :
http: //localhost/redmine/projects/PROJECT_ID/ copy
to copy a project.

This is not what i want.

So i decided to allow the non-user copy of project only for public project.

Still in app/controllers/projects_controller.rb
line 115, i added :

if !@source_project.is_public && !User.current.admin?
render_404
end
So in the end, i can copy a project if :
  • The project is public and i'm not admin
  • or i'm admin

if i'm not admin and the project is not public and i try to copy it using http: //localhost/redmine/projects/PROJECT_ID/ copy, i will go to the 404 page error.

Hope this will help you

With this you can have a templating of project by having some projects that are public and by having a copy button in your public project (no need to add /copy at the end of the url).

If you have anything you would like to add or say, don't hesitate. Maybe i missed some authorization but it actually is working in my prod environnement.


Files

copy.PNG (21.4 KB) copy.PNG Thibaut Comte, 2015-01-14 09:18
Actions

Also available in: Atom PDF