manual-changeset-relation.patch

Patch for manual changeset managing - Jan Losinski, 2009-08-21 19:55

Download (8.15 KB)

View differences:

app/controllers/changeset_relations_controller.rb
1
class ChangesetRelationsController < ApplicationController
2

  
3

  
4
  before_filter  :find_project, :authorize
5
  
6
  def new
7
    @changeset = Changeset.find(:first, :conditions => {:revision => params[:changeset][:revision], :repository_id => @project.repository})
8
    if  @changeset.nil?
9
      @changeset = Changeset.new(:revision => params[:changeset][:revision])
10
      @changeset.errors.add  l(:revision_not_found_error)
11
    else
12
      @changeset.issues << @issue
13
      @changeset.save if request.post?
14
    end
15
    @issue.reload
16
    respond_to do |format|
17
      format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
18
      format.js do
19
        render :update do |page|
20
          page.replace_html "changeset_list", :partial => 'issues/changeset_list', :locals => { :changesets => @issue.changesets}
21
          page.replace_html "issue-changesets-list", :partial => 'issues/changesets', :locals => { :changesets => @issue.changesets}
22
          if @changeset.errors.empty?
23
            page << "$('changeset_revision').value = ''"
24
          end
25
        end
26
      end
27
    end
28
  end
29
  
30
  def destroy
31
    changeset = Changeset.find(params[:id])
32
    if request.post? && ! changeset.nil? && changeset.issues.include?(@issue)
33
      changeset.issues.delete(@issue)
34
      @issue.reload
35
    end
36
    respond_to do |format|
37
      format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
38
      format.js do
39
        render(:update) do |page|
40
          page.replace_html "changeset_list", :partial => 'issues/changeset_list', :locals => { :changesets => @issue.changesets}
41
          page.replace_html "issue-changesets-list", :partial => 'issues/changesets', :locals => { :changesets => @issue.changesets}
42
        end
43
      end
44
    end
45
  end
46

  
47

  
48
  private
49
  def find_project
50
    @issue = Issue.find(params[:issue_id])
51
    @project = @issue.project
52
  rescue ActiveRecord::RecordNotFound
53
    render_404
54
  end
55
end
app/helpers/changeset_relations_helper.rb
1
module ChangesetRelationsHelper
2
end
app/views/changeset_relations/_form.html.erb
1
<%= error_messages_for 'changeset' %>
2

  
3
<p><%= l(:label_revision) %> <%= f.text_field :revision, :size => 6 %>
4
<%= submit_tag l(:button_add) %>
5
<%= toggle_link l(:button_cancel), 'new-changeset-form'%>
6
</p>
7

  
8
<%= javascript_tag "setPredecessorFieldsVisibility();" %>
app/views/issues/_changeset_list.rhtml
1
<div class="contextual">
2
<% if authorize_for('changeset_relations', 'new') %>
3
    <%= toggle_link l(:button_add), 'new-changeset-form'%>
4
<% end %>
5
</div>
6

  
7
<p><strong><%=l(:label_associated_revisions)%></strong></p>
8

  
9
<% if changesets.any? %>
10
<table style="width:100%">
11
<% changesets.each do |changeset| %>
12
<tr>
13
  <td><%= link_to("#{l(:label_revision)} #{changeset.revision}",
14
                :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision) %>
15
  </td>
16
  <td><%= h changeset.author %></td>
17
  <td><%= h truncate changeset.comments.split("\n").first, :length => 40 %></td>
18
  <td><%= format_date(changeset.committed_on) %></td>
19
  <td><%= link_to_remote(image_tag('delete.png'), { :url => {:controller => 'changeset_relations', :action => 'destroy', :issue_id => @issue, :id => changeset},
20
                                                  :method => :post
21
                                                }, :title => l(:label_changeset_delete)) if authorize_for('changeset_relations', 'destroy') %>
22
  </td>
23
</tr>
24
<% end %>
25
</table>
26
<% end %>
27

  
28
<% remote_form_for(:changeset, @changeset,
29
                 :url => {:controller => 'changeset_relations', :action => 'new', :issue_id => @issue},
30
                 :method => :post,
31
                 :html => {:id => 'new-changeset-form', :style => (@changeset ? '' : 'display: none;')}) do |f| %>
32
<%= render :partial => 'changeset_relations/form', :locals => {:f => f}%>
33
<% end %>
app/views/issues/show.rhtml
70 70
</div>
71 71
<% end %>
72 72

  
73
<% if !@project.repository.nil? && (authorize_for('changeset_relations', 'new') || @changesets.relations.any?) %>
74
<hr />
75
<div id="changeset_list">
76
<%= render :partial => 'changeset_list', :locals => { :changesets => @changesets} %>
77
</div>
78
<% end %>
79

  
73 80
<% if User.current.allowed_to?(:add_issue_watchers, @project) ||
74 81
        (@issue.watchers.any? && User.current.allowed_to?(:view_issue_watchers, @project)) %>
75 82
<hr />
......
83 90
<% if @changesets.any? && User.current.allowed_to?(:view_changesets, @project) %>
84 91
<div id="issue-changesets">
85 92
<h3><%=l(:label_associated_revisions)%></h3>
93
<div id="issue-changesets-list">
86 94
<%= render :partial => 'changesets', :locals => { :changesets => @changesets} %>
87 95
</div>
96
</div>
88 97
<% end %>
89 98

  
90 99
<% if @journals.any? %>
config/locales/de.yml
833 833
  label_view_all_revisions: View all revisions
834 834
  label_tag: Tag
835 835
  label_branch: Branch
836
  revision_not_found_error: Revision nicht gefunden im SCM des Projektes
config/locales/en.yml
804 804
  enumeration_issue_priorities: Issue priorities
805 805
  enumeration_doc_categories: Document categories
806 806
  enumeration_activities: Activities (time tracking)
807
  revision_not_found_error: Revision not found at project SCM
db/migrate/20090821144826_add_manage_changeset_relations_permission.rb
1
class AddManageChangesetRelationsPermission < ActiveRecord::Migration
2
  def self.up
3
    Role.find(:all).each do |r|
4
      r.add_permission!(:manage_changeset_relations) if r.has_permission?(:manage_issue_relations)
5
    end
6
  end
7

  
8
  def self.down
9
    Role.find(:all).each do |r|
10
      r.remove_permission!(:manage_changeset_relations)
11
    end
12
  end
13
end
lib/redmine.rb
38 38
    map.permission :add_issues, {:issues => :new}
39 39
    map.permission :edit_issues, {:issues => [:edit, :reply, :bulk_edit]}
40 40
    map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
41
    map.permission :manage_changeset_relations, {:changeset_relations => [:new, :destroy]}
41 42
    map.permission :add_issue_notes, {:issues => [:edit, :reply]}
42 43
    map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
43 44
    map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
test/functional/changeset_relations_controller_test.rb
1
require 'test_helper'
2

  
3
class ChangesetRelationsControllerTest < ActionController::TestCase
4
  # Replace this with your real tests.
5
  test "the truth" do
6
    assert true
7
  end
8
end