enju_message 0.1.14.pre14 → 0.1.14.pre15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/message_requests_controller.rb +5 -5
  3. data/app/controllers/messages_controller.rb +17 -17
  4. data/app/models/message.rb +34 -24
  5. data/app/models/message_request.rb +25 -30
  6. data/app/models/message_request_state_machine.rb +12 -0
  7. data/app/models/message_request_transition.rb +20 -0
  8. data/app/models/message_state_machine.rb +24 -0
  9. data/app/models/message_template.rb +3 -3
  10. data/app/models/message_transition.rb +20 -0
  11. data/app/views/layouts/messages.html.erb +3 -3
  12. data/app/views/message_requests/edit.html.erb +1 -1
  13. data/app/views/message_requests/index.html.erb +8 -8
  14. data/app/views/message_requests/new.html.erb +2 -2
  15. data/app/views/message_requests/show.html.erb +2 -2
  16. data/app/views/message_templates/_form.html.erb +4 -4
  17. data/app/views/message_templates/edit.html.erb +1 -1
  18. data/app/views/message_templates/index.html.erb +3 -3
  19. data/app/views/message_templates/new.html.erb +1 -1
  20. data/app/views/message_templates/show.html.erb +1 -1
  21. data/app/views/messages/_form.html.erb +0 -4
  22. data/app/views/messages/edit.html.erb +5 -5
  23. data/app/views/messages/index.atom.builder +2 -2
  24. data/app/views/messages/index.html.erb +7 -7
  25. data/app/views/messages/index.rss.builder +9 -9
  26. data/app/views/messages/new.html.erb +7 -7
  27. data/app/views/messages/show.html.erb +5 -5
  28. data/app/views/notifier/message_notification.en.text.erb +1 -1
  29. data/app/views/notifier/message_notification.ja.text.erb +1 -1
  30. data/config/initializers/statesman.rb +3 -0
  31. data/db/migrate/154_create_messages.rb +0 -1
  32. data/db/migrate/20080819181903_create_message_requests.rb +0 -2
  33. data/db/migrate/20140518111006_create_message_transitions.rb +14 -0
  34. data/db/migrate/20140518135713_create_message_request_transitions.rb +14 -0
  35. data/lib/enju_message/engine.rb +1 -1
  36. data/lib/enju_message/user.rb +2 -2
  37. data/lib/enju_message/version.rb +1 -1
  38. data/lib/generators/enju_message/setup/setup_generator.rb +2 -0
  39. data/lib/generators/enju_message/setup/templates/db/fixtures/message_templates.yml +41 -20
  40. data/lib/tasks/enju_message_tasks.rake +10 -0
  41. data/lib/tasks/message_template.rb +13 -0
  42. data/spec/controllers/message_requests_controller_spec.rb +15 -15
  43. data/spec/controllers/message_templates_controller_spec.rb +21 -21
  44. data/spec/controllers/messages_controller_spec.rb +7 -13
  45. data/spec/dummy/app/mailers/notifier.rb +6 -6
  46. data/spec/dummy/db/migrate/001_create_agents.rb +0 -2
  47. data/spec/dummy/db/migrate/20140110122216_create_user_import_files.rb +18 -0
  48. data/spec/dummy/db/migrate/20140110131010_create_user_import_results.rb +11 -0
  49. data/spec/dummy/db/migrate/20140122054321_create_profiles.rb +20 -0
  50. data/spec/dummy/db/migrate/20140524074813_create_user_import_file_transitions.rb +14 -0
  51. data/spec/dummy/db/migrate/20140610123439_drop_email_unique_constraint_enju_leaf_rc10.rb +11 -0
  52. data/spec/dummy/db/migrate/20140628072217_add_user_encoding_to_user_import_file.rb +5 -0
  53. data/spec/dummy/db/migrate/20140709113413_create_user_export_files.rb +11 -0
  54. data/spec/dummy/db/migrate/20140709113905_create_user_export_file_transitions.rb +14 -0
  55. data/spec/dummy/db/migrate/20140720170714_add_default_library_id_to_user_import_file.rb +5 -0
  56. data/spec/dummy/db/migrate/20140720170735_add_default_user_group_id_to_user_import_file.rb +5 -0
  57. data/spec/dummy/db/migrate/20140811031145_add_expired_at_to_profile.rb +5 -0
  58. data/spec/dummy/db/schema.rb +105 -8
  59. data/spec/dummy/db/test.sqlite3 +0 -0
  60. data/spec/dummy/solr/default/data/index/_oj.fdt +0 -0
  61. data/spec/dummy/solr/default/data/index/{_n.si → _oj.si} +0 -0
  62. data/spec/dummy/solr/default/data/index/{_n_Lucene41_0.tim → _oj_Lucene41_0.tim} +0 -0
  63. data/spec/dummy/solr/default/data/index/segments.gen +0 -0
  64. data/spec/dummy/solr/default/data/index/segments_14v +0 -0
  65. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001460 +0 -0
  66. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001461 +0 -0
  67. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001462 +0 -0
  68. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001463 +0 -0
  69. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001464 +0 -0
  70. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001465 +0 -0
  71. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001466 +0 -0
  72. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001467 +0 -0
  73. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001468 +0 -0
  74. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000001469 +0 -0
  75. data/spec/factories/message.rb +2 -2
  76. data/spec/factories/profile.rb +10 -0
  77. data/spec/fixtures/agents.yml +0 -12
  78. data/spec/fixtures/message_requests.yml +0 -3
  79. data/spec/fixtures/messages.yml +0 -5
  80. data/spec/fixtures/profiles.yml +98 -0
  81. data/spec/fixtures/users.yml +3 -23
  82. data/spec/models/message_request_spec.rb +0 -2
  83. data/spec/models/message_spec.rb +2 -4
  84. data/spec/spec_helper.rb +3 -0
  85. metadata +95 -47
  86. data/spec/dummy/solr/default/data/index/_n.fdt +0 -0
  87. data/spec/dummy/solr/default/data/index/segments_15 +0 -0
  88. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000030 +0 -0
  89. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000031 +0 -0
  90. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000032 +0 -0
  91. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000033 +0 -0
  92. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000034 +0 -0
  93. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000035 +0 -0
  94. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000036 +0 -0
  95. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000037 +0 -0
  96. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000038 +0 -0
  97. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000039 +0 -0
  98. /data/spec/dummy/solr/default/data/index/{_n.fdx → _oj.fdx} +0 -0
  99. /data/spec/dummy/solr/default/data/index/{_n.fnm → _oj.fnm} +0 -0
  100. /data/spec/dummy/solr/default/data/index/{_n.nvd → _oj.nvd} +0 -0
  101. /data/spec/dummy/solr/default/data/index/{_n.nvm → _oj.nvm} +0 -0
  102. /data/spec/dummy/solr/default/data/index/{_n_Lucene41_0.doc → _oj_Lucene41_0.doc} +0 -0
  103. /data/spec/dummy/solr/default/data/index/{_n_Lucene41_0.pos → _oj_Lucene41_0.pos} +0 -0
  104. /data/spec/dummy/solr/default/data/index/{_n_Lucene41_0.tip → _oj_Lucene41_0.tip} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 869988f70f80ccd9cae4dca9f743165abdefc4cd
