Edit:
I think I figured it out (thanks to this hint). This seems to work, but there might be a more elegant way (I donāt know how to define and hand over an array)
# levels: :watching :watching_first_post
level = :watching
category_slug = "local-news"
parent_category_slug = "news" # <== added
category = Category.find_by_slug(category_slug, parent_category_slug)
group_name = "trust_level_0" # all users
group = group = Group.find_by_name(group_name)
group.users.each do |user|
watched_categories = CategoryUser.lookup(user, level).pluck(:category_id)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[level],
category.id) unless watched_categories.include?(category.id)
end
If I can save the time I have spent with this thread to someone in the futureā¦
If you want to reset the notification level of a subcategory for all users from e.g. āmutedā to āregularā (being regular a special case), this is what you need to do:
./launcher enter app rails c
And then paste your version of
level = :muted
category_slug = "cats" # this is the subcategory
parent_category_slug = "mammals" # this is the parent category
CategoryUser.where(category_id: Category.find_by_slug(category_slug, parent_category_slug), notification_level: CategoryUser.notification_levels[level]).delete_all
Can this be modified to work in group PM inboxes? For example, I was on an extended vacation, and Iām now returning. I updated my notification state for a shared inbox to ātrackingā so I didnāt have thousands of green notifications, and now I want to update the state for all messages back to āwatchingā.
Courtesy of @sam, hereās the code to update the notification level for PMs historically. The following placeholders must be replaced: <user_id>, <group_id_1> ,<group_id_2>.
TopicUser.where('notification_level < 3 and user_id = <user_id> and topic_id in (select topic_id from topic_allowed_groups where group_id in (<group_id_1>,<group_id_2>) )').update_all(notification_level: 3)
Assuming that this still works, Iām wondering whether category permissions will be honoured here.
I have a number of restricted categories and whoever has access to any of those should be watching first post by default. So if I follow the above steps for each of those categories, will only only users who actually hsve access be watching them?
Okay, just to double check: am I right in assuming that I can use the above procedure to add the category in question to all users but if a user doesnāt have access to that category it will remain ineffective and invisible for that user until the user gains access?
How can this be made to work with a two-container setup? If I enter data there is no rails. And if I enter web_only I get NoMethodError: undefined method `id' for nil:NilClass.
Yesterday I discovered where our email volume of 100K+/mo was coming fromā¦ All new users were getting set as subscribed to our āGeneral kartingā categoryā¦
So I need to correct thatā¦
I need some help with the syntax of part 1 in the OP. Bare with me hereā¦ Iām not exactly sure what Iām doing wrongā¦
I tried both " and ā for quotations, but otherwise, Iām not sure what I need to correct in my syntax