parlement 0.10 → 0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data/CHANGES +11 -0
  2. data/MEMORY +9 -1
  3. data/README +5 -4
  4. data/app/controllers/account_controller.rb +10 -13
  5. data/app/controllers/application.rb +4 -5
  6. data/app/controllers/elt_controller.rb +9 -7
  7. data/app/controllers/person_controller.rb +1 -3
  8. data/app/controllers/subscriber_controller.rb +10 -10
  9. data/app/helpers/elt_helper.rb +2 -0
  10. data/app/models/elt.rb +28 -19
  11. data/app/models/mail.rb +26 -14
  12. data/app/models/mail_notify.rb +5 -4
  13. data/app/models/person.rb +11 -2
  14. data/app/views/account/_login.rhtml +3 -3
  15. data/app/views/account/_show.rhtml +12 -14
  16. data/app/views/elt/_choice.rhtml +3 -3
  17. data/app/views/elt/_elt.rhtml +4 -4
  18. data/app/views/elt/_list.rhtml +2 -2
  19. data/app/views/elt/_listByDate.rhtml +1 -1
  20. data/app/views/elt/_listByVote.rhtml +1 -1
  21. data/app/views/elt/new.rhtml +3 -3
  22. data/app/views/elt/show.rhtml +2 -2
  23. data/app/views/layouts/top.rhtml +6 -0
  24. data/app/views/mail_notify/publish.text.html.rhtml +1 -1
  25. data/app/views/person/_listElts.rhtml +5 -3
  26. data/app/views/person/show.rhtml +1 -2
  27. data/config/boot.rb +5 -4
  28. data/config/environment.rb +6 -4
  29. data/config/routes.rb +3 -2
  30. data/db/development_structure.sql +15 -4
  31. data/db/migrate/006_last_activity.rb +10 -0
  32. data/db/schema.rb +67 -49
  33. data/public/dispatch.fcgi +1 -0
  34. data/public/javascripts/controls.js +41 -23
  35. data/public/javascripts/dragdrop.js +317 -99
  36. data/public/javascripts/effects.js +301 -166
  37. data/public/javascripts/prototype.js +932 -402
  38. data/public/stylesheets/default.css +3 -2
  39. data/test/unit/elt_test.rb +13 -0
  40. data/test/unit/mail_test.rb +3 -1
  41. data/vendor/plugins/engines/CHANGELOG +203 -99
  42. data/vendor/plugins/engines/MIT-LICENSE +1 -1
  43. data/vendor/plugins/engines/README +32 -384
  44. data/vendor/plugins/engines/Rakefile +14 -0
  45. data/vendor/plugins/engines/UPGRADING +93 -0
  46. data/vendor/plugins/engines/about.yml +7 -0
  47. data/vendor/plugins/engines/generators/plugin_migration/USAGE +45 -0
  48. data/vendor/plugins/engines/generators/plugin_migration/plugin_migration_generator.rb +79 -0
  49. data/vendor/plugins/engines/generators/plugin_migration/templates/plugin_migration.erb +13 -0
  50. data/vendor/plugins/engines/init.rb +34 -47
  51. data/vendor/plugins/engines/install.rb +32 -0
  52. data/vendor/plugins/engines/lib/engines/{ruby_extensions.rb → deprecated_config_support.rb} +135 -113
  53. data/vendor/plugins/engines/lib/engines/plugin.rb +214 -0
  54. data/vendor/plugins/engines/lib/engines/plugin_list.rb +31 -0
  55. data/vendor/plugins/engines/lib/engines/plugin_migrator.rb +60 -0
  56. data/vendor/plugins/engines/lib/engines/rails_extensions/active_record.rb +19 -0
  57. data/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb +143 -0
  58. data/vendor/plugins/engines/lib/engines/rails_extensions/migrations.rb +155 -0
  59. data/vendor/plugins/engines/lib/engines/rails_extensions/public_asset_helpers.rb +116 -0
  60. data/vendor/plugins/engines/lib/engines/rails_extensions/rails.rb +20 -0
  61. data/vendor/plugins/engines/lib/engines/rails_extensions/rails_initializer.rb +86 -0
  62. data/vendor/plugins/engines/lib/engines/rails_extensions/routing.rb +77 -0
  63. data/vendor/plugins/engines/lib/engines/rails_extensions/templates.rb +140 -0
  64. data/vendor/plugins/engines/lib/engines/rails_extensions.rb +6 -0
  65. data/vendor/plugins/engines/lib/engines/testing.rb +88 -0
  66. data/vendor/plugins/engines/lib/engines.rb +281 -425
  67. data/vendor/plugins/engines/tasks/engines.rake +108 -137
  68. metadata +218 -250
  69. data/db/ROOT/perso.txt +0 -214
  70. data/public/images/indicator.gif +0 -0
  71. data/public/images/orange_by_darren_Hester_350o.jpg +0 -0
  72. data/public/images/smile.png +0 -0
  73. data/vendor/plugins/engines/generators/engine/USAGE +0 -26
  74. data/vendor/plugins/engines/generators/engine/engine_generator.rb +0 -199
  75. data/vendor/plugins/engines/generators/engine/templates/README +0 -85
  76. data/vendor/plugins/engines/generators/engine/templates/init_engine.erb +0 -15
  77. data/vendor/plugins/engines/generators/engine/templates/install.erb +0 -4
  78. data/vendor/plugins/engines/generators/engine/templates/lib/engine.erb +0 -6
  79. data/vendor/plugins/engines/generators/engine/templates/licenses/GPL +0 -18
  80. data/vendor/plugins/engines/generators/engine/templates/licenses/LGPL +0 -19
  81. data/vendor/plugins/engines/generators/engine/templates/licenses/MIT +0 -22
  82. data/vendor/plugins/engines/generators/engine/templates/licenses/None +0 -1
  83. data/vendor/plugins/engines/generators/engine/templates/public/javascripts/engine.js +0 -0
  84. data/vendor/plugins/engines/generators/engine/templates/public/stylesheets/engine.css +0 -0
  85. data/vendor/plugins/engines/generators/engine/templates/tasks/engine.rake +0 -0
  86. data/vendor/plugins/engines/generators/engine/templates/test/test_helper.erb +0 -17
  87. data/vendor/plugins/engines/lib/bundles/require_resource.rb +0 -124
  88. data/vendor/plugins/engines/lib/bundles.rb +0 -77
  89. data/vendor/plugins/engines/lib/engines/action_mailer_extensions.rb +0 -140
  90. data/vendor/plugins/engines/lib/engines/action_view_extensions.rb +0 -141
  91. data/vendor/plugins/engines/lib/engines/active_record_extensions.rb +0 -21
  92. data/vendor/plugins/engines/lib/engines/dependencies_extensions.rb +0 -129
  93. data/vendor/plugins/engines/lib/engines/migration_extensions.rb +0 -53
  94. data/vendor/plugins/engines/lib/engines/routing_extensions.rb +0 -28
  95. data/vendor/plugins/engines/lib/engines/testing_extensions.rb +0 -327
  96. data/vendor/plugins/engines/tasks/deprecated_engines.rake +0 -7
  97. data/vendor/plugins/engines/test/action_view_extensions_test.rb +0 -9
  98. data/vendor/plugins/engines/test/ruby_extensions_test.rb +0 -115
  99. data/vendor/plugins/guid/README.TXT +0 -29
  100. data/vendor/plugins/guid/init.rb +0 -30
  101. data/vendor/plugins/guid/lib/usesguid.rb +0 -37
  102. data/vendor/plugins/guid/lib/uuid22.rb +0 -43
  103. data/vendor/plugins/guid/lib/uuidtools.rb +0 -572
  104. data/vendor/plugins/responds_to_parent/MIT-LICENSE +0 -20
  105. data/vendor/plugins/responds_to_parent/README +0 -42
  106. data/vendor/plugins/responds_to_parent/Rakefile +0 -22
  107. data/vendor/plugins/responds_to_parent/init.rb +0 -1
  108. data/vendor/plugins/responds_to_parent/lib/responds_to_parent.rb +0 -46
  109. data/vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb +0 -115
