radiant-reader-extension 1.3.13 → 2.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/README.md +2 -2
  2. data/Rakefile +0 -19
  3. data/app/controllers/admin/group_invitations_controller.rb +78 -0
  4. data/app/controllers/admin/groups_controller.rb +8 -0
  5. data/app/controllers/admin/memberships_controller.rb +42 -0
  6. data/app/controllers/admin/messages_controller.rb +8 -3
  7. data/app/controllers/admin/permissions_controller.rb +42 -0
  8. data/app/controllers/admin/reader_configuration_controller.rb +0 -1
  9. data/app/controllers/admin/readers_controller.rb +1 -1
  10. data/app/controllers/password_resets_controller.rb +5 -5
  11. data/app/controllers/reader_action_controller.rb +13 -33
  12. data/app/controllers/reader_activations_controller.rb +4 -8
  13. data/app/controllers/reader_sessions_controller.rb +15 -26
  14. data/app/controllers/readers_controller.rb +26 -9
  15. data/app/helpers/reader_helper.rb +45 -17
  16. data/app/models/group.rb +80 -0
  17. data/app/models/membership.rb +13 -0
  18. data/app/models/message.rb +10 -7
  19. data/app/models/permission.rb +11 -0
  20. data/app/models/reader.rb +79 -35
  21. data/app/models/reader_notifier.rb +1 -0
  22. data/app/views/admin/group_invitations/new.html.haml +31 -0
  23. data/app/views/admin/group_invitations/preview.html.haml +58 -0
  24. data/app/views/admin/groups/_add_readers.html.haml +0 -0
  25. data/app/views/admin/groups/_form.html.haml +26 -0
  26. data/app/views/admin/groups/_list_head.html.haml +12 -0
  27. data/app/views/admin/groups/edit.html.haml +9 -0
  28. data/app/views/admin/groups/index.html.haml +44 -0
  29. data/app/views/admin/groups/new.html.haml +7 -0
  30. data/app/views/admin/groups/remove.html.haml +31 -0
  31. data/app/views/admin/groups/show.html.haml +74 -0
  32. data/app/views/admin/memberships/_reader.html.haml +9 -0
  33. data/app/views/admin/messages/_function.haml +31 -0
  34. data/app/views/admin/messages/_list_function.haml +7 -3
  35. data/app/views/admin/messages/_list_notes.html.haml +9 -0
  36. data/app/views/admin/messages/_message_description.html.haml +5 -1
  37. data/app/views/admin/messages/_message_group.html.haml +5 -0
  38. data/app/views/admin/messages/index.haml +4 -4
  39. data/app/views/admin/messages/show.html.haml +15 -15
  40. data/app/views/admin/pages/_listed.html.haml +16 -0
  41. data/app/views/admin/pages/_page_groups.html.haml +13 -0
  42. data/app/views/admin/permissions/_page.html.haml +24 -0
  43. data/app/views/admin/reader_configuration/edit.html.haml +3 -1
  44. data/app/views/admin/reader_configuration/show.html.haml +4 -2
  45. data/app/views/admin/readers/_form.html.haml +7 -7
  46. data/app/views/admin/readers/_password_fields.html.haml +6 -6
  47. data/app/views/admin/readers/_reader_groups.html.haml +7 -0
  48. data/app/views/admin/readers/edit.html.haml +2 -1
  49. data/app/views/admin/readers/index.html.haml +5 -2
  50. data/app/views/password_resets/create.html.haml +13 -8
  51. data/app/views/password_resets/edit.html.haml +26 -26
  52. data/app/views/password_resets/new.html.haml +28 -25
  53. data/app/views/reader_activations/_activation_required.haml +2 -2
  54. data/app/views/reader_activations/show.html.haml +11 -13
  55. data/app/views/reader_sessions/_login_form.html.haml +13 -12
  56. data/app/views/reader_sessions/new.html.haml +6 -8
  57. data/app/views/readers/_controls.html.haml +11 -9
  58. data/app/views/readers/_form.html.haml +32 -33
  59. data/app/views/readers/_memberships.html.haml +11 -0
  60. data/app/views/readers/edit.html.haml +11 -11
  61. data/app/views/readers/index.html.haml +9 -10
  62. data/app/views/readers/login.html.haml +10 -12
  63. data/app/views/readers/new.html.haml +11 -13
  64. data/app/views/readers/permission_denied.html.haml +7 -7
  65. data/app/views/readers/show.html.haml +7 -8
  66. data/app/views/shared/_standard_reader_parts.html.haml +14 -0
  67. data/app/views/site/not_allowed.html.haml +4 -0
  68. data/config/initializers/authlogic_connect_config.rb +12 -0
  69. data/config/initializers/radiant_config.rb +1 -0
  70. data/config/locales/en.yml +217 -177
  71. data/config/routes.rb +5 -0
  72. data/db/migrate/20090921125654_group_messages.rb +35 -0
  73. data/db/migrate/20091120083119_groups_public.rb +11 -0
  74. data/db/migrate/20110214101339_multiple_ownership.rb +13 -0
  75. data/lib/controller_extensions.rb +1 -1
  76. data/lib/group_tags.rb +65 -0
  77. data/lib/grouped_model.rb +125 -0
  78. data/lib/grouped_page.rb +39 -0
  79. data/lib/message_tags.rb +183 -0
  80. data/lib/radiant-reader-extension.rb +8 -0
  81. data/lib/reader_admin_ui.rb +29 -6
  82. data/lib/reader_tags.rb +7 -183
  83. data/lib/sanitize/config/generous.rb +49 -0
  84. data/lib/site_controller_extensions.rb +35 -0
  85. data/public/javascripts/reader.js +1 -1
  86. data/public/stylesheets/sass/reader.sass +18 -8
  87. data/radiant-reader-extension.gemspec +30 -176
  88. data/reader_extension.rb +31 -23
  89. data/spec/controllers/admin/messages_controller_spec.rb +1 -1
  90. data/spec/controllers/admin/readers_controller_spec.rb +0 -1
  91. data/spec/controllers/password_resets_controller_spec.rb +1 -1
  92. data/spec/controllers/reader_activations_controller_spec.rb +1 -1
  93. data/spec/controllers/readers_controller_spec.rb +67 -40
  94. data/spec/controllers/site_controller_spec.rb +63 -0
  95. data/spec/datasets/readers_dataset.rb +100 -11
  96. data/spec/models/group_spec.rb +46 -0
  97. data/spec/models/message_spec.rb +40 -15
  98. data/spec/models/page_spec.rb +81 -0
  99. data/spec/models/reader_notifier_spec.rb +1 -1
  100. data/spec/models/reader_spec.rb +17 -12
  101. metadata +99 -67
  102. data/.gitignore +0 -2
  103. data/VERSION +0 -1
  104. data/app/views/readers/_standard_parts.html.haml +0 -23
  105. data/spec/datasets/messages_dataset.rb +0 -49
  106. data/spec/datasets/reader_layouts_dataset.rb +0 -26
  107. data/spec/datasets/reader_sites_dataset.rb +0 -10
