about summary refs log tree commit diff
path: root/app/controllers/admin
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2020-01-27 15:46:50 +0100
committerThibaut Girka <thib@sitedethib.com>2020-01-27 15:46:50 +0100
commitc56a504d116d62fe669d15a270133d7c78dd61f1 (patch)
tree7400f3182f2a4ebd1606c37a1a5cad4cc95e443b /app/controllers/admin
parent8924743349ec5ce37cd949445e071c14968ec2ec (diff)
parentc2dfd5e4e24a70fbfa02678fde4cfc6f6750deb4 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- `app/serializers/rest/account_serializer.rb`:
  Upstream added code too close to glitch-soc-specific followers-hiding code.
  Ported upstream changes.
Diffstat (limited to 'app/controllers/admin')
-rw-r--r--app/controllers/admin/announcements_controller.rb25
1 files changed, 22 insertions, 3 deletions
diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb
index 02198f0b5..494fd13d0 100644
--- a/app/controllers/admin/announcements_controller.rb
+++ b/app/controllers/admin/announcements_controller.rb
@@ -20,8 +20,9 @@ class Admin::AnnouncementsController < Admin::BaseController
     @announcement = Announcement.new(resource_params)
 
     if @announcement.save
+      PublishScheduledAnnouncementWorker.perform_async(@announcement.id) if @announcement.published?
       log_action :create, @announcement
-      redirect_to admin_announcements_path
+      redirect_to admin_announcements_path, notice: @announcement.published? ? I18n.t('admin.announcements.published_msg') : I18n.t('admin.announcements.scheduled_msg')
     else
       render :new
     end
@@ -35,18 +36,36 @@ class Admin::AnnouncementsController < Admin::BaseController
     authorize :announcement, :update?
 
     if @announcement.update(resource_params)
+      PublishScheduledAnnouncementWorker.perform_async(@announcement.id) if @announcement.published?
       log_action :update, @announcement
-      redirect_to admin_announcements_path
+      redirect_to admin_announcements_path, notice: I18n.t('admin.announcements.updated_msg')
     else
       render :edit
     end
   end
 
+  def publish
+    authorize :announcement, :update?
+    @announcement.publish!
+    PublishScheduledAnnouncementWorker.perform_async(@announcement.id)
+    log_action :update, @announcement
+    redirect_to admin_announcements_path, notice: I18n.t('admin.announcements.published_msg')
+  end
+
+  def unpublish
+    authorize :announcement, :update?
+    @announcement.unpublish!
+    UnpublishAnnouncementWorker.perform_async(@announcement.id)
+    log_action :update, @announcement
+    redirect_to admin_announcements_path, notice: I18n.t('admin.announcements.unpublished_msg')
+  end
+
   def destroy
     authorize :announcement, :destroy?
     @announcement.destroy!
+    UnpublishAnnouncementWorker.perform_async(@announcement.id) if @announcement.published?
     log_action :destroy, @announcement
-    redirect_to admin_announcements_path
+    redirect_to admin_announcements_path, notice: I18n.t('admin.announcements.destroyed_msg')
   end
 
   private