parlement 0.14 → 0.17
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.
- data/CHANGES +41 -1
- data/MEMORY +66 -5
- data/README +10 -5
- data/Rakefile +15 -23
- data/app/controllers/account_controller.rb +48 -43
- data/app/controllers/{application.rb → application_controller.rb} +15 -12
- data/app/controllers/elt_controller.rb +77 -32
- data/app/controllers/subscriber_controller.rb +11 -10
- data/app/helpers/application_helper.rb +14 -1
- data/app/helpers/elt_helper.rb +9 -7
- data/app/models/elt.rb +25 -24
- data/app/models/mail.rb +44 -47
- data/app/models/person_notify.rb +2 -2
- data/app/models/user.rb +128 -2
- data/app/models/user_notify.rb +15 -15
- data/app/views/account/_login.rhtml +39 -39
- data/app/views/account/_show.rhtml +22 -30
- data/app/views/account/signup.rhtml +2 -2
- data/app/views/elt/_choice.rhtml +6 -6
- data/app/views/elt/_elt.rhtml +27 -32
- data/app/views/elt/choices.rhtml +16 -18
- data/app/views/elt/list/_byDate.rhtml +14 -14
- data/app/views/elt/list/_byVote.rhtml +15 -15
- data/app/views/elt/list/_children.rhtml +48 -40
- data/app/views/elt/list/_subscribers.rhtml +1 -1
- data/app/views/elt/new.rhtml +22 -21
- data/app/views/elt/rss.rxml +4 -11
- data/app/views/elt/show.rhtml +65 -61
- data/app/views/elt/vote_rss.rxml +4 -11
- data/app/views/layouts/top.rhtml +39 -50
- data/app/views/person/_listElts.rhtml +1 -1
- data/app/views/person/show.rhtml +1 -1
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/change_password.rhtml +0 -0
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/delete.rhtml +0 -0
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/forgot_password.rhtml +0 -0
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/pending_delete.rhtml +0 -0
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/signup.rhtml +0 -0
- data/config/boot.rb +97 -32
- data/config/environment.rb +37 -35
- data/config/environments/development.rb +2 -3
- data/config/environments/production.rb +3 -0
- data/config/initializers/string_ruby_1.8.rb +10 -0
- data/config/routes.rb +17 -22
- data/db/schema.rb +102 -74
- data/lib/tasks/rspec.rake +167 -0
- data/public/404.html +25 -7
- data/public/500.html +26 -7
- data/public/dispatch.cgi +0 -0
- data/public/dispatch.fcgi +0 -0
- data/public/dispatch.rb +0 -0
- data/public/images/live_tree_branch_collapsed_icon.gif +0 -0
- data/public/images/live_tree_branch_expanded_icon.gif +0 -0
- data/public/images/live_tree_leaf_icon.gif +0 -0
- data/public/javascripts/application.js +258 -0
- data/public/javascripts/controls.js +544 -414
- data/public/javascripts/dragdrop.js +229 -198
- data/public/javascripts/effects.js +499 -459
- data/public/javascripts/prototype.js +2926 -1121
- data/public/javascripts/shadedborder.js +68 -50
- data/public/stylesheets/default.css +34 -34
- data/public/stylesheets/live_tree.css +0 -0
- data/public/stylesheets/scaffold.css +6 -6
- data/script/about +0 -0
- data/script/autospec +6 -0
- data/script/benchmarker +0 -0
- data/script/breakpointer +0 -0
- data/script/console +0 -0
- data/script/dbconsole +3 -0
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/plugin +0 -0
- data/script/profiler +0 -0
- data/script/runner +0 -0
- data/script/server +0 -0
- data/script/spec +10 -0
- data/script/spec_server +9 -0
- data/test/unit/attachment_test.rb +4 -4
- data/test/unit/choice_test.rb +1 -1
- data/test/unit/elt_test.rb +9 -9
- data/test/unit/mail_notify_test.rb +2 -2
- data/test/unit/mail_test.rb +18 -11
- data/test/unit/person_notify_test.rb +1 -1
- data/test/unit/person_test.rb +1 -1
- data/test/unit/subscriber_test.rb +1 -1
- data/test/unit/user_test.rb +81 -0
- data/test/unit/visit_test.rb +6 -6
- data/vendor/plugins/activerecord_foreign_key_extensions/init.rb +2 -0
- data/vendor/plugins/activerecord_foreign_key_extensions/lib/active_record_extensions.rb +182 -0
- data/vendor/plugins/activerecord_text_id_extensions/init.rb +2 -0
- data/vendor/plugins/activerecord_text_id_extensions/lib/active_record_extensions.rb +24 -0
- data/vendor/plugins/acts_as_nested_set/README +15 -0
- data/vendor/plugins/acts_as_nested_set/init.rb +1 -0
- data/vendor/plugins/acts_as_nested_set/lib/active_record/acts/nested_set.rb +210 -0
- data/vendor/plugins/acts_as_nested_set/test/nested_set_test.rb +269 -0
- data/vendor/plugins/acts_as_tree/README +26 -0
- data/vendor/plugins/acts_as_tree/Rakefile +22 -0
- data/vendor/plugins/acts_as_tree/init.rb +1 -0
- data/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +96 -0
- data/vendor/plugins/{output_compression/CHANGELOG → acts_as_tree/test/abstract_unit.rb} +0 -0
- data/vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb +219 -0
- data/vendor/plugins/acts_as_tree/test/database.yml +0 -0
- data/vendor/plugins/acts_as_tree/test/fixtures/mixin.rb +0 -0
- data/vendor/plugins/acts_as_tree/test/fixtures/mixins.yml +0 -0
- data/vendor/plugins/acts_as_tree/test/schema.rb +0 -0
- data/vendor/plugins/classic_pagination/CHANGELOG +152 -0
- data/vendor/plugins/classic_pagination/README +18 -0
- data/vendor/plugins/{output_compression/rakefile → classic_pagination/Rakefile} +22 -22
- data/vendor/plugins/classic_pagination/init.rb +33 -0
- data/vendor/plugins/classic_pagination/install.rb +1 -0
- data/vendor/plugins/classic_pagination/lib/pagination.rb +405 -0
- data/vendor/plugins/classic_pagination/lib/pagination_helper.rb +135 -0
- data/vendor/plugins/classic_pagination/test/fixtures/companies.yml +24 -0
- data/vendor/plugins/classic_pagination/test/fixtures/company.rb +9 -0
- data/vendor/plugins/classic_pagination/test/fixtures/developer.rb +7 -0
- data/vendor/plugins/classic_pagination/test/fixtures/developers.yml +21 -0
- data/vendor/plugins/classic_pagination/test/fixtures/developers_projects.yml +13 -0
- data/vendor/plugins/classic_pagination/test/fixtures/project.rb +3 -0
- data/vendor/plugins/classic_pagination/test/fixtures/projects.yml +7 -0
- data/vendor/plugins/classic_pagination/test/fixtures/replies.yml +13 -0
- data/vendor/plugins/classic_pagination/test/fixtures/reply.rb +5 -0
- data/vendor/plugins/classic_pagination/test/fixtures/schema.sql +42 -0
- data/vendor/plugins/classic_pagination/test/fixtures/topic.rb +3 -0
- data/vendor/plugins/classic_pagination/test/fixtures/topics.yml +22 -0
- data/vendor/plugins/classic_pagination/test/helper.rb +117 -0
- data/vendor/plugins/classic_pagination/test/pagination_helper_test.rb +38 -0
- data/vendor/plugins/classic_pagination/test/pagination_test.rb +177 -0
- data/vendor/plugins/file_column/lib/file_column.rb +1 -1
- data/vendor/plugins/file_column/test/file_column_test.rb +0 -0
- metadata +151 -197
- data/app/helpers/live_tree.rb +0 -238
- data/app/views/elt/_form.rhtml +0 -31
- data/app/views/elt/show_tree.rhtml +0 -8
- data/config/environments/user_environment.rb +0 -1
- data/db/ROOT/Titemagli.txt +0 -3
- data/db/ROOT/titemagli.txt +0 -9
- data/public/javascripts/behaviour.js +0 -254
- data/public/javascripts/ie7-load.htc +0 -1
- data/public/javascripts/ie7.js +0 -6
- data/public/javascripts/live_tree.js +0 -749
- data/public/javascripts/mybehaviour.js +0 -225
- data/public/javascripts/scriptaculous.js +0 -47
- data/public/javascripts/slider.js +0 -283
- data/public/stylesheets/blue.css +0 -471
- data/vendor/plugins/engines/CHANGELOG +0 -241
- data/vendor/plugins/engines/MIT-LICENSE +0 -21
- data/vendor/plugins/engines/README +0 -64
- data/vendor/plugins/engines/Rakefile +0 -32
- data/vendor/plugins/engines/UPGRADING +0 -93
- data/vendor/plugins/engines/about.yml +0 -7
- data/vendor/plugins/engines/generators/plugin_migration/USAGE +0 -45
- data/vendor/plugins/engines/generators/plugin_migration/plugin_migration_generator.rb +0 -79
- data/vendor/plugins/engines/generators/plugin_migration/templates/plugin_migration.erb +0 -13
- data/vendor/plugins/engines/init.rb +0 -40
- data/vendor/plugins/engines/install.rb +0 -32
- data/vendor/plugins/engines/lib/engines.rb +0 -323
- data/vendor/plugins/engines/lib/engines/deprecated_config_support.rb +0 -135
- data/vendor/plugins/engines/lib/engines/plugin.rb +0 -214
- data/vendor/plugins/engines/lib/engines/plugin_list.rb +0 -31
- data/vendor/plugins/engines/lib/engines/plugin_migrator.rb +0 -60
- data/vendor/plugins/engines/lib/engines/rails_extensions.rb +0 -6
- data/vendor/plugins/engines/lib/engines/rails_extensions/active_record.rb +0 -19
- data/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb +0 -143
- data/vendor/plugins/engines/lib/engines/rails_extensions/migrations.rb +0 -155
- data/vendor/plugins/engines/lib/engines/rails_extensions/public_asset_helpers.rb +0 -116
- data/vendor/plugins/engines/lib/engines/rails_extensions/rails.rb +0 -20
- data/vendor/plugins/engines/lib/engines/rails_extensions/rails_initializer.rb +0 -86
- data/vendor/plugins/engines/lib/engines/rails_extensions/routing.rb +0 -77
- data/vendor/plugins/engines/lib/engines/rails_extensions/templates.rb +0 -140
- data/vendor/plugins/engines/lib/engines/testing.rb +0 -87
- data/vendor/plugins/engines/tasks/engines.rake +0 -149
- data/vendor/plugins/login_engine/CHANGELOG +0 -22
- data/vendor/plugins/login_engine/README +0 -344
- data/vendor/plugins/login_engine/app/controllers/user_controller.rb +0 -262
- data/vendor/plugins/login_engine/app/helpers/user_helper.rb +0 -88
- data/vendor/plugins/login_engine/app/models/user.rb +0 -7
- data/vendor/plugins/login_engine/app/models/user_notify.rb +0 -75
- data/vendor/plugins/login_engine/app/views/user/_edit.rhtml +0 -11
- data/vendor/plugins/login_engine/app/views/user/_password.rhtml +0 -9
- data/vendor/plugins/login_engine/app/views/user/change_password.rhtml +0 -17
- data/vendor/plugins/login_engine/app/views/user/edit.rhtml +0 -23
- data/vendor/plugins/login_engine/app/views/user/forgot_password.rhtml +0 -18
- data/vendor/plugins/login_engine/app/views/user/home.rhtml +0 -7
- data/vendor/plugins/login_engine/app/views/user/login.rhtml +0 -17
- data/vendor/plugins/login_engine/app/views/user/logout.rhtml +0 -8
- data/vendor/plugins/login_engine/app/views/user/signup.rhtml +0 -17
- data/vendor/plugins/login_engine/db/migrate/001_initial_schema.rb +0 -25
- data/vendor/plugins/login_engine/init_engine.rb +0 -11
- data/vendor/plugins/login_engine/install.rb +0 -4
- data/vendor/plugins/login_engine/lib/login_engine.rb +0 -62
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_system.rb +0 -113
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb +0 -155
- data/vendor/plugins/login_engine/public/stylesheets/login_engine.css +0 -81
- data/vendor/plugins/login_engine/test/fixtures/users.yml +0 -41
- data/vendor/plugins/login_engine/test/functional/user_controller_test.rb +0 -536
- data/vendor/plugins/login_engine/test/mocks/mail.rb +0 -14
- data/vendor/plugins/login_engine/test/mocks/time.rb +0 -19
- data/vendor/plugins/login_engine/test/test_helper.rb +0 -11
- data/vendor/plugins/login_engine/test/unit/user_test.rb +0 -114
- data/vendor/plugins/output_compression/MIT-LICENSE +0 -20
- data/vendor/plugins/output_compression/README +0 -4
- data/vendor/plugins/output_compression/init.rb +0 -1
- data/vendor/plugins/output_compression/lib/output_compression.rb +0 -84
- data/vendor/plugins/output_compression/test/output_test.rb +0 -11
- data/vendor/plugins/output_compression/test/test_controller.rb +0 -3
- data/vendor/plugins/output_compression/test/test_helper.rb +0 -14
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
# The filters added to this controller will be run for all controllers in the application.
|
|
2
2
|
# Likewese will all the methods added be available for all controllers.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
# Added temporarily, until gettext has evolved to invlude it
|
|
5
|
+
## See http://zargony.com/2008/02/12/edge-rails-and-gettext-undefined-method-file_exists-nomethoderror
|
|
6
|
+
module ActionView
|
|
7
|
+
class Base
|
|
8
|
+
delegate :file_exists?, :to => :finder unless respond_to?(:file_exists?)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
6
11
|
|
|
7
12
|
class ApplicationController < ActionController::Base
|
|
8
|
-
helper_method :filter
|
|
9
|
-
|
|
10
|
-
include LoginEngine
|
|
11
13
|
include Term::ANSIColor
|
|
12
14
|
|
|
13
15
|
init_gettext "parlement"
|
|
14
16
|
|
|
17
|
+
helper_method :filter
|
|
18
|
+
|
|
15
19
|
before_filter :set_login_from_cookie
|
|
16
20
|
#after_filter :fix_unicode_for_safari
|
|
17
|
-
after_filter OutputCompressionFilter
|
|
18
21
|
|
|
19
22
|
# automatically and transparently fixes utf-8 bug
|
|
20
23
|
# with Safari when using xmlhttp
|
|
@@ -26,15 +29,15 @@ class ApplicationController < ActionController::Base
|
|
|
26
29
|
end
|
|
27
30
|
|
|
28
31
|
def set_login_from_cookie
|
|
29
|
-
unless session[:lastUpdatedView] or session[:
|
|
32
|
+
unless session[:lastUpdatedView] or session[:person_id]
|
|
30
33
|
if (cookies[:person_name] and \
|
|
31
34
|
person = Person.find_by_name(cookies[:person_name])) and \
|
|
32
35
|
((!person.user and !cookies[:salted_password]) \
|
|
33
36
|
or (person.user \
|
|
34
37
|
and person.user.salted_password == cookies[:salted_password]))
|
|
35
38
|
logger.info yellow { bold { "#{person.name} is back" } }
|
|
36
|
-
session[:
|
|
37
|
-
session[:
|
|
39
|
+
session[:person_id] = person.id
|
|
40
|
+
session[:user_id] = person.user.id if person.user
|
|
38
41
|
|
|
39
42
|
person.last_login = Time.now
|
|
40
43
|
person.save!
|
|
@@ -43,11 +46,11 @@ class ApplicationController < ActionController::Base
|
|
|
43
46
|
end
|
|
44
47
|
|
|
45
48
|
def filter
|
|
46
|
-
if request.cookies['filter'] && request.cookies['filter']
|
|
47
|
-
filter = request.cookies['filter']
|
|
49
|
+
if request.cookies['filter'] && request.cookies['filter']
|
|
50
|
+
filter = request.cookies['filter'].to_i - 1
|
|
48
51
|
filter = nil unless filter >= 0
|
|
49
52
|
else
|
|
50
|
-
filter =
|
|
53
|
+
filter = 1
|
|
51
54
|
end
|
|
52
55
|
filter
|
|
53
56
|
end
|
|
@@ -1,26 +1,43 @@
|
|
|
1
1
|
#
|
|
2
|
-
# This is the central
|
|
2
|
+
# This is the central element to parlement
|
|
3
3
|
#
|
|
4
4
|
# An element is just the name for a poll/message/issue
|
|
5
5
|
#
|
|
6
6
|
class EltController < ApplicationController
|
|
7
7
|
def index
|
|
8
|
-
params[:id] = params[:id].gsub(/.html/, '')
|
|
9
8
|
show
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
def show
|
|
12
|
+
params[:id] = request.subdomains[0] unless params[:id]
|
|
13
|
+
params[:id] = Elt.find(:first, :conditions => "parent_id = 'ROOT'", :order => 'created_on').id unless params[:id]
|
|
13
14
|
params[:id] = params[:id].gsub(/.html/, '')
|
|
15
|
+
|
|
14
16
|
@elt = Elt.find(params[:id])
|
|
15
17
|
@title = @elt.subject
|
|
16
18
|
@title += " (parlement)" if !@title.downcase.include? "parlement"
|
|
17
19
|
|
|
18
|
-
render :layout => 'top'
|
|
20
|
+
render :layout => 'top', :template => 'elt/show'
|
|
21
|
+
|
|
22
|
+
#rescue ActiveRecord::StatementInvalid => e
|
|
23
|
+
# load 'db/schema.rb'
|
|
24
|
+
# redirect_to '/'
|
|
19
25
|
|
|
20
26
|
rescue ActiveRecord::RecordNotFound => e
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
root = Elt.find_by_id('ROOT')
|
|
28
|
+
if root and root.children.size > 0
|
|
29
|
+
render :status => 404, :file => "#{RAILS_ROOT}/public/404.html"
|
|
30
|
+
else
|
|
31
|
+
if root
|
|
32
|
+
@elt = root
|
|
33
|
+
else
|
|
34
|
+
@elt = Elt.new :subject => '', :lft => 0, :rgt => 1, :last_activity => Time.now
|
|
35
|
+
@elt.id = 'ROOT'
|
|
36
|
+
@elt.save
|
|
37
|
+
end
|
|
38
|
+
flash[:notice] = _("You need to create a top object (click on the new icon below)")
|
|
39
|
+
render :layout => 'top'
|
|
40
|
+
end
|
|
24
41
|
end
|
|
25
42
|
|
|
26
43
|
def list
|
|
@@ -49,14 +66,7 @@ class EltController < ApplicationController
|
|
|
49
66
|
end
|
|
50
67
|
|
|
51
68
|
def updateView
|
|
52
|
-
|
|
53
|
-
# Protection against some browsers updating too fast
|
|
54
|
-
logger.info "Too soon"
|
|
55
|
-
render :inline => ""
|
|
56
|
-
return
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
session[:lastUpdatedView] ||= Time.now - 10
|
|
69
|
+
session[:lastUpdatedView] ||= Time.now - UPDATE_VIEW_PERIOD
|
|
60
70
|
|
|
61
71
|
@elt = Elt.find(params[:id])
|
|
62
72
|
acts = ""
|
|
@@ -69,7 +79,7 @@ class EltController < ApplicationController
|
|
|
69
79
|
</script> \
|
|
70
80
|
" if @elt.last_activity > session[:lastUpdatedView]
|
|
71
81
|
|
|
72
|
-
if person = session[:
|
|
82
|
+
if person = Person.find_by_id(session[:person_id])
|
|
73
83
|
visits = Visit.count \
|
|
74
84
|
:joins => "JOIN elts e1 ON e1.id = '#{params[:id]}' \
|
|
75
85
|
JOIN elts e2 ON visits.elt_id = e2.id \
|
|
@@ -98,14 +108,14 @@ class EltController < ApplicationController
|
|
|
98
108
|
|
|
99
109
|
visit = Visit.find_by_person_id_and_elt_id(person, params[:id])
|
|
100
110
|
if visit and person.last_login and person.last_login > visit.created_on then
|
|
101
|
-
logger.info "New visit"
|
|
111
|
+
logger.info yellow { "New visit" }
|
|
102
112
|
visit.destroy
|
|
103
113
|
visit = nil
|
|
104
114
|
end
|
|
105
115
|
visit = Visit.new(:person => person, :elt_id => params[:id]) unless visit
|
|
106
116
|
visit.filter = filter
|
|
107
117
|
visit.save!
|
|
108
|
-
logger.info "#{visits} visit(s), #{subscribers} subscriber(s)"
|
|
118
|
+
logger.info magenta { "#{visits} visit(s), #{subscribers} subscriber(s)" }
|
|
109
119
|
end
|
|
110
120
|
|
|
111
121
|
session[:lastUpdatedView] = Time.now
|
|
@@ -113,37 +123,61 @@ class EltController < ApplicationController
|
|
|
113
123
|
end
|
|
114
124
|
|
|
115
125
|
def rss
|
|
126
|
+
params[:id] = nil if params[:id].size == 0
|
|
127
|
+
params[:id] = request.subdomains[0] unless params[:id]
|
|
128
|
+
params[:id] = Elt.find(:first, :conditions => "parent_id = 'ROOT'", :order => 'created_on').id unless params[:id]
|
|
116
129
|
params[:id] = params[:id].gsub(/.rss/, '')
|
|
117
130
|
headers["Content-Type"] = "text/xml; charset=utf-8"
|
|
118
131
|
@elt = Elt.find(params[:id]) if @elt == nil
|
|
132
|
+
|
|
133
|
+
rescue ActiveRecord::RecordNotFound => e
|
|
134
|
+
redirect_to '/404.html'
|
|
119
135
|
end
|
|
120
136
|
|
|
121
137
|
def vote_rss
|
|
138
|
+
params[:id] = nil if params[:id].size == 0
|
|
139
|
+
params[:id] = request.subdomains[0] unless params[:id]
|
|
140
|
+
params[:id] = Elt.find(:first, :conditions => "parent_id = 'ROOT'", :order => 'created_on').id unless params[:id]
|
|
122
141
|
params[:id] = params[:id].gsub(/.rss/, '')
|
|
123
142
|
headers["Content-Type"] = "text/xml; charset=utf-8"
|
|
124
143
|
@elt = Elt.find(params[:id]) if @elt == nil
|
|
144
|
+
|
|
145
|
+
rescue ActiveRecord::RecordNotFound => e
|
|
146
|
+
redirect_to '/404.html'
|
|
125
147
|
end
|
|
126
148
|
|
|
127
149
|
# Used to initialise the elt, its subject mainly
|
|
128
150
|
def new
|
|
129
151
|
@elt = Elt.new(:parent_id => params[:id], :body => "")
|
|
130
152
|
|
|
131
|
-
if @elt.parent
|
|
132
|
-
|
|
153
|
+
if @elt.parent then
|
|
154
|
+
if @elt.parent.subject.include? 'Re: '
|
|
155
|
+
@elt.subject = @elt.parent.subject
|
|
156
|
+
else
|
|
157
|
+
@elt.subject = 'Re: '+@elt.parent.subject
|
|
158
|
+
end
|
|
133
159
|
else
|
|
134
|
-
|
|
160
|
+
# Rejected if you are not coming from a valid elt
|
|
161
|
+
render :status => 404, :file => "#{RAILS_ROOT}/public/404.html"
|
|
135
162
|
end
|
|
136
163
|
end
|
|
137
164
|
|
|
138
165
|
def create
|
|
139
166
|
@elt = Elt.new(params[:elt])
|
|
140
|
-
@elt.person = session[:
|
|
167
|
+
@elt.person = Person.find_by_id(session[:person_id])
|
|
141
168
|
|
|
142
|
-
if
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
169
|
+
if !@elt.parent then
|
|
170
|
+
# Rejected if you are not coming from a valid elt
|
|
171
|
+
render :status => 404, :file => "#{RAILS_ROOT}/public/404.html"
|
|
172
|
+
return
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
if ((!@elt.person \
|
|
176
|
+
and (@elt.subject =~ /([<>\/]|href)/ \
|
|
177
|
+
or @elt.body =~ /(.*(http|href)(.*\n)*)/ \
|
|
178
|
+
or @elt.body =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i \
|
|
179
|
+
or @elt.body =~ /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}.*){3}/i)) \
|
|
180
|
+
or ((!@elt.person or @elt.person.elts.size <= 1) and @elt.body =~ /(http|href)/)) then
|
|
147
181
|
logger.error red { underline { "SPAM! '#{@elt.subject}'" } }
|
|
148
182
|
logger.error "SPAM! '#{@elt.body}'"
|
|
149
183
|
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!')
|
|
@@ -182,7 +216,13 @@ class EltController < ApplicationController
|
|
|
182
216
|
|
|
183
217
|
def vote
|
|
184
218
|
@elt = Elt.find params[:id]
|
|
185
|
-
|
|
219
|
+
if !session[:person_id] then
|
|
220
|
+
flash[:error] = 'Sorry, need to be authenticated to vote!'
|
|
221
|
+
render :partial => '/elt/choice', :locals => { :elt => @elt }
|
|
222
|
+
return
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
if !params[:choice][:value] =~ /^\s*(-1|0|\+1)(\s|$)/ then
|
|
186
226
|
logger.error red { underline { "SPAM! through the vote" } }
|
|
187
227
|
logger.error params[:choice][:value]
|
|
188
228
|
flash[:error] = 'Sorry, you can only vote here!'
|
|
@@ -191,24 +231,29 @@ class EltController < ApplicationController
|
|
|
191
231
|
end
|
|
192
232
|
|
|
193
233
|
vote = @elt.children.build
|
|
194
|
-
vote.person = session[:
|
|
234
|
+
vote.person = Person.find_by_id(session[:person_id])
|
|
195
235
|
vote.subject = @elt.subject
|
|
196
236
|
vote.subject = 'Re: '+vote.subject if vote.subject and !vote.subject.include? 'Re: '
|
|
197
237
|
vote.body = params[:choice][:value]
|
|
198
238
|
|
|
199
|
-
choice = Choice.find_by_elt_id_and_person_id @elt.id,
|
|
239
|
+
choice = Choice.find_by_elt_id_and_person_id @elt.id, session[:person_id]
|
|
200
240
|
|
|
201
241
|
if choice and choice.value == vote.body.to_i then
|
|
202
|
-
logger.info "#{
|
|
242
|
+
logger.info "#{session[:person_id]} voting 0"
|
|
203
243
|
vote.body = "0"
|
|
204
244
|
else
|
|
205
|
-
logger.info "#{
|
|
245
|
+
logger.info "#{session[:person_id]} voting #{params[:choice][:value]}"
|
|
206
246
|
end
|
|
207
247
|
|
|
208
248
|
vote.publish
|
|
209
249
|
@elt.add_child vote
|
|
210
|
-
expire_fragment :action => 'show', :id => @elt.id
|
|
211
250
|
|
|
212
251
|
render :partial => '/elt/choice', :locals => { :elt => @elt }
|
|
213
252
|
end
|
|
253
|
+
|
|
254
|
+
def choices
|
|
255
|
+
@elt = Elt.find params[:id]
|
|
256
|
+
rescue ActiveRecord::RecordNotFound => e
|
|
257
|
+
render :status => 404, :file => "#{RAILS_ROOT}/public/404.html"
|
|
258
|
+
end
|
|
214
259
|
end
|
|
@@ -6,19 +6,20 @@
|
|
|
6
6
|
class SubscriberController < ApplicationController
|
|
7
7
|
def subscribe
|
|
8
8
|
@elt = Elt.find params[:id]
|
|
9
|
+
@person = Person.find(session[:person_id])
|
|
9
10
|
|
|
10
|
-
if
|
|
11
|
-
if @elt.subscribers.include?(
|
|
12
|
-
Subscription.find_by_person_id_and_elt_id(
|
|
13
|
-
logger.info yellow { "User #{
|
|
14
|
-
elsif @elt.all_recipients.include?(
|
|
11
|
+
if @person
|
|
12
|
+
if @elt.subscribers.include?(@person)
|
|
13
|
+
Subscription.find_by_person_id_and_elt_id(@person.id, @elt.id).destroy
|
|
14
|
+
logger.info yellow { "User #{@person.name} unsubscribed from #{@elt.subject}..." }
|
|
15
|
+
elsif @elt.all_recipients.include?(@person)
|
|
15
16
|
elt2 = @elt
|
|
16
|
-
elt2 = elt2.parent until elt2.subscribers.include?(
|
|
17
|
-
Subscription.find_by_person_id_and_elt_id(
|
|
18
|
-
logger.info yellow { "User #{
|
|
17
|
+
elt2 = elt2.parent until elt2.subscribers.include?(@person)
|
|
18
|
+
Subscription.find_by_person_id_and_elt_id(@person.id, elt2.id).destroy
|
|
19
|
+
logger.info yellow { "User #{@person.name} unsubscribed from #{elt2.subject}..." }
|
|
19
20
|
else
|
|
20
|
-
@elt.subscriptions.create :person =>
|
|
21
|
-
logger.info yellow { "User #{
|
|
21
|
+
@elt.subscriptions.create :person => @person, :filter => filter
|
|
22
|
+
logger.info yellow { "User #{@person.name} subscribed to #{@elt.id} with filter #{filter}..." }
|
|
22
23
|
end
|
|
23
24
|
else
|
|
24
25
|
puts "Not logged in!"
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
# Methods added to this helper will be available to all templates in the application.
|
|
2
2
|
module ApplicationHelper
|
|
3
|
-
|
|
3
|
+
def link_to(*args, &block)
|
|
4
|
+
if (request.subdomains[0] \
|
|
5
|
+
and args[1][:id] \
|
|
6
|
+
and (args[1][:id] == request.subdomains[0] \
|
|
7
|
+
or (args[1][:id].class == Elt and args[1][:id].id == request.subdomains[0])))
|
|
8
|
+
args[1][:id] = ''
|
|
9
|
+
elsif ! request.subdomains[0] \
|
|
10
|
+
and args[1][:id].class == Elt \
|
|
11
|
+
and args[1][:id].id == Elt.find(:first, :conditions => "parent_id = 'ROOT'", :order => 'created_on').id
|
|
12
|
+
args[1][:id] = ''
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
super(*args)
|
|
16
|
+
end
|
|
4
17
|
end
|
data/app/helpers/elt_helper.rb
CHANGED
|
@@ -61,14 +61,16 @@ module EltHelper
|
|
|
61
61
|
'\1\3\3* <a class="readMore" href="#" onclick="Element.hide(this.parentNode.parentNode); Element.removeClassName(this.parentNode.parentNode.nextSibling.nextSibling, \'tooLarge\'); return false;">Read more... / Lire plus...</a>\3\3<div class="tooLarge">\3\3\2</div>') \
|
|
62
62
|
if data and text.strip =~ /(?:(?:^\*\s+.+$\n){#{NB_PARAGRAPH_TO_DISPLAY*2+2}})/
|
|
63
63
|
|
|
64
|
-
#hard_breaks = true
|
|
65
64
|
textiled = text.blank? ? "" : RedCloth.new(text)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
if !textiled.blank?
|
|
66
|
+
begin
|
|
67
|
+
textiled.hard_breaks = false
|
|
68
|
+
textiled = textiled.to_html
|
|
69
|
+
rescue
|
|
70
|
+
# TODO discover why RedCloth fails on this!!!
|
|
71
|
+
textiled = textiled.gsub(/[->\[]/, ' ')
|
|
72
|
+
textiled = textiled.to_html
|
|
73
|
+
end
|
|
72
74
|
end
|
|
73
75
|
if ! textiled.match(/[.\s]<p>/) and textiled.size < 200 then
|
|
74
76
|
# Remove any leading and finishing <p> </p> as they are not required
|
data/app/models/elt.rb
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
#
|
|
18
18
|
class Elt < ActiveRecord::Base
|
|
19
19
|
belongs_to :person
|
|
20
|
+
|
|
20
21
|
has_one :mail, :dependent => :destroy
|
|
21
22
|
|
|
22
23
|
has_many :choices, :dependent => :destroy, :order => "choices.created_on"
|
|
@@ -44,9 +45,9 @@ class Elt < ActiveRecord::Base
|
|
|
44
45
|
|
|
45
46
|
def all_subscriptions
|
|
46
47
|
if parent
|
|
47
|
-
|
|
48
|
+
(subscriptions + parent.all_subscriptions).uniq
|
|
48
49
|
else
|
|
49
|
-
|
|
50
|
+
subscriptions
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
|
@@ -78,39 +79,39 @@ class Elt < ActiveRecord::Base
|
|
|
78
79
|
|
|
79
80
|
parent.vote Regexp.last_match(1), person if body =~ /^\s*(-1|0|\+1)(\s|$)/
|
|
80
81
|
if Regexp.last_match(1) and self.body.gsub(/(-1|0|\+1)/, '').strip.empty?
|
|
81
|
-
|
|
82
|
+
# Hide simple votes
|
|
82
83
|
vote -1
|
|
83
84
|
else
|
|
84
85
|
vote if person
|
|
85
86
|
end
|
|
86
87
|
|
|
87
|
-
|
|
88
|
+
parent.add_child(self) unless lft or rgt
|
|
88
89
|
true
|
|
89
90
|
end
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
def before_create
|
|
93
|
+
# Let's generate a nice looking id
|
|
94
|
+
self.id ||= new_id =
|
|
95
|
+
subject.gsub(/\[[\w-]*\]/, '').strip \
|
|
96
|
+
.gsub(/\s/, '_').gsub(/[^\w]+/, '') \
|
|
97
|
+
.gsub(/_+/, '_').gsub(/(^_|_$)/, '') if subject
|
|
98
|
+
self.id ||= "elt"
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
i = 0
|
|
101
|
+
self.id = "#{new_id}_#{i+=1}" while self.class.find_by_id self.id
|
|
102
|
+
end
|
|
102
103
|
|
|
103
104
|
def add_child(c)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
result = super(c)
|
|
106
|
+
p = c
|
|
107
|
+
while p
|
|
108
|
+
if !p.last_activity or p.last_activity < c.created_on then
|
|
109
|
+
p.last_activity = c.created_on
|
|
110
|
+
p.save!
|
|
111
|
+
end
|
|
112
|
+
p = p.parent
|
|
113
|
+
end
|
|
114
|
+
result
|
|
114
115
|
end
|
|
115
116
|
|
|
116
117
|
#
|
data/app/models/mail.rb
CHANGED
|
@@ -30,17 +30,17 @@ class Mail < ActiveRecord::Base
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
44
|
|
|
45
45
|
""" _
|
|
46
46
|
_ __ ___ ___ ___(_)_ _____
|
|
@@ -60,7 +60,13 @@ class Mail < ActiveRecord::Base
|
|
|
60
60
|
logger.info "Receive mail #{mail.message_id}"
|
|
61
61
|
self.mail_parents = mail.references
|
|
62
62
|
self.message = mail.message_id
|
|
63
|
-
|
|
63
|
+
if mail.encoded.isutf8
|
|
64
|
+
self.file = mail.encoded
|
|
65
|
+
else
|
|
66
|
+
charset = mail.type_param 'charset'
|
|
67
|
+
charset ||= 'iso-8859-1'
|
|
68
|
+
self.file = Iconv.iconv('utf-8', charset, mail.encoded).to_s
|
|
69
|
+
end
|
|
64
70
|
|
|
65
71
|
build_elt :created_on => mail.date,
|
|
66
72
|
:subject => unquote(mail.subject),
|
|
@@ -106,19 +112,18 @@ class Mail < ActiveRecord::Base
|
|
|
106
112
|
logger.info "Creating a parent elt with id #{parentId}"
|
|
107
113
|
#puts "Creating a parent elt with id #{parentId}"
|
|
108
114
|
elt.build_parent :parent_id => 'mail', :subject => parentId, :body => ''
|
|
109
|
-
elt.parent.id = parentId
|
|
110
115
|
elt.parent.publish
|
|
111
|
-
elt.save
|
|
112
116
|
end
|
|
113
117
|
|
|
118
|
+
elt.save!
|
|
114
119
|
mngAttachment mail if mail
|
|
115
120
|
|
|
116
121
|
elt.person = Person.find_by_email(mail.from) \
|
|
117
122
|
|| Person.find_by_name(unquote(mail.friendly_from)) \
|
|
118
123
|
|| elt.build_person(:id => unquote(mail.friendly_from).gsub(/\s/, '_'),
|
|
119
124
|
:name => unquote(mail.friendly_from),
|
|
120
|
-
:email => mail.from.first
|
|
121
|
-
|
|
125
|
+
:email => mail.from.first
|
|
126
|
+
) unless mail.from.first.match(/#{ANONYMOUS_POSTER}@#{ActionMailer::Base.smtp_settings[:domain]}/)
|
|
122
127
|
|
|
123
128
|
elt.publish
|
|
124
129
|
|
|
@@ -139,8 +144,8 @@ class Mail < ActiveRecord::Base
|
|
|
139
144
|
# An elt needs to be published as a mail
|
|
140
145
|
#
|
|
141
146
|
def publish
|
|
142
|
-
logger.info "Publish mail for elt #{elt.subject} [#{elt.id}]"
|
|
143
|
-
#puts "Publish mail for elt #{elt.subject} [#{elt.id}]"
|
|
147
|
+
logger.info "Publish mail for elt '#{elt.subject}' [#{elt.id}]"
|
|
148
|
+
#puts "Publish mail for elt '#{elt.subject}' [#{elt.id}]"
|
|
144
149
|
|
|
145
150
|
if message and not message.blank? and file
|
|
146
151
|
mail = TMail::Mail.parse file
|
|
@@ -153,25 +158,18 @@ class Mail < ActiveRecord::Base
|
|
|
153
158
|
self.file = mail.encoded
|
|
154
159
|
end
|
|
155
160
|
|
|
156
|
-
|
|
157
|
-
mail
|
|
158
|
-
mail['List-Archive'] = "http://"+ActionMailer::Base.smtp_settings[:domain]
|
|
159
|
-
mail['Errors-To'] = "errors@"+ActionMailer::Base.smtp_settings[:domain]
|
|
160
|
-
|
|
161
|
-
subscriptions = elt.all_subscriptions \
|
|
161
|
+
# Record all people to whom it was sent
|
|
162
|
+
mail.bcc = elt.all_subscriptions \
|
|
162
163
|
.select { |s| s.person.email and not s.person.email.blank? } \
|
|
163
164
|
.select { |s| #puts "Person: #{s.person.name}, elt: #{s.elt.id}, filter: #{s.filter}";
|
|
164
165
|
not s.filter or (elt.result and elt.result >= s.filter) } \
|
|
165
166
|
.reject { |s| recipients.include? s.person } \
|
|
167
|
+
.uniq \
|
|
168
|
+
.each { |r| person_mails.build :person => r.person } \
|
|
169
|
+
.collect { |i| i.person.email } \
|
|
166
170
|
.uniq
|
|
167
171
|
|
|
168
|
-
|
|
169
|
-
subscriptions.each { |r| person_mails.create :person => r.person }
|
|
170
|
-
# mostly because otherwise the tests don't see it
|
|
171
|
-
person_mails.reload
|
|
172
|
-
recipients.reload
|
|
173
|
-
|
|
174
|
-
mail.bcc = subscriptions.collect { |i| i.person.email }.uniq.join(', ')
|
|
172
|
+
logger.info "Recipients: #{recipients}"
|
|
175
173
|
#puts "mail.bcc: #{mail.bcc}"
|
|
176
174
|
|
|
177
175
|
#
|
|
@@ -192,6 +190,11 @@ class Mail < ActiveRecord::Base
|
|
|
192
190
|
|
|
193
191
|
# Added to make sure it is not lost, but not modified if already existant
|
|
194
192
|
mail['X-Message-Id'] = mail.message_id if not mail['X-Message-Id']
|
|
193
|
+
mail['Precedence'] = 'list'
|
|
194
|
+
mail['X-Loop'] = ActionMailer::Base.smtp_settings[:domain]
|
|
195
|
+
mail['Errors-To'] = "errors@"+ActionMailer::Base.smtp_settings[:domain]
|
|
196
|
+
mail['List-Archive'] = "http://"+ActionMailer::Base.smtp_settings[:domain]
|
|
197
|
+
mail['Parlement-elt-id'] = elt.id
|
|
195
198
|
|
|
196
199
|
if mail.message_id
|
|
197
200
|
# Let's not change the message id
|
|
@@ -223,30 +226,24 @@ class Mail < ActiveRecord::Base
|
|
|
223
226
|
elsif attachment.disposition_param 'filename'
|
|
224
227
|
File.open("/tmp/#{attachment.disposition_param('filename')}", 'w') { |file|
|
|
225
228
|
file << attachment.body
|
|
226
|
-
elt.attachments.build :file => file, :content_type => attachment.content_type
|
|
229
|
+
att = elt.attachments.build :file => file, :content_type => attachment.content_type
|
|
230
|
+
att.save!
|
|
227
231
|
}
|
|
228
232
|
elsif attachment.type_param 'name'
|
|
229
233
|
File.open("/tmp/#{attachment.type_param('name')}", 'w') { |file|
|
|
230
234
|
file << attachment.body
|
|
231
|
-
elt.attachments.build :file => file, :content_type => attachment.content_type
|
|
235
|
+
att = elt.attachments.build :file => file, :content_type => attachment.content_type
|
|
236
|
+
att.save!
|
|
232
237
|
}
|
|
233
238
|
elsif (attachment.content_type and attachment.content_type.match(/text\/plain/)) \
|
|
234
239
|
or (!attachment.content_type and attachment.parts.size == 0)
|
|
235
|
-
|
|
236
|
-
if
|
|
237
|
-
|
|
238
|
-
# Here to correct a null character which can occur in some mails
|
|
239
|
-
# It looks like ==0 or ^@ !!!
|
|
240
|
-
# Otherwise the elt can not be saved in the db :(
|
|
241
|
-
elt.body += Iconv.new(charset, 'iso-8859-1').iconv(attachment.body).gsub(/\0/, '')
|
|
242
|
-
elsif !charset =~ 'uft-8'
|
|
243
|
-
elt.body += Iconv.new(charset, 'iso-8859-1').iconv(attachment.body)
|
|
244
|
-
else
|
|
245
|
-
elt.body += attachment.body
|
|
246
|
-
end
|
|
240
|
+
# Here too have to remove any eventual null character!
|
|
241
|
+
if attachment.body.isutf8
|
|
242
|
+
elt.body += attachment.body
|
|
247
243
|
else
|
|
248
|
-
|
|
249
|
-
|
|
244
|
+
charset = attachment.type_param 'charset'
|
|
245
|
+
charset = 'iso-8859-1' unless charset and charset != 'utf-8'
|
|
246
|
+
elt.body += Iconv.iconv('utf-8', charset, attachment.body).to_s
|
|
250
247
|
end
|
|
251
248
|
end
|
|
252
249
|
end
|