Revision 1297:0a574315af3e .svn/pristine/db

View differences:

.svn/pristine/db/db1913fc4efda154284af35ccff3e42e0708bad8.svn-base
1
require File.expand_path('../../test_helper', __FILE__)
2

  
3
class ActivitiesControllerTest < ActionController::TestCase
4
  fixtures :projects, :trackers, :issue_statuses, :issues,
5
           :enumerations, :users, :issue_categories,
6
           :projects_trackers,
7
           :roles,
8
           :member_roles,
9
           :members,
10
           :groups_users,
11
           :enabled_modules,
12
           :workflows,
13
           :journals, :journal_details
14

  
15

  
16
  def test_project_index
17
    get :index, :id => 1, :with_subprojects => 0
18
    assert_response :success
19
    assert_template 'index'
20
    assert_not_nil assigns(:events_by_day)
21

  
22
    assert_tag :tag => "h3",
23
               :content => /#{2.days.ago.to_date.day}/,
24
               :sibling => { :tag => "dl",
25
                 :child => { :tag => "dt",
26
                   :attributes => { :class => /issue-edit/ },
27
                   :child => { :tag => "a",
28
                     :content => /(#{IssueStatus.find(2).name})/,
29
                   }
30
                 }
31
               }
32
  end
33

  
34
  def test_project_index_with_invalid_project_id_should_respond_404
35
    get :index, :id => 299
36
    assert_response 404
37
  end
38

  
39
  def test_previous_project_index
40
    get :index, :id => 1, :from => 2.days.ago.to_date
41
    assert_response :success
42
    assert_template 'index'
43
    assert_not_nil assigns(:events_by_day)
44

  
45
    assert_tag :tag => "h3",
46
               :content => /#{3.day.ago.to_date.day}/,
47
               :sibling => { :tag => "dl",
48
                 :child => { :tag => "dt",
49
                   :attributes => { :class => /issue/ },
50
                   :child => { :tag => "a",
51
                     :content => /Can&#x27;t print recipes/,
52
                   }
53
                 }
54
               }
55
  end
56

  
57
  def test_global_index
58
    @request.session[:user_id] = 1
59
    get :index
60
    assert_response :success
61
    assert_template 'index'
62
    assert_not_nil assigns(:events_by_day)
63

  
64
    i5 = Issue.find(5)
65
    d5 = User.find(1).time_to_date(i5.created_on)
66
    assert_tag :tag => "h3",
67
               :content => /#{d5.day}/,
68
               :sibling => { :tag => "dl",
69
                 :child => { :tag => "dt",
70
                   :attributes => { :class => /issue/ },
71
                   :child => { :tag => "a",
72
                     :content => /Subproject issue/,
73
                   }
74
                 }
75
               }
76
  end
77

  
78
  def test_user_index
79
    @request.session[:user_id] = 1
80
    get :index, :user_id => 2
81
    assert_response :success
82
    assert_template 'index'
83
    assert_not_nil assigns(:events_by_day)
84

  
85
    assert_select 'h2 a[href=/users/2]', :text => 'John Smith'
86

  
87
    i1 = Issue.find(1)
88
    d1 = User.find(1).time_to_date(i1.created_on)
89

  
90
    assert_tag :tag => "h3",
91
               :content => /#{d1.day}/,
92
               :sibling => { :tag => "dl",
93
                 :child => { :tag => "dt",
94
                   :attributes => { :class => /issue/ },
95
                   :child => { :tag => "a",
96
                     :content => /Can&#x27;t print recipes/,
97
                   }
98
                 }
99
               }
100
  end
101

  
102
  def test_user_index_with_invalid_user_id_should_respond_404
103
    get :index, :user_id => 299
104
    assert_response 404
105
  end
106

  
107
  def test_index_atom_feed
108
    get :index, :format => 'atom', :with_subprojects => 0
109
    assert_response :success
110
    assert_template 'common/feed'
111

  
112
    assert_tag :tag => 'link', :parent =>  {:tag => 'feed', :parent => nil },
113
        :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
114
    assert_tag :tag => 'link', :parent =>  {:tag => 'feed', :parent => nil },
115
        :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}