data/CHANGES CHANGED
@@ -1,5 +1,16 @@
1
1
  - parlement changelog
2
2
 
3
+ == Version 0.11
4
+
5
+ Most active forums presented first
6
+
7
+ * Corrected a small javascript error displaying subscriptionLink
8
+ * last_activity field added to elts
9
+ * passage to rails 1.2
10
+ * removal of the guid plugin, now id are generated from internal data
11
+ * better anti spam check. Won't block on any url
12
+ * corrected person's page
13
+
3
14
  == Version 0.10
4
15
 
5
16
  Democratically moderated mails.
data/MEMORY CHANGED
@@ -47,5 +47,13 @@ select count(*) from mails;
47
47
  select * from people;
48
48
  select * from subscriptions;
49
49
  select * from person_mails;
50
- \dt
50
+ select distinct last_activity from elts;
51
+ UPDATE elts SET last_activity = (SELECT MAX(created_on) FROM elts c WHERE elts.lft <= c.lft AND c.rgt <= elts.rgt);
52
+
53
+
54
+ Processing EltController#create (for 192.168.0.254 at 2007-02-11 00:07:05) [POST]
55
+ Session ID: 23a1ab5f9b11763838d64c50157610f3
56
+ Parameters: {"commit"=>"Propose!", "elt"=>{"body"=>"arg", "subject"=>"Re: Testez", "parent_id"=>"Testez"}, "submit"=>"preview", "action"=>"create", "id"=>"Testez", "controller"=>"elt"}
57
+ Response body was encoded with gzip
58
+ Completed in 0.05879 (17 reqs/sec) | Rendering: 0.05682 (96%) | DB: 0.00072 (1%) | 200 OK [http://leparlement.org/elt/create/Testez?submit=preview]
51
59
 
data/README CHANGED
@@ -5,7 +5,7 @@
5
5
  | .__/ \__,_|_| |_|\___|_| |_| |_|\___|_| |_|\__|
6
6
  |_|
7
7
 
8
- On debian, here are the commands used to setup the parlement machine:
8
+ On debian, here are the commands used to setup a parlement server:
9
9
  # apt-get install postgresql
10
10
  # sudo su - postgres
11
11
  ~ createuser /your_login/
@@ -16,7 +16,7 @@ On debian, here are the commands used to setup the parlement machine:
16
16
  # apt-get install rdoc
17
17
 
18
18
  Basically this install postgresql, ruby and the ruby driver to psql. Ruby on
19
- Rails is database agnostic, parlement will be sometimes in the near future.
19
+ Rails is database agnostic, parlement will be sometimes in the future.
20
20
 
21
21
  You need to install "ruby gems":http://docs.rubygems.org
22
22
 
@@ -45,8 +45,9 @@ filtering tool), define this kind of rule:
45
45
  Once you have everything set up (ruby, postgresql, redcloth, irb), you can