4
- data.tar.gz: 14e79c288fc791ff5a992113b0cccdf203d6bbda
3
+ metadata.gz: aa7226f02e724390856a0810eedfa918919e6372
4
+ data.tar.gz: 5c14bde97fb83a850976bd4086c8b747bfe2ba49
5
5
  SHA512:
6
- metadata.gz: 3bc8eb81d35f71bde3801351f5b7212cbacad4dfafb4f5aff650b4ac3cb55fae2dc8608016496b96afc689aee7aab686f1f672964eb62fcbfadba2f7bd9684a8
7
- data.tar.gz: ee79ecf7341ccf337be7c4c324831bc900f9e442b82307b10f7773e8e5505862e2e500ae4493daf24ca776e1a48313fbb3fb5993c2b3330532cc7c81a5af43cc
6
+ metadata.gz: 1c0ffc98ecc09fbb2e5b813afca45cec557626992c0fe8ff9f006376bca0f1878bf1100803bd00a3fbd8e6b97623730fdc43323ede9aecbf1c6ce0df28327ea9
7
+ data.tar.gz: a86cf99b228feae38aaa21d1cad63f9e6d3251473d5491b232ba03b5e85feb89dfbeaef944e5b63c4eaaaae0c1f35beb335833ff05851ed8cca209673832fc5c
@@ -15,7 +15,7 @@ class MessageRequestsController < ApplicationController
15
15
 
16
16
  respond_to do |format|
17
17
  format.html # index.html.erb
18
- format.json { render :json => @message_requests }
18
+ format.json { render json: @message_requests }
19
19
  end
20
20
  end
21
21
 
@@ -24,7 +24,7 @@ class MessageRequestsController < ApplicationController
24
24
  def show
