1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-14 13:08:14 +00:00

added mailman wrapper for creating/deleting lists

git-svn-id: http://redmine.rubyforge.org/svn/branches/work@267 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-02-25 16:37:06 +00:00
parent 9b43057aa8
commit 512fd3f604
4 changed files with 51 additions and 6 deletions

View File

@ -57,7 +57,7 @@ class MailingListsController < ApplicationController
end
def destroy
@mailing_list.destroy
@mailing_list.update_attribute :status, MailingList::STATUS_TO_BE_DELETED
redirect_to :controller => 'projects', :action => 'settings', :tab => 'mailing-lists', :id => @project
end

View File

@ -15,12 +15,15 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'mailman_wrapper'
class MailingList < ActiveRecord::Base
belongs_to :project
belongs_to :admin, :class_name => 'User', :foreign_key => 'admin_id'
has_many :messages, :class_name => 'MailingMessage', :dependent => :delete_all
validates_presence_of :name, :description
validates_presence_of :name, :description, :password
validates_confirmation_of :password
STATUSES = {
(STATUS_REQUESTED = 1) => :mailing_list_status_requested,
@ -32,17 +35,27 @@ class MailingList < ActiveRecord::Base
STATUSES[self.status]
end
# Should be called to create requested lists (from cron, for example)
# eg: ruby script/runner 'MailingList.create_requested_lists'
# Should be called to create requested lists and destroy unwanted ones
# From cron, for example:
# ruby script/runner 'MailingList.create_and_destroy_lists'
def self.create_and_destroy_lists
self.create_requested_lists
self.destroy_unwanted_lists
end
def self.create_requested_lists
find(:all, :conditions => ["status=?", STATUS_REQUESTED]).each do |list|
# TO DO: call wrapper to create the list
if MailmanWrapper::create_list(list)
list.update_attribute(:status, STATUS_CREATED)
end
end
end
def self.destroy_unwanted_lists
find(:all, :conditions => ["status=?", STATUS_TO_BE_DELETED]).each do |list|
# TO DO: call wrapper to delete the list
if MailmanWrapper::destroy_list(list)
list.destroy
end
end
end
end

View File

@ -6,5 +6,7 @@
<p><%= f.text_field :description, :size => 60, :required => true %></p>
<p><%= f.check_box :is_public %></p>
<p><%= f.select :admin_id, @project.users.collect {|p| [p.name, p.id]}, :required => true %></p>
<p><%= f.password_field :password, :size => 25, :required => true %></p>
<p><%= f.password_field :password_confirmation, :size => 25, :required => true %></p>
<!--[eoform:mailing_list]-->
</div>

View File

@ -0,0 +1,30 @@
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module MailmanWrapper
def self.create_list(list)
cmd = "newlist #{list.name} #{list.admin.mail} #{list.password}"
puts "Shelling out: #{cmd}"
system(cmd) && $? && $?.exitstatus == 0 ? true : false
end
def self.destroy_list(list)
cmd = "rmlist #{list.name}"
puts "Shelling out: #{cmd}"
system(cmd) && $? && $?.exitstatus == 0 ? true : false
end
end