Revision 1297:0a574315af3e .svn/pristine/0a

View differences:

.svn/pristine/0a/0a055f44f53eaf38a0291650c6688831162451af.svn-base
1
$('#message_subject').val("<%= raw escape_javascript(@subject) %>");
2
$('#message_content').val("<%= raw escape_javascript(@content) %>");
3
showAndScrollTo("reply", "message_content");
4
$('#message_content').scrollTop = $('#message_content').scrollHeight - $('#message_content').clientHeight;
.svn/pristine/0a/0a53e228ad2ca76e975fdb76cc443721ba07788d.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 Group < Principal
19
  include Redmine::SafeAttributes
20

  
21
  has_and_belongs_to_many :users, :after_add => :user_added,
22
                                  :after_remove => :user_removed
23

  
24
  acts_as_customizable
25

  
26
  validates_presence_of :lastname
27
  validates_uniqueness_of :lastname, :case_sensitive => false
28
  validates_length_of :lastname, :maximum => 30
29

  
30
  before_destroy :remove_references_before_destroy
31

  
32
  scope :sorted, order("#{table_name}.lastname ASC")
33

  
34
  safe_attributes 'name',
35
    'user_ids',
36
    'custom_field_values',
37
    'custom_fields',
38
    :if => lambda {|group, user| user.admin?}
39

  
40
  def to_s
41
    lastname.to_s
42
  end
43

  
44
  def name
45
    lastname
46
  end
47

  
48
  def name=(arg)
49
    self.lastname = arg
50
  end
51

  
52
  def user_added(user)
53
    members.each do |member|
54
      next if member.project.nil?
55
      user_member = Member.find_by_project_id_and_user_id(member.project_id, user.id) || Member.new(:project_id => member.project_id, :user_id => user.id)
56
      member.member_roles.each do |member_role|
57
        user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
58
      end
59
      user_member.save!
60
    end
61
  end
62

  
63
  def user_removed(user)
64
    members.each do |member|
65
      MemberRole.find(:all, :include => :member,
66
                            :conditions => ["#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids]).each(&:destroy)
67
    end
68
  end
69

  
70
  def self.human_attribute_name(attribute_key_name, *args)
71
    attr_name = attribute_key_name.to_s
72
    if attr_name == 'lastname'
73
      attr_name = "name"
74
    end
75
    super(attr_name, *args)
76
  end
77

  
78
  private
79

  
80
  # Removes references that are not handled by associations
81
  def remove_references_before_destroy
82
    return if self.id.nil?
83

  
84
    Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id]
85
  end
86
end
.svn/pristine/0a/0a7193067757b43aa4a973fedb71a5a6507643df.svn-base
1
--- 
2
changesets_001: 
3
  commit_date: 2007-04-11
4
  committed_on: 2007-04-11 15:14:44 +02:00
5
  revision: 1
6
  id: 100
7
  comments: My very first commit
8
  repository_id: 10
9
  committer: dlopper
10
  user_id: 3
11
changesets_002: 
12
  commit_date: 2007-04-12
13
  committed_on: 2007-04-12 15:14:44 +02:00
14
  revision: 2
15
  id: 101
16
  comments: 'This commit fixes #1, #2 and references #1 & #3'
17
  repository_id: 10
18
  committer: dlopper
19
  user_id: 3
20
changesets_003: 
21
  commit_date: 2007-04-12
22
  committed_on: 2007-04-12 15:14:44 +02:00
23
  revision: 3
24
  id: 102
25
  comments: |-
26
    A commit with wrong issue ids
27
    IssueID #666 #3
28
  repository_id: 10
29
  committer: dlopper
30
  user_id: 3
31
changesets_004: 
32
  commit_date: 2007-04-12
33
  committed_on: 2007-04-12 15:14:44 +02:00
34
  revision: 4
35
  id: 103
36
  comments: |-
37
    A commit with an issue id of an other project
38
    IssueID 4 2
39
  repository_id: 10
40
  committer: dlopper
41
  user_id: 3
42
changesets_005: 
43
  commit_date: "2007-09-10"
44
  comments: Modified one file in the folder.
45
  committed_on: 2007-09-10 19:01:08
46
  revision: "5"
47
  id: 104
48
  scmid:
49
  user_id: 3
50
  repository_id: 10
51
  committer: dlopper
52
changesets_006: 
53
  commit_date: "2007-09-10"
54
  comments: Moved helloworld.rb from / to /folder.
55
  committed_on: 2007-09-10 19:01:47
56
  revision: "6"
57
  id: 105
58
  scmid:
59
  user_id: 3
60
  repository_id: 10
61
  committer: dlopper
62
changesets_007: 
63
  commit_date: "2007-09-10"
64
  comments: Removed one file.
65
  committed_on: 2007-09-10 19:02:16
66
  revision: "7"
67
  id: 106
68
  scmid:
69
  user_id: 3
70
  repository_id: 10
71
  committer: dlopper
72
changesets_008: 
73
  commit_date: "2007-09-10"
74
  comments: |-
75
    This commits references an issue.
76
    Refs #2
77
  committed_on: 2007-09-10 19:04:35
78
  revision: "8"
79
  id: 107
80
  scmid:
81
  user_id: 3
82
  repository_id: 10
83
  committer: dlopper
84
changesets_009: 
85
  commit_date: "2009-09-10"
86
  comments: One file added.
87
  committed_on: 2009-09-10 19:04:35
88
  revision: "9"
89
  id: 108
90
  scmid:
91
  user_id: 3
92
  repository_id: 10
93
  committer: dlopper
94
changesets_010: 
95
  commit_date: "2009-09-10"
96
  comments: Same file modified.
97
  committed_on: 2009-09-10 19:04:35
98
  revision: "10"
99
  id: 109
100
  scmid:
101
  user_id: 3
102
  repository_id: 10
103
  committer: dlopper
.svn/pristine/0a/0ac45c1808f5ee15f2487069dcbe64385e65e79f.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 Tracker < ActiveRecord::Base
19

  
20
  CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject description priority_id is_private).freeze