data/README.md CHANGED
@@ -10,9 +10,9 @@ The purpose of this extension is to provide a common core that supports other vi
10
10
 
11
11
  ## Latest
12
12
 
13
- This version requires edge radiant, or radiant 0.9.2 when it becomes available. We are using a lot of the new configuration and sheets code.
13
+ This version requires edge radiant, or radiant 1 when it becomes available. We are using a lot of the new configuration and sheets code.
14
14
 
15
- Right now we are **not compatible with multi_site or the sites extension**: that's mostly because neither is radiant edge: it will all be sorted out in time for the release of 0.9.2, which isn't far away.
15
+ Right now we are **not compatible with multi_site or the sites extension**: that's mostly because neither is radiant edge: it will all be sorted out in time for the release of v1, which isn't far away.
16
16
 
17
17
  * public interface internationalized;
18
18
  * Uses the new configuration interface;
data/Rakefile CHANGED
@@ -1,22 +1,3 @@
1
- begin
2
- require 'jeweler'
3
- Jeweler::Tasks.new do |gem|
4
- gem.name = "radiant-reader-extension"
5
- gem.summary = %Q{User-services extension for Radiant CMS}
6
- gem.description = %Q{Centralises reader/member/user registration and management tasks for the benefit of other extensions}
7
- gem.email = "will@spanner.org"
8
- gem.homepage = "http://github.com/spanner/radiant-reader-extension"
9
- gem.authors = ["spanner"]
10
- gem.add_dependency "radiant", ">= 0.9.0"
11
- gem.add_dependency 'radiant-layouts-extension'
12
- gem.add_dependency 'radiant-mailer_layouts-extension'
13
- gem.add_dependency 'authlogic'
14
- gem.add_dependency 'sanitize'
15
- end
16
- rescue LoadError
17
- puts "Jeweler (or a dependency) not available. This is only required if you plan to package reader as a gem."
18
- end
19
-
20
1
  # In rails 1.2, plugins aren't available in the path until they're loaded.
