Revision 1298:4f746d8966dd .svn/pristine/0b

View differences:

.svn/pristine/0b/0b7befce1d7322f245834ffc9480adf8d5c60890.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2013  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
require File.expand_path('../test_case', __FILE__)
19
require 'tmpdir'
20

  
21
class RedminePmTest::RepositorySubversionTest < RedminePmTest::TestCase
22
  fixtures :projects, :users, :members, :roles, :member_roles, :auth_sources
23

  
24
  SVN_BIN = Redmine::Configuration['scm_subversion_command'] || "svn"
25

  
26
  def test_anonymous_read_on_public_repo_with_permission_should_succeed
27
    assert_success "ls", svn_url
28
  end
29

  
30
  def test_anonymous_read_on_public_repo_without_permission_should_fail
31
    Role.anonymous.remove_permission! :browse_repository
32
    assert_failure "ls", svn_url
33
  end
34

  
35
  def test_anonymous_read_on_private_repo_should_fail
36
    Project.find(1).update_attribute :is_public, false
37
    assert_failure "ls", svn_url
38
  end
39

  
40
  def test_anonymous_commit_on_public_repo_should_fail
41
    Role.anonymous.add_permission! :commit_access
42
    assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
43
  end
44

  
45
  def test_anonymous_commit_on_private_repo_should_fail
46
    Role.anonymous.add_permission! :commit_access
47
    Project.find(1).update_attribute :is_public, false
48
    assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
49
  end
50

  
51
  def test_non_member_read_on_public_repo_with_permission_should_succeed
52
    Role.anonymous.remove_permission! :browse_repository
53
    with_credentials "miscuser8", "foo" do
54
      assert_success "ls", svn_url
55
    end
56
  end
57

  
58
  def test_non_member_read_on_public_repo_without_permission_should_fail
59
    Role.anonymous.remove_permission! :browse_repository
60
    Role.non_member.remove_permission! :browse_repository
61
    with_credentials "miscuser8", "foo" do
62
      assert_failure "ls", svn_url
63
    end
64
  end
65

  
66
  def test_non_member_read_on_private_repo_should_fail
67
    Project.find(1).update_attribute :is_public, false
68
    with_credentials "miscuser8", "foo" do
69
      assert_failure "ls", svn_url
70
    end
71
  end
72

  
73
  def test_non_member_commit_on_public_repo_should_fail
74
    Role.non_member.add_permission! :commit_access
75
    assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
76
  end
77

  
78
  def test_non_member_commit_on_private_repo_should_fail
79
    Role.non_member.add_permission! :commit_access
80
    Project.find(1).update_attribute :is_public, false
81
    assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
82
  end
83

  
84
  def test_member_read_on_public_repo_with_permission_should_succeed
85
    Role.anonymous.remove_permission! :browse_repository
86
    Role.non_member.remove_permission! :browse_repository
87
    with_credentials "dlopper", "foo" do
88
      assert_success "ls", svn_url
89
    end
90
  end
91

  
92
  def test_member_read_on_public_repo_without_permission_should_fail
93
    Role.anonymous.remove_permission! :browse_repository
94
    Role.non_member.remove_permission! :browse_repository
95
    Role.find(2).remove_permission! :browse_repository
96
    with_credentials "dlopper", "foo" do
97
      assert_failure "ls", svn_url
98
    end
99
  end
100

  
101
  def test_member_read_on_private_repo_with_permission_should_succeed
102
    Project.find(1).update_attribute :is_public, false
103
    with_credentials "dlopper", "foo" do
104
      assert_success "ls", svn_url
105
    end
106
  end
107

  
108
  def test_member_read_on_private_repo_without_permission_should_fail
109
    Role.find(2).remove_permission! :browse_repository
110
    Project.find(1).update_attribute :is_public, false
111
    with_credentials "dlopper", "foo" do
112
      assert_failure "ls", svn_url
113
    end
114
  end
115

  
116
  def test_member_commit_on_public_repo_with_permission_should_succeed
117
    Role.find(2).add_permission! :commit_access