21
  # Fields that can be disabled
22
  # Other (future) fields should be appended, not inserted!
23
  CORE_FIELDS = %w(assigned_to_id category_id fixed_version_id parent_issue_id start_date due_date estimated_hours done_ratio).freeze
24
  CORE_FIELDS_ALL = (CORE_FIELDS_UNDISABLABLE + CORE_FIELDS).freeze
25

  
26
  before_destroy :check_integrity
27
  has_many :issues
28
  has_many :workflow_rules, :dependent => :delete_all do
29
    def copy(source_tracker)
30
      WorkflowRule.copy(source_tracker, nil, proxy_association.owner, nil)
31
    end
32
  end
33

  
34
  has_and_belongs_to_many :projects
35
  has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
36
  acts_as_list
37

  
38
  attr_protected :field_bits
39

  
40
  validates_presence_of :name
41
  validates_uniqueness_of :name
42
  validates_length_of :name, :maximum => 30
43

  
44
  scope :sorted, order("#{table_name}.position ASC")
45
  scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
46

  
47
  def to_s; name end
48

  
49
  def <=>(tracker)
50
    position <=> tracker.position
51
  end
52

  
53
  # Returns an array of IssueStatus that are used
54
  # in the tracker's workflows
55
  def issue_statuses
56
    if @issue_statuses
57
      return @issue_statuses
58
    elsif new_record?
59
      return []
60
    end
61

  
62
    ids = WorkflowTransition.
63
            connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{WorkflowTransition.table_name} WHERE tracker_id = #{id} AND type = 'WorkflowTransition'").
64
            flatten.
65
            uniq
66

  
67
    @issue_statuses = IssueStatus.find_all_by_id(ids).sort
68
  end
69

  
70
  def disabled_core_fields
71
    i = -1
72
    @disabled_core_fields ||= CORE_FIELDS.select { i += 1; (fields_bits || 0) & (2 ** i) != 0}
73
  end
74

  
75
  def core_fields
76
    CORE_FIELDS - disabled_core_fields
77
  end
78

  
79
  def core_fields=(fields)
80
    raise ArgumentError.new("Tracker.core_fields takes an array") unless fields.is_a?(Array)
81

  
82
    bits = 0
83
    CORE_FIELDS.each_with_index do |field, i|
84
      unless fields.include?(field)
85
        bits |= 2 ** i
86
      end
87
    end
88
    self.fields_bits = bits
89
    @disabled_core_fields = nil
90
    core_fields
91
  end
92

  
93
  # Returns the fields that are disabled for all the given trackers
94
  def self.disabled_core_fields(trackers)
95
    if trackers.present?
96
      trackers.uniq.map(&:disabled_core_fields).reduce(:&)
97
    else
98
      []
99
    end
100
  end
101

  
102
  # Returns the fields that are enabled for one tracker at least
103
  def self.core_fields(trackers)
104
    if trackers.present?
105
      trackers.uniq.map(&:core_fields).reduce(:|)
106
    else
107
      CORE_FIELDS.dup
108
    end
109
  end
110

  
111
private
112
  def check_integrity
113
    raise Exception.new("Can't delete tracker") if Issue.where(:tracker_id => self.id).any?
114
  end
115
end

Also available in: Unified diff