21
2
  # Check to see if the rspec plugin is installed first and require
22
3
  # it if it is. If not, use the gem version.
@@ -0,0 +1,78 @@
1
+ class Admin::GroupInvitationsController < ApplicationController
2
+ require 'csv'
3
+
4
+ before_filter :find_group, :only => [:new, :create]
5
+
6
+ def new
7
+
8
+ end
9
+
10
+ def create
11
+ if params[:invite_reader] || params[:import_reader]
12
+ notice = []
13
+ if invites = params[:invite_reader]
14
+ invite_counter = 0
15
+ invites.each do |i|
16
+ if reader = Reader.find_by_id(i)
17
+ reader.groups << @group unless reader.is_in?(@group)
18
+ @group.send_welcome_to(reader)
19
+ invite_counter += 1
20
+ end
21
+ end
22
+ notice << "#{invite_counter} existing"
23
+ end
24
+ if imports = params[:import_reader]
25
+ import_counter = 0
26
+ imports.each do |i|
27
+ r = params["reader_#{i}".to_sym]
28
+ reader = Reader.new(r)
29
+ reader.create_password!
30
+ if reader.save!
31
+ reader.groups << @group
32
+ reader.send_group_invitation_message(@group)
33
+ import_counter += 1
34
+ end
35
+ notice << "#{import_counter} new"
36
+ end
37
+ end
38
+ flash[:notice] = notice.join(' and ') + " readers invited into the #{@group.name} group"
39
+ redirect_to admin_group_url(@group)
40
+ else
41
+ if params[:readerlist] && @readers = readers_from_csv(params[:readerlist])
42
+ render :action => 'preview'
43
+ else
44
+ render :action => 'new'
45
+ end
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def find_group
52
+ @group = Group.find(params[:group_id])
53
+ end
54
+
55
+ def readers_from_csv(readerdata)
56
+ readers = []
57
+ CSV::StringReader.parse(readerdata).each do |line|
58
+ csv = line.collect {|value| value ? value.gsub(/^ */, '').chomp : ''}
59
+ input = {}
60
+ input[:honorific] = csv.shift if Radiant::Config['reader.use_honorifics?']
61
+ [:name, :email, :login, :phone].each {|field| input[field] = csv.shift}
62
+ r = Reader.find_by_email(input[:email]) || Reader.new(input)
63
+ r.create_password! #only for validation purposes: not saved not passed through
64
+ r.login = generate_login(input[:name]) if r.login.blank?
65
+ r.valid? # so that errors can be shown on the confirmation form
66
+ readers << r
67
+ end
68
+ readers
69
+ end
70
+
71
+ def generate_login(name)
72
+ names = name.split
73
+ initials = names.map {|n| n.slice(0,1)}
74
+ initials.pop
75
+ initials.push(names.last).join('_').downcase
76
+ end
77
+
78
+ end
@@ -0,0 +1,8 @@
1
+ class Admin::GroupsController < Admin::ResourceController
2
+ skip_before_filter :load_model
3
+ before_filter :load_model, :except => :index # we want the filter to run before :show too
4
+
5
+ def show
6
+
7
+ end
8
+ end
@@ -0,0 +1,42 @@
1
+ class Admin::MembershipsController < ApplicationController
2
+
3
+ before_filter :find_group
4
+
5
+ def index
6
+ redirect_to admin_group_url(@group)
7
+ end
8
+
9
+ def create
10
+ @reader = Reader.find(params[:reader_id])
11
+ raise ActiveRecord::RecordNotFound unless @reader
12
+ @membership = Membership.find_or_create_by_reader_id_and_group_id(@reader.id, @group.id)
13
+ respond_to do |format|
14
+ format.html {
15
+ flash[:notice] = "#{@reader.name} added to group #{@group.name}"
16
+ redirect_to admin_group_url(@group)
17
+ }
18
+ format.js { render :partial => 'reader' }
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ @membership = @group.memberships.find(params[:id])
24
+ @reader = @membership.reader
25
+ @membership.delete if @membership
26
+ respond_to do |format|
27
+ format.html {
28
+ flash[:notice] = "#{@reader.name} removed from group #{@group.name}" if @membership
29
+ redirect_to admin_group_url(@group)
30
+ }
31
+ format.js { render :partial => 'reader' }
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def find_group
38
+ @group = Group.find(params[:group_id])
39
+ raise ActiveRecord::RecordNotFound unless @group
40
+ end
41
+
42
+ end
@@ -3,6 +3,7 @@ class Admin::MessagesController < Admin::ResourceController
3
3
  skip_before_filter :load_model