118
    with_credentials "dlopper", "foo" do
119
      assert_success "mkdir --message Creating_a_directory", svn_url(random_filename)
120
    end
121
  end
122

  
123
  def test_member_commit_on_public_repo_without_permission_should_fail
124
    Role.find(2).remove_permission! :commit_access
125
    with_credentials "dlopper", "foo" do
126
      assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
127
    end
128
  end
129

  
130
  def test_member_commit_on_private_repo_with_permission_should_succeed
131
    Role.find(2).add_permission! :commit_access
132
    Project.find(1).update_attribute :is_public, false
133
    with_credentials "dlopper", "foo" do
134
      assert_success "mkdir --message Creating_a_directory", svn_url(random_filename)
135
    end
136
  end
137

  
138
  def test_member_commit_on_private_repo_without_permission_should_fail
139
    Role.find(2).remove_permission! :commit_access
140
    Project.find(1).update_attribute :is_public, false
141
    with_credentials "dlopper", "foo" do
142
      assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
143
    end
144
  end
145

  
146
  def test_invalid_credentials_should_fail
147
    Project.find(1).update_attribute :is_public, false
148
    with_credentials "dlopper", "foo" do
149
      assert_success "ls", svn_url
150
    end
151
    with_credentials "dlopper", "wrong" do
152
      assert_failure "ls", svn_url
153
    end
154
  end
155

  
156
  def test_anonymous_read_should_fail_with_login_required
157
    assert_success "ls", svn_url
158
    with_settings :login_required => '1' do
159
      assert_failure "ls", svn_url
160
    end
161
  end
162

  
163
  def test_authenticated_read_should_succeed_with_login_required
164
    with_settings :login_required => '1' do
165
      with_credentials "miscuser8", "foo" do
166
        assert_success "ls", svn_url
167
      end
168
    end
169
  end
170

  
171
  def test_read_on_archived_projects_should_fail
172
    Project.find(1).update_attribute :status, Project::STATUS_ARCHIVED
173
    assert_failure "ls", svn_url
174
  end
175

  
176
  def test_read_on_archived_private_projects_should_fail
177
    Project.find(1).update_attribute :status, Project::STATUS_ARCHIVED
178
    Project.find(1).update_attribute :is_public, false
179
    with_credentials "dlopper", "foo" do
180
      assert_failure "ls", svn_url
181
    end
182
  end
183

  
184
  def test_read_on_closed_projects_should_succeed
185
    Project.find(1).update_attribute :status, Project::STATUS_CLOSED
186
    assert_success "ls", svn_url
187
  end
188

  
189
  def test_read_on_closed_private_projects_should_succeed
190
    Project.find(1).update_attribute :status, Project::STATUS_CLOSED
191
    Project.find(1).update_attribute :is_public, false
192
    with_credentials "dlopper", "foo" do
193
      assert_success "ls", svn_url
194
    end
195
  end
196

  
197
  def test_commit_on_closed_projects_should_fail
198
    Project.find(1).update_attribute :status, Project::STATUS_CLOSED
199
    Role.find(2).add_permission! :commit_access
200
    with_credentials "dlopper", "foo" do
201
      assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
202
    end
203
  end
204

  
205
  def test_commit_on_closed_private_projects_should_fail
206
    Project.find(1).update_attribute :status, Project::STATUS_CLOSED
207
    Project.find(1).update_attribute :is_public, false
208
    Role.find(2).add_permission! :commit_access
209
    with_credentials "dlopper", "foo" do
210
      assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
211
    end
212
  end
213

  
214
  if ldap_configured?
215
    def test_user_with_ldap_auth_source_should_authenticate_with_ldap_credentials
216
      ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1)
217
      ldap_user.login = 'example1'
218
      ldap_user.save!
219
  
220
      with_settings :login_required => '1' do
221
        with_credentials "example1", "123456" do
222
          assert_success "ls", svn_url
223
        end
224
      end
225
  
226
      with_settings :login_required => '1' do
227
        with_credentials "example1", "wrong" do
228
          assert_failure "ls", svn_url
229
        end
230
      end
231
    end
