Class: Group

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/group.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_retrieval_methods(classname) ⇒ Object

we can’t has_many through the polymorphic permission relationship, so this is called from has_groups and for eg. Page, it defines: Permission.for_pages named_scope Group.page_permissions => set of permission objects Group.pages => set of page objects



116
117
118
119
120
121
122
123
124
# File 'app/models/group.rb', line 116

def self.define_retrieval_methods(classname)
  type_scope = "for_#{classname.downcase.pluralize}".intern
  Permission.send :named_scope, type_scope, :conditions => { :permitted_type => classname }
  define_method("#{classname.downcase}_permissions") { self.permissions.send type_scope }
  define_method("#{classname.downcase.pluralize}") {
    ids = self.send("#{classname.to_s.downcase}_permissions".intern).map(&:permitted_id)
    classname.constantize.find_these(ids)
  }
end

.visible_to(reader = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/group.rb', line 61

def self.visible_to(reader=nil)
  case Radiant.config['reader.directory_visibility']
  when 'public'
    self.all
  when 'private'
    reader ? self.all : self.none
  when 'grouped'
    (reader && reader.is_grouped?) ? reader.groups : self.none
  else
    self.none
  end
end

Instance Method Details

#admit(reader) ⇒ Object



98
99
100
# File 'app/models/group.rb', line 98

def admit(reader)
  self.readers << reader
end

#filenameObject



86
87
88
# File 'app/models/group.rb', line 86

def filename
  name.downcase.gsub(/\W/, '_')
end

#membersObject



78
79
80
# File 'app/models/group.rb', line 78

def members
  readers
end

#membership_for(reader) ⇒ Object



106
107
108
# File 'app/models/group.rb', line 106

def membership_for(reader)
  self.memberships.for(reader).first
end

#permission_for(object) ⇒ Object



102
103
104
# File 'app/models/group.rb', line 102

def permission_for(object)
  self.permissions.for(object).first
end

#send_welcome_to(reader) ⇒ Object



90
91
92
93
94
95
96
# File 'app/models/group.rb', line 90

def send_welcome_to(reader)
  if reader.activated?                                                             # welcomes are also triggered on activation
    if message = Message.belonging_to(self).for_function('group_welcome').first    # only if a group_welcome message exists *belonging to this group*
      message.deliver_to(reader)
    end
  end
end

#urlObject



82
83
84
# File 'app/models/group.rb', line 82

def url
  homepage.url if homepage
end

#visible_to?(reader = nil) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/models/group.rb', line 74

def visible_to?(reader=nil)
  self.class.visible_to(reader).map(&:id).include? self.id
end