Mercurial > hg > soundsoftware-site
comparison app/models/.svn/text-base/role.rb.svn-base @ 514:7eba09d624db live
Merge
author | Chris Cannam |
---|---|
date | Thu, 14 Jul 2011 10:50:53 +0100 |
parents | cbce1fd3b1b7 |
children |
comparison
equal
deleted
inserted
replaced
512:b9aebdd7dd40 | 514:7eba09d624db |
---|---|
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 validates_format_of :name, :with => /^[\w\s\'\-]*$/i | 52 validates_inclusion_of :issues_visibility, |
47 | 53 :in => ISSUES_VISIBILITY_OPTIONS.collect(&:first), |
54 :if => lambda {|role| role.respond_to?(:issues_visibility)} | |
55 | |
48 def permissions | 56 def permissions |
49 read_attribute(:permissions) || [] | 57 read_attribute(:permissions) || [] |
50 end | 58 end |
51 | 59 |
52 def permissions=(perms) | 60 def permissions=(perms) |
81 role ? position <=> role.position : -1 | 89 role ? position <=> role.position : -1 |
82 end | 90 end |
83 | 91 |
84 def to_s | 92 def to_s |
85 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 | |
86 end | 102 end |
87 | 103 |
88 # Return true if the role is a builtin role | 104 # Return true if the role is a builtin role |
89 def builtin? | 105 def builtin? |
90 self.builtin != 0 | 106 self.builtin != 0 |