Project

General

Profile

Feature #2009 » manually_add_remove_related_changesets-new-r3078.patch

Patch created against trunk@r3078 - Mischa The Evil, 2009-11-27 01:59

View differences:

app/helpers/changeset_relations_helper.rb (revision 0)
1
module ChangesetRelationsHelper
2
end
app/controllers/changeset_relations_controller.rb (revision 0)
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(:field_error_revision_not_found)
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 "issue-changesets-list", :partial => 'issues/changesets', :locals => { :changesets => @issue.changesets}
21
          if @changeset.errors.empty?
22
            page << "$('changeset_revision').value = ''"
23
          end
24
        end
25
      end
26
    end
27
  end
28
  
29
  def destroy
30
    changeset = Changeset.find(params[:id])
31
    if request.post? && ! changeset.nil? && changeset.issues.include?(@issue)
32
      changeset.issues.delete(@issue)
33
      @issue.reload
34
    end
35
    respond_to do |format|
36
      format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
37
      format.js do
38
        render(:update) do |page|
39
          page.replace_html "issue-changesets-list", :partial => 'issues/changesets', :locals => { :changesets => @issue.changesets}
40
        end
41
      end
42
    end
43
  end
44

  
45

  
46
  private
47
  def find_project
48
    @issue = Issue.find(params[:issue_id])
49
    @project = @issue.project
50
  rescue ActiveRecord::RecordNotFound
51
    render_404
52
  end
53
end
app/views/changeset_relations/_form.html.erb (revision 0)
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/show.rhtml (working copy)
82 82

  
83 83
<% if @changesets.any? && User.current.allowed_to?(:view_changesets, @project) %>
84 84
<div id="issue-changesets">
85
<div class="contextual">
86
<% if authorize_for('changeset_relations', 'new') %>
87
    <%= toggle_link l(:button_add), 'new-changeset-form'%>
88
<% end %>
89
</div>
90

  
85 91
<h3><%=l(:label_associated_revisions)%></h3>
92

  
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? %>
app/views/issues/_changesets.rhtml (working copy)
1
<% remote_form_for(:changeset, @changeset,
2
                 :url => {:controller => 'changeset_relations', :action => 'new', :issue_id => @issue},
3
                 :method => :post,
4
                 :html => {:id => 'new-changeset-form', :style => (@changeset ? '' : 'display: none;')}) do |f| %>
5
<%= render :partial => 'changeset_relations/form', :locals => {:f => f}%>
6
<% end %>
7

  
1 8
<% changesets.each do |changeset| %>
2 9
    <div class="changeset <%= cycle('odd', 'even') %>">
3 10
    <p><%= link_to("#{l(:label_revision)} #{changeset.revision}",
4
                :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision) %><br />
5
        <span class="author"><%= authoring(changeset.committed_on, changeset.author) %></span></p>
11
                :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision) %>
12
       <span class="contextual">
13
       <%= link_to_remote(image_tag('delete.png'), { :url => {:controller => 'changeset_relations', :action => 'destroy', :issue_id => @issue, :id => changeset},
14
                                                     :method => :post
15
                                                   }, :title => l(:label_changeset_delete)) if authorize_for('changeset_relations', 'destroy') %>
16
       </span>
17
       <br />
18
       <span class="author"><%= authoring(changeset.committed_on, changeset.author) %></span></p>
6 19
    <%= textilizable(changeset, :comments) %>
7 20
    </div>
8 21
<% end %>
db/migrate/20091124053250_add_manage_changeset_relations_permission.rb (revision 0)
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
config/locales/en.yml (working copy)
840 841
  enumeration_doc_categories: Document categories
841 842
  enumeration_activities: Activities (time tracking)
842 843
  enumeration_system_activity: System Activity
844
  
845
  label_changeset_delete: Delete associated revision
846
  field_error_revision_not_found: Revision not found at project SCM
lib/redmine.rb (working copy)
45 45
    map.permission :add_issues, {:issues => :new}
46 46
    map.permission :edit_issues, {:issues => [:edit, :reply, :bulk_edit]}
47 47
    map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
48
    map.permission :manage_changeset_relations, {:changeset_relations => [:new, :destroy]}
48 49
    map.permission :add_issue_notes, {:issues => [:edit, :reply]}
49 50
    map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
50 51
    map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
(6-6/14)