プロジェクト

全般

プロフィール

Vote #75931

未完了

Copy projects - Templating projects

Admin Redmine さんが約2年前に追加. 約2年前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
Projects_11
対象バージョン:
-
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
11
version_id:
0
issue_org_id:
18835
author_id:
114322
assigned_to_id:
0
comments:
2
status_id:
1
tracker_id:
2
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[New]

説明

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".
!copy.PNG!
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.


journals

Update :

It seems that i did the tests in admin so it worked everytime but with a non-admin user, the project was created but the user not added in the project.

So i added these lines in app/controllers/projects_controller.rb at line 126
@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')
unless User.current.admin?
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => User.current, :roles => [r])
@project.members << m
end@

This will add the user in the copied project (but not the admin)

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

Admin Redmine さんが約2年前に更新

  • カテゴリProjects_11 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0