232
  end
233

  
234
  def test_checkout
235
    Dir.mktmpdir do |dir|
236
      assert_success "checkout", svn_url, dir
237
    end
238
  end
239

  
240
  def test_read_commands
241
    assert_success "info", svn_url
242
    assert_success "ls", svn_url
243
    assert_success "log", svn_url
244
  end
245

  
246
  def test_write_commands
247
    Role.find(2).add_permission! :commit_access
248
    filename = random_filename
249

  
250
    Dir.mktmpdir do |dir|
251
      assert_success "checkout", svn_url, dir
252
      Dir.chdir(dir) do
253
        # creates a file in the working copy
254
        f = File.new(File.join(dir, filename), "w")
255
        f.write "test file content"
256
        f.close
257

  
258
        assert_success "add", filename
259
        with_credentials "dlopper", "foo" do
260
          assert_success "commit --message Committing_a_file"
261
          assert_success "copy   --message Copying_a_file", svn_url(filename), svn_url("#{filename}_copy")
262
          assert_success "delete --message Deleting_a_file", svn_url(filename)
263
          assert_success "mkdir  --message Creating_a_directory", svn_url("#{filename}_dir")
264
        end
265
        assert_success "update"
266

  
267
        # checks that the working copy was updated
268
        assert File.exists?(File.join(dir, "#{filename}_copy"))
269
        assert File.directory?(File.join(dir, "#{filename}_dir"))
270
      end
271
    end
272
  end
273

  
274
  def test_read_invalid_repo_should_fail
275
    assert_failure "ls", svn_url("invalid")
276
  end
277

  
278
  protected
279

  
280
  def execute(*args)
281
    a = [SVN_BIN, "--no-auth-cache --non-interactive"]
282
    a << "--username #{username}" if username
283
    a << "--password #{password}" if password
284

  
285
    super a, *args
286
  end
287

  
288
  def svn_url(path=nil)
289
    host = ENV['REDMINE_TEST_DAV_SERVER'] || '127.0.0.1'
290
    url = "http://#{host}/svn/ecookbook"
291
    url << "/#{path}" if path
292
    url
293
  end
294
end
.svn/pristine/0b/0b8467ea6271bd6bbf31748ec5f34d49b8671c8b.svn-base
1
/* Azerbaijani (UTF-8) initialisation for the jQuery UI date picker plugin. */
2
/* Written by Jamil Najafov (necefov33@gmail.com). */
3
jQuery(function($) {
4
	$.datepicker.regional['az'] = {
5
		closeText: 'Bağla',
6
		prevText: '&#x3C;Geri',
7
		nextText: 'İrəli&#x3E;',
8
		currentText: 'Bugün',
9
		monthNames: ['Yanvar','Fevral','Mart','Aprel','May','İyun',
10
		'İyul','Avqust','Sentyabr','Oktyabr','Noyabr','Dekabr'],
11
		monthNamesShort: ['Yan','Fev','Mar','Apr','May','İyun',
12
		'İyul','Avq','Sen','Okt','Noy','Dek'],
13
		dayNames: ['Bazar','Bazar ertəsi','Çərşənbə axşamı','Çərşənbə','Cümə axşamı','Cümə','Şənbə'],
14
		dayNamesShort: ['B','Be','Ça','Ç','Ca','C','Ş'],
15
		dayNamesMin: ['B','B','Ç','С','Ç','C','Ş'],
16
		weekHeader: 'Hf',
17
		dateFormat: 'dd.mm.yy',
18
		firstDay: 1,
19
		isRTL: false,
20
		showMonthAfterYear: false,
21
		yearSuffix: ''};
22
	$.datepicker.setDefaults($.datepicker.regional['az']);
23
});
.svn/pristine/0b/0b8a142f46ed608799d7faf6016772f4b1f09f42.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2013  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
require File.expand_path('../../../test_helper', __FILE__)
19

  
20
class RoutingAdminTest < ActionController::IntegrationTest
21
  def test_administration_panel
22
    assert_routing(
23
        { :method => 'get', :path => "/admin" },
24
        { :controller => 'admin', :action => 'index' }
25
      )