4
4
  before_filter :load_model, :except => :index # we want the filter to run before :show too
5
5
  before_filter :set_function, :only => :new
6
+ before_filter :get_group, :only => :new
6
7
 
7
8
  # here :show is the preview/send page
8
9
  def show
@@ -30,13 +31,13 @@ class Admin::MessagesController < Admin::ResourceController
30
31
  failures = @message.deliver(@readers) || []
31
32
  if failures.any?
32
33
  if failures.length == @readers.length
33
- flash[:error] = t("all_deliveries_failed")
34
+ flash[:error] = t("reader_extension.all_deliveries_failed")
34
35
  else
35
36
  addresses = failures.map(&:email).to_sentence
36
- flash[:notice] = t("some_deliveries_failed")
37
+ flash[:notice] = t("reader_extension.some_deliveries_failed")
37
38
  end
38
39
  else
39
- flash[:notice] = t("message_delivered")
40
+ flash[:notice] = t("reader_extension.message_delivered")
40
41
  end
41
42
  redirect_to admin_message_url(@message)
42
43
  end
@@ -57,4 +58,8 @@ protected
57
58
  end
58
59
  end
59
60
 
61
+ def get_group
62
+ model.group = Group.find(params[:group_id]) if params[:group_id]
63
+ end
64
+
60
65
  end
@@ -0,0 +1,42 @@
1
+ class Admin::PermissionsController < ApplicationController
2
+
3
+ before_filter :find_group
4
+
5
+ def index
6
+ redirect_to admin_group_url(@group)
7
+ end
8
+
9
+ def create
10
+ @page = Page.find(params[:page_id])
11
+ raise ActiveRecord::RecordNotFound unless @page
12
+ @permission = Permission.find_or_create_by_page_id_and_group_id(@page.id, @group.id)
13
+ respond_to do |format|
14
+ format.html {
15
+ flash[:notice] = "#{@page.name} bound to group #{@group.name}"
16
+ redirect_to admin_group_url(@group)
17
+ }
18
+ format.js { render :partial => 'page' }
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ @permission = @group.permissions.find(params[:id])
24
+ @page = @permission.page
25
+ @permission.delete if @permission
26
+ respond_to do |format|
27
+ format.html {
28
+ flash[:notice] = "#{@page.name} released from group #{@group.name}"
29
+ redirect_to admin_group_url(@group)
30
+ }
31
+ format.js { render :partial => 'page' }
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def find_group
38
+ @group = Group.find(params[:group_id])
39
+ raise ActiveRecord::RecordNotFound unless @group
40
+ end
41
+
42
+ end
@@ -1,4 +1,3 @@
1
1
  class Admin::ReaderConfigurationController < Admin::ConfigurationController
2
2
  helper :reader
3
-
4
3
  end
@@ -12,7 +12,7 @@ class Admin::ReadersController < Admin::ResourceController
12
12
  model.update_attributes!(params[:reader])
13
13
  model.clear_password = params[:reader][:password] if params[:reader] && params[:reader][:password] # condition is so that radiant tests pass
14
14
  model.send_invitation_message
15
- flash[:notice] = t('reader_saved')
15
+ flash[:notice] = t('reader_extension.reader_saved')
16
16
  response_for :create
17
17
  end
18
18
 
@@ -23,14 +23,14 @@ class PasswordResetsController < ReaderActionController
23
23
  redirect_to new_reader_activation_url
24
24
  end
25
25
  else
26
- @error = flash[:error] = t("email_unknown")
26
+ @error = flash[:error] = t("reader_extension.email_unknown")
27
27
  render :action => :new