46
46
  initialise and launch parlement this way:
47
47
 
48
- ~ svn checkout svn://rubyforge.org/var/svn/parlement # Get the code source
49
- ~ cd parlement/trunk # Go into the right folder
48
+ # Get the source code
49
+ ~ svn checkout svn://rubyforge.org/var/svn/parlement/trunk parlement
50
+ ~ cd parlement # Go into the right folder
50
51
  ~ createdb parlement_development # Create database
51
52
  ~ psql -q template1 -f db/schema.sql # Initiate the db schema
52
53
  ~ rake migrate # Get the db to its last version
@@ -2,18 +2,15 @@
2
2
  # This class manages users inscription, login and logout
3
3
  #
4
4
  class AccountController < UserController
5
- model :person
6
- model :user
7
-
8
5
  def login
9
6
  # Cleaning up
10
7
  session[:person] = @person = session[:user] = @user = nil
11
8
  cookies.delete :person_name
12
9
  cookies.delete :salted_password
13
10
 
14
- login = @params[:person][:name]
15
- email = @params[:person][:email]
16
- password = @params[:user][:password]
11
+ login = params[:person][:name]
12
+ email = params[:person][:email]
13
+ password = params[:user][:password]
17
14
 
18
15
  @person = Person.find_by_name(login)
19
16
  @user = @person.user if @person
@@ -22,7 +19,7 @@ class AccountController < UserController
22
19
  if not @person
23
20
  # Create the pseudo
24
21
  begin
25
- Person.transaction(@person) do
22
+ Person.transaction do
26
23
  @person = Person.new :id => login.gsub(/\s/, '_'), :name => login
27
24
  if @person.save
28
25
  logger.info yellow { bold { "Person: #{@person.name}, id: #{@person.id}" } }
@@ -59,7 +56,7 @@ class AccountController < UserController
59
56
  elsif email and not email.empty?
60
57
  # There is a check key, used to change the password
61
58
  begin
62
- User.transaction(@user) do
59
+ User.transaction do
63
60
  if User.authenticate_by_token(@user.id, email)
64
61
  @user.change_password(password)
65
62
  @user.security_token = nil
@@ -127,7 +124,7 @@ class AccountController < UserController
127
124
  end
128
125
 
129
126
  def check_key
130
- if @user = User.authenticate_by_token(@params[:user][:id], @params[:key])
127
+ if @user = User.authenticate_by_token(params[:user][:id], params[:key])
131
128
  #@user = User.find(:first, :conditions => "security_token = '#{params[:key]}'")
132
129
  @person = Person.find_by_name(@user.login) if @user
133
130
  @person.email = @user.email
@@ -200,10 +197,10 @@ class AccountController < UserController
200
197
  protected
201
198
 
202
199
  def mngPassword
203
- if @person and password = @params[:user][:password] and !password.empty?
200
+ if @person and password = params[:user][:password] and !password.empty?
204
201
  @user = @person.user || User.new()
205
202
  begin
206
- User.transaction(@user) do
203
+ User.transaction do
207
204
  @user.login = @person.name
208
205
  # To make sure even a non email protected user can use a password
209
206
  @user.email ||= @person.name+'@nomailyet'
@@ -232,9 +229,9 @@ class AccountController < UserController
232
229
  @user.login = @person.name
233
230
  end
234
231
 
235
- @user.email = @params[:person][:email]
232
+ @user.email = params[:person][:email]
236
233
  begin
237
- User.transaction(@user) do
234
+ User.transaction do
238
235
  unless LoginEngine.config(:use_email_notification)
239
236
  @user.verified = 1
240
237
  end
@@ -7,7 +7,6 @@ require 'term/ansicolor'
7
7
  class ApplicationController < ActionController::Base
8
8
  include LoginEngine
9
9
  include Term::ANSIColor
10
- model :user
11
10
 
12
11
  before_filter :set_charset
13
12
  before_filter :set_login_from_cookie
@@ -17,15 +16,15 @@ class ApplicationController < ActionController::Base
17
16
  # automatically and transparently fixes utf-8 bug
18
17
  # with Safari when using xmlhttp
19
18
  def fix_unicode_for_safari
20
- if @headers["Content-Type"] == "text/html; charset=utf-8" and
21
- @request.env['HTTP_USER_AGENT'].to_s.include? 'AppleWebKit' then
22
- @response.body = @response.body.gsub(/([^\x00-\xa0])/u) { |s| "&#x%x;" % $1.unpack('U')[0] }
19
+ if headers["Content-Type"] == "text/html; charset=utf-8" and
20
+ request.env['HTTP_USER_AGENT'].to_s.include? 'AppleWebKit' then
21
+ response.body = response.body.gsub(/([^\x00-\xa0])/u) { |s| "&#x%x;" % $1.unpack('U')[0] }
23
22
  end
