Skip to content

Commit

Permalink
refs #1096, indicates activated mass_uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Jurke committed Dec 3, 2014
1 parent fb96c7a commit 579f282
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
10 changes: 1 addition & 9 deletions app/controllers/mass_uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def create

def update
authorize @mass_upload
Indexer.delay.index_mass_upload @mass_upload.id
@mass_upload.articles_for_mass_activation.update_all(state: 'active')
send_emails_for @mass_upload
@mass_upload.mass_activate
flash[:notice] = I18n.t('article.notices.mass_upload_create_html').html_safe
redirect_to user_path(@mass_upload.user)
end
Expand All @@ -44,10 +42,4 @@ def update
def set_mass_upload
@mass_upload = current_user.mass_uploads.find(params[:id])
end

def send_emails_for mass_upload
if mass_upload.articles_for_mass_activation.any?
ArticleMailer.delay.mass_upload_activation_message(mass_upload.id)
end
end
end
13 changes: 12 additions & 1 deletion app/models/mass_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ class MassUpload < ActiveRecord::Base
transition :finished => :finished
end

after_transition :to => :finished do |mass_upload,transition|
event :mass_activate do
transition :finished => :activated
transition :activated => :activated
end

after_transition :to => :finished do |mass_upload, transition|
ArticleMailer.delay.mass_upload_finished_message(mass_upload.id)
end

Expand All @@ -47,6 +52,12 @@ class MassUpload < ActiveRecord::Base
mass_upload.save
ArticleMailer.delay.mass_upload_failed_message(mass_upload.id)
end

after_transition :to => :activated do |mass_upload, transition|
Indexer.delay.index_mass_upload mass_upload.id
mass_upload.articles_for_mass_activation.update_all(state: 'active')
ArticleMailer.delay.mass_upload_activation_message(mass_upload.id)
end
end

scope :processing, -> { where(state: :processing) }
Expand Down
2 changes: 1 addition & 1 deletion app/policies/mass_upload_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class MassUploadPolicy < Struct.new(:user, :mass_upload)

def show?
mass_upload.finished? && own?
(mass_upload.finished? || mass_upload.activated?) && own?
end

def new?
Expand Down
2 changes: 1 addition & 1 deletion app/views/mass_uploads/_mass_activation.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
dt
= t('article.preview.fees_and_donations.quarter_fee')
.activation
- if articles.all? { |article| article.state == "active" }
- if resource.activated?
a.Button.Button--large.Button--disabled.Button--red
= t("mass_uploads.labels.all_articles_activated")
- else
Expand Down
4 changes: 4 additions & 0 deletions app/views/mass_uploads/_table.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
| Abgeschlossen
- elsif mass_upload.failed?
= mass_upload.failure_reason
- elsif mass_upload.activated?
= t("mass_uploads.labels.all_articles_activated")
td
- if mass_upload.finished?
= link_to t("mass_uploads.labels.show_report_activate"), mass_upload_path(mass_upload), class: 'Button'
- elsif mass_upload.activated?
= link_to t("mass_uploads.labels.show_report"), mass_upload_path(mass_upload), class: 'Button'
2 changes: 2 additions & 0 deletions test/controllers/mass_uploads_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
describe 'PUT ::update' do
it "should update description" do
post :create, mass_upload: attributes
mass_upload = MassUpload.last
mass_upload.finish!
post :update, :id => MassUpload.last.id
assert_redirected_to user_path(user)
MassUpload.last.articles.first.active?.must_equal true
Expand Down

0 comments on commit 579f282

Please sign in to comment.