28
28
  end
29
29
  end
30
30
 
31
31
  def edit
32
32
  unless @reader
33
- flash[:error] = t('reset_not_found')
33
+ flash[:error] = t('reader_extension.reset_not_found')
34
34
  end
35
35
  render
36
36
  end
@@ -41,14 +41,14 @@ class PasswordResetsController < ReaderActionController
41
41
  @reader.password_confirmation = params[:reader][:password_confirmation]
42
42
  if @reader.save
43
43
  self.current_reader = @reader
44
- flash[:notice] = t('password_updated_notice')
44
+ flash[:notice] = t('reader_extension.password_updated_notice')
45
45
  redirect_to url_for(@reader)
46
46
  else
47
- flash[:error] = t('password_mismatch')
47
+ flash[:error] = t('reader_extension.password_mismatch')
48
48
  render :action => :edit
49
49
  end
50
50
  else
51
- flash[:error] = t('reset_not_found')
51
+ flash[:error] = t('reader_extension.reset_not_found')
52
52
  render :action => :edit # without @reader, this will take us back to the enter-your-code form
53
53
  end
54
54
  end
@@ -3,9 +3,6 @@ class ReaderActionController < ApplicationController
3
3
 
4
4
  helper :reader
5
5
  helper_method :current_site, :current_site=, :logged_in?, :logged_in_user?, :logged_in_admin?
6
-
7
- attr_accessor :css, :js
8
- helper_method :reader_css_paths, :reader_js_paths, :add_reader_js, :add_reader_css
9
6
 
10
7
  no_login_required
11
8
  before_filter :set_site_title
@@ -15,31 +12,6 @@ class ReaderActionController < ApplicationController
15
12
 
16
13
  radiant_layout { |controller| Radiant::Config['reader.layout'] }
17
14
 
18
- # allow reader-based extensions to contribute to the public interface
19
- # these methods can be called from any view
20
-
21
- def add_reader_css(path)
22
- @css ||= []
23
- @css << path
24
- end
25
-
26
- def add_reader_js(path)
27
- @js ||= []
28
- @js << path
29
- end
30
-
31
- # these methods are called from :reader_css and :reader_js page parts defined in view/readers/_standard_parts
32
-
33
- def reader_css_paths
34
- @css ||= []
35
- @css.uniq
36
- end
37
-
38
- def reader_js_paths
39
- @js ||= []
40
- @js.uniq
41
- end
42
-
43
15
  # authorisation helpers
44
16
 
45
17
  def logged_in?
@@ -56,9 +28,17 @@ class ReaderActionController < ApplicationController
56
28
 
57
29
  def permission_denied
58
30
  session[:return_to] ||= request.referer
59
- @title = flash[:error] || t('permission_denied')
31
+ @title = flash[:error] || t('reader_extension.permission_denied')
60
32
  render
61
33
  end
34
+
35
+ def default_welcome_url(reader)
36
+ if page = reader.find_homepage
37
+ page.url
38
+ else
39
+ reader_url(reader) #TODO make this interesting
40
+ end
41
+ end
62
42
 
63
43
  protected
64
44
 
@@ -81,8 +61,8 @@ protected
81
61
  store_location
82
62
  respond_to do |format|
83
63
  format.html {
84
- flash[:explanation] = t('reader_required')
85
- flash[:notice] = t('please_log_in')
64
+ flash[:explanation] = t('reader_extension.reader_required')
65
+ flash[:notice] = t('reader_extension.please_log_in')
86
66
  redirect_to reader_login_url
87
67
  }