24
23
  end
25
24
 
26
25
  def set_charset
27
26
  #@headers["Content-Type"] = "text/html; charset=iso-8859-15"
28
- @headers["Content-Type"] = "text/html; charset=utf-8"
27
+ headers["Content-Type"] = "text/html; charset=utf-8"
29
28
  end
30
29
 
31
30
  def set_login_from_cookie
@@ -4,7 +4,6 @@
4
4
  # An element is just the name for a poll/message/issue
5
5
  #
6
6
  class EltController < ApplicationController
7
-
8
7
  def index
9
8
  params[:id] = params[:id].gsub(/.html/, '')
10
9
  show
@@ -40,13 +39,13 @@ class EltController < ApplicationController
40
39
 
41
40
  def rss
42
41
  params[:id] = params[:id].gsub(/.rss/, '')
43
- @headers["Content-Type"] = "text/xml; charset=utf-8"
42
+ headers["Content-Type"] = "text/xml; charset=utf-8"
44
43
  @elt = Elt.find(params[:id]) if @elt == nil
45
44
  end
46
45
 
47
46
  def vote_rss
48
47
  params[:id] = params[:id].gsub(/.rss/, '')
49
- @headers["Content-Type"] = "text/xml; charset=utf-8"
48
+ headers["Content-Type"] = "text/xml; charset=utf-8"
50
49
  @elt = Elt.find(params[:id]) if @elt == nil
51
50
  end
52
51
 
@@ -64,12 +63,13 @@ class EltController < ApplicationController
64
63
 
65
64
  def create
66
65
  @elt = Elt.new(params[:elt])
67
- @elt.person = @session[:person]
66
+ @elt.person = session[:person]
68
67
 
69
- if @elt.subject =~ /([<>\/]|href)/ \
70
- or @elt.body =~ /(.*([<>\/]|href).*){3}/ \
68
+ if !session[:person] and \
69
+ (@elt.subject =~ /([<>\/]|href)/ \
70
+ or @elt.body =~ /(.*(http|href).*){3}/ \
71
71
  or @elt.body =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i \
72
- or @elt.body =~ /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}.*){3}/i
72
+ or @elt.body =~ /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}.*){3}/i) then
73
73
  logger.error red { underline { "SPAM! '#{@elt.subject}'" } }
74
74
  logger.error "SPAM! '#{@elt.body}'"
75
75
  flash[:error] = 'Sorry, to fight spam "<" ">" or "href" are forbidden in the subject, and there can not be more than 3 links in the body, you also can\'t input one simple email or more than 3 emails!'
@@ -79,6 +79,8 @@ class EltController < ApplicationController
79
79
  #headers["Status"] = "201 Created"
80
80
  render :partial => '/elt/elt', :locals => { :elt => @elt, :eltTop => false }
81
81
  else
82
+ logger.error "Strange error, can't preview or save an element"
83
+ puts "Strange error, can't preview or save an element"
82
84
  flash[:notice] = 'Error'
83
85
  render :controller => 'elt', :action => 'new'
84
86
  end
@@ -3,8 +3,6 @@ class PersonController < ApplicationController
3
3
  helper :elt
4
4
 
5
5
  layout 'top'
6
- model :person
7
-
8
6
  def show
9
7
  @person = Person.find(params[:id])
10
8
  @title = @person.name+' (parlement)'
@@ -15,7 +13,7 @@ class PersonController < ApplicationController
15
13
  end
16
14
 
17
15
  def list
18
- @person = Person.find(params[:id]) unless @person
16
+ @person = Person.find(params[:id])
19
17
  render :partial => '/person/listElts', :locals => { :person => @person }
20
18
  end
21
19
  end
@@ -7,15 +7,15 @@ class SubscriberController < ApplicationController
7
7
  def subscribe
8
8
  @elt = Elt.find params[:id]
9
9
 
10
- if @session[:person]
11
- if @elt.subscribers.include?(@session[:person])
12
- Subscription.find_by_person_id_and_elt_id(@session[:person].id, @elt.id).destroy
13
- logger.info yellow { "User #{@session[:person].name} unsubscribed from #{@elt.subject}..." }
14
- elsif @elt.all_recipients.include?(@session[:person])
10
+ if session[:person]
11
+ if @elt.subscribers.include?(session[:person])
12
+ Subscription.find_by_person_id_and_elt_id(session[:person].id, @elt.id).destroy
13
+ logger.info yellow { "User #{session[:person].name} unsubscribed from #{@elt.subject}..." }
14
+ elsif @elt.all_recipients.include?(session[:person])
15
15
  elt2 = @elt
16
- elt2 = elt2.parent until elt2.subscribers.include?(@session[:person])
17
- Subscription.find_by_person_id_and_elt_id(@session[:person].id, elt2.id).destroy
18
- logger.info yellow { "User #{@session[:person].name} unsubscribed from #{elt2.subject}..." }
16
+ elt2 = elt2.parent until elt2.subscribers.include?(session[:person])
17
+ Subscription.find_by_person_id_and_elt_id(session[:person].id, elt2.id).destroy
18
+ logger.info yellow { "User #{session[:person].name} unsubscribed from #{elt2.subject}..." }
19
19
  else