26
    assert_routing(
27
        { :method => 'get', :path => "/admin/projects" },
28
        { :controller => 'admin', :action => 'projects' }
29
      )
30
    assert_routing(
31
        { :method => 'get', :path => "/admin/plugins" },
32
        { :controller => 'admin', :action => 'plugins' }
33
      )
34
    assert_routing(
35
        { :method => 'get', :path => "/admin/info" },
36
        { :controller => 'admin', :action => 'info' }
37
      )
38
    assert_routing(
39
        { :method => 'get', :path => "/admin/test_email" },
40
        { :controller => 'admin', :action => 'test_email' }
41
      )
42
    assert_routing(
43
        { :method => 'post', :path => "/admin/default_configuration" },
44
        { :controller => 'admin', :action => 'default_configuration' }
45
      )
46
  end
47
end
.svn/pristine/0b/0b97b483eed443a57933ffcafedb4eb971db5cf5.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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 ScmFetchError < Exception; end
19

  
20
class Repository < ActiveRecord::Base
21
  include Redmine::Ciphering
22

  
23
  belongs_to :project
24
  has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
25
  has_many :changes, :through => :changesets
26

  
27
  serialize :extra_info
28

  
29
  # Raw SQL to delete changesets and changes in the database
30
  # has_many :changesets, :dependent => :destroy is too slow for big repositories
31
  before_destroy :clear_changesets
32

  
33
  validates_length_of :password, :maximum => 255, :allow_nil => true
34
  # Checks if the SCM is enabled when creating a repository
35
  validate :repo_create_validation, :on => :create
36

  
37
  def repo_create_validation
38
    unless Setting.enabled_scm.include?(self.class.name.demodulize)
39
      errors.add(:type, :invalid)
40
    end
41
  end
42

  
43
  def self.human_attribute_name(attribute_key_name)
44
    attr_name = attribute_key_name
45
    if attr_name == "log_encoding"
46
      attr_name = "commit_logs_encoding"
47
    end
48
    super(attr_name)
49
  end
50

  
51
  # Removes leading and trailing whitespace
52
  def url=(arg)
53
    write_attribute(:url, arg ? arg.to_s.strip : nil)
54
  end
55

  
56
  # Removes leading and trailing whitespace
57
  def root_url=(arg)
58
    write_attribute(:root_url, arg ? arg.to_s.strip : nil)
59
  end
60

  
61
  def password
62
    read_ciphered_attribute(:password)
63
  end
64

  
65
  def password=(arg)
66
    write_ciphered_attribute(:password, arg)
67
  end
68

  
69
  def scm_adapter
70
    self.class.scm_adapter_class
71
  end
72

  
73
  def scm
74
    @scm ||= self.scm_adapter.new(url, root_url,
75
                                  login, password, path_encoding)
76
    update_attribute(:root_url, @scm.root_url) if root_url.blank?
77
    @scm
78
  end
79

  
80
  def scm_name
81
    self.class.scm_name
82
  end
83

  
84
  def merge_extra_info(arg)
85
    h = extra_info || {}
86
    return h if arg.nil?
87
    h.merge!(arg)
88
    write_attribute(:extra_info, h)
89
  end
90

  
91
  def report_last_commit
92
    true
93
  end
94

  
95
  def supports_cat?
96
    scm.supports_cat?
97
  end
98

  
99
  def supports_annotate?
100
    scm.supports_annotate?
101
  end
102

  
103
  def supports_all_revisions?
104
    true
105
  end
106

  
107
  def supports_directory_revisions?
108
    false
109
  end
110

  
111
  def supports_revision_graph?
112
    false
113
  end
114

  
115
  def entry(path=nil, identifier=nil)
116
    scm.entry(path, identifier)
117
  end
118

  
119
  def entries(path=nil, identifier=nil)
120
    scm.entries(path, identifier)
121
  end
122

  
123
  def branches
124
    scm.branches
125
  end
126

  
127
  def tags
128
    scm.tags
129
  end
130

  
131
  def default_branch
132
    nil