25
25
  respond_to do |format|
26
26
  format.html # show.html.erb
27
- format.json { render :json => @message_request }
27
+ format.json { render json: @message_request }
28
28
  end
29
29
  end
30
30
 
@@ -38,13 +38,13 @@ class MessageRequestsController < ApplicationController
38
38
  def update
39
39
  respond_to do |format|
40
40
  if @message_request.update_attributes(params[:message_request])
41
- flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.message_request'))
41
+ flash[:notice] = t('controller.successfully_updated', model: t('activerecord.models.message_request'))
42
42
  format.html { redirect_to(@message_request) }
43
43
  format.json { head :no_content }
44
44
  else
45
45
  @message_templates = MessageTemplate.all
46
- format.html { render :action => "edit" }
47
- format.json { render :json => @message_request.errors, :status => :unprocessable_entity }
46
+ format.html { render action: "edit" }
47
+ format.json { render json: @message_request.errors, status: :unprocessable_entity }
48
48
  end
49
49
  end
50
50
  end
@@ -1,8 +1,8 @@
1
1
  class MessagesController < ApplicationController
2
- load_and_authorize_resource :except => [:index, :show]
3
- authorize_resource :only => [:index, :show]
4
- before_filter :get_user, :only => :index
5
- after_filter :solr_commit, :only => [:create, :update, :destroy, :destroy_selected]
2
+ load_and_authorize_resource except: [:index, :show]
3
+ authorize_resource only: [:index, :show]
4
+ before_filter :get_user, only: :index
5
+ after_filter :solr_commit, only: [:create, :update, :destroy, :destroy_selected]
6
6
 
7
7
  # GET /messages
8
8
  # GET /messages.json
@@ -34,7 +34,7 @@ class MessagesController < ApplicationController
34
34
 
35
35
  respond_to do |format|
36
36
  format.html # index.html.erb
37
- format.json { render :json => @messages }
37
+ format.json { render json: @messages }
38
38
  format.rss
39
39
  format.atom
40
40
  end
@@ -44,11 +44,11 @@ class MessagesController < ApplicationController
44
44
  # GET /messages/1.json
45
45
  def show
46
46
  @message = current_user.received_messages.find(params[:id])
47
- @message.sm_read!
47
+ @message.transition_to!(:read) if @message.current_state != 'read'
48
48
 
49
49
  respond_to do |format|
50
50
  format.html # show.html.erb
51
- format.json { render :json => @message }
51
+ format.json { render json: @message }
52
52
  end
53
53
  end
54
54
 
@@ -64,14 +64,14 @@ class MessagesController < ApplicationController
64
64
 
65
65
  respond_to do |format|
66
66
  format.html # new.html.erb
67
- format.json { render :json => @message }
67
+ format.json { render json: @message }
68
68
  end
69
69
  end
70
70
 
71
71
  # GET /messages/1/edit
72
72
  def edit
73
73
  @message = current_user.received_messages.find(params[:id])
74
- @message.sm_read!
74
+ @message.transition_to!(:read)
75
75
  end
76
76
 
77
77
  # POST /messages
@@ -84,11 +84,11 @@ class MessagesController < ApplicationController
84
84
 
85
85
  respond_to do |format|
86
86
  if @message.save
87
- format.html { redirect_to messages_url, :notice => t('controller.successfully_created', :model => t('activerecord.models.message')) }
88
- format.json { render :json => @message, :status => :created, :location => @message }
87
+ format.html { redirect_to messages_url, notice: t('controller.successfully_created', model: t('activerecord.models.message')) }
88
+ format.json { render json: @message, status: :created, location: @message }
89
89
  else
90
- format.html { render :action => "new" }
91
- format.json { render :json => @message.errors, :status => :unprocessable_entity }
90
+ format.html { render action: "new" }
91
+ format.json { render json: @message.errors, status: :unprocessable_entity }
92
92
  end
93
93
  end
94
94
  end
@@ -99,11 +99,11 @@ class MessagesController < ApplicationController
99
99
  @message = current_user.received_messages.find(params[:id])
100
100
 
101
101
  if @message.update_attributes(params[:message])
102
- format.html { redirect_to @message, :notice => t('controller.successfully_updated', :model => t('activerecord.models.message')) }
102
+ format.html { redirect_to @message, notice: t('controller.successfully_updated', model: t('activerecord.models.message')) }
103
103
  format.json { head :no_content }
104
104
  else
