added mailing_list model and controller
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@264 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
94e6de465c
commit
73e822834d
13 files changed
+300
No files matched your search
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
class Project < ActiveRecord::Base
|
class Project < ActiveRecord::Base
|
||||||
has_many :versions, :dependent => :destroy, :order => "versions.effective_date DESC, versions.name DESC"
|
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 :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 :users, :through => :members
|
||||||
has_many :custom_values, :dependent => :delete_all, :as => :customized
|
has_many :custom_values, :dependent => :delete_all, :as => :customized
|
||||||
has_many :issues, :dependent => :destroy, :order => "issues.created_on DESC", :include => [:status, :tracker]
|
has_many :issues, :dependent => :destroy, :order => "issues.created_on DESC", :include => [:status, :tracker]
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||||
|
<title>MailingLists: <%= controller.action_name %></title>
|
||||||
|
<%= stylesheet_link_tag 'scaffold' %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p style="color: green"><%= flash[:notice] %></p>
|
||||||
|
|
||||||
|
<%= yield %>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<%= error_messages_for 'mailing_list' %>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<!--[form:mailing_list]-->
|
||||||
|
<p><%= f.text_field :name, :size => 25, :required => true %></p>
|
||||||
|
<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>
|
||||||
|
<!--[eoform:mailing_list]-->
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<h2><%= l(:label_mailing_list_new) %></h2>
|
||||||
|
|
||||||
|
<% 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 %>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<h2><%= l(:label_mailing_list )%> <%= @mailing_list.name %></h2>
|
||||||
|
|
||||||
|
<% 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 %>
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><%= link_to l(:label_information_plural), {}, :id=> "tab-info", :onclick => "showTab('info'); this.blur(); return false;" %></li>
|
<li><%= link_to l(:label_information_plural), {}, :id=> "tab-info", :onclick => "showTab('info'); this.blur(); return false;" %></li>
|
||||||
<li><%= link_to l(:label_member_plural), {}, :id=> "tab-members", :onclick => "showTab('members'); this.blur(); return false;" %></li>
|
<li><%= link_to l(:label_member_plural), {}, :id=> "tab-members", :onclick => "showTab('members'); this.blur(); return false;" %></li>
|
||||||
|
<li><%= link_to l(:label_mailing_list_plural), {}, :id=> "tab-mailing-lists", :onclick => "showTab('mailing-lists'); this.blur(); return false;" %></li>
|
||||||
<li><%= link_to l(:label_version_plural), {}, :id=> "tab-versions", :onclick => "showTab('versions'); this.blur(); return false;" %></li>
|
<li><%= link_to l(:label_version_plural), {}, :id=> "tab-versions", :onclick => "showTab('versions'); this.blur(); return false;" %></li>
|
||||||
<li><%= link_to l(:label_issue_category_plural), {}, :id=> "tab-categories", :onclick => "showTab('categories'); this.blur(); return false;" %></li>
|
<li><%= link_to l(:label_issue_category_plural), {}, :id=> "tab-categories", :onclick => "showTab('categories'); this.blur(); return false;" %></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -59,6 +60,26 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="tab-content-mailing-lists" class="tab-content" style="display:none;">
|
||||||
|
<table class="list">
|
||||||
|
<thead><th><%= l(:field_name) %></th><th><%= l(:field_admin) %></th><th><%= l(:field_is_public) %></th><th><%= l(:field_status) %></th><th><%= l(:field_created_on) %></th><th></th><th></th></thead>
|
||||||
|
<tbody>
|
||||||
|
<% for mailing_list in @project.mailing_lists %>
|
||||||
|
<tr class="<%= cycle 'odd', 'even' %>">
|
||||||
|
<td><%= mailing_list.name %></td>
|
||||||
|
<td align="center"><%= mailing_list.admin.name if mailing_list.admin %></td>
|
||||||
|
<td align="center"><%= image_tag('true.png') if mailing_list.is_public? %></td>
|
||||||
|
<td align="center"><%= l(mailing_list.status_name) if mailing_list.status_name %></td>
|
||||||
|
<td align="center"><%= format_date(mailing_list.created_on) %></td>
|
||||||
|
<td align="center" style="width:10%"><%= link_to_if_authorized l(:button_edit), {:controller => 'mailing_lists', :action => 'edit', :id => mailing_list}, :class => 'icon icon-edit' %></td>
|
||||||
|
<td align="center" style="width:10%"><%= link_to_if_authorized l(:button_delete), {:controller => 'mailing_lists', :action => 'destroy', :id => mailing_list}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></td>
|
||||||
|
</tr>
|
||||||
|
<% end; reset_cycle %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<%= link_to_if_authorized l(:label_mailing_list_new), :controller => 'mailing_lists', :action => 'add', :project_id => @project %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="tab-content-versions" class="tab-content" style="display:none;">
|
<div id="tab-content-versions" class="tab-content" style="display:none;">
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead><th><%= l(:label_version) %></th><th><%= l(:field_effective_date) %></th><th><%= l(:field_description) %></th><th></th><th></th></thead>
|
<thead><th><%= l(:label_version) %></th><th><%= l(:field_effective_date) %></th><th><%= l(:field_description) %></th><th></th><th></th></thead>
|
||||||
|
|||||||
@@ -315,6 +315,9 @@ label_sort_higher: Remonter
|
|||||||
label_sort_lower: Descendre
|
label_sort_lower: Descendre
|
||||||
label_sort_lowest: Descendre en dernier
|
label_sort_lowest: Descendre en dernier
|
||||||
label_roadmap: Roadmap
|
label_roadmap: Roadmap
|
||||||
|
label_mailing_list: Liste
|
||||||
|
label_mailing_list_plural: Listes
|
||||||
|
label_mailing_list_new: Nouvelle liste
|
||||||
|
|
||||||
button_login: Connexion
|
button_login: Connexion
|
||||||
button_submit: Soumettre
|
button_submit: Soumettre
|
||||||
@@ -375,3 +378,7 @@ default_priority_immediate: Immédiat
|
|||||||
|
|
||||||
enumeration_issue_priorities: Priorités des demandes
|
enumeration_issue_priorities: Priorités des demandes
|
||||||
enumeration_doc_categories: Catégories des documents
|
enumeration_doc_categories: Catégories des documents
|
||||||
|
|
||||||
|
mailing_list_status_requested: En attente de création
|
||||||
|
mailing_list_status_created: Créée
|
||||||
|
mailing_list_status_to_be_deleted: En attente de suppression
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||||
|
one:
|
||||||
|
id: 1
|
||||||
|
two:
|
||||||
|
id: 2
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
require 'mailing_lists_controller'
|
||||||
|
|
||||||
|
# Re-raise errors caught by the controller.
|
||||||
|
class MailingListsController; def rescue_action(e) raise e end; end
|
||||||
|
|
||||||
|
class MailingListsControllerTest < Test::Unit::TestCase
|
||||||
|
fixtures :mailing_lists
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@controller = MailingListsController.new
|
||||||
|
@request = ActionController::TestRequest.new
|
||||||
|
@response = ActionController::TestResponse.new
|
||||||
|
|
||||||
|
@first_id = mailing_lists(:first).id
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_index
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'list'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_list
|
||||||
|
get :list
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'list'
|
||||||
|
|
||||||
|
assert_not_nil assigns(:mailing_lists)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_show
|
||||||
|
get :show, :id => @first_id
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'show'
|
||||||
|
|
||||||
|
assert_not_nil assigns(:mailing_list)
|
||||||
|
assert assigns(:mailing_list).valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_new
|
||||||
|
get :new
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'new'
|
||||||
|
|
||||||
|
assert_not_nil assigns(:mailing_list)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_create
|
||||||
|
num_mailing_lists = MailingList.count
|
||||||
|
|
||||||
|
post :create, :mailing_list => {}
|
||||||
|
|
||||||
|
assert_response :redirect
|
||||||
|
assert_redirected_to :action => 'list'
|
||||||
|
|
||||||
|
assert_equal num_mailing_lists + 1, MailingList.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_edit
|
||||||
|
get :edit, :id => @first_id
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'edit'
|
||||||
|
|
||||||
|
assert_not_nil assigns(:mailing_list)
|
||||||
|
assert assigns(:mailing_list).valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update
|
||||||
|
post :update, :id => @first_id
|
||||||
|
assert_response :redirect
|
||||||
|
assert_redirected_to :action => 'show', :id => @first_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_destroy
|
||||||
|
assert_nothing_raised {
|
||||||
|
MailingList.find(@first_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
post :destroy, :id => @first_id
|
||||||
|
assert_response :redirect
|
||||||
|
assert_redirected_to :action => 'list'
|
||||||
|
|
||||||
|
assert_raise(ActiveRecord::RecordNotFound) {
|
||||||
|
MailingList.find(@first_id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
|
||||||
|
class MailingListTest < Test::Unit::TestCase
|
||||||
|
fixtures :mailing_lists
|
||||||
|
|
||||||
|
# Replace this with your real tests.
|
||||||
|
def test_truth
|
||||||
|
assert true
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in new issue
Block a user