Sha256: c451b90fc093cddf54bb795fd68b313d87a3a1a9a8d8321bcba574394a43d83d

Contents?: true

Size: 1.77 KB

Versions: 18

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require File.expand_path('../../lib/discourse_api', __FILE__)

config = DiscourseApi::ExampleHelper.load_yml

client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
client.api_key = config['api_key'] || "YOUR_API_KEY"
client.api_username = config['api_username'] || "YOUR_USERNAME"

@target_username = "YOUR_TARGET_USERNAME"
@target_group_id =   # YOUR NUMERIC TARGET GROUP ID

@user = client.user(@target_username)

# each user's group and the group's default notification level are stored under user['groups']
@user['groups'].each do |group|
  if group['id'] == @target_group_id
    @group_name = group['name']
    @default_level = group['default_notification_level']
  end
end

# and the user's notification setting for each group is stored under user['group_users]
@user['group_users'].each do |users_group|
  if users_group['group_id'] == @target_group_id
    @notification_level = users_group['notification_level']
    puts "Group ID:#{@target_group_id} #{@group_name}    Current Notification Level: #{@notification_level}    Default: #{@default_level}"
    response = client.group_set_user_notification_level(@group_name, @user['id'], @default_level)
    puts response
    @users_group_users_after_update = client.user(@target_username)['group_users']
    # this just pulls the user from the database again to make sure we updated the user's group notification level
    @users_group_users_after_update.each do |users_group_second_pass|
      if users_group_second_pass['group_id'] == @target_group_id
        puts "Updated ID:#{@target_group_id} #{@group_name}    Notification Level: #{users_group_second_pass['notification_level']}    Default: #{@default_level}"
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
discourse_api-1.1.0 examples/group_set_user_notification_level.rb
discourse_api-1.0.0 examples/group_set_user_notification_level.rb
discourse_api-0.48.1 examples/group_set_user_notification_level.rb
discourse_api-0.48.0 examples/group_set_user_notification_level.rb
discourse_api-0.47.0 examples/group_set_user_notification_level.rb
discourse_api-0.46.0 examples/group_set_user_notification_level.rb
discourse_api-0.45.1 examples/group_set_user_notification_level.rb
discourse_api-0.45.0 examples/group_set_user_notification_level.rb
discourse_api-0.44.0 examples/group_set_user_notification_level.rb
discourse_api-0.43.1 examples/group_set_user_notification_level.rb
discourse_api-0.43.0 examples/group_set_user_notification_level.rb
discourse_api-0.42.0 examples/group_set_user_notification_level.rb
discourse_api-0.41.0 examples/group_set_user_notification_level.rb
discourse_api-0.40.0 examples/group_set_user_notification_level.rb
discourse_api-0.39.3 examples/group_set_user_notification_level.rb
discourse_api-0.39.2 examples/group_set_user_notification_level.rb
discourse_api-0.39.1 examples/group_set_user_notification_level.rb
discourse_api-0.39.0 examples/group_set_user_notification_level.rb