105
- format.html { render :action => "edit" }
106
- format.json { render :json => @message.errors, :status => :unprocessable_entity }
105
+ format.html { render action: "edit" }
106
+ format.json { render json: @message.errors, status: :unprocessable_entity }
107
107
  end
108
108
  end
109
109
 
@@ -147,7 +147,7 @@ class MessagesController < ApplicationController
147
147
 
148
148
  private
149
149
  def get_parent(id)
150
- parent = Message.where(:id => id).first
150
+ parent = Message.where(id: id).first
151
151
  unless current_user.has_role?('Librarian')
152
152
  unless parent.try(:receiver) == current_user
153
153
  access_denied; return
@@ -1,13 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  class Message < ActiveRecord::Base
3
+ include Statesman::Adapters::ActiveRecordModel
3
4
  attr_accessible :subject, :body, :sender, :recipient
4
- scope :unread, where(:state => 'unread')
5
+ scope :unread, -> {in_state('unread')}
5
6
  belongs_to :message_request
6
- belongs_to :sender, :class_name => 'User'
7
- belongs_to :receiver, :class_name => 'User'
7
+ belongs_to :sender, class_name: 'User'
8
+ belongs_to :receiver, class_name: 'User'
8
9
  validates_presence_of :subject, :body #, :sender
9
- validates_presence_of :recipient, :on => :create
10
- validates_presence_of :receiver, :on => :update
10
+ validates_presence_of :recipient, on: :create
11
+ validates_presence_of :receiver, on: :update
11
12
  before_save :set_receiver
12
13
  after_save :index
13
14
  after_destroy :remove_from_index
@@ -16,19 +17,13 @@ class Message < ActiveRecord::Base
16
17
  acts_as_nested_set
17
18
  attr_accessor :recipient
18
19
 
19
- state_machine :initial => :unread do
20
- before_transition any => :read, :do => :read
21
- before_transition :read => :unread, :do => :unread
22
-
23
- event :sm_read do
24
- transition any => :read
25
- end
26
-
27
- event :sm_unread do
28
- transition :read => :unread
29
- end
20
+ def state_machine
21
+ ResourceImportFileStateMachine.new(self, transition_class: ResourceImportFileTransition)
30
22
  end
31
23
 
24
+ delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
25
+ to: :state_machine
26
+
32
27
  searchable do
33
28
  text :body, :subject
34
29
  string :subject
@@ -36,15 +31,24 @@ class Message < ActiveRecord::Base
36
31
  integer :sender_id
37
32
  time :created_at
38
33
  boolean :is_read do
39
- self.read?
34
+ read?
40
35
  end
41
36
  end
42
37
 
43
38
  paginates_per 10
39
+ has_many :message_transitions
40
+ before_create :set_default_state
41
+
42
+ def state_machine
43
+ @state_machine ||= MessageStateMachine.new(self, transition_class: MessageTransition)
44
+ end
45
+
46
+ delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
47
+ to: :state_machine
44
48
 
45
49
  def set_receiver
46
- if self.recipient
47
- self.receiver = User.find(self.recipient)
50
+ if recipient
51
+ self.receiver = User.find(recipient)
48
52
  end
49
53
  end
50
54
 
@@ -53,14 +57,22 @@ class Message < ActiveRecord::Base
53
57
  end
54
58
 
55
59
  def read
56
- self.read_at = Time.zone.now unless self.read_at
57
- self.save(:validate => false)
60
+ transition_to!(:read)
58
61
  end
59
62
 
60
63
  def read?
61
- return true if state == 'read'
64
+ return true if current_state == 'read'
62
65
  false
63
66
  end
67
+
68
+ private
69
+ def self.transition_class
70
+ MessageTransition
71
+ end
72
+
73
+ def set_default_state
74
+ transition_to(:unread)
75
+ end
64
76
  end
65
77
 
66
78
  # == Schema Information
@@ -74,7 +86,6 @@ end
74
86
  # subject :string(255) not null
75
87
  # body :text
76
88
  # message_request_id :integer
77
- # state :string(255)
78
89
  # parent_id :integer
79
90
  # created_at :datetime not null
80
91
  # updated_at :datetime not null
@@ -82,4 +93,3 @@ end
82
93
  # rgt :integer
83
94
  # depth :integer
84
95
  #
85
-
@@ -1,37 +1,29 @@
1
1
  require 'erubis'
2
2
  class MessageRequest < ActiveRecord::Base
3
+ include Statesman::Adapters::ActiveRecordModel
3
4
  attr_accessible :body
