about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-01-27 11:05:33 +0100
committerGitHub <noreply@github.com>2020-01-27 11:05:33 +0100
commit663ea84b08162578cd06b54bfb998072b2bef8b9 (patch)
treeadb4e2701655dd2d62140f101ebb1815e399d1ff /app/models
parent4363d06986bb2df1bb15db54df41ddf1d9682afb (diff)
Add publish/unpublish controls to announcements in admin UI (#12967)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/announcement.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/announcement.rb b/app/models/announcement.rb
index 670b24f01..d99502f44 100644
--- a/app/models/announcement.rb
+++ b/app/models/announcement.rb
@@ -32,6 +32,14 @@ class Announcement < ApplicationRecord
   before_validation :set_all_day
   before_validation :set_published, on: :create
 
+  def publish!
+    update!(published: true, published_at: Time.now.utc, scheduled_at: nil)
+  end
+
+  def unpublish!
+    update!(published: false, scheduled_at: nil)
+  end
+
   def time_range?
     starts_at.present? && ends_at.present?
   end