diff options
author | Johan Sørensen <johan@johansorensen.com> | 2009-12-03 13:30:40 +0100 |
---|---|---|
committer | Johan Sørensen <johan@johansorensen.com> | 2009-12-03 13:30:40 +0100 |
commit | 5956763e544412d0ff8ebadbc472b788ab9bb373 (patch) | |
tree | d27f72bce7cbcc65e81568c1b7ebfe5f121fae7d /app/models | |
parent | a93864a18f11ca360f0073bd594b70e84e4266a3 (diff) | |
download | gitorious-mainline-outdated-5956763e544412d0ff8ebadbc472b788ab9bb373.zip gitorious-mainline-outdated-5956763e544412d0ff8ebadbc472b788ab9bb373.tar.gz gitorious-mainline-outdated-5956763e544412d0ff8ebadbc472b788ab9bb373.tar.bz2 |
Whitespace shenenigans in group.rb
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/group.rb | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index 797becb..7607c04 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -18,8 +18,8 @@ class Group < ActiveRecord::Base has_many :committerships, :as => :committer, :dependent => :destroy - has_many :participated_repositories, :through => :committerships, - :source => :repository, :class_name => 'Repository' + has_many :participated_repositories, :through => :committerships, + :source => :repository, :class_name => 'Repository' belongs_to :creator, :class_name => "User", :foreign_key => "user_id" has_many :memberships, :dependent => :destroy has_many :members, :through => :memberships, :source => :user @@ -27,31 +27,31 @@ class Group < ActiveRecord::Base Repository::KINDS_INTERNAL_REPO], :dependent => :destroy has_many :projects, :as => :owner - + attr_protected :public, :role_id, :user_id - + NAME_FORMAT = /[a-z0-9\-]+/.freeze validates_presence_of :name validates_uniqueness_of :name - validates_format_of :name, :with => /^#{NAME_FORMAT}$/, + validates_format_of :name, :with => /^#{NAME_FORMAT}$/, :message => "Must be alphanumeric, and optional dash" - + before_validation :downcase_name - + Paperclip::Attachment.interpolations['group_name'] = lambda{|attachment,style| attachment.instance.name} - + avatar_local_path = '/system/group_avatars/:group_name/:style/:basename.:extension' - has_attached_file :avatar, + has_attached_file :avatar, :default_url =>'/images/default_group_avatar.png', :styles => { :normal => "300x300>", :medium => "64x64>", :thumb => '32x32>', :icon => '16x16>' }, :url => avatar_local_path, :path => ":rails_root/public#{avatar_local_path}" - - + + def self.human_name I18n.t("activerecord.models.group") end - + def self.all_participating_in_projects(projects) mainline_ids = projects.map do |project| project.repositories.mainlines.map{|r| r.id } @@ -59,24 +59,24 @@ class Group < ActiveRecord::Base Committership.groups.find(:all, :conditions => { :repository_id => mainline_ids }).map{|c| c.committer }.uniq end - + # Finds the most active groups by activity in repositories they're committers in def self.most_active(limit = 10, cutoff = 5) Rails.cache.fetch("groups:most_active:#{limit}:#{cutoff}", :expires_in => 1.hour) do # FIXME: there's a certain element of approximation in here find(:all, :joins => [{:committerships => {:repository => :events}}], - :select => %Q{groups.*, committerships.repository_id, - repositories.id, events.id, events.target_id, events.target_type, + :select => %Q{groups.*, committerships.repository_id, + repositories.id, events.id, events.target_id, events.target_type, count(events.id) as event_count}, :group => "groups.id", - :conditions => ["committerships.repository_id = events.target_id and - events.target_type = ? AND events.created_at > ?", + :conditions => ["committerships.repository_id = events.target_id and " + + "events.target_type = ? AND events.created_at > ?", "Repository", cutoff.days.ago], :order => "event_count desc", :limit => limit) end end - + def all_related_project_ids all_project_ids = projects.map{|p| p.id } all_project_ids << repositories.map{|r| r.project_id } @@ -84,28 +84,28 @@ class Group < ActiveRecord::Base all_project_ids.flatten!.uniq! all_project_ids end - + def to_param name end - + def to_param_with_prefix "+#{to_param}" end - + def title name end - + def breadcrumb_parent nil end - + # is this +user+ a member of this group? def member?(user) members.include?(user) end - + # returns the Role of +user+ in this group def role_of_user(candidate) if !candidate || candidate == :false @@ -115,26 +115,26 @@ class Group < ActiveRecord::Base return unless membership membership.role end - + # is +candidate+ an admin in this group? def admin?(candidate) role_of_user(candidate) == Role.admin end - + # is +candidate+ a committer (or admin) in this group? def committer?(candidate) [Role.admin, Role.member].include?(role_of_user(candidate)) end - + # Adds +a_user+ as a member to this group with a role of +a_role+ def add_member(a_user, a_role) memberships.create!(:user => a_user, :role => a_role) end - + def deletable? members.count <= 1 && projects.blank? end - + protected def downcase_name name.downcase! if name |