4
- attr_accessible :sender, :receiver, :message_template, :body, :as => :admin
5
- scope :not_sent, where('sent_at IS NULL AND state = ?', 'pending')
6
- scope :sent, where(:state => 'sent')
7
- scope :started, where(:state => 'started')
8
- belongs_to :message_template, :validate => true
9
- belongs_to :sender, :class_name => "User", :foreign_key => "sender_id", :validate => true
10
- belongs_to :receiver, :class_name => "User", :foreign_key => "receiver_id", :validate => true
5
+ attr_accessible :sender, :receiver, :message_template, :body, as: :admin
6
+ scope :not_sent, -> {in_state(:pending).where('sent_at IS NULL')}
7
+ scope :sent, -> {in_state(:sent)}
8
+ belongs_to :message_template, validate: true
9
+ belongs_to :sender, class_name: "User", foreign_key: "sender_id", validate: true
10
+ belongs_to :receiver, class_name: "User", foreign_key: "receiver_id", validate: true
11
11
  has_many :messages
12
12
 
13
13
  validates_associated :sender, :receiver, :message_template
14
14
  validates_presence_of :sender, :receiver, :message_template
15
- validates_presence_of :body, :on => :update
15
+ validates_presence_of :body, on: :update
16
16
 
17
- state_machine :initial => :pending do
18
- before_transition any - :sent => :sent, :do => :send_message
17
+ paginates_per 10
19
18
 
20
- event :sm_send_message do
21
- transition any - :sent => :sent
22
- end
19
+ has_many :message_request_transitions
23
20
 
24
- event :sm_start do
25
- transition :pending => :started
26
- end
21
+ def state_machine
22
+ @state_machine ||= MessageRequestStateMachine.new(self, transition_class: MessageRequestTransition)
27
23
  end
28
24
 
29
- paginates_per 10
30
-
31
- def start_sending_message
32
- sm_start!
33
- sm_send_message!
34
- end
25
+ delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
26
+ to: :state_machine
35
27
 
36
28
  def send_message
37
29
  message = nil
@@ -47,11 +39,11 @@ class MessageRequest < ActiveRecord::Base
47
39
  raise 'body is empty!'
48
40
  end
49
41
  self.sent_at = Time.zone.now
50
- save(:validate => false)
42
+ save(validate: false)
51
43
  if ['reservation_expired_for_patron', 'reservation_expired_for_patron'].include?(message_template.status)
52
44
  self.receiver.reserves.each do |reserve|
53
45
  reserve.expiration_notice_to_patron = true
54
- reserve.save(:validate => false)
46
+ reserve.save(validate: false)
55
47
  end
56
48
  end
57
49
  end
@@ -64,19 +56,24 @@ class MessageRequest < ActiveRecord::Base
64
56
 
65
57
  def save_message_body(options = {})
66
58
  options = {
67
- :receiver => receiver,
68
- :locale => receiver.locale
59
+ receiver: receiver,
60
+ locale: receiver.profile.locale
69
61
  }.merge(options)
70
- self.update_attributes!({:body => message_template.embed_body(options)})
62
+ self.update_attributes!({body: message_template.embed_body(options)})
71
63
  end
72
64
 
73
65
  def self.send_messages
74
66
  count = MessageRequest.not_sent.size
75
67
  MessageRequest.not_sent.each do |request|
76
- request.start_sending_message
68
+ request.transition_to!(:sent)
77
69
  end
78
70
  logger.info "#{Time.zone.now} sent #{count} messages!"
79
71
  end
72
+
73
+ private
74
+ def self.transition_class
75
+ MessageRequestTransition
76
+ end
80
77
  end
81
78
 
82
79
  # == Schema Information
@@ -90,8 +87,6 @@ end
90
87
  # sent_at :datetime
91
88
  # deleted_at :datetime
92
89
  # body :text
93
- # state :string(255)
94
90
  # created_at :datetime not null
95
91
  # updated_at :datetime not null
96
92
  #