116

  
117
    assert_tag :tag => 'entry', :child => {
118
      :tag => 'link',
119
      :attributes => {:href => 'http://test.host/issues/11'}}
120
  end
121

  
122
  def test_index_atom_feed_with_explicit_selection
123
    get :index, :format => 'atom', :with_subprojects => 0,
124
      :show_changesets => 1,
125
      :show_documents => 1,
126
      :show_files => 1,
127
      :show_issues => 1,
128
      :show_messages => 1,
129
      :show_news => 1,
130
      :show_time_entries => 1,
131
      :show_wiki_edits => 1
132

  
133
    assert_response :success
134
    assert_template 'common/feed'
135

  
136
    assert_tag :tag => 'link', :parent =>  {:tag => 'feed', :parent => nil },
137
        :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
138
    assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
139
        :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
140

  
141
    assert_tag :tag => 'entry', :child => {
142
      :tag => 'link',
143
      :attributes => {:href => 'http://test.host/issues/11'}}
144
  end
145

  
146
  def test_index_atom_feed_with_one_item_type
147
    get :index, :format => 'atom', :show_issues => '1'
148
    assert_response :success
149
    assert_template 'common/feed'
150
    assert_tag :tag => 'title', :content => /Issues/
151
  end
152

  
153
  def test_index_should_show_private_notes_with_permission_only
154
    journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
155
    @request.session[:user_id] = 2
156

  
157
    get :index
158
    assert_response :success
159
    assert_include journal, assigns(:events_by_day).values.flatten
160

  
161
    Role.find(1).remove_permission! :view_private_notes
162
    get :index
163
    assert_response :success
164
    assert_not_include journal, assigns(:events_by_day).values.flatten
165
  end
166
end
.svn/pristine/db/db78dc41b63948b8d9e9d114615e04997bccd4b3.svn-base
1
class <%= @model_class %> < ActiveRecord::Base
2
  unloadable
3
end
.svn/pristine/db/db8f4e77d30a8490da79511166f71ee7a646520b.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class ContextMenusController < ApplicationController
19
  helper :watchers
20
  helper :issues
21

  
22
  def issues
23
    @issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
24
    if (@issues.size == 1)
25
      @issue = @issues.first
26
    end
27
    @issue_ids = @issues.map(&:id).sort
28

  
29
    @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
30
    @projects = @issues.collect(&:project).compact.uniq
31
    @project = @projects.first if @projects.size == 1
32

  
33
    @can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
34
            :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
35
            :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
36
            :move => (@project && User.current.allowed_to?(:move_issues, @project)),
37
            :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
38
            :delete => User.current.allowed_to?(:delete_issues, @projects)
39
            }
40
    if @project
41
      if @issue
42
        @assignables = @issue.assignable_users
43
      else
44
        @assignables = @project.assignable_users
45
      end
46
      @trackers = @project.trackers
47
    else
48
      #when multiple projects, we only keep the intersection of each set
49
      @assignables = @projects.map(&:assignable_users).reduce(:&)
50
      @trackers = @projects.map(&:trackers).reduce(:&)
51
    end
52
    @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
53

  
54
    @priorities = IssuePriority.active.reverse
55
    @back = back_url
56

  
57
    @options_by_custom_field = {}
58
    if @can[:edit]
59
      custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f|
60
        %w(bool list user version).include?(f.field_format) && !f.multiple?
61
      end
62
      custom_fields.each do |field|
63
        values = field.possible_values_options(@projects)
64
        if values.any?
65
          @options_by_custom_field[field] = values
66
        end
67
      end
68
    end
69

  
70
    @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
71
    render :layout => false
72
  end
73

  
74
  def time_entries
75
    @time_entries = TimeEntry.all(
76
       :conditions => {:id => params[:ids]}, :include => :project)
77
    @projects = @time_entries.collect(&:project).compact.uniq
78
    @project = @projects.first if @projects.size == 1
79
    @activities = TimeEntryActivity.shared.active
80
    @can = {:edit   => User.current.allowed_to?(:edit_time_entries, @projects),
81
            :delete => User.current.allowed_to?(:edit_time_entries, @projects)
82
            }