88
68
  format.js {
@@ -98,7 +78,7 @@ protected
98
78
  unless current_reader && current_reader.activated?
99
79
  respond_to do |format|
100
80
  format.html {
101
- flash[:explanation] = t('activation_required')
81
+ flash[:explanation] = t('reader_extension.activation_required')
102
82
  redirect_to reader_activation_url
103
83
  }
104
84
  format.js {
@@ -113,7 +93,7 @@ protected
113
93
  def require_no_reader
114
94
  if set_reader
115
95
  store_location
116
- flash[:notice] = t('please_log_out')
96
+ flash[:notice] = t('reader_extension.please_log_out')
117
97
  redirect_back_or_to url_for(current_reader)
118
98
  return false
119
99
  end
@@ -21,7 +21,7 @@ class ReaderActivationsController < ReaderActionController
21
21
  if current_reader
22
22
  @reader = current_reader
23
23
  @reader.send_activation_message
24
- flash[:notice] = t("activation_message_sent")
24
+ flash[:notice] = t("reader_extension.activation_message_sent")
25
25
  end
26
26
  expires_now
27
27
  render :action => 'show'
@@ -32,7 +32,7 @@ class ReaderActivationsController < ReaderActionController
32
32
  @reader.activate!
33
33
  self.current_reader = @reader
34
34
  else
35
- @error = t("please_check_message")
35
+ @error = t("reader_extension.please_check_message")
36
36
  end
37
37
  expires_now
38
38
  render :action => 'show'
@@ -47,14 +47,10 @@ protected
47
47
 
48
48
  def check_reader_inactive
49
49
  if @reader && @reader.activated?
50
- flash[:notice] = t('hello').titlecase + " #{@reader.name}! " + t('already_active')
51
- redirect_back_or_to default_activated_url
50
+ flash[:notice] = t('reader_extension.hello').titlecase + " #{@reader.name}! " + t('reader_extension.already_active')
51
+ redirect_back_or_to default_welcome_url(@reader)
52
52
  false
53
53
  end
54
54
  end
55
55
 
56
- def default_activated_url
57
- reader_url(@reader)
58
- end
59
-
60
56
  end
@@ -25,10 +25,10 @@ class ReaderSessionsController < ReaderActionController
25
25
  def new
26
26
  if current_reader
27
27
  if current_reader.activated?
28
- cookies[:error] = t('already_logged_in')
28
+ cookies[:error] = t('reader_extension.already_logged_in')
29
29
  redirect_to reader_url(current_reader)
30
30
  else
31
- cookies[:error] = t('account_requires_activation')
31
+ cookies[:error] = t('reader_extension.account_requires_activation')
32
32
  redirect_to reader_activation_url
33
33
  end
34
34
  else
@@ -39,29 +39,24 @@ class ReaderSessionsController < ReaderActionController
39
39
 
40
40
  def create
41
41
  @reader_session = ReaderSession.new(params[:reader_session])
42
- if @reader_session.save
43
- if @reader_session.reader.activated? && @reader_session.reader.clear_password
44
- @reader_session.reader.clear_password = "" # we forget the cleartext version on the first successful login
45
- @reader_session.reader.save(false)
46
- end
47
- respond_to do |format|
42
+ @reader_session.save do |success|
43
+ if success
44
+ if @reader_session.reader.activated? && @reader_session.reader.clear_password
45
+ @reader_session.reader.clear_password = "" # we forget the cleartext version on the first successful login
46
+ @reader_session.reader.save(false)
47
+ end
48
48
  format.html {
49
- flash[:notice] = t('hello').titlecase + " #{@reader_session.reader.name}. " + t('welcome_back')
50
- redirect_back_or_to default_loggedin_url
49
+ flash[:notice] = t('reader_extension.hello').titlecase + " #{@reader_session.reader.name}. " + t('reader_extension.welcome_back')
50
+ redirect_back_or_to default_welcome_url(@reader_session.reader)
51
51
  }
52
52
  format.js {
53
53
  redirect_back_with_format(:js)
54
54
  }
55
- end
56
-
57
- else
58
- respond_to do |format|
59
- format.html {
60
- render :action => :new
61
- }
62
- format.js {
63
- render :action => :new, :layout => false
64
- }
55
+ else
56
+ respond_to do |format|
57
+ format.html { render :action => :new }
58
+ format.js { render :action => :new, :layout => false }
59
+ end
65
60
  end
66
61
  end
67
62
  end
@@ -76,11 +71,5 @@ class ReaderSessionsController < ReaderActionController
76
71
  end
77
72
  redirect_to reader_login_url
78
73
  end
79
-
80
- protected
81
-
82
- def default_loggedin_url
83
- reader_url(@reader_session.reader)
84
- end
85
74
 
86
75
  end
@@ -7,9 +7,10 @@ class ReadersController < ReaderActionController
7
7
  before_filter :initialize_partials
8
8
  before_filter :i_am_me, :only => [:show, :edit]
9
9
  before_filter :require_reader, :except => [:new, :create, :activate]
10
+ before_filter :default_to_self, :only => [:show]
10
11
  before_filter :restrict_to_self, :only => [:edit, :update, :resend_activation]
11
12
  before_filter :no_removing, :only => [:remove, :destroy]
12
- before_filter :require_password, :only => [:update]
13
+ before_filter :ensure_groups_subscribable, :only => [:update, :create]
13
14
 
14
15
  def index
15
16
  @readers = Reader.active.paginate(pagination_parameters.merge(:per_page => 60))
@@ -21,7 +22,7 @@ class ReadersController < ReaderActionController
21
22
 
22
23
  def new
23
24
  if current_reader
24
- flash[:error] = t('already_logged_in')
25
+ flash[:error] = t('reader_extension.already_logged_in')
25
26
  redirect_to url_for(current_reader) and return
26
27
  end
27
28
  @reader = Reader.new
@@ -38,9 +39,9 @@ class ReadersController < ReaderActionController
38
39
  @reader.clear_password = params[:reader][:password]
39
40
 
40
41
  unless @reader.email.blank?
41
- flash[:error] = t('please_avoid_spam_trap')
42
+ flash[:error] = t('reader_extension.please_avoid_spam_trap')
42
43
  @reader.email = ''
43
- @reader.errors.add(:trap, t("must_be_empty"))
44
+ @reader.errors.add(:trap, t("reader_extension.must_be_empty"))
44
45
  render :action => 'new' and return
45
46
  end
46
47
 
@@ -56,6 +57,7 @@ class ReadersController < ReaderActionController
56
57
  self.current_reader = @reader
57
58
  redirect_to reader_activation_url
58
59
  else
60
+ @reader.email_field = session[:email_field]
59
61
  render :action => 'new'
60
62
  end
61
63
  end
@@ -64,7 +66,7 @@ class ReadersController < ReaderActionController
64
66
  @reader.attributes = params[:reader]
65
67
  @reader.clear_password = params[:reader][:password] if params[:reader][:password]
66
68
  if @reader.save
67
- flash[:notice] = t('account_updated')
69
+ flash[:notice] = t('reader_extension.account_updated')
68
70
  redirect_to url_for(@reader)
69
71
  else
70
72
  render :action => 'edit'
@@ -77,8 +79,12 @@ protected
77
79
  params[:id] = current_reader.id if current_reader && params[:id] == 'me'
78
80
  end
79
81
 
82
+ def default_to_self
83
+ params[:id] ||= current_reader.id
84
+ end
85
+
80
86
  def restrict_to_self
81
- flash[:error] = t("cannot_edit_others") if params[:id] && params[:id] != current_reader.id
87
+ flash[:error] = t("reader_extension.cannot_edit_others") if params[:id] && params[:id] != current_reader.id
82
88
  @reader = current_reader
83
89
  end
84
90
 
@@ -89,19 +95,19 @@ protected
89
95
  @reader.attributes = params[:reader]
90
96
  @reader.valid?
91
97
 
92
- flash[:error] = t('password_incorrect')
98
+ flash[:error] = t('reader_extension.password_incorrect')
93
99
  @reader.errors.add(:current_password, "not_correct")
94
100
  render :action => 'edit' and return false
95
101
  end
96
102
 
97
103
  def no_removing
98
- flash[:error] = t('cannot_delete_readers')
104
+ flash[:error] = t('reader_extension.cannot_delete_readers')
99
105
  redirect_to admin_readers_url
100
106
  end
101
107
 
102
108
  def check_registration_allowed
103
109
  unless Radiant::Config['reader.allow_registration?']
104
- flash[:error] = t("registration_disallowed")
110
+ flash[:error] = t("reader_extension.registration_disallowed")
105
111
  redirect_to reader_login_url
106
112
  false
107
113
  end
@@ -129,4 +135,15 @@ private
129
135
  @index_partials = index_partials
130
136
  end
131
137
 
138
+ def ensure_groups_subscribable
139
+ if params[:reader] && params[:reader][:group_ids]
140
+ params[:reader][:group_ids].each do |g|
141
+ raise ActiveRecord::RecordNotFound unless Group.find(g).public?
142
+ end
143
+ end
144
+ true
145
+ rescue ActiveRecord::RecordNotFound
146
+ false
147
+ end
148
+
132
149
  end