97
-
@@ -0,0 +1,12 @@
1
+ class MessageRequestStateMachine
2
+ include Statesman::Machine
3
+
4
+ state :pending, initial: true
5
+ state :sent
6
+
7
+ transition from: :pending, to: :sent
8
+
9
+ before_transition(from: :pending, to: :sent) do |message_request|
10
+ message_request.send_message
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ class MessageRequestTransition < ActiveRecord::Base
2
+ include Statesman::Adapters::ActiveRecordTransition
3
+
4
+
5
+ belongs_to :message_request, inverse_of: :message_request_transitions
6
+ attr_accessible :to_state, :sort_key, :metadata
7
+ end
8
+
9
+ # == Schema Information
10
+ #
11
+ # Table name: message_request_transitions
12
+ #
13
+ # id :integer not null, primary key
14
+ # to_state :string(255)
15
+ # metadata :text default("{}")
16
+ # sort_key :integer
17
+ # message_request_id :integer
18
+ # created_at :datetime not null
19
+ # updated_at :datetime not null
20
+ #
@@ -0,0 +1,24 @@
1
+ class MessageStateMachine
2
+ include Statesman::Machine
3
+
4
+ state :pending, initial: true
5
+ state :unread
6
+ state :read
7
+
8
+ transition from: :pending, to: :unread
9
+ transition from: :pending, to: :read
10
+ transition from: :unread, to: :read
11
+ transition from: :read, to: :unread
12
+
13
+ before_transition(from: :pending, to: :read) do |message|
14
+ message.read_at = Time.zone.now unless message.read_at
15
+ end
16
+
17
+ before_transition(from: :unread, to: :read) do |message|
18
+ message.read_at = Time.zone.now unless message.read_at
19
+ end
20
+
21
+ before_transition(from: :read, to: :unread) do |message|
22
+ message.read_at = nil
23
+ end
24
+ end
@@ -1,6 +1,6 @@
1
1
  class MessageTemplate < ActiveRecord::Base
2
2
  attr_accessible :status, :title, :body, :locale
3
- default_scope :order => "message_templates.position"
3
+ default_scope {order("message_templates.position")}
4
4
  has_many :message_requests
5
5
 
6
6
  validates_uniqueness_of :status
@@ -13,13 +13,13 @@ class MessageTemplate < ActiveRecord::Base
13
13
  def embed_body(options = {})
14
14
  template = Erubis::Eruby.new(body)
15
15
  context = {
16
- :library_group => LibraryGroup.site_config
16
+ library_group: LibraryGroup.site_config
17
17
  }.merge(options)
18
18
  template.evaluate(context)
19
19
  end
20
20
 
21
21
  def self.localized_template(status, locale)
22
- MessageTemplate.where(:status => status, :locale => locale).first || MessageTemplate.where(:status => status).first
22
+ MessageTemplate.where(status: status, locale: locale).first || MessageTemplate.where(status: status).first
23
23
  end
24
24
  end
25
25
 
@@ -0,0 +1,20 @@
1
+ class MessageTransition < ActiveRecord::Base
2
+ include Statesman::Adapters::ActiveRecordTransition
3
+
4
+
5
+ belongs_to :message, inverse_of: :message_transitions
6
+ attr_accessible :to_state, :sort_key, :metadata
7
+ end
8
+
9
+ # == Schema Information
10
+ #
11
+ # Table name: message_transitions
12
+ #
13
+ # id :integer not null, primary key
14
+ # to_state :string(255)
15
+ # metadata :text default("{}")
16
+ # sort_key :integer
17
+ # message_id :integer
18
+ # created_at :datetime not null
19
+ # updated_at :datetime not null
20
+ #
@@ -2,10 +2,10 @@
2
2
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= @locale.to_s -%>" lang="<%= @locale.to_s -%>">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <title><%= t('message.user_message', :login_name => current_user.username) -%></title>
5
+ <title><%= t('message.user_message', login_name: current_user.username) -%></title>
6
6
  <%= render 'page/include' -%>
7
- <%= auto_discovery_link_tag(:rss, messages_url(:format => :rss), :title => (t('message.user_message', :login_name => current_user.username) + " (RSS)")) %>
8
- <%= auto_discovery_link_tag(:atom, messages_url(:format => :atom), :title => (t('message.user_message', :login_name => current_user.username) + " (Atom)")) %>
7
+ <%= auto_discovery_link_tag(:rss, messages_url(format: :rss), title: (t('message.user_message', login_name: current_user.username) + " (RSS)")) %>
8
+ <%= auto_discovery_link_tag(:atom, messages_url(format: :atom), title: (t('message.user_message', login_name: current_user.username) + " (Atom)")) %>
9
9
  </head>
10
10
  <body>
11
11
 
@@ -1,5 +1,5 @@
1
1
  <div id="content_detail" class="ui-corner-all ui-widget-content">
2
- <h1 class="title"><%= t('page.editing', :model => t('activerecord.models.message_request')) -%></h1>
2
+ <h1 class="title"><%= t('page.editing', model: t('activerecord.models.message_request')) -%></h1>
3
3
  <div id="content_list">
