mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-20 15:31:12 +00:00
shorten long line of app/models/project.rb
git-svn-id: http://svn.redmine.org/redmine/trunk@20639 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
690135e1c5
commit
fd112cb766
@ -64,25 +64,31 @@ class Project < ActiveRecord::Base
|
|||||||
:delete_permission => :manage_files
|
:delete_permission => :manage_files
|
||||||
|
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
acts_as_searchable :columns => ['name', 'identifier', 'description'], :project_key => "#{Project.table_name}.id", :permission => nil
|
acts_as_searchable :columns => ['name', 'identifier', 'description'],
|
||||||
acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
|
:project_key => "#{Project.table_name}.id",
|
||||||
:url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}},
|
:permission => nil
|
||||||
|
acts_as_event :title => proc {|o| "#{l(:label_project)}: #{o.name}"},
|
||||||
|
:url => proc {|o| {:controller => 'projects', :action => 'show', :id => o}},
|
||||||
:author => nil
|
:author => nil
|
||||||
|
|
||||||
validates_presence_of :name, :identifier
|
validates_presence_of :name, :identifier
|
||||||
validates_uniqueness_of :identifier, :if => Proc.new {|p| p.identifier_changed?}
|
validates_uniqueness_of :identifier, :if => proc {|p| p.identifier_changed?}
|
||||||
validates_length_of :name, :maximum => 255
|
validates_length_of :name, :maximum => 255
|
||||||
validates_length_of :homepage, :maximum => 255
|
validates_length_of :homepage, :maximum => 255
|
||||||
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH
|
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH
|
||||||
# downcase letters, digits, dashes but not digits only
|
# downcase letters, digits, dashes but not digits only
|
||||||
validates_format_of :identifier, :with => /\A(?!\d+$)[a-z0-9\-_]*\z/, :if => Proc.new {|p| p.identifier_changed?}
|
validates_format_of :identifier, :with => /\A(?!\d+$)[a-z0-9\-_]*\z/,
|
||||||
|
:if => proc {|p| p.identifier_changed?}
|
||||||
# reserved words
|
# reserved words
|
||||||
validates_exclusion_of :identifier, :in => %w(new)
|
validates_exclusion_of :identifier, :in => %w(new)
|
||||||
validate :validate_parent
|
validate :validate_parent
|
||||||
|
|
||||||
after_save :update_inherited_members, :if => Proc.new {|project| project.saved_change_to_inherit_members?}
|
after_save :update_inherited_members,
|
||||||
after_save :remove_inherited_member_roles, :add_inherited_member_roles, :if => Proc.new {|project| project.saved_change_to_parent_id?}
|
:if => proc {|project| project.saved_change_to_inherit_members?}
|
||||||
after_update :update_versions_from_hierarchy_change, :if => Proc.new {|project| project.saved_change_to_parent_id?}
|
after_save :remove_inherited_member_roles, :add_inherited_member_roles,
|
||||||
|
:if => proc {|project| project.saved_change_to_parent_id?}
|
||||||
|
after_update :update_versions_from_hierarchy_change,
|
||||||
|
:if => proc {|project| project.saved_change_to_parent_id?}
|
||||||
before_destroy :delete_all_members
|
before_destroy :delete_all_members
|
||||||
|
|
||||||
scope :has_module, (lambda do |mod|
|
scope :has_module, (lambda do |mod|
|
||||||
@ -240,11 +246,13 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def principals
|
def principals
|
||||||
@principals ||= Principal.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
|
@principals ||=
|
||||||
|
Principal.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
|
||||||
end
|
end
|
||||||
|
|
||||||
def users
|
def users
|
||||||
@users ||= User.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
|
@users ||=
|
||||||
|
User.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the Systemwide and project specific activities
|
# Returns the Systemwide and project specific activities
|
||||||
@ -1253,7 +1261,12 @@ class Project < ActiveRecord::Base
|
|||||||
|
|
||||||
def allowed_permissions
|
def allowed_permissions
|
||||||
@allowed_permissions ||= begin
|
@allowed_permissions ||= begin
|
||||||
module_names = enabled_modules.loaded? ? enabled_modules.map(&:name) : enabled_modules.pluck(:name)
|
module_names =
|
||||||
|
if enabled_modules.loaded?
|
||||||
|
enabled_modules.map(&:name)
|
||||||
|
else
|
||||||
|
enabled_modules.pluck(:name)
|
||||||
|
end
|
||||||
Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
|
Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user