83
    @back = back_url
84
    render :layout => false
85
  end
86
end
.svn/pristine/db/dbe1bda8432254ab1c9b544c6336106917863bf8.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class MessagesController < ApplicationController
19
  menu_item :boards
20
  default_search_scope :messages
21
  before_filter :find_board, :only => [:new, :preview]
22
  before_filter :find_message, :except => [:new, :preview]
23
  before_filter :authorize, :except => [:preview, :edit, :destroy]
24

  
25
  helper :boards
26
  helper :watchers
27
  helper :attachments
28
  include AttachmentsHelper
29

  
30
  REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
31

  
32
  # Show a topic and its replies
33
  def show
34
    page = params[:page]
35
    # Find the page of the requested reply
36
    if params[:r] && page.nil?
37
      offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
38
      page = 1 + offset / REPLIES_PER_PAGE
39
    end
40

  
41
    @reply_count = @topic.children.count
42
    @reply_pages = Paginator.new self, @reply_count, REPLIES_PER_PAGE, page
43
    @replies =  @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}],
44
                                           :order => "#{Message.table_name}.created_on ASC",
45
                                           :limit => @reply_pages.items_per_page,
46
                                           :offset => @reply_pages.current.offset)
47

  
48
    @reply = Message.new(:subject => "RE: #{@message.subject}")
49
    render :action => "show", :layout => false if request.xhr?
50
  end
51

  
52
  # Create a new topic
53
  def new
54
    @message = Message.new
55
    @message.author = User.current
56
    @message.board = @board
57
    @message.safe_attributes = params[:message]
58
    if request.post?
59
      @message.save_attachments(params[:attachments])
60
      if @message.save
61
        call_hook(:controller_messages_new_after_save, { :params => params, :message => @message})
62
        render_attachment_warning_if_needed(@message)
63
        redirect_to board_message_path(@board, @message)
64
      end
65
    end
66
  end
67

  
68
  # Reply to a topic
69
  def reply
70
    @reply = Message.new
71
    @reply.author = User.current
72
    @reply.board = @board
73
    @reply.safe_attributes = params[:reply]
74
    @topic.children << @reply
75
    if !@reply.new_record?
76
      call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
77
      attachments = Attachment.attach_files(@reply, params[:attachments])
78
      render_attachment_warning_if_needed(@reply)
79
    end
80
    redirect_to board_message_path(@board, @topic, :r => @reply)
81
  end
82

  
83
  # Edit a message
84
  def edit
85
    (render_403; return false) unless @message.editable_by?(User.current)
86
    @message.safe_attributes = params[:message]
87
    if request.post? && @message.save
88
      attachments = Attachment.attach_files(@message, params[:attachments])
89
      render_attachment_warning_if_needed(@message)
90
      flash[:notice] = l(:notice_successful_update)
91
      @message.reload
92
      redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id))
93
    end
94
  end
95

  
96
  # Delete a messages
97
  def destroy
98
    (render_403; return false) unless @message.destroyable_by?(User.current)
99
    r = @message.to_param
100
    @message.destroy
101
    if @message.parent
102
      redirect_to board_message_path(@board, @message.parent, :r => r)
103
    else
104
      redirect_to project_board_path(@project, @board)
105
    end
106
  end
107

  
108
  def quote
109
    @subject = @message.subject
110
    @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
111

  
112
    @content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
113
    @content << @message.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
114
  end
115

  
116
  def preview
117
    message = @board.messages.find_by_id(params[:id])
118
    @attachements = message.attachments if message
119
    @text = (params[:message] || params[:reply])[:content]
120
    @previewed = message
121
    render :partial => 'common/preview'
122
  end
123

  
124
private
125
  def find_message
126
    find_board
127
    @message = @board.messages.find(params[:id], :include => :parent)
128
    @topic = @message.root
129
  rescue ActiveRecord::RecordNotFound
130
    render_404
131
  end
132

  
133
  def find_board
134
    @board = Board.find(params[:board_id], :include => :project)
135
    @project = @board.project
136
  rescue ActiveRecord::RecordNotFound
137
    render_404
138
  end
139
end

Also available in: Unified diff