4
4
 
5
5
  <%= form_for(@message_request) do |f| -%>
@@ -1,5 +1,5 @@
1
1
  <div id="content_detail" class="ui-corner-all ui-widget-content">
2
- <h1 class="title"><%= t('page.listing', :model => t('activerecord.models.message_request')) -%></h1>
2
+ <h1 class="title"><%= t('page.listing', model: t('activerecord.models.message_request')) -%></h1>
3
3
  <div id="content_list">
4
4
 
5
5
  <table class="table table-striped index">
@@ -31,7 +31,7 @@
31
31
  <td>
32
32
  <%= link_to t('page.show'), message_request -%>
33
33
  <%= link_to t('page.edit'), edit_message_request_path(message_request) -%>
34
- <%= link_to t('page.destroy'), message_request, :data => {:confirm => t('page.are_you_sure')}, :method => :delete -%>
34
+ <%= link_to t('page.destroy'), message_request, data: {confirm: t('page.are_you_sure')}, method: :delete -%>
35
35
  </td>
36
36
  </tr>
37
37
  <%- end -%>
@@ -44,14 +44,14 @@
44
44
  <div id="submenu" class="ui-corner-all ui-widget-content">
45
45
  <ul>
46
46
  <%- case params[:mode] when 'sent' -%>
47
- <li><%= link_to t('message_request.not_sent'), message_requests_path(:mode => 'not_sent') -%></li>
48
- <li><%= link_to t('message_request.all'), message_requests_path(:mode => 'all') -%></li>
47
+ <li><%= link_to t('message_request.not_sent'), message_requests_path(mode: 'not_sent') -%></li>
48
+ <li><%= link_to t('message_request.all'), message_requests_path(mode: 'all') -%></li>
49
49
  <%- when 'all' -%>
50
- <li><%= link_to t('message_request.not_sent'), message_requests_path(:mode => 'not_sent') -%></li>
51
- <li><%= link_to t('message_request.sent'), message_requests_path(:mode => 'sent') -%></li>
50
+ <li><%= link_to t('message_request.not_sent'), message_requests_path(mode: 'not_sent') -%></li>
51
+ <li><%= link_to t('message_request.sent'), message_requests_path(mode: 'sent') -%></li>
52
52
  <%- else -%>
53
- <li><%= link_to t('message_request.sent'), message_requests_path(:mode => 'sent') -%></li>
54
- <li><%= link_to t('message_request.all'), message_requests_path(:mode => 'all') -%></li>
53
+ <li><%= link_to t('message_request.sent'), message_requests_path(mode: 'sent') -%></li>
54
+ <li><%= link_to t('message_request.all'), message_requests_path(mode: 'all') -%></li>
55
55
  <%- end -%>
56
56
  </ul>
57
57
  </div>
@@ -1,5 +1,5 @@
1
1
  <div id="content_detail" class="ui-corner-all ui-widget-content">
2
- <h1 class="title"><%= t('page.new', :model => t('activerecord.models.message_request')) -%></h1>
2
+ <h1 class="title"><%= t('page.new', model: t('activerecord.models.message_request')) -%></h1>
3
3
  <div id="content_list">
4
4
 
5
5
  <%= form_for(@message_request) do |f| -%>
@@ -7,7 +7,7 @@
7
7
 
8
8
  <div class="field">
9
9
  <%= f.label t('message.sender') -%><br />
10
- <%= link_to current_user.username, current_user -%>
10
+ <%= link_to current_user.username, current_user.profile if current_user.profile -%>
11
11
  <%= f.hidden_field :sender_id -%>
12
12
  </div>
13
13
  <div class="field">
@@ -1,5 +1,5 @@
1
1
  <div id="content_detail" class="ui-corner-all ui-widget-content">
2
- <h1 class="title"><%= t('page.showing', :model => t('activerecord.models.message_request')) -%></h1>
2
+ <h1 class="title"><%= t('page.showing', model: t('activerecord.models.message_request')) -%></h1>
3
3
  <div id="content_list">
4
4
  <p id="notice"><%= notice %></p>
5
5
 
@@ -50,6 +50,6 @@
50
50
  <ul>
51
51
  <li><%= link_to t('page.edit'), edit_message_request_path(@message_request) -%></li>
52
52
  <li><%= back_to_index(flash[:page_info]) -%></li>
