@@ -1,6 +1,23 | |||
|
1 | # redMine - project management software | |
|
2 | # Copyright (C) 2006 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 | ||
|
1 | 18 | class Comment < ActiveRecord::Base |
|
2 | 19 | belongs_to :commented, :polymorphic => true, :counter_cache => true |
|
3 | 20 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
4 | 21 | |
|
5 | 22 | validates_presence_of :commented, :author, :comment |
|
6 | 23 | end |
@@ -1,43 +1,43 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class CustomField < ActiveRecord::Base |
|
19 |
has_many :custom_values, :dependent => t |
|
|
19 | has_many :custom_values, :dependent => :delete_all | |
|
20 | 20 | |
|
21 | 21 | FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 }, |
|
22 | 22 | "text" => { :name => :label_text, :order => 2 }, |
|
23 | 23 | "int" => { :name => :label_integer, :order => 3 }, |
|
24 | 24 | "list" => { :name => :label_list, :order => 4 }, |
|
25 | 25 | "date" => { :name => :label_date, :order => 5 }, |
|
26 | 26 | "bool" => { :name => :label_boolean, :order => 6 } |
|
27 | 27 | }.freeze |
|
28 | 28 | |
|
29 | 29 | validates_presence_of :name, :field_format |
|
30 | 30 | validates_uniqueness_of :name |
|
31 | 31 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
32 | 32 | validates_inclusion_of :field_format, :in => FIELD_FORMATS.keys |
|
33 | 33 | validates_presence_of :possible_values, :if => Proc.new { |field| field.field_format == "list" } |
|
34 | 34 | |
|
35 | 35 | # to move in project_custom_field |
|
36 | 36 | def self.for_all |
|
37 | 37 | find(:all, :conditions => ["is_for_all=?", true]) |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def type_name |
|
41 | 41 | nil |
|
42 | 42 | end |
|
43 | 43 | end |
@@ -1,24 +1,24 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Document < ActiveRecord::Base |
|
19 | 19 | belongs_to :project |
|
20 | 20 | belongs_to :category, :class_name => "Enumeration", :foreign_key => "category_id" |
|
21 |
has_many :attachments, :as => :container, :dependent => |
|
|
21 | has_many :attachments, :as => :container, :dependent => :destroy | |
|
22 | 22 | |
|
23 | 23 | validates_presence_of :project, :title, :category |
|
24 | 24 | end |
@@ -1,103 +1,102 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Issue < ActiveRecord::Base |
|
19 | 19 | |
|
20 | 20 | belongs_to :project |
|
21 | 21 | belongs_to :tracker |
|
22 | 22 | belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' |
|
23 | 23 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
24 | 24 | belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id' |
|
25 | 25 | belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id' |
|
26 | 26 | belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id' |
|
27 | 27 | belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id' |
|
28 | 28 | |
|
29 | #has_many :histories, :class_name => 'IssueHistory', :dependent => true, :order => "issue_histories.created_on DESC", :include => :status | |
|
30 |
has_many : |
|
|
31 | has_many :attachments, :as => :container, :dependent => true | |
|
29 | has_many :journals, :as => :journalized, :dependent => :destroy | |
|
30 | has_many :attachments, :as => :container, :dependent => :destroy | |
|
32 | 31 | |
|
33 |
has_many :custom_values, :dependent => t |
|
|
32 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
|
34 | 33 | has_many :custom_fields, :through => :custom_values |
|
35 | 34 | |
|
36 | 35 | validates_presence_of :subject, :description, :priority, :tracker, :author, :status |
|
37 | 36 | validates_inclusion_of :done_ratio, :in => 0..100 |
|
38 | 37 | validates_associated :custom_values, :on => :update |
|
39 | 38 | |
|
40 | 39 | # set default status for new issues |
|
41 | 40 | def before_validation |
|
42 | 41 | self.status = IssueStatus.default if new_record? |
|
43 | 42 | end |
|
44 | 43 | |
|
45 | 44 | def validate |
|
46 | 45 | if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? |
|
47 | 46 | errors.add :due_date, :activerecord_error_not_a_date |
|
48 | 47 | end |
|
49 | 48 | |
|
50 | 49 | if self.due_date and self.start_date and self.due_date < self.start_date |
|
51 | 50 | errors.add :due_date, :activerecord_error_greater_than_start_date |
|
52 | 51 | end |
|
53 | 52 | end |
|
54 | 53 | |
|
55 | 54 | #def before_create |
|
56 | 55 | # build_history |
|
57 | 56 | #end |
|
58 | 57 | |
|
59 | 58 | def before_save |
|
60 | 59 | if @current_journal |
|
61 | 60 | # attributes changes |
|
62 | 61 | (Issue.column_names - %w(id description)).each {|c| |
|
63 | 62 | @current_journal.details << JournalDetail.new(:property => 'attr', |
|
64 | 63 | :prop_key => c, |
|
65 | 64 | :old_value => @issue_before_change.send(c), |
|
66 | 65 | :value => send(c)) unless send(c)==@issue_before_change.send(c) |
|
67 | 66 | } |
|
68 | 67 | # custom fields changes |
|
69 | 68 | custom_values.each {|c| |
|
70 | 69 | @current_journal.details << JournalDetail.new(:property => 'cf', |
|
71 | 70 | :prop_key => c.custom_field_id, |
|
72 | 71 | :old_value => @custom_values_before_change[c.custom_field_id], |
|
73 | 72 | :value => c.value) unless @custom_values_before_change[c.custom_field_id]==c.value |
|
74 | 73 | } |
|
75 | 74 | @current_journal.save unless @current_journal.details.empty? and @current_journal.notes.empty? |
|
76 | 75 | end |
|
77 | 76 | end |
|
78 | 77 | |
|
79 | 78 | def long_id |
|
80 | 79 | "%05d" % self.id |
|
81 | 80 | end |
|
82 | 81 | |
|
83 | 82 | def custom_value_for(custom_field) |
|
84 | 83 | self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id } |
|
85 | 84 | return nil |
|
86 | 85 | end |
|
87 | 86 | |
|
88 | 87 | def init_journal(user, notes = "") |
|
89 | 88 | @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) |
|
90 | 89 | @issue_before_change = self.clone |
|
91 | 90 | @custom_values_before_change = {} |
|
92 | 91 | self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } |
|
93 | 92 | @current_journal |
|
94 | 93 | end |
|
95 | 94 | |
|
96 | 95 | private |
|
97 | 96 | # Creates an history for the issue |
|
98 | 97 | #def build_history |
|
99 | 98 | # @history = self.histories.build |
|
100 | 99 | # @history.status = self.status |
|
101 | 100 | # @history.author = self.author |
|
102 | 101 | #end |
|
103 | 102 | end |
@@ -1,22 +1,22 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Journal < ActiveRecord::Base |
|
19 | 19 | belongs_to :journalized, :polymorphic => true |
|
20 | 20 | belongs_to :user |
|
21 |
has_many :details, :class_name => "JournalDetail", :dependent => t |
|
|
21 | has_many :details, :class_name => "JournalDetail", :dependent => :delete_all | |
|
22 | 22 | end |
@@ -1,29 +1,29 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class News < ActiveRecord::Base |
|
19 | 19 | belongs_to :project |
|
20 | 20 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
21 |
has_many :comments, :as => :commented, :dependent => t |
|
|
21 | has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on" | |
|
22 | 22 | |
|
23 | 23 | validates_presence_of :title, :description |
|
24 | 24 | |
|
25 | 25 | # returns last created news |
|
26 | 26 | def self.latest |
|
27 | 27 | find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC") |
|
28 | 28 | end |
|
29 | 29 | end |
@@ -1,61 +1,61 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Project < ActiveRecord::Base |
|
19 |
has_many :versions, :dependent => |
|
|
20 |
has_many :members, :dependent => t |
|
|
19 | has_many :versions, :dependent => :destroy, :order => "versions.effective_date DESC, versions.name DESC" | |
|
20 | has_many :members, :dependent => :delete_all, :include => :user, :conditions => "users.status=#{User::STATUS_ACTIVE}" | |
|
21 | 21 | has_many :users, :through => :members |
|
22 |
has_many :custom_values, :dependent => t |
|
|
23 |
has_many :issues, :dependent => |
|
|
24 |
has_many :queries, :dependent => t |
|
|
25 |
has_many :documents, :dependent => |
|
|
26 |
has_many :news, :dependent => t |
|
|
27 |
has_many :issue_categories, :dependent => t |
|
|
28 |
has_one :repository, :dependent => |
|
|
22 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
|
23 | has_many :issues, :dependent => :destroy, :order => "issues.created_on DESC", :include => [:status, :tracker] | |
|
24 | has_many :queries, :dependent => :delete_all | |
|
25 | has_many :documents, :dependent => :destroy | |
|
26 | has_many :news, :dependent => :delete_all, :include => :author | |
|
27 | has_many :issue_categories, :dependent => :delete_all, :order => "issue_categories.name" | |
|
28 | has_one :repository, :dependent => :destroy | |
|
29 | 29 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => 'custom_fields_projects', :association_foreign_key => 'custom_field_id' |
|
30 | 30 | acts_as_tree :order => "name", :counter_cache => true |
|
31 | 31 | |
|
32 | 32 | validates_presence_of :name, :description |
|
33 | 33 | validates_uniqueness_of :name |
|
34 | 34 | validates_associated :custom_values, :on => :update |
|
35 | 35 | validates_associated :repository |
|
36 | 36 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
37 | 37 | |
|
38 | 38 | # returns 5 last created projects |
|
39 | 39 | def self.latest |
|
40 | 40 | find(:all, :limit => 5, :order => "created_on DESC") |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | # Returns an array of all custom fields enabled for project issues |
|
44 | 44 | # (explictly associated custom fields and custom fields enabled for all projects) |
|
45 | 45 | def custom_fields_for_issues(tracker) |
|
46 | 46 | tracker.custom_fields.find(:all, :include => :projects, |
|
47 | 47 | :conditions => ["is_for_all=? or project_id=?", true, self.id]) |
|
48 | 48 | #(CustomField.for_all + custom_fields).uniq |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | def all_custom_fields |
|
52 | 52 | @all_custom_fields ||= IssueCustomField.find(:all, :include => :projects, |
|
53 | 53 | :conditions => ["is_for_all=? or project_id=?", true, self.id]) |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | protected |
|
57 | 57 | def validate |
|
58 | 58 | errors.add(parent_id, " must be a root project") if parent and parent.parent |
|
59 | 59 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and projects_count > 0 |
|
60 | 60 | end |
|
61 | 61 | end |
@@ -1,32 +1,32 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Role < ActiveRecord::Base |
|
19 | 19 | before_destroy :check_integrity |
|
20 | 20 | has_and_belongs_to_many :permissions |
|
21 |
has_many :workflows, :dependent => t |
|
|
21 | has_many :workflows, :dependent => :delete_all | |
|
22 | 22 | has_many :members |
|
23 | 23 | |
|
24 | 24 | validates_presence_of :name |
|
25 | 25 | validates_uniqueness_of :name |
|
26 | 26 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
27 | 27 | |
|
28 | 28 | private |
|
29 | 29 | def check_integrity |
|
30 | 30 | raise "Can't delete role" if Member.find(:first, :conditions =>["role_id=?", self.id]) |
|
31 | 31 | end |
|
32 | 32 | end |
@@ -1,32 +1,32 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Tracker < ActiveRecord::Base |
|
19 | 19 | before_destroy :check_integrity |
|
20 | 20 | has_many :issues |
|
21 |
has_many :workflows, :dependent => t |
|
|
21 | has_many :workflows, :dependent => :delete_all | |
|
22 | 22 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => 'custom_fields_trackers', :association_foreign_key => 'custom_field_id' |
|
23 | 23 | |
|
24 | 24 | validates_presence_of :name |
|
25 | 25 | validates_uniqueness_of :name |
|
26 | 26 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
27 | 27 | |
|
28 | 28 | private |
|
29 | 29 | def check_integrity |
|
30 | 30 | raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) |
|
31 | 31 | end |
|
32 | 32 | end |
@@ -1,130 +1,130 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require "digest/sha1" |
|
19 | 19 | |
|
20 | 20 | class User < ActiveRecord::Base |
|
21 |
has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :dependent => t |
|
|
21 | has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :dependent => :delete_all | |
|
22 | 22 | has_many :projects, :through => :memberships |
|
23 |
has_many :custom_values, :dependent => t |
|
|
24 |
has_one :preference, :dependent => |
|
|
23 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
|
24 | has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' | |
|
25 | 25 | belongs_to :auth_source |
|
26 | 26 | |
|
27 | 27 | attr_accessor :password, :password_confirmation |
|
28 | 28 | attr_accessor :last_before_login_on |
|
29 | 29 | # Prevents unauthorized assignments |
|
30 | 30 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password |
|
31 | 31 | |
|
32 | 32 | validates_presence_of :login, :firstname, :lastname, :mail |
|
33 | 33 | validates_uniqueness_of :login, :mail |
|
34 | 34 | # Login must contain lettres, numbers, underscores only |
|
35 | 35 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i |
|
36 | 36 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i |
|
37 | 37 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i |
|
38 | 38 | # Password length between 4 and 12 |
|
39 | 39 | validates_length_of :password, :in => 4..12, :allow_nil => true |
|
40 | 40 | validates_confirmation_of :password, :allow_nil => true |
|
41 | 41 | validates_associated :custom_values, :on => :update |
|
42 | 42 | |
|
43 | 43 | # Account statuses |
|
44 | 44 | STATUS_ACTIVE = 1 |
|
45 | 45 | STATUS_REGISTERED = 2 |
|
46 | 46 | STATUS_LOCKED = 3 |
|
47 | 47 | |
|
48 | 48 | def before_save |
|
49 | 49 | # update hashed_password if password was set |
|
50 | 50 | self.hashed_password = User.hash_password(self.password) if self.password |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | # Returns the user that matches provided login and password, or nil |
|
54 | 54 | def self.try_to_login(login, password) |
|
55 | 55 | user = find(:first, :conditions => ["login=?", login]) |
|
56 | 56 | if user |
|
57 | 57 | # user is already in local database |
|
58 | 58 | return nil if !user.active? |
|
59 | 59 | if user.auth_source |
|
60 | 60 | # user has an external authentication method |
|
61 | 61 | return nil unless user.auth_source.authenticate(login, password) |
|
62 | 62 | else |
|
63 | 63 | # authentication with local password |
|
64 | 64 | return nil unless User.hash_password(password) == user.hashed_password |
|
65 | 65 | end |
|
66 | 66 | else |
|
67 | 67 | # user is not yet registered, try to authenticate with available sources |
|
68 | 68 | attrs = AuthSource.authenticate(login, password) |
|
69 | 69 | if attrs |
|
70 | 70 | onthefly = new(*attrs) |
|
71 | 71 | onthefly.login = login |
|
72 | 72 | onthefly.language = $RDM_DEFAULT_LANG |
|
73 | 73 | if onthefly.save |
|
74 | 74 | user = find(:first, :conditions => ["login=?", login]) |
|
75 | 75 | logger.info("User '#{user.login}' created on the fly.") if logger |
|
76 | 76 | end |
|
77 | 77 | end |
|
78 | 78 | end |
|
79 | 79 | user.update_attribute(:last_login_on, Time.now) if user |
|
80 | 80 | user |
|
81 | 81 | |
|
82 | 82 | rescue => text |
|
83 | 83 | raise text |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | # Return user's full name for display |
|
87 | 87 | def display_name |
|
88 | 88 | firstname + " " + lastname |
|
89 | 89 | end |
|
90 | 90 | |
|
91 | 91 | def name |
|
92 | 92 | display_name |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def active? |
|
96 | 96 | self.status == STATUS_ACTIVE |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | def registered? |
|
100 | 100 | self.status == STATUS_REGISTERED |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | def locked? |
|
104 | 104 | self.status == STATUS_LOCKED |
|
105 | 105 | end |
|
106 | 106 | |
|
107 | 107 | def check_password?(clear_password) |
|
108 | 108 | User.hash_password(clear_password) == self.hashed_password |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def role_for_project(project_id) |
|
112 | 112 | @role_for_projects ||= |
|
113 | 113 | begin |
|
114 | 114 | roles = {} |
|
115 | 115 | self.memberships.each { |m| roles.store m.project_id, m.role_id } |
|
116 | 116 | roles |
|
117 | 117 | end |
|
118 | 118 | @role_for_projects[project_id] |
|
119 | 119 | end |
|
120 | 120 | |
|
121 | 121 | def pref |
|
122 | 122 | self.preference ||= UserPreference.new(:user => self) |
|
123 | 123 | end |
|
124 | 124 | |
|
125 | 125 | private |
|
126 | 126 | # Return password digest |
|
127 | 127 | def self.hash_password(clear_password) |
|
128 | 128 | Digest::SHA1.hexdigest(clear_password || "") |
|
129 | 129 | end |
|
130 | 130 | end |
@@ -1,32 +1,32 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Version < ActiveRecord::Base |
|
19 | 19 | before_destroy :check_integrity |
|
20 | 20 | belongs_to :project |
|
21 | 21 | has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id' |
|
22 |
has_many :attachments, :as => :container, :dependent => |
|
|
22 | has_many :attachments, :as => :container, :dependent => :destroy | |
|
23 | 23 | |
|
24 | 24 | validates_presence_of :name |
|
25 | 25 | validates_uniqueness_of :name, :scope => [:project_id] |
|
26 | 26 | validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date |
|
27 | 27 | |
|
28 | 28 | private |
|
29 | 29 | def check_integrity |
|
30 | 30 | raise "Can't delete version" if self.fixed_issues.find(:first) |
|
31 | 31 | end |
|
32 | 32 | end |
General Comments 0
You need to be logged in to leave comments.
Login now