20
20
  if cookies[:filter]
21
21
  filter = cookies[:filter].to_i - 1
@@ -23,8 +23,8 @@ class SubscriberController < ApplicationController
23
23
  else
24
24
  filter = 0
25
25
  end
26
- @elt.subscriptions.create :person => @session[:person], :filter => filter
27
- logger.info yellow { "User #{@session[:person].name} subscribed to #{@elt.id} with filter #{filter}..." }
26
+ @elt.subscriptions.create :person => session[:person], :filter => filter
27
+ logger.info yellow { "User #{session[:person].name} subscribed to #{@elt.id} with filter #{filter}..." }
28
28
  end
29
29
  else
30
30
  puts "Not logged in!"
@@ -9,6 +9,7 @@ module EltHelper
9
9
  # /italic/
10
10
  # - listElement
11
11
  # 1. numbered list
12
+ # *headed list* text
12
13
  # chat log lines become list elements
13
14
  # short lines to which are added a break
14
15
  # positions have a special treatment in the view
@@ -20,6 +21,7 @@ module EltHelper
20
21
  .gsub(/^-\s/, '* ') \
21
22
  .gsub(/^\d+[\.-]\s+/, '# ') \
22
23
  .gsub(/^(\d\d:\d\d\s)/, '* \\1') \
24
+ .gsub(/^\s\*(.*)\*/, '*\\1*') \
23
25
  .gsub(/^\b(.{2,50})$(\n)\b/, '\\1<br/>\\2') \
24
26
  .gsub(/\n*^\b(position:\s*(\d*(\.\d+)?))\s*$\n*/, ' <span class="position">\1</span>') \
25
27
  if data != nil
data/app/models/elt.rb CHANGED
@@ -25,8 +25,8 @@ class Elt < ActiveRecord::Base
25
25
  has_many :subscriptions, :dependent => :destroy
26
26
  has_many :subscribers, :through => :subscriptions, :source => :person
27
27
 
28
- acts_as_nested_set :order => "position is not null, position, created_on"
29
- acts_as_tree :order => "position is not null, position, created_on", :counter_cache => true
28
+ acts_as_nested_set :order => "position is not null, position, last_activity DESC, created_on DESC"
29
+ acts_as_tree :order => "position is not null, position, last_activity DESC, created_on DESC", :counter_cache => true
30
30
 
31
31
  # Just a quick method to get all subscribers as a simple list
32
32
  def all_recipients
@@ -39,9 +39,9 @@ class Elt < ActiveRecord::Base
39
39
 
40
40
  def all_subscriptions
41
41
  if parent
42
- (subscriptions + parent.all_subscriptions).uniq
42
+ (subscriptions + parent.all_subscriptions).uniq
43
43
  else
44
- subscriptions
44
+ subscriptions
45
45
  end
46
46
  end
47
47
 
@@ -73,7 +73,7 @@ class Elt < ActiveRecord::Base
73
73
 
74
74
  parent.vote Regexp.last_match(1), person if body =~ /^\s*(-1|0|\+1)(\s|$)/
75
75
  if Regexp.last_match(1) and self.body.gsub(/(-1|0|\+1)/, '').strip.empty?
76
- # Hide simple votes
76
+ # Hide simple votes
77
77
  vote -1
78
78
  else
79
79
  vote if person
@@ -81,20 +81,29 @@ class Elt < ActiveRecord::Base
81
81
  true
82
82
  end
83
83
 
84
- def save
85
- if new_record?
86
- # Let's generate a nice looking id
87
- self.id = new_id =
88
- subject.gsub(/\[[\w-]*\]/, '').strip \
89
- .gsub(/\s/, '_').gsub(/[^\w]+/, '') \
90
- .gsub(/_+/, '_').gsub(/(^_|_$)/, '') if subject
91
- self.id ||= "elt"
92
-
93
- i = 0
94
- self.id = "#{new_id}_#{i+=1}" while self.class.find_by_id self.id
95
- end
96
-
97
- super
84
+ def before_create
85
+ # Let's generate a nice looking id
86
+ self.id ||= new_id =
87
+ subject.gsub(/\[[\w-]*\]/, '').strip \
88
+ .gsub(/\s/, '_').gsub(/[^\w]+/, '') \
89
+ .gsub(/_+/, '_').gsub(/(^_|_$)/, '') if subject
90
+ self.id ||= "elt"
91
+
92
+ i = 0
93
+ self.id = "#{new_id}_#{i+=1}" while self.class.find_by_id self.id
94
+ end
95
+
96
+ def add_child(c)
97
+ result = super(c)
98
+ p = c
99
+ while p
100
+ if !p.last_activity or p.last_activity < c.created_on then
101
+ p.last_activity = c.created_on
102
+ p.save!
103
+ end
104
+ p = p.parent
105
+ end
106
+ result
98
107
  end
99
108
 
100
109
  #
data/app/models/mail.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # are also managed in an associated table
6
6
  #
7
7
  class Mail < ActiveRecord::Base
8
- usesguid
8
+ #usesguid
9
9
 
10
10
  belongs_to :elt
