FIX: mute new categories for all users, and add rake task to mute old categories
This commit is contained in:
Родитель
575369c2fc
Коммит
1d15d63e6d
2
api.yml
2
api.yml
|
@ -1,7 +1,7 @@
|
|||
openapi: 3.0.0
|
||||
info:
|
||||
title: Discourse Mozilla GCM API
|
||||
version: 0.1.3
|
||||
version: 0.1.4
|
||||
description: |-
|
||||
API to create/manage namespaced groups and categories on a Discourse instance.
|
||||
|
||||
|
|
|
@ -16,6 +16,13 @@ module MozillaGCM
|
|||
|
||||
category.save!
|
||||
|
||||
# shamelessly adapted from https://github.com/discourse/discourse/blob/4e4844f4dbcbab50502f9feb973dbd13c6a75246/app/controllers/admin/site_settings_controller.rb#L54-L71
|
||||
User.select(:id).find_in_batches do |users|
|
||||
category_users = []
|
||||
users.each { |user| category_users << { category_id: category.id, user_id: user.id, notification_level: NotificationLevels.all[:muted] } }
|
||||
CategoryUser.insert_all!(category_users)
|
||||
end
|
||||
|
||||
DistributedMutex.synchronize("mozilla_gcm_default_categories_muted") do
|
||||
SiteSetting.default_categories_muted = [SiteSetting.default_categories_muted, category.id].reject(&:blank?).join("|")
|
||||
end
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# shamelessly adapted from https://github.com/discourse/discourse/blob/4e4844f4dbcbab50502f9feb973dbd13c6a75246/app/controllers/admin/site_settings_controller.rb#L54-L71
|
||||
task "mozilla_gcm:mute_all_externally_managed_categories" => :environment do
|
||||
notification_level = NotificationLevels.all[:muted]
|
||||
categories = MozillaGCM::Client.all.pluck(:category_id).map {|x| Category.find(x).subcategories.pluck(:id) }.flatten
|
||||
|
||||
CategoryUser.where(category_id: categories, notification_level: notification_level).delete_all
|
||||
|
||||
categories.each do |category_id|
|
||||
skip_user_ids = CategoryUser.where(category_id: category_id).pluck(:user_id)
|
||||
|
||||
User.where.not(id: skip_user_ids).select(:id).find_in_batches do |users|
|
||||
category_users = []
|
||||
users.each { |user| category_users << { category_id: category_id, user_id: user.id, notification_level: notification_level } }
|
||||
CategoryUser.insert_all!(category_users)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# name: mozilla-gcm
|
||||
# about: API to create/manage namespaced groups and categories on a Discourse instance
|
||||
# version: 0.1.3
|
||||
# version: 0.1.4
|
||||
# authors: Leo McArdle
|
||||
# url: https://github.com/mozilla/discourse-mozilla-gcm
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ describe MozillaGCM::CategoriesController do
|
|||
include_examples "insert_groups_if_allowed"
|
||||
|
||||
it "succeeds" do
|
||||
normal_user = Fabricate(:user)
|
||||
c1 = Fabricate(:category).id
|
||||
c2 = Fabricate(:category).id
|
||||
SiteSetting.default_categories_muted = "#{c1}|#{c2}"
|
||||
|
@ -63,6 +64,7 @@ describe MozillaGCM::CategoriesController do
|
|||
check_user_subscribed(user1, category)
|
||||
check_user_subscribed(user2, category)
|
||||
expect(SiteSetting.default_categories_muted.split("|")).to match_array([c1.to_s, c2.to_s, category.id.to_s])
|
||||
check_user_subscribed(normal_user, category, :muted)
|
||||
end
|
||||
|
||||
context "with no name" do
|
||||
|
|
Загрузка…
Ссылка в новой задаче