diff --git a/mailing_lists/app/controllers/mailing_lists_controller.rb b/mailing_lists/app/controllers/mailing_lists_controller.rb index c41bcda0d..1aa3c21a6 100644 --- a/mailing_lists/app/controllers/mailing_lists_controller.rb +++ b/mailing_lists/app/controllers/mailing_lists_controller.rb @@ -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 diff --git a/mailing_lists/app/models/mailing_list.rb b/mailing_lists/app/models/mailing_list.rb index b9f9fc7af..101044677 100644 --- a/mailing_lists/app/models/mailing_list.rb +++ b/mailing_lists/app/models/mailing_list.rb @@ -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 diff --git a/mailing_lists/app/views/mailing_lists/_form.rhtml b/mailing_lists/app/views/mailing_lists/_form.rhtml index e414deb40..5daba6f52 100644 --- a/mailing_lists/app/views/mailing_lists/_form.rhtml +++ b/mailing_lists/app/views/mailing_lists/_form.rhtml @@ -6,5 +6,7 @@
<%= f.text_field :description, :size => 60, :required => true %>
<%= f.check_box :is_public %>
<%= f.select :admin_id, @project.users.collect {|p| [p.name, p.id]}, :required => true %>
+<%= f.password_field :password, :size => 25, :required => true %>
+<%= f.password_field :password_confirmation, :size => 25, :required => true %>
\ No newline at end of file diff --git a/mailing_lists/lib/mailman_wrapper.rb b/mailing_lists/lib/mailman_wrapper.rb new file mode 100644 index 000000000..fca1edcea --- /dev/null +++ b/mailing_lists/lib/mailman_wrapper.rb @@ -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 \ No newline at end of file