133
  end
134

  
135
  def properties(path, identifier=nil)
136
    scm.properties(path, identifier)
137
  end
138

  
139
  def cat(path, identifier=nil)
140
    scm.cat(path, identifier)
141
  end
142

  
143
  def diff(path, rev, rev_to)
144
    scm.diff(path, rev, rev_to)
145
  end
146

  
147
  def diff_format_revisions(cs, cs_to, sep=':')
148
    text = ""
149
    text << cs_to.format_identifier + sep if cs_to
150
    text << cs.format_identifier if cs
151
    text
152
  end
153

  
154
  # Returns a path relative to the url of the repository
155
  def relative_path(path)
156
    path
157
  end
158

  
159
  # Finds and returns a revision with a number or the beginning of a hash
160
  def find_changeset_by_name(name)
161
    return nil if name.blank?
162
    changesets.find(:first, :conditions => (name.match(/^\d*$/) ?
163
          ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
164
  end
165

  
166
  def latest_changeset
167
    @latest_changeset ||= changesets.find(:first)
168
  end
169

  
170
  # Returns the latest changesets for +path+
171
  # Default behaviour is to search in cached changesets
172
  def latest_changesets(path, rev, limit=10)
173
    if path.blank?
174
      changesets.find(
175
         :all,
176
         :include => :user,
177
         :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
178
         :limit => limit)
179
    else
180
      changes.find(
181
         :all,
182
         :include => {:changeset => :user},
183
         :conditions => ["path = ?", path.with_leading_slash],
184
         :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
185
         :limit => limit
186
       ).collect(&:changeset)
187
    end
188
  end
189

  
190
  def scan_changesets_for_issue_ids
191
    self.changesets.each(&:scan_comment_for_issue_ids)
192
  end
193

  
194
  # Returns an array of committers usernames and associated user_id
195
  def committers
196
    @committers ||= Changeset.connection.select_rows(
197
         "SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
198
  end
199

  
200
  # Maps committers username to a user ids
201
  def committer_ids=(h)
202
    if h.is_a?(Hash)
203
      committers.each do |committer, user_id|
204
        new_user_id = h[committer]
205
        if new_user_id && (new_user_id.to_i != user_id.to_i)
206
          new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil)
207
          Changeset.update_all(
208
               "user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }",
209
               ["repository_id = ? AND committer = ?", id, committer])
210
        end
211
      end
212
      @committers            = nil
213
      @found_committer_users = nil
214
      true
215
    else
216
      false
217
    end
218
  end
219

  
220
  # Returns the Redmine User corresponding to the given +committer+
221
  # It will return nil if the committer is not yet mapped and if no User
222
  # with the same username or email was found
223
  def find_committer_user(committer)
224
    unless committer.blank?
225
      @found_committer_users ||= {}
226
      return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
227

  
228
      user = nil
229
      c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
230
      if c && c.user
231
        user = c.user
232
      elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
233
        username, email = $1.strip, $3
234
        u = User.find_by_login(username)
235
        u ||= User.find_by_mail(email) unless email.blank?
236
        user = u
237
      end
238
      @found_committer_users[committer] = user
239
      user
240
    end
241
  end
242

  
243
  def repo_log_encoding
244
    encoding = log_encoding.to_s.strip
245
    encoding.blank? ? 'UTF-8' : encoding
246
  end
247

  
248
  # Fetches new changesets for all repositories of active projects
249
  # Can be called periodically by an external script
250
  # eg. ruby script/runner "Repository.fetch_changesets"
251
  def self.fetch_changesets
252
    Project.active.has_module(:repository).find(:all, :include => :repository).each do |project|
253
      if project.repository
254
        begin
255
          project.repository.fetch_changesets
256
        rescue Redmine::Scm::Adapters::CommandFailed => e
257
          logger.error "scm: error during fetching changesets: #{e.message}"
258
        end
259
      end
260
    end
261
  end
262

  
263
  # scan changeset comments to find related and fixed issues for all repositories
264
  def self.scan_changesets_for_issue_ids
265
    find(:all).each(&:scan_changesets_for_issue_ids)
266
  end
267

  
268
  def self.scm_name
269
    'Abstract'
270
  end
271

  
272
  def self.available_scm
273
    subclasses.collect {|klass| [klass.scm_name, klass.name]}
274
  end
275

  
276
  def self.factory(klass_name, *args)
277
    klass = "Repository::#{klass_name}".constantize
278
    klass.new(*args)
279
  rescue
280
    nil
281
  end
282

  
283
  def self.scm_adapter_class
284
    nil
285
  end
286

  
287
  def self.scm_command
288
    ret = ""
289
    begin
290
      ret = self.scm_adapter_class.client_command if self.scm_adapter_class
291
    rescue Exception => e
292
      logger.error "scm: error during get command: #{e.message}"
293
    end
294
    ret
295
  end
296

  
297
  def self.scm_version_string
298
    ret = ""
299
    begin
300
      ret = self.scm_adapter_class.client_version_string if self.scm_adapter_class
301
    rescue Exception => e
302
      logger.error "scm: error during get version string: #{e.message}"
303
    end
304
    ret
305
  end
306

  
307
  def self.scm_available
308
    ret = false
309
    begin
310
      ret = self.scm_adapter_class.client_available if self.scm_adapter_class
311
    rescue Exception => e
312
      logger.error "scm: error during get scm available: #{e.message}"
313
    end
314
    ret
315
  end
316

  
317
  private
318

  
319
  def clear_changesets
320
    cs, ch, ci = Changeset.table_name, Change.table_name, "#{table_name_prefix}changesets_issues#{table_name_suffix}"
321
    connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
322
    connection.delete("DELETE FROM #{ci} WHERE #{ci}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
323
    connection.delete("DELETE FROM #{cs} WHERE #{cs}.repository_id = #{id}")
324
  end
325
end
.svn/pristine/0b/0bc8b19a332c3f8ffc74fbaa182a97b748ff7feb.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2013  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
require File.expand_path('../../test_helper', __FILE__)
19

  
20
class WatcherTest < ActiveSupport::TestCase
21
  fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules,
22
           :issues, :issue_statuses, :enumerations, :trackers, :projects_trackers,
23
           :boards, :messages,
24
           :wikis, :wiki_pages,
25
           :watchers
26

  
27
  def setup
28
    @user = User.find(1)
29
    @issue = Issue.find(1)
30
  end
31

  
32
  def test_validate
33
    user = User.find(5)
34
    assert !user.active?
35
    watcher = Watcher.new(:user_id => user.id)
36
    assert !watcher.save
37
  end
38

  
39
  def test_watch
40
    assert @issue.add_watcher(@user)
41
    @issue.reload
42
    assert @issue.watchers.detect { |w| w.user == @user }
43
  end
44

  
45
  def test_cant_watch_twice
46
    assert @issue.add_watcher(@user)
47
    assert !@issue.add_watcher(@user)
48
  end
49

  
50
  def test_watched_by
51
    assert @issue.add_watcher(@user)
52
    @issue.reload
53
    assert @issue.watched_by?(@user)
54
    assert Issue.watched_by(@user).include?(@issue)
55
  end
56

  
57
  def test_watcher_users
58
    watcher_users = Issue.find(2).watcher_users
59
    assert_kind_of Array, watcher_users
60
    assert_kind_of User, watcher_users.first
61
  end
62

  
63
  def test_watcher_users_should_not_validate_user
64
    User.update_all("firstname = ''", "id=1")
65
    @user.reload
66
    assert !@user.valid?
67

  
68
    issue = Issue.new(:project => Project.find(1), :tracker_id => 1, :subject => "test", :author => User.find(2))
69
    issue.watcher_users << @user
70
    issue.save!
71
    assert issue.watched_by?(@user)
72
  end
73

  
74
  def test_watcher_user_ids
75
    assert_equal [1, 3], Issue.find(2).watcher_user_ids.sort
76
  end
77

  
78
  def test_watcher_user_ids=
79
    issue = Issue.new
80
    issue.watcher_user_ids = ['1', '3']
81
    assert issue.watched_by?(User.find(1))
82
  end
83

  
84
  def test_watcher_user_ids_should_make_ids_uniq
85
    issue = Issue.new(:project => Project.find(1), :tracker_id => 1, :subject => "test", :author => User.find(2))
86
    issue.watcher_user_ids = ['1', '3', '1']
87
    issue.save!
88
    assert_equal 2, issue.watchers.count
89
  end
90

  
91
  def test_addable_watcher_users
92
    addable_watcher_users = @issue.addable_watcher_users
93
    assert_kind_of Array, addable_watcher_users
94
    assert_kind_of User, addable_watcher_users.first
95
  end
96

  
97
  def test_addable_watcher_users_should_not_include_user_that_cannot_view_the_object
98
    issue = Issue.new(:project => Project.find(1), :is_private => true)
99
    assert_nil issue.addable_watcher_users.detect {|user| !issue.visible?(user)}
100
  end
101

  
102
  def test_recipients
103
    @issue.watchers.delete_all
104
    @issue.reload
105

  
106
    assert @issue.watcher_recipients.empty?
107
    assert @issue.add_watcher(@user)
108

  
109
    @user.mail_notification = 'all'
110
    @user.save!
111
    @issue.reload
112
    assert @issue.watcher_recipients.include?(@user.mail)
113

  
114
    @user.mail_notification = 'none'
115
    @user.save!
116
    @issue.reload
117
    assert !@issue.watcher_recipients.include?(@user.mail)
118
  end
119

  
120
  def test_unwatch
121
    assert @issue.add_watcher(@user)
122
    @issue.reload
123
    assert_equal 1, @issue.remove_watcher(@user)
124
  end
125

  
126
  def test_prune
127
    Watcher.delete_all("user_id = 9")
128
    user = User.find(9)
129

  
130
    # public
131
    Watcher.create!(:watchable => Issue.find(1), :user => user)
132
    Watcher.create!(:watchable => Issue.find(2), :user => user)
133
    Watcher.create!(:watchable => Message.find(1), :user => user)
134
    Watcher.create!(:watchable => Wiki.find(1), :user => user)
135
    Watcher.create!(:watchable => WikiPage.find(2), :user => user)
136

  
137
    # private project (id: 2)
138
    Member.create!(:project => Project.find(2), :principal => user, :role_ids => [1])
139
    Watcher.create!(:watchable => Issue.find(4), :user => user)
140
    Watcher.create!(:watchable => Message.find(7), :user => user)
141
    Watcher.create!(:watchable => Wiki.find(2), :user => user)
142
    Watcher.create!(:watchable => WikiPage.find(3), :user => user)
143

  
144
    assert_no_difference 'Watcher.count' do
145
      Watcher.prune(:user => User.find(9))
146
    end
147

  
148
    Member.delete_all
149

  
150
    assert_difference 'Watcher.count', -4 do
151
      Watcher.prune(:user => User.find(9))
152
    end
153

  
154
    assert Issue.find(1).watched_by?(user)
155
    assert !Issue.find(4).watched_by?(user)
156
  end
157

  
158
  def test_prune_all
159
    user = User.find(9)
160
    Watcher.new(:watchable => Issue.find(4), :user => User.find(9)).save(:validate => false)
161

  
162
    assert Watcher.prune > 0
163
    assert !Issue.find(4).watched_by?(user)
164
  end
165
end
.svn/pristine/0b/0beba908a316302bd0ca691f7555fdce76127696.svn-base
1
--- 
2
wiki_contents_001: 
3
  text: |-
4
    h1. CookBook documentation
5

  
6
    {{child_pages}}
7

  
8
    Some updated [[documentation]] here with gzipped history
9
  updated_on: 2007-03-07 00:10:51 +01:00
10
  page_id: 1
11
  id: 1
12
  version: 3
13
  author_id: 1
14
  comments: Gzip compression activated
15
wiki_contents_002: 
16
  text: |-
17
    h1. Another page
18
    
19
    This is a link to a ticket: #2
20
    And this is an included page:
21
    {{include(Page with an inline image)}}
22
  updated_on: 2007-03-08 00:18:07 +01:00
23
  page_id: 2
24
  id: 2
25
  version: 1
26
  author_id: 1
27
  comments: 
28
wiki_contents_003: 
29
  text: |-
30
    h1. Start page
31
    
32
    E-commerce web site start page
33
  updated_on: 2007-03-08 00:18:07 +01:00
34
  page_id: 3
35
  id: 3
36
  version: 1
37
  author_id: 1
38
  comments: 
39
wiki_contents_004: 
40
  text: |-
41
    h1. Page with an inline image
42
    
43
    This is an inline image:
44
    
45
    !logo.gif!
46
  updated_on: 2007-03-08 00:18:07 +01:00
47
  page_id: 4
48
  id: 4
49
  version: 1
50
  author_id: 1
51
  comments: 
52
wiki_contents_005: 
53
  text: |-
54
    h1. Child page 1
55
    
56
    This is a child page
57
  updated_on: 2007-03-08 00:18:07 +01:00
58
  page_id: 5
59
  id: 5
60
  version: 1
61
  author_id: 1
62
  comments: 
63
wiki_contents_006: 
64
  text: |-
65
    h1. Child page 2
66
    
67
    This is a child page
68
  updated_on: 2007-03-08 00:18:07 +01:00
69
  page_id: 6
70
  id: 6
71
  version: 1
72
  author_id: 1
73
  comments: 
74
wiki_contents_007: 
75
  text: This is a child page
76
  updated_on: 2007-03-08 00:18:07 +01:00
77
  page_id: 7
78
  id: 7
79
  version: 1
80
  author_id: 1
81
  comments: 
82
wiki_contents_008: 
83
  text: This is a parent page
84
  updated_on: 2007-03-08 00:18:07 +01:00
85
  page_id: 8
86
  id: 8
87
  version: 1
88
  author_id: 1
89
  comments: 
90
wiki_contents_009: 
91
  text: This is a child page
92
  updated_on: 2007-03-08 00:18:07 +01:00
93
  page_id: 9
94
  id: 9
95
  version: 1
96
  author_id: 1
97
  comments: 
98
wiki_contents_010: 
99
  text: Page with cyrillic title
100
  updated_on: 2007-03-08 00:18:07 +01:00
101
  page_id: 10
102
  id: 10
103
  version: 1
104
  author_id: 1
105
  comments: 
106
wiki_contents_011: 
107
  text: |-
108
    h1. Title
109
    
110
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
111
    
112
    h2. Heading 1
113
    
114
    @WHATEVER@
115
    
116
    Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in.
117

  
118
    Cras ipsum felis, ultrices at porttitor vel, faucibus eu nunc.
119
    
120
    h2. Heading 2
121

  
122
    Morbi facilisis accumsan orci non pharetra.
123
  updated_on: 2007-03-08 00:18:07 +01:00
124
  page_id: 11
125
  id: 11
126
  version: 3
127
  author_id: 1
128
  comments: 
129
  
.svn/pristine/0b/0bfbd6508bed6a33543df0df9a316455bb2e521a.svn-base
1
<h2><%=h @attachment.filename %></h2>
2

  
3
<div class="attachments">
4
<p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %>
5
   <span class="author"><%= link_to_user(@attachment.author) %>, <%= format_time(@attachment.created_on) %></span></p>
6
<p><%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%>
7
   <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p>
8
</div>
9
<p>
10
<% form_tag({}, :method => 'get') do %>
11
    <label><%= l(:label_view_diff) %></label>
12
    <%= select_tag 'type',
13
                    options_for_select(
14
                      [[l(:label_diff_inline), "inline"], [l(:label_diff_side_by_side), "sbs"]], @diff_type),
15
                    :onchange => "if (this.value != '') {this.form.submit()}" %>
16
<% end %>
17
</p>
18
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
19

  
20
<% html_title @attachment.filename %>
21

  
22
<% content_for :header_tags do -%>
23
    <%= stylesheet_link_tag "scm" -%>
24
<% end -%>

Also available in: Unified diff