11
11
  has_many :person_mails, :dependent => :destroy
@@ -30,6 +30,18 @@ class Mail < ActiveRecord::Base
30
30
  end
31
31
  end
32
32
 
33
+ def before_create
34
+ # Let's generate a nice looking id
35
+ self.id ||= new_id =
36
+ message.gsub(/\[[\w-]*\]/, '').strip \
37
+ .gsub(/\s/, '_').gsub(/[^\w]+/, '') \
38
+ .gsub(/_+/, '_').gsub(/(^_|_$)/, '') if message
39
+ self.id ||= "mail"
40
+
41
+ i = 0
42
+ self.id = "#{new_id}_#{i+=1}" while self.class.find_by_id self.id
43
+ end
44
+
33
45
  """ _
34
46
  _ __ ___ ___ ___(_)_ _____
35
47
  | '__/ _ \/ __/ _ \ \ \ / / _ \
@@ -41,12 +53,15 @@ class Mail < ActiveRecord::Base
41
53
  # The algorithm to define its parent is simple:
42
54
  # - header "references"
43
55
  # - or any subject between []
44
- # - the "to" part before @#{ActionMailer::Base.server_settings[:domain]}
56
+ # - the "to" part before @#{ActionMailer::Base.smtp_settings[:domain]}
45
57
  # - in a "mail/lost+found" thread
46
58
  #
47
59
  def receive(mail)
48
60
  logger.info "Receive mail #{mail.message_id}"
49
- #puts "Receive mail #{mail.message_id}"
61
+ self.mail_parents = mail.references
62
+ self.message = mail.message_id
63
+ self.file = mail.encoded
64
+
50
65
  build_elt :created_on => mail.date,
51
66
  :subject => unquote(mail.subject),
52
67
  :body => '',
@@ -76,9 +91,9 @@ class Mail < ActiveRecord::Base
76
91
 
77
92
  # No reference matching an existing parent, let's try the "to" field
78
93
  to = mail["Envelope-to"].to_s + ', ' + mail.to.to_s
79
- if not elt.parent and to.match(/[\w-]*@#{ActionMailer::Base.server_settings[:domain]}/)
80
- parentId = to.match(/[\w-]*@#{ActionMailer::Base.server_settings[:domain]}/)[0] \
81
- .gsub(/@#{ActionMailer::Base.server_settings[:domain]}/, '')
94
+ if not elt.parent and to.match(/[\w-]*@#{ActionMailer::Base.smtp_settings[:domain]}/)
95
+ parentId = to.match(/[\w-]*@#{ActionMailer::Base.smtp_settings[:domain]}/)[0] \
96
+ .gsub(/@#{ActionMailer::Base.smtp_settings[:domain]}/, '')
82
97
  elt.parent = Elt.find parentId
83
98
  end
84
99
 
@@ -104,14 +119,11 @@ class Mail < ActiveRecord::Base
104
119
  || elt.build_person(:id => unquote(mail.friendly_from).gsub(/\s/, '_'),
105
120
  :name => unquote(mail.friendly_from),
106
121
  :email => mail.from.first) \
107
- if not mail.from.first.match(/#{ANONYMOUS_POSTER}@#{ActionMailer::Base.server_settings[:domain]}/)
122
+ if not mail.from.first.match(/#{ANONYMOUS_POSTER}@#{ActionMailer::Base.smtp_settings[:domain]}/)
108
123
 
109
- self.mail_parents = mail.references
110
- self.message = mail.message_id
111
- self.file = mail.encoded
112
124
  elt.publish
113
125
 
114
- if mail.to.to_s.match(/people@#{ActionMailer::Base.server_settings[:domain]}/)
126
+ if mail.to.to_s.match(/people@#{ActionMailer::Base.smtp_settings[:domain]}/)
115
127
  elt.person.image = "/attachment/file/#{elt.attachments.first.file_relative_path}"
116
128
  elt.person.save
117
129
  end
@@ -145,9 +157,9 @@ class Mail < ActiveRecord::Base
145
157
  end
146
158
 
147
159
  mail['Precedence'] = 'list'
148
- mail['X-Loop'] = ActionMailer::Base.server_settings[:domain]
149
- mail['List-Archive'] = "http://"+ActionMailer::Base.server_settings[:domain]
150
- mail['Errors-To'] = "errors@"+ActionMailer::Base.server_settings[:domain]
160
+ mail['X-Loop'] = ActionMailer::Base.smtp_settings[:domain]
161
+ mail['List-Archive'] = "http://"+ActionMailer::Base.smtp_settings[:domain]
162
+ mail['Errors-To'] = "errors@"+ActionMailer::Base.smtp_settings[:domain]
151
163
 
152
164
  subscriptions = elt.all_subscriptions \
153
165
  .select { |s| s.person.email and not s.person.email.blank? } \
@@ -12,12 +12,12 @@ class MailNotify < ActionMailer::Base
12
12
  ml = mailing_list(elt.parent)
13
13
 
14
14
  recipients ml.subject.to_s \
15
- + " <#{ml.id}@#{ActionMailer::Base.server_settings[:domain]}>"
15
+ + " <#{ml.id}@#{ActionMailer::Base.smtp_settings[:domain]}>"
16
16
 
17
17
  from ((elt.person and elt.person.name) ? elt.person.name : ANONYMOUS_POSTER) \
18
18
  + " <" \
19
19
  + ((elt.person and elt.person.email) \
20
- ? elt.person.email : "#{ANONYMOUS_POSTER}@#{ActionMailer::Base.server_settings[:domain]}") \
20
+ ? elt.person.email : "#{ANONYMOUS_POSTER}@#{ActionMailer::Base.smtp_settings[:domain]}") \
21
21
  + ">"
22
22
 
23
23
  # Try to render the element as html
@@ -49,7 +49,8 @@ class MailNotify < ActionMailer::Base
49
49
  # This is the essential of a mailing list, you reply to the mailing list,
50
50
  # where every body sends their mail.
51
51
  # This very mail can be a mailing list all by itself...
52
- @headers['Reply-to'] = "#{ml.id}@#{ActionMailer::Base.server_settings[:domain]}"
52
+ @headers['Reply-to'] = "#{ml.id}@#{ActionMailer::Base.smtp_settings[:domain]}"
53
+ #puts "#{ml.id}@#{ActionMailer::Base.smtp_settings[:domain]}"
53
54
 
54
55
  @headers['In-Reply-To'] = elt.parent.mail.message \
55
56
  if elt.parent and elt.parent.mail and elt.parent.mail.message
@@ -64,7 +65,7 @@ class MailNotify < ActionMailer::Base
64
65
  @headers['references'] << parentMsg.message if parentMsg.message
65
66
  end
66
67
 
67
- @headers['X-Mailer'] = "#{ActionMailer::Base.server_settings[:domain]} v#{PARLEMENT_VERSION}"
68
+ @headers['X-Mailer'] = "#{ActionMailer::Base.smtp_settings[:domain]} v#{PARLEMENT_VERSION}"
68
69
 
69
70
  logger.info "Mail created"
70
71
  end
data/app/models/person.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  class Person < ActiveRecord::Base
2
- usesguid
3
-
4
2
  has_many :elts
5
3
 
6
4
  has_many :choices, :dependent => :destroy
@@ -20,5 +18,16 @@ class Person < ActiveRecord::Base
20
18
  def user
21
19
  return User.find_by_login(name)
22
20
  end
21
+
22
+ def before_create
23
+ # Let's generate a nice looking id
24
+ self.id ||= new_id =
25
+ name.gsub(/\[[\w-]*\]/, '').strip \
26
+ .gsub(/\s/, '_').gsub(/[^\w]+/, '') \
27
+ .gsub(/_+/, '_').gsub(/(^_|_$)/, '') if name
28
+
29
+ i = 0
30
+ self.id = "#{new_id}_#{i+=1}" while self.class.find_by_id self.id
31
+ end
23
32
  end
24
33
 
@@ -1,8 +1,8 @@
1
- <%= form_remote_tag(
1
+ <% form_remote_tag(
2
2
  :update => 'identity',
3
3
  :url => { :controller => 'account', :action => 'login', :elt => @elt },
4
4
  :before => visual_effect(:BlindUp, 'identity')+";resetChoices();",
5
- :loaded => visual_effect(:BlindDown, 'identity')) %>
5
+ :loaded => visual_effect(:BlindDown, 'identity')) do %>
6
6
 
7
7
  <div class="login">Please, choose a pseudo</div>
8
8
 
@@ -58,5 +58,5 @@
58
58
  A login must contain [3..40] characters, a password [5..40].
59
59
  </p>
60
60
  ' } %>
61
- <%= end_form_tag %>
61
+ <% end %>
62
62
 
@@ -1,4 +1,4 @@
1
- <% @flash.each do |key, value| %>
1
+ <% flash.each do |key, value| %>
2
2
  <div class="<%= key %>"><%= value %></div>
3
3
  <% end %>
4
4
 
@@ -15,6 +15,7 @@
15
15
  };
16
16
  updateChoices(choices_to_update);
17
17
  </script>
18
+ <script language="JavaScript">Element.show($('subscriptionLink'));</script>
18
19
  </span>
19
20
  <% end %>
20
21
 
@@ -23,7 +24,7 @@
23
24
  <%= link_to_remote('[X]',
24
25
  { :update => 'identity',
25
26
  :url => { :controller => 'account', :action => 'logout', :elt => @elt },
26
- :before => visual_effect(:BlindUp, 'identity')+";resetChoices();",
27
+ :before => visual_effect(:BlindUp, 'identity')+visual_effect(:BlindUp, 'subscriptionLink')+";resetChoices();",
27
28
  :loaded => visual_effect(:BlindDown, 'identity') },
28
29
  { :href => url_for(:controller => 'account', :action => 'logout') }) %>
29
30
  </span>
@@ -40,40 +41,37 @@
40
41
  </div>
41
42
 
42
43
  <fieldset id="edit"><legend>Edit</legend>
43
- <%= form_remote_tag(
44
+ <% form_remote_tag(
44
45
  :update => 'identity',
45
46
  :url => { :controller => 'account', :action => 'setPassword' },
46
47
  :before => visual_effect(:BlindUp, 'identity'),
47
- :loaded => visual_effect(:BlindDown, 'identity')) %>
48
+ :loaded => visual_effect(:BlindDown, 'identity')) do %>
48
49
  <label for="user_password">Password:</label>
49
50
  <%= password_field "user", "password", :size => 12 %>
50
51
  <%= submit_tag 'OK' %>
51
- <%= end_form_tag %>
52
+ <% end %>
52
53
 
53
- <%= form_remote_tag(
54
+ <% form_remote_tag(
54
55
  :update => 'identity',
55
56
  :url => { :controller => 'account', :action => 'setEmail' },
56
57
  :before => visual_effect(:BlindUp, 'identity'),
57
- :loaded => visual_effect(:BlindDown, 'identity')) %>
58
+ :loaded => visual_effect(:BlindDown, 'identity')) do %>
58
59
  <label for="person_email">Email:</label>
59
60
  <%= text_field "person", "email", :size => 16 %>
60
61
  <%= submit_tag 'OK' %>
61
- <%= end_form_tag %>
62
+ <% end %>
62
63
 
63
- <%= form_tag( { :controller => "account", :action => "setAvatar"},
64
- :multipart => true, :target => "avatar", :class => "setAvatar") %>
64
+ <% form_tag( { :controller => "account", :action => "setAvatar"},
65
+ :multipart => true, :target => "avatar", :class => "setAvatar") do %>
65
66
  <label>Avatar:</label>
66
67
  <%= file_field "person", "image", :onchange => "submit()", :size => 3 %>
67
68
  <%= submit_tag 'OK' %>
68
- <%= end_form_tag %>
69
+ <% end %>
69
70
  </fieldset>
70
71
 
71
72
  <iframe id="avatar" name="avatar" style="display: none"></iframe>
72
-
73
- <script language="JavaScript">Element.show($('subscriptionLink'));</script>
74
73
  <% else %>
75
74
 
76
75
  <%= render :partial => '/account/login' %>
77
- <script language="JavaScript">Element.hide($('subscriptionLink'));</script>
78
76
  <% end %>
79
77
 
@@ -5,7 +5,7 @@ result = elt.result
5
5
 
6
6
  <label class="con <%= choice and choice.value == -1 ? "selected" : "" %>"
7
7
  title="-1" for="choice_<%= elt.id %>_con">
8
- <%= image_tag 'vote_minus' %>
8
+ <%= image_tag 'vote_minus.png' %>
9
9
  <%= radio_button_tag "choice[value]", "-1",
10
10
  (choice and choice.value == -1),
11
11
  :id => "choice_#{elt.id}_con",
@@ -22,7 +22,7 @@ result = elt.result
22
22
 
23
23
  <label class="pro <%= choice and choice.value == 1 ? "selected" : "" %>"
24
24
  title="+1" for="choice_<%= elt.id %>_pro">
25
- <%= image_tag 'vote_plus' %>
25
+ <%= image_tag 'vote_plus.png' %>
26
26
  <%= radio_button_tag "choice[value]", "+1",
27
27
  (choice and choice.value == +1),
28
28
  :id => "choice_#{elt.id}_pro",
@@ -32,7 +32,7 @@ result = elt.result
32
32
  <%= submit_tag 'Vote!' %>
33
33
 
34
34
  <span class="eltQuickAdd" id="eltQuickAdd_<%= elt.id %>" title="<%= elt.created_on %>">
35
- <%= link_to_remote(image_tag('write'),
35
+ <%= link_to_remote(image_tag('write.png'),
36
36
  { :update => 'eltNew_'+elt.id.to_s,
37
37
  :url => { :controller => 'elt', :action => 'new', :id => elt },
38
38
  :loaded => visual_effect(:BlindDown, 'eltNew_'+elt.id.to_s)+
@@ -2,13 +2,13 @@
2
2
  <script>setKnobs($('elt_<%= elt.id %>'));</script>
3
3
 
4
4
  <!-- The form is here to make sure a text browser can see it all on one line -->
5
- <%= form_remote_tag(
5
+ <% form_remote_tag(
6
6
  :update => 'eltChoice_'+elt.id.to_s,
7
7
  :url => { :action => 'vote', :id => elt },
8
8
  :before => visual_effect(:DropOut, 'eltChoice_'+elt.id.to_s, { :queue => 'end' }),
9
- :loaded => visual_effect(:Grow, 'eltChoice_'+elt.id.to_s, { :queue => 'end' })) %>
9
+ :loaded => visual_effect(:Grow, 'eltChoice_'+elt.id.to_s, { :queue => 'end' })) do
10
10
 
11
- <% cache :action => 'show', :id => elt.id do %>
11
+ cache :action => 'show', :id => elt.id do %>
12
12
  <% if displayTitle? elt and elt.created_on %>
13
13
  <span class="created_on"><%= elt.created_on.strftime('%d/%m/%y %H:%M') %></span>
14
14
  <% end %>
@@ -67,7 +67,7 @@
67
67
  { :href => url_for(:controller => 'elt', :action => 'show', :id => elt) }) %>
68
68
  </span>
69
69
  <!-- The choice end form, here to make sure it looks nice in text browsers -->
70
- <%= end_form_tag %>
70
+ <% end %>
71
71
 
72
72
  <ul class="eltNew" id="eltNew_<%= elt.id %>"></ul>
73
73