Class: List
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- List
- Defined in:
- app/models/list.rb
Overview
COPYRIGHT:
Copyright (c) 2005-2009 North Carolina State University
Developed with funding for the National eXtension Initiative.
LICENSE:
BSD(-compatible)
see LICENSE file or view at http://about.extension.org/wiki/LICENSE
Constant Summary
- MAILMAN_TRUE =
MAILMAN TYPES
1- MAILMAN_FALSE =
0- MAILMAN_UNLIMITED =
0- MAILMAN_SUBSCRIBE_CONFIRM =
1- MAILMAN_SUBSCRIBE_MODERATE =
subscribers must confirm email admins must approve subscriptions
2- MAILMAN_SUBSCRIBE_CONFIRM_AND_MODERATE =
confirm and admin approval
3- MAILMAN_ACCEPT =
0- MAILMAN_HOLD =
1
Instance Attribute Summary (collapse)
-
- (Object) mailman_configuration(forcerefresh = false)
Returns the value of attribute mailman_configuration.
-
- (Object) mailman_invalid_members
Returns the value of attribute mailman_invalid_members.
-
- (Object) mailman_members(forcerefresh = false)
Returns the value of attribute mailman_members.
-
- (Object) mailman_owners(forcerefresh = false)
Returns the value of attribute mailman_owners.
Class Method Summary (collapse)
- + (Object) defaultoptions
- + (Object) find_announce_list
- + (Object) find_by_name_or_id(searchterm)
- + (Object) find_or_createnewlist(listoptions)
- + (Object) per_page
Instance Method Summary (collapse)
- - (Object) create_or_update_mailman_list(forceupdate = false)
- - (Object) default_mailman_configuration
-
- (Boolean) has_mailman_list?
calls mailman_members as a side effect.
- - (Boolean) is_announce_list?
- - (Object) list_subscriptions
- - (Object) set_random_password(size = 12)
- - (Object) subscriber_count
-
- (Boolean) update_mailman?
MailMan methods ———————————–.
- - (Object) update_mailman_members
Instance Attribute Details
- (Object) mailman_configuration(forcerefresh = false)
Returns the value of attribute mailman_configuration
33 34 35 |
# File 'app/models/list.rb', line 33 def mailman_configuration @mailman_configuration end |
- (Object) mailman_invalid_members
Returns the value of attribute mailman_invalid_members
33 34 35 |
# File 'app/models/list.rb', line 33 def mailman_invalid_members @mailman_invalid_members end |
- (Object) mailman_members(forcerefresh = false)
Returns the value of attribute mailman_members
33 34 35 |
# File 'app/models/list.rb', line 33 def mailman_members @mailman_members end |
- (Object) mailman_owners(forcerefresh = false)
Returns the value of attribute mailman_owners
33 34 35 |
# File 'app/models/list.rb', line 33 def mailman_owners @mailman_owners end |
Class Method Details
+ (Object) defaultoptions
104 105 106 |
# File 'app/models/list.rb', line 104 def self. return {:advertised => false, :managed => true} end |
+ (Object) find_announce_list
108 109 110 |
# File 'app/models/list.rb', line 108 def self.find_announce_list List.find_by_name(AppConfig.configtable['list-announce']) end |
+ (Object) find_by_name_or_id(searchterm)
80 81 82 83 84 85 86 |
# File 'app/models/list.rb', line 80 def self.find_by_name_or_id(searchterm) list = find_by_id(searchterm) if(list.nil?) list = find_by_name(searchterm) end return list end |
+ (Object) find_or_createnewlist(listoptions)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/list.rb', line 88 def self.find_or_createnewlist() if(.nil? or [:name].nil?) return nil end makelistname = [:name].downcase list = List.find_by_name(makelistname) if(list.nil?) = List.().merge() # force the lowercase name [:name] = makelistname list = List.create() end return list end |
+ (Object) per_page
76 77 78 |
# File 'app/models/list.rb', line 76 def self.per_page 25 end |
Instance Method Details
- (Object) create_or_update_mailman_list(forceupdate = false)
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'app/models/list.rb', line 260 def create_or_update_mailman_list(forceupdate=false) if(!self.update_mailman? and !forceupdate) return true end if(!self.has_mailman_list?) process = "#{AppConfig.configtable['mailmanpath']}/newlist -l en #{self.name} #{AppConfig.configtable['default-list-owner']} #{self.password}" proc = IO.popen(process, "w+") proc.close_write proc.close end # set default configuration self.mailman_configuration=self.default_mailman_configuration # update members return self.update_mailman_members end |
- (Object) default_mailman_configuration
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'app/models/list.rb', line 234 def default_mailman_configuration = "\"\"\"_______________________________________________\n%(real_name)s mailing list\n%(real_name)s@%(host_name)s\nhttps://www.extension.org/people/lists/%(real_name)s\n\n\"\"\"" default_configuration = Hash.new default_configuration["real_name"] = "'#{self.name}'" default_configuration["subject_prefix"] = "'[#{self.name}]'" default_configuration["msg_footer"] = default_configuration["digest_footer"] = default_configuration["send_goodbye_msg"] = MAILMAN_FALSE default_configuration["send_welcome_msg"] = MAILMAN_FALSE default_configuration["subscribe_policy"] = MAILMAN_SUBSCRIBE_CONFIRM_AND_MODERATE default_configuration["advertised"] = MAILMAN_FALSE default_configuration["send_reminders"] = MAILMAN_FALSE default_configuration["max_message_size"] = MAILMAN_UNLIMITED default_configuration["archive_private"] = MAILMAN_TRUE default_configuration["max_num_recipients"] = MAILMAN_UNLIMITED default_configuration["admin_notify_mchanges"] = MAILMAN_FALSE if(!self.name.blank? and self.name == 'announce') default_configuration["generic_nonmember_action"] = MAILMAN_HOLD else default_configuration["generic_nonmember_action"] = MAILMAN_ACCEPT end owners = ["'#{AppConfig.configtable['default-list-owner']}'"] default_configuration["owner"] = "[#{owners.uniq.join(",")}]" return default_configuration end |
- (Boolean) has_mailman_list?
calls mailman_members as a side effect
126 127 128 129 130 131 132 133 134 135 |
# File 'app/models/list.rb', line 126 def has_mailman_list? if(@has_mailman_list.nil?) if(members = self.mailman_members) @has_mailman_list = true else @has_mailman_list = false end end @has_mailman_list end |
- (Boolean) is_announce_list?
38 39 40 |
# File 'app/models/list.rb', line 38 def is_announce_list? return (self.name == AppConfig.configtable['list-announce']) end |
- (Object) list_subscriptions
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/list.rb', line 59 def list_subscriptions if(self.is_announce_list?) User.where(:announcements => true).list_eligible.map(&:email) else case connectiontype when 'leaders' self.community.leaders.list_eligible.map(&:email) when 'joined' self.community.joined.list_eligible.map(&:email) when 'interested' self.community.interested.list_eligible.map(&:email) else [] end end end |
- (Object) set_random_password(size = 12)
112 113 114 115 |
# File 'app/models/list.rb', line 112 def set_random_password(size = 12) alphanumerics = [('0'..'9'),('A'..'Z'),('a'..'z')].map {|range| range.to_a}.flatten self.password = ((0...size).map { alphanumerics[Kernel.rand(alphanumerics.size)] }.join) end |
- (Object) subscriber_count
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/list.rb', line 42 def subscriber_count if(self.is_announce_list?) User.where(:announcements => true).list_eligible.count else case connectiontype when 'leaders' self.community.leaders.list_eligible.count when 'joined' self.community.joined.list_eligible.count when 'interested' self.community.interested.list_eligible.count else 0 end end end |
- (Boolean) update_mailman?
MailMan methods
121 122 123 |
# File 'app/models/list.rb', line 121 def update_mailman? return (self.last_mailman_update.nil? or self.updated_at > self.last_mailman_update) end |
- (Object) update_mailman_members
223 224 225 226 227 228 229 230 231 232 |
# File 'app/models/list.rb', line 223 def update_mailman_members current_mailman_members = self.mailman_members subscriber_emails = self.list_subscriptions add_members = subscriber_emails - current_mailman_members remove_members = current_mailman_members - subscriber_emails self.add_mailman_members(add_members) self.remove_mailman_members(remove_members) self.touch(:last_mailman_update) return {:add_count => add_members.size, :remove_count => remove_members.size} end |