comparison app/models/.svn/text-base/role.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 8661b858af72
children
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
17 17
18 class Role < ActiveRecord::Base 18 class Role < ActiveRecord::Base
19 # Built-in roles 19 # Built-in roles
20 BUILTIN_NON_MEMBER = 1 20 BUILTIN_NON_MEMBER = 1
21 BUILTIN_ANONYMOUS = 2 21 BUILTIN_ANONYMOUS = 2
22
23 ISSUES_VISIBILITY_OPTIONS = [
24 ['all', :label_issues_visibility_all],
25 ['default', :label_issues_visibility_public],
26 ['own', :label_issues_visibility_own]
27 ]
22 28
23 named_scope :givable, { :conditions => "builtin = 0", :order => 'position' } 29 named_scope :givable, { :conditions => "builtin = 0", :order => 'position' }
24 named_scope :builtin, lambda { |*args| 30 named_scope :builtin, lambda { |*args|
25 compare = 'not' if args.first == true 31 compare = 'not' if args.first == true
26 { :conditions => "#{compare} builtin = 0" } 32 { :conditions => "#{compare} builtin = 0" }
41 attr_protected :builtin 47 attr_protected :builtin
42 48
43 validates_presence_of :name 49 validates_presence_of :name
44 validates_uniqueness_of :name 50 validates_uniqueness_of :name
45 validates_length_of :name, :maximum => 30 51 validates_length_of :name, :maximum => 30
46 52 validates_inclusion_of :issues_visibility,
53 :in => ISSUES_VISIBILITY_OPTIONS.collect(&:first),
54 :if => lambda {|role| role.respond_to?(:issues_visibility)}
55
47 def permissions 56 def permissions
48 read_attribute(:permissions) || [] 57 read_attribute(:permissions) || []
49 end 58 end
50 59
51 def permissions=(perms) 60 def permissions=(perms)
80 role ? position <=> role.position : -1 89 role ? position <=> role.position : -1
81 end 90 end
82 91
83 def to_s 92 def to_s
84 name 93 name
94 end
95
96 def name
97 case builtin
98 when 1; l(:label_role_non_member, :default => read_attribute(:name))
99 when 2; l(:label_role_anonymous, :default => read_attribute(:name))
100 else; read_attribute(:name)
101 end
85 end 102 end
86 103
87 # Return true if the role is a builtin role 104 # Return true if the role is a builtin role
88 def builtin? 105 def builtin?
89 self.builtin != 0 106 self.builtin != 0