53
- <li><%= link_to t('message.send'), new_message_path(:message_request_id => @message_request.id) -%></li>
53
+ <li><%= link_to t('message.send'), new_message_path(message_request_id: @message_request.id) -%></li>
54
54
  </ul>
55
55
  </div>
@@ -1,9 +1,9 @@
1
- <%= simple_form_for(@message_template, :validate => true) do |f| %>
1
+ <%= simple_form_for(@message_template, validate: true) do |f| %>
2
2
  <%= f.error_notification %>
3
3
 
4
4
  <div class="field">
5
5
  <%= f.label :status %><br />
6
- <%= f.text_field :status, :class => 'resource_title' %>
6
+ <%= f.text_field :status, class: 'resource_title' %>
7
7
  </div>
8
8
 
9
9
  <div class="field">
@@ -13,12 +13,12 @@
13
13
 
14
14
  <div class="field">
15
15
  <%= f.label :title %><br />
16
- <%= f.text_field :title, :class => 'resource_title' %>
16
+ <%= f.text_field :title, class: 'resource_title' %>
17
17
  </div>
18
18
 
19
19
  <div class="field">
20
20
  <%= f.label :body %><br />
21
- <%= f.text_area :body, :class => 'resource_textarea' %>
21
+ <%= f.text_area :body, class: 'resource_textarea' %>
22
22
  </div>
23
23
 
24
24
  <div class="actions">
@@ -1,5 +1,5 @@
1
1
  <div id="content_detail" class="ui-corner-all ui-widget-content">
2
- <h1 class="title"><%= t('page.editing', :model => t('activerecord.models.message_template')) -%></h1>
2
+ <h1 class="title"><%= t('page.editing', model: t('activerecord.models.message_template')) -%></h1>
3
3
  <div id="content_list">
4
4
  <%= render 'form' %>
5
5
  </div>
@@ -1,5 +1,5 @@
1
1
  <div id="content_detail" class="ui-corner-all ui-widget-content">
2
- <h1 class="title"><%= t('page.listing', :model => t('activerecord.models.message_template')) -%></h1>
2
+ <h1 class="title"><%= t('page.listing', model: t('activerecord.models.message_template')) -%></h1>
3
3
  <div id="content_list">
4
4
 
5
5
  <table class="table table-striped index">
@@ -26,7 +26,7 @@
26
26
  <%= link_to t('page.edit'), edit_message_template_path(message_template) -%>
27
27
  <% end %>
28
28
  <%- if can? :delete, message_template -%>
29
- <%= link_to t('page.destroy'), message_template, :data => {:confirm => t('page.are_you_sure')}, :method => :delete -%>
29
+ <%= link_to t('page.destroy'), message_template, data: {confirm: t('page.are_you_sure')}, method: :delete -%>
30
30
  <%- end -%>
31
31
  </td>
32
32
  </tr>
@@ -39,6 +39,6 @@
39
39
 
40
40
  <div id="submenu" class="ui-corner-all ui-widget-content">
41
41
  <ul>
42
- <li><%= link_to t('page.new', :model => t('activerecord.models.message_template')), new_message_template_path -%></li>
42
+ <li><%= link_to t('page.new', model: t('activerecord.models.message_template')), new_message_template_path -%></li>
43
43
  </ul>
44
44
  </div>
@@ -1,5 +1,5 @@
1
1
  <div id="content_detail" class="ui-corner-all ui-widget-content">
2
- <h1 class="title"><%= t('page.new', :model => t('activerecord.models.message_template')) -%></h1>
2
+ <h1 class="title"><%= t('page.new', model: t('activerecord.models.message_template')) -%></h1>
3
3
  <div id="content_list">
4
4
  <%= render 'form' %>
5
5
  </div>
@@ -1,5 +1,5 @@
1
1
  <div id="content_detail" class="ui-corner-all ui-widget-content">
2
- <h1 class="title"><%= t('page.showing', :model => t('activerecord.models.message_template')) -%></h1>
2
+ <h1 class="title"><%= t('page.showing', model: t('activerecord.models.message_template')) -%></h1>
3
3
  <div id="content_list">
4
4
  <p id="notice"><%= notice %></p>
5
5
 
@@ -19,10 +19,6 @@
19
19
  <%= f.label :receiver_id %><br />
20
20
  <%= f.text_field :receiver_id %>
21
21
  </div>
22
- <div class="field">
23
- <%= f.label :state %><br />
24
- <%= f.text_field :state %>
25
- </div>
26
22
  <div class="field">
27
23
  <%= f.label :subject %><br />
28
24
  <%= f.text_field :subject %>