diff --git a/mailing_lists/app/controllers/mailing_lists_controller.rb b/mailing_lists/app/controllers/mailing_lists_controller.rb new file mode 100644 index 000000000..ff05fbea7 --- /dev/null +++ b/mailing_lists/app/controllers/mailing_lists_controller.rb @@ -0,0 +1,59 @@ +# 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. + +class MailingListsController < ApplicationController + layout 'base' + + before_filter :find_project, :authorize + + # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) + verify :method => :post, :only => [ :destroy ] + + def add + @mailing_list = MailingList.new(:project => @project, :admin => logged_in_user) + @mailing_list.attributes = params[:mailing_list] + if request.post? and @mailing_list.save + flash[:notice] = l(:notice_successful_create) + redirect_to :controller => 'projects', :action => 'settings', :tab => 'mailing-lists', :id => @project + end + end + + def edit + @mailing_list = MailingList.find(params[:id]) + if request.post? and @mailing_list.update_attributes(params[:mailing_list]) + flash[:notice] = l(:notice_successful_update) + redirect_to :controller => 'projects', :action => 'settings', :tab => 'mailing-lists', :id => @project + end + end + + def destroy + @mailing_list.destroy + redirect_to :controller => 'projects', :action => 'settings', :tab => 'mailing-lists', :id => @project + end + +private + def find_project + if params[:id] + @mailing_list = MailingList.find(params[:id]) + @project = @mailing_list.project + else + @project = Project.find(params[:project_id]) + end + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/mailing_lists/app/helpers/mailing_lists_helper.rb b/mailing_lists/app/helpers/mailing_lists_helper.rb new file mode 100644 index 000000000..bc1eb6ddc --- /dev/null +++ b/mailing_lists/app/helpers/mailing_lists_helper.rb @@ -0,0 +1,19 @@ +# 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 MailingListsHelper +end diff --git a/mailing_lists/app/models/mailing_list.rb b/mailing_lists/app/models/mailing_list.rb new file mode 100644 index 000000000..4f11cd960 --- /dev/null +++ b/mailing_lists/app/models/mailing_list.rb @@ -0,0 +1,47 @@ +# 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. + +class MailingList < ActiveRecord::Base + belongs_to :project + belongs_to :admin, :class_name => 'User', :foreign_key => 'admin_id' + + validates_presence_of :name, :description + + STATUSES = { + (STATUS_REQUESTED = 1) => :mailing_list_status_requested, + (STATUS_CREATED = 2) => :mailing_list_status_created, + (STATUS_TO_BE_DELETED = 3) => :mailing_list_status_to_be_deleted + }.freeze + + def status_name + STATUSES[self.status] + end + + # Should be called to create requested lists (from cron, for example) + # eg: ruby script/runner 'MailingList.create_requested_lists' + def self.create_requested_lists + find(:all, :conditions => ["status=?", STATUS_REQUESTED]).each do |list| + # TO DO: call wrapper to create the list + 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 + end + end +end diff --git a/mailing_lists/app/models/project.rb b/mailing_lists/app/models/project.rb index e36100dcf..3fd88bea6 100644 --- a/mailing_lists/app/models/project.rb +++ b/mailing_lists/app/models/project.rb @@ -18,6 +18,7 @@ class Project < ActiveRecord::Base has_many :versions, :dependent => :destroy, :order => "versions.effective_date DESC, versions.name DESC" has_many :members, :dependent => :delete_all, :include => :user, :conditions => "users.status=#{User::STATUS_ACTIVE}" + has_many :mailing_lists, :dependent => :destroy has_many :users, :through => :members has_many :custom_values, :dependent => :delete_all, :as => :customized has_many :issues, :dependent => :destroy, :order => "issues.created_on DESC", :include => [:status, :tracker] diff --git a/mailing_lists/app/views/layouts/mailing_lists.rhtml b/mailing_lists/app/views/layouts/mailing_lists.rhtml new file mode 100644 index 000000000..99d5a709f --- /dev/null +++ b/mailing_lists/app/views/layouts/mailing_lists.rhtml @@ -0,0 +1,17 @@ + + + + + + MailingLists: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/mailing_lists/app/views/mailing_lists/_form.rhtml b/mailing_lists/app/views/mailing_lists/_form.rhtml new file mode 100644 index 000000000..e414deb40 --- /dev/null +++ b/mailing_lists/app/views/mailing_lists/_form.rhtml @@ -0,0 +1,10 @@ +<%= error_messages_for 'mailing_list' %> + +
+ +

<%= f.text_field :name, :size => 25, :required => true %>

+

<%= 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 %>

+ +
\ No newline at end of file diff --git a/mailing_lists/app/views/mailing_lists/add.rhtml b/mailing_lists/app/views/mailing_lists/add.rhtml new file mode 100644 index 000000000..02672357f --- /dev/null +++ b/mailing_lists/app/views/mailing_lists/add.rhtml @@ -0,0 +1,6 @@ +

<%= l(:label_mailing_list_new) %>

+ +<% labelled_tabular_form_for :mailing_list, @mailing_list, :url => { :action => 'add', :project_id => @project } do |f| %> +<%= render :partial => 'form', :locals => { :f => f } %> +<%= submit_tag l(:button_create) %> +<% end %> \ No newline at end of file diff --git a/mailing_lists/app/views/mailing_lists/edit.rhtml b/mailing_lists/app/views/mailing_lists/edit.rhtml new file mode 100644 index 000000000..9e60671ff --- /dev/null +++ b/mailing_lists/app/views/mailing_lists/edit.rhtml @@ -0,0 +1,6 @@ +

<%= l(:label_mailing_list )%> <%= @mailing_list.name %>

+ +<% labelled_tabular_form_for :mailing_list, @mailing_list, :url => { :action => 'edit' } do |f| %> +<%= render :partial => 'form', :locals => { :f => f } %> +<%= submit_tag l(:button_save) %> +<% end %> \ No newline at end of file diff --git a/mailing_lists/app/views/projects/settings.rhtml b/mailing_lists/app/views/projects/settings.rhtml index d5f9fab49..4ca65a23c 100644 --- a/mailing_lists/app/views/projects/settings.rhtml +++ b/mailing_lists/app/views/projects/settings.rhtml @@ -4,6 +4,7 @@ @@ -59,6 +60,